import { ServicePriceCategorySchema } from "../../../client";
import BaseFormModal, {
    CreateEditFormProps,
} from "../../ClientsPage/modals/BaseFormModal/BaseFormModal.tsx";
import { ContextModalProps } from "@mantine/modals";
import { TextInput } from "@mantine/core";
import { useForm } from "@mantine/form";

type Props = CreateEditFormProps<ServicePriceCategorySchema>;

const ServicePriceCategoryForm = ({
    context,
    id,
    innerProps,
}: ContextModalProps<Props>) => {
    const isEditing = "element" in innerProps;
    const initialValues: Partial<ServicePriceCategorySchema> = isEditing
        ? innerProps.element
        : {
              name: "",
          };
    const form = useForm<Partial<ServicePriceCategorySchema>>({
        initialValues,
    });
    return (
        <BaseFormModal
            {...innerProps}
            form={form}
            closeOnSubmit
            onClose={() => context.closeContextModal(id)}>
            <BaseFormModal.Body>
                <>
                    <TextInput
                        label={"Название"}
                        placeholder={"Введите название категории"}
                        {...form.getInputProps("name")}
                    />
                </>
            </BaseFormModal.Body>
        </BaseFormModal>
    );
};

export default ServicePriceCategoryForm;
