import { modals } from "@mantine/modals";
import { useClientsContext } from "@/app/clients/contexts/ClientsContext";
import { ClientSchema } from "@/lib/client";

const useClientsActions = () => {
    const { clientsCrud } = useClientsContext();

    const onCreateClick = () => {
        modals.openContextModal({
            modal: "clientEditorModal",
            title: "Создание клиента",
            innerProps: {
                onCreate: clientsCrud.onCreate,
                isEditing: false,
            },
        });
    };

    const onUpdateClick = (client: ClientSchema) => {
        modals.openContextModal({
            modal: "clientEditorModal",
            title: "Редактирование клиента",
            innerProps: {
                onChange: updates => clientsCrud.onUpdate(client.id, updates),
                entity: client,
                isEditing: true,
            },
        });
    };

    return {
        onCreateClick,
        onUpdateClick,
    };
};

export default useClientsActions;
