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

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

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

/** 新增/修改的表单 - 基本信息 */
export function useBasicFormSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'id',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'supplierCode',
      label: '供应商编码',
      component: 'Input',
      componentProps: {
        placeholder: '请输入供应商编码',
      },
      rules: z.string().min(1, { message: '请输入供应商编码' }),
    },
    {
      fieldName: 'coopStatus',
      label: '合作状态',
      component: 'Select',
      componentProps: {
        placeholder: '请选择合作状态',
        options: [
          { label: '已合作', value: '已合作' },
          { label: '终止合作', value: '终止合作' },
          { label: '洽谈中', value: '洽谈中' },
          { label: '合约过期', value: '合约过期' },
        ],
      },
      rules: z.string().min(1, { message: '请选择合作状态' }),
    },
    {
      fieldName: 'supplierName',
      label: '供应商名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入供应商名称',
      },
      rules: z.string().min(1, { message: '请输入供应商名称' }),
    },
    {
      fieldName: 'type',
      label: '供应商类型',
      component: 'Select',
      componentProps: {
        placeholder: '请选择供应商类型',
        options: [
          { label: '备件供应商', value: '备件供应商' },
          { label: '保险公司', value: '保险公司' },
          { label: '加氢站', value: '加氢站' },
          { label: '充电站', value: '充电站' },
          { label: '维修站', value: '维修站' },
          { label: '救援车队', value: '救援车队' },
          { label: '整车厂', value: '整车厂' },
          { label: '其他', value: '其他' },
        ],
      },
      rules: z.string().min(1, { message: '请选择供应商类型' }),
    },
    {
      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: 'region',
      label: '区域',
      component: 'Select',
      componentProps: {
        placeholder: '请选择区域',
        options: [
          { label: '华北', value: '华北' },
          { label: '华东', value: '华东' },
          { label: '华南', value: '华南' },
          { label: '华中', value: '华中' },
          { label: '东北', value: '东北' },
          { label: '西南', value: '西南' },
          { label: '西北', value: '西北' },
        ],
      },
    },
    {
      fieldName: 'contact',
      label: '联系人',
      component: 'Input',
      componentProps: {
        placeholder: '请输入联系人',
      },
    },
    {
      fieldName: 'contactMobile',
      label: '联系手机',
      component: 'Input',
      componentProps: {
        placeholder: '请输入联系手机',
      },
    },
    {
      fieldName: 'contactPhone',
      label: '联系电话',
      component: 'Input',
      componentProps: {
        placeholder: '请输入联系电话',
      },
    },
    {
      fieldName: 'email',
      label: '邮箱',
      component: 'Input',
      componentProps: {
        placeholder: '请输入邮箱',
      },
    },
    {
      fieldName: 'creditCodeOrId',
      label: '统一社会信用代码/身份证',
      component: 'Input',
      componentProps: {
        placeholder: '请输入统一社会信用代码或身份证号',
      },
    },
    {
      fieldName: 'remark',
      label: '备注',
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入备注',
        rows: 3,
      },
    },
  ];
}

/** 新增/修改的表单 - 开票信息 */
export function useInvoiceFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'taxId',
      label: '税号',
      component: 'Input',
      componentProps: {
        placeholder: '请输入税号',
      },
    },
    {
      fieldName: 'invoiceAddress',
      label: '开票地址',
      component: 'Input',
      componentProps: {
        placeholder: '请输入开票地址',
      },
    },
    {
      fieldName: 'invoicePhone',
      label: '开票电话',
      component: 'Input',
      componentProps: {
        placeholder: '请输入开票电话',
      },
    },
    {
      fieldName: 'account',
      label: '银行账号',
      component: 'Input',
      componentProps: {
        placeholder: '请输入银行账号',
      },
    },
    {
      fieldName: 'openingBank',
      label: '开户行',
      component: 'Input',
      componentProps: {
        placeholder: '请输入开户行',
      },
    },
    {
      fieldName: 'mailingAddress',
      label: '邮寄地址',
      component: 'Input',
      componentProps: {
        placeholder: '请输入邮寄地址',
      },
    },
  ];
}

/** 搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'supplierCode',
      label: '供应商编码',
      component: 'Input',
      componentProps: {
        placeholder: '请输入供应商编码',
      },
    },
    {
      fieldName: 'supplierName',
      label: '供应商名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入供应商名称',
      },
    },
    {
      fieldName: 'type',
      label: '供应商类型',
      component: 'Select',
      componentProps: {
        placeholder: '请选择供应商类型',
        mode: 'multiple',
        options: [
          { label: '备件供应商', value: '备件供应商' },
          { label: '保险公司', value: '保险公司' },
          { label: '加氢站', value: '加氢站' },
          { label: '充电站', value: '充电站' },
          { label: '维修站', value: '维修站' },
          { label: '救援车队', value: '救援车队' },
          { label: '整车厂', value: '整车厂' },
          { label: '其他', value: '其他' },
        ],
      },
    },
    {
      fieldName: 'coopStatus',
      label: '合作状态',
      component: 'Select',
      componentProps: {
        placeholder: '请选择合作状态',
        mode: 'multiple',
        options: [
          { label: '已合作', value: '已合作' },
          { label: '终止合作', value: '终止合作' },
          { label: '洽谈中', value: '洽谈中' },
          { label: '合约过期', value: '合约过期' },
        ],
      },
    },
    {
      fieldName: 'region',
      label: '区域',
      component: 'Select',
      componentProps: {
        placeholder: '请选择区域',
        mode: 'multiple',
        options: [
          { label: '华北', value: '华北' },
          { label: '华东', value: '华东' },
          { label: '华南', value: '华南' },
          { label: '华中', value: '华中' },
          { label: '东北', value: '东北' },
          { label: '西南', value: '西南' },
          { label: '西北', value: '西北' },
        ],
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: getRangePickerDefaultProps(),
    },
  ];
}

/** 表格列配置 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    { type: 'checkbox', width: 60, fixed: 'left' },
    {
      field: 'supplierCode',
      title: '供应商编码',
      minWidth: 120,
      fixed: 'left',
    },
    {
      field: 'supplierName',
      title: '供应商名称',
      minWidth: 180,
    },
    {
      field: 'type',
      title: '供应商类型',
      minWidth: 120,
    },
    {
      field: 'coopStatus',
      title: '合作状态',
      minWidth: 100,
    },
    {
      field: 'region',
      title: '区域',
      minWidth: 80,
    },
    {
      field: 'province',
      title: '省份',
      minWidth: 100,
    },
    {
      field: 'city',
      title: '城市',
      minWidth: 100,
    },
    {
      field: 'address',
      title: '地址',
      minWidth: 200,
    },
    {
      field: 'contact',
      title: '联系人',
      minWidth: 100,
    },
    {
      field: 'contactMobile',
      title: '联系手机',
      minWidth: 120,
    },
    {
      field: 'contactPhone',
      title: '联系电话',
      minWidth: 120,
    },
    {
      field: 'email',
      title: '邮箱',
      minWidth: 150,
    },
    {
      field: 'creditCodeOrId',
      title: '统一社会信用代码',
      minWidth: 180,
    },
    {
      field: 'remark',
      title: '备注',
      minWidth: 150,
    },
    {
      field: 'creator',
      title: '创建人',
      minWidth: 100,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    useActionColumn(3),
  ];
}
