"use client"

import { CrudDialog } from "@/shared/components/crud-dialog"
import { ColumnHeader } from "@/shared/data-view/table-view"
import { useAuthApi } from "@/shared/useApi"
import { PAYMENT_TERM_ROUTES } from "@garage/api"
import { PaymentTermForm } from "./payment-term-form"

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

    return (
        <CrudDialog
            title="Payment Terms"
            queryKey={[PAYMENT_TERM_ROUTES.INDEX]}
            getClient={() => api.paymentTerms}
            resourceLabel="payment term"
            columns={() => [
                {
                    accessorKey: "title",
                    header: ({ column }) => <ColumnHeader column={column} title="Name" />,
                },
            ]}
            renderForm={({ resourceId, initialData, onSuccess }) => (
                <PaymentTermForm
                    resourceId={resourceId}
                    initialData={initialData}
                    onSuccess={onSuccess}
                />
            )}
        />
    )
}
