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 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" }, ]; 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 handleGridSizeChange(event, dimension) { const value = parseInt(event.target.value); onSettingsChange("grid", { ...map.grid, size: { ...map.grid.size, [dimension]: value, }, }); } 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 ( handleGridSizeChange(e, "x")} disabled={mapEmpty || map.type === "default"} min={1} my={1} /> handleGridSizeChange(e, "y")} disabled={mapEmpty || map.type === "default"} min={1} my={1} /> 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;