"use client"

import { ResourcePage } from "@/shared/data-view/resource-page"
import { ColumnHeader } from "@/shared/data-view/table-view"
import FormDialog from "@/shared/components/form-dialog"
import { TaskForm } from "@/modules/tasks/task-form"
import { TASK_ROUTES } from "@garage/api"
import type { TasksClient } from "@garage/api"

export default function TasksPage() {
    return (
        <ResourcePage<TasksClient>
            routeKey={TASK_ROUTES.INDEX}
            getClient={(api) => api.tasks}
            headerProps={({ selectedItem, invalidateQuery }) => ({
                title: "Tasks",
                actions: (
                    <FormDialog title="Task">
                        {(resourceId) => (
                            <TaskForm
                                resourceId={resourceId}
                                initialData={selectedItem}
                                onSuccess={invalidateQuery}
                            />
                        )}
                    </FormDialog>
                ),
            })}
            columns={({ actionsColumn }) => [
                {
                    accessorKey: "task_number",
                    header: ({ column }) => <ColumnHeader column={column} title="Task #" />,
                },
                {
                    accessorKey: "subject",
                    header: ({ column }) => <ColumnHeader column={column} title="Subject" />,
                },
                {
                    accessorKey: "priority",
                    header: ({ column }) => <ColumnHeader column={column} title="Priority" />,
            
                },
                {
                    accessorKey: "status",
                    header: ({ column }) => <ColumnHeader column={column} title="Status" />,
               
                },
                {
                    accessorKey: "due_date",
                    header: ({ column }) => <ColumnHeader column={column} title="Due Date" />,
                
                },
                actionsColumn(),
            ]}
        />
    )
}
