import React from "react"; import { Flex, Box, Label, Input, Checkbox, IconButton } from "theme-ui"; import ExpandMoreIcon from "../../icons/ExpandMoreIcon"; import { isEmpty } from "../../helpers/shared"; import { getGridUpdatedInset } from "../../helpers/grid"; import Divider from "../Divider"; import Select from "../Select"; const qualitySettings = [ { value: "low", label: "Low" }, { value: "medium", label: "Medium" }, { value: "high", label: "High" }, { value: "ultra", label: "Ultra High" }, { value: "original", label: "Original" }, ]; const gridTypeSettings = [ { value: "square", label: "Square" }, { value: "hexVertical", label: "Hex Vertical" }, { value: "hexHorizontal", label: "Hex Horizontal" }, ]; function MapSettings({ map, mapState, onSettingsChange, onStateSettingsChange, showMore, onShowMoreChange, }) { function handleFlagChange(event, flag) { if (event.target.checked) { onStateSettingsChange("editFlags", [...mapState.editFlags, flag]); } else { onStateSettingsChange( "editFlags", mapState.editFlags.filter((f) => f !== flag) ); } } function handleGridSizeXChange(event) { const value = parseInt(event.target.value) || 0; let grid = { ...map.grid, size: { ...map.grid.size, x: value, }, }; grid.inset = getGridUpdatedInset(grid, map.width, map.height); onSettingsChange("grid", grid); } function handleGridSizeYChange(event) { const value = parseInt(event.target.value) || 0; let grid = { ...map.grid, size: { ...map.grid.size, y: value, }, }; grid.inset = getGridUpdatedInset(grid, map.width, map.height); onSettingsChange("grid", grid); } function handleGridTypeChange(option) { let grid = { ...map.grid, type: option.value }; grid.inset = getGridUpdatedInset(grid, map.width, map.height); onSettingsChange("grid", grid); } function getMapSize() { let size = 0; if (map.quality === "original") { size = map.file.length; } else { size = map.resolutions[map.quality].file.length; } size /= 1000000; // Bytes to Megabytes return `${size.toFixed(2)}MB`; } const mapEmpty = !map || isEmpty(map); const mapStateEmpty = !mapState || isEmpty(mapState); return ( onSettingsChange("name", e.target.value)} disabled={mapEmpty || map.type === "default"} my={1} /> {showMore && ( <> s.value === map.quality) } isDisabled={mapEmpty} onChange={(option) => onSettingsChange("quality", option.value) } isOptionDisabled={(option) => mapEmpty || (option.value !== "original" && !map.resolutions[option.value]) } isSearchable={false} /> )} )} { e.stopPropagation(); e.preventDefault(); onShowMoreChange(!showMore); }} sx={{ transform: `rotate(${showMore ? "180deg" : "0"})`, alignSelf: "center", }} aria-label={showMore ? "Show Less" : "Show More"} title={showMore ? "Show Less" : "Show More"} > ); } export default MapSettings;