import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { AssetParkingApi } from '#/api/asset/parking';

import { $t } from '@vben/locales';
import { useActionColumn } from '#/utils/table';

import { z } from '#/adapter/form';
import { getRangePickerDefaultProps } from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'id',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'name',
      label: '停车场名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入停车场名称',
      },
      rules: z.string().min(1, { message: '请输入停车场名称' }),
    },
    {
      fieldName: 'capacity',
      label: '容量',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入容量',
        min: 1,
        style: { width: '100%' },
      },
      rules: z.number().min(1, { message: '容量必须大于等于1' }),
    },
    {
      fieldName: 'province',
      label: '省份',
      component: 'Input',
      componentProps: {
        placeholder: '请输入省份',
      },
      rules: z.string().min(1, { message: '请输入省份' }),
    },
    {
      fieldName: 'city',
      label: '城市',
      component: 'Input',
      componentProps: {
        placeholder: '请输入城市',
      },
      rules: z.string().min(1, { message: '请输入城市' }),
    },
    {
      fieldName: 'address',
      label: '地址',
      component: 'Input',
      componentProps: {
        placeholder: '请输入详细地址',
      },
      rules: z.string().min(1, { message: '请输入详细地址' }),
    },
    {
      fieldName: 'managerName',
      label: '负责人',
      component: 'Input',
      componentProps: {
        placeholder: '请输入负责人姓名',
      },
      rules: z.string().min(1, { message: '请输入负责人姓名' }),
    },
    {
      fieldName: 'managerPhone',
      label: '负责人联系方式',
      component: 'Input',
      componentProps: {
        placeholder: '请输入负责人联系方式',
      },
      rules: z.string().min(1, { message: '请输入负责人联系方式' }),
    },
    {
      fieldName: 'contactName',
      label: '停车场联系人',
      component: 'Input',
      componentProps: {
        placeholder: '请输入停车场联系人',
      },
    },
    {
      fieldName: 'contactPhone',
      label: '停车场联系方式',
      component: 'Input',
      componentProps: {
        placeholder: '请输入停车场联系方式',
      },
    },
    {
      fieldName: 'leaseStartDate',
      label: '租赁开始时间',
      component: 'DatePicker',
      componentProps: {
        placeholder: '请选择租赁开始时间',
        format: 'YYYY-MM-DD',
        valueFormat: 'YYYY-MM-DD',
      },
    },
    {
      fieldName: 'leaseEndDate',
      label: '租赁结束时间',
      component: 'DatePicker',
      componentProps: {
        placeholder: '请选择租赁结束时间',
        format: 'YYYY-MM-DD',
        valueFormat: 'YYYY-MM-DD',
      },
    },
    {
      fieldName: 'rentFee',
      label: '租金费用（元/月）',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入租金费用',
        min: 0,
        precision: 2,
        style: { width: '100%' },
      },
    },
    {
      fieldName: 'longitude',
      label: '经度',
      component: 'Input',
      componentProps: {
        placeholder: '请输入经度',
      },
    },
    {
      fieldName: 'latitude',
      label: '纬度',
      component: 'Input',
      componentProps: {
        placeholder: '请输入纬度',
      },
    },
  ];
}

/** 搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'name',
      label: '停车场名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入停车场名称',
      },
    },
    {
      fieldName: 'province',
      label: '省份',
      component: 'Input',
      componentProps: {
        placeholder: '请输入省份',
      },
    },
    {
      fieldName: 'city',
      label: '城市',
      component: 'Input',
      componentProps: {
        placeholder: '请输入城市',
      },
    },
    {
      fieldName: 'managerName',
      label: '负责人',
      component: 'Input',
      componentProps: {
        placeholder: '请输入负责人',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: getRangePickerDefaultProps(),
    },
  ];
}

/** 表格列配置 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    { type: 'checkbox', width: 60, fixed: 'left' },
    {
      field: 'name',
      title: '停车场名称',
      minWidth: 150,
      fixed: 'left',
    },
    {
      field: 'capacity',
      title: '容量',
      minWidth: 80,
      align: 'center',
    },
    {
      field: 'parkedAmount',
      title: '已停车辆数',
      minWidth: 100,
      align: 'center',
    },
    {
      field: 'province',
      title: '省份',
      minWidth: 100,
    },
    {
      field: 'city',
      title: '城市',
      minWidth: 100,
    },
    {
      field: 'address',
      title: '地址',
      minWidth: 200,
    },
    {
      field: 'managerName',
      title: '负责人',
      minWidth: 100,
    },
    {
      field: 'managerPhone',
      title: '负责人联系方式',
      minWidth: 120,
    },
    {
      field: 'contactName',
      title: '停车场联系人',
      minWidth: 120,
    },
    {
      field: 'contactPhone',
      title: '停车场联系方式',
      minWidth: 120,
    },
    {
      field: 'leaseStartDate',
      title: '租赁开始时间',
      minWidth: 120,
      formatter: 'formatDate',
    },
    {
      field: 'leaseEndDate',
      title: '租赁结束时间',
      minWidth: 120,
      formatter: 'formatDate',
    },
    {
      field: 'rentFee',
      title: '租金费用（元/月）',
      minWidth: 120,
      align: 'right',
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    useActionColumn(3),
  ];
}
