import { FormGroup } from '@admin/components/ui/forms/form-group';
import { FormNumberInput } from '@admin/components/ui/forms/form-number-input';
import { FormSwitch } from '@admin/components/ui/forms/form-switch';

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

export function PricingUnitFormFields({ data, errors, setData }: PricingUnitFormFieldsProps) {
    return (
        <>
            <FormGroup
                label="Name"
                helpText="Label shown when selecting a unit, e.g. Per month, Per project."
                error={errors.name}
                inputProps={{
                    value: data.name,
                    onChange: (event) => setData('name', event.target.value),
                    required: true,
                }}
            />

            <FormGroup
                label="Suffix"
                helpText="Optional text shown after the price on the site, e.g. /month or /project. Leave empty for no suffix."
                error={errors.suffix}
                inputProps={{
                    value: data.suffix,
                    onChange: (event) => setData('suffix', event.target.value),
                    placeholder: '/month',
                }}
            />

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

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