import { useState } from 'react'
import { EditIcon } from 'shared/components/icons.mjs'
import { useTranslation } from 'next-i18next'
import { formatMm, round } from 'shared/utils.mjs'
import { ChoiceButton } from 'shared/components/choice-button.mjs'
const EditCount = (props) => (
)
export const CountOptionInput = ({ name, design, config, current, update, t, override }) => {
const { count, max, min } = config
if (typeof current === 'undefined') current = count
const [value, setValue] = useState(current)
const handleChange = (evt) => {
const newCurrent = evt.target.value
setValue(newCurrent)
update.settings(['options', name], newCurrent)
}
const reset = () => {
setValue(count)
update.settings(['options', name])
}
return (
<>
{t(`${design}:o.${name}.d`)}
{override ? (
) : (
<>
{min}
{current}
{max}
>
)}
>
)
}
export const ListOptionInput = ({ design, name, config, current, update, t }) => {
const { dflt, list, doNotTranslate = false } = config
if (typeof current === 'undefined') current = dflt
const [value, setValue] = useState(current)
const handleChange = (newCurrent) => {
if (newCurrent === dflt) reset()
else {
setValue(newCurrent)
update.settings(['options', name], newCurrent)
}
}
const reset = () => {
setValue(dflt)
update.settings(['options', name])
}
return (
<>
{t(`${design}:o.${name}.d`)}
{config.list.map((entry) => (
handleChange(entry)}
>
{t(`core-settings:${config.choiceTitles[entry]}.d`)}
))}
>
)
}
export const BoolOptionInput = ListOptionInput
const EditOption = (props) => (
)
export const PctOptionInput = ({
name,
design,
config,
settings,
current,
update,
t,
type = 'pct',
override,
}) => {
const suffix = type === 'deg' ? '°' : '%'
const factor = type === 'deg' ? 1 : 100
const { max, min } = config
const dflt = config[type]
if (typeof current === 'undefined') current = dflt
else current = current * factor
const [value, setValue] = useState(current)
const handleChange = (evt) => {
const newCurrent = evt.target.value
setValue(newCurrent)
update.settings(['options', name], newCurrent / factor)
}
const reset = () => {
setValue(dflt)
update.settings(['options', name])
}
return (
<>
{t(`${design}:${name}.d`)}
{override ? (
) : (
<>
{round(min)}
{suffix}
{round(current)}
{suffix}
{round(max)}
{suffix}
>
)}
{config.toAbs && settings.measurements
? formatMm(config.toAbs(value / 100, settings))
: ' '}
>
)
}
export const DegOptionInput = (props) =>
export const MmOptionInput = () => (
FIXME: Mm options are deprecated. Please report this
)
export const ConstantOptionInput = () => FIXME: Constant options are not implemented (yet)