"use client";

import { createDeliveryListPage } from "@/modules/delivery/components/DeliveryListCrudPage";
import { deliveryApi } from "@/modules/delivery/services/delivery-api";

export const DriversPage = createDeliveryListPage({
  title: "رانندگان",
  breadcrumb: "رانندگان",
  resourceKey: "drivers",
  permission: "delivery.drivers.view",
  api: {
    list: async (tenantId, params) => {
      const res = await deliveryApi.drivers.list(tenantId, params);
      return Array.isArray(res) ? res : res.items;
    },
    get: deliveryApi.drivers.get,
    create: deliveryApi.drivers.create,
    update: deliveryApi.drivers.update,
    remove: deliveryApi.drivers.remove,
  },
  columns: [
    { key: "code", header: "کد", type: "link", linkPrefix: "/delivery/drivers" },
    { key: "display_name", header: "نام" },
    { key: "mobile", header: "موبایل" },
    { key: "status", header: "وضعیت", type: "status" },
    { key: "created_at", header: "ایجاد", type: "datetime" },
  ],
  createFields: [
    { name: "organization_id", label: "سازمان", type: "organization", required: true },
    { name: "hub_id", label: "هاب", type: "hub" },
    { name: "code", label: "کد", required: true },
    { name: "display_name", label: "نام نمایشی", required: true },
    { name: "mobile", label: "موبایل" },
    { name: "email", label: "ایمیل", type: "email" },
  ],
  detailHref: (row) => row.id ? `/delivery/drivers/${row.id}` : null,
});

export default DriversPage;
