"use client"

import { CrudDialog } from "@/shared/components/crud-dialog"
import { ColumnHeader } from "@/shared/data-view/table-view"
import { useAuthApi } from "@/shared/useApi"
import { INSURANCE_TYPE_ROUTES } from "@garage/api"
import { InsuranceTypeForm } from "./insurance-type-form"

export function InsuranceTypeCrudDialog() {
    const api = useAuthApi()

    return (
        <CrudDialog
            title="Insurance Type"
            queryKey={[INSURANCE_TYPE_ROUTES.INDEX]}
            getClient={() => api.insuranceTypes}
            resourceLabel="insurance type"
            columns={() => [
                {
                    accessorKey: "title",
                    header: ({ column }) => <ColumnHeader column={column} title="Name" />,
                },
                {
                    accessorKey: "description",
                    header: ({ column }) => <ColumnHeader column={column} title="Description" />,
                },
            ]}
            renderForm={({ resourceId, initialData, onSuccess }) => (
                <InsuranceTypeForm
                    resourceId={resourceId}
                    initialData={initialData}
                    onSuccess={onSuccess}
                />
            )}
        />
    )
}
