import { FormGroup } from '@admin/components/ui/forms/form-group';
import { FormNumberInput } from '@admin/components/ui/forms/form-number-input';
import { FormSelect } from '@admin/components/ui/forms/form-select';
import { FormSwitch } from '@admin/components/ui/forms/form-switch';
import { statisticCounterSymbolOptions } from '@admin/lib/statistic-counter-symbols';

type StatisticCounterFormFieldsProps = {
    data: {
        name: string;
        count: number;
        symbol: string;
        sort_order: number;
        status: boolean;
    };
    errors: Partial<Record<'name' | 'count' | 'symbol' | 'sort_order' | 'status', string>>;
    setData: (key: string, value: unknown) => void;
};

export function StatisticCounterFormFields({ data, errors, setData }: StatisticCounterFormFieldsProps) {
    return (
        <>
            <FormGroup
                label="Name"
                helpText="Label shown below the counter, e.g. Projects Completed."
                error={errors.name}
                inputProps={{
                    value: data.name,
                    onChange: (event) => setData('name', event.target.value),
                    required: true,
                }}
            />

            <FormNumberInput
                label="Count"
                min={0}
                value={data.count}
                error={errors.count}
                required
                onChange={(value) => setData('count', value)}
            />

            <FormSelect
                label="Symbol"
                value={data.symbol}
                options={statisticCounterSymbolOptions}
                placeholder="No symbol"
                helpText="Optional suffix displayed after the count."
                error={errors.symbol}
                onChange={(value) => setData('symbol', value)}
            />

            <FormNumberInput
                label="Display order"
                helpText="Lower numbers appear first on the site."
                min={0}
                value={data.sort_order}
                error={errors.sort_order}
                required
                onChange={(value) => setData('sort_order', value)}
            />

            <FormSwitch
                id="statistic-counter-status"
                label="Published"
                checked={data.status}
                onChange={(event) => setData('status', event.target.checked)}
            />
        </>
    );
}
