import type { VbenFormProps } from '#/adapter/form';

import { getRegionOptionPidApi } from '#/views/system/region/api';

export const modalFormProps: VbenFormProps = {
  wrapperClass: 'grid-cols-12',
  commonConfig: {
    formItemClass: 'col-span-12',
    componentProps: {
      class: 'w-full',
    },
  },
  layout: 'horizontal',
  schema: [
    {
      component: 'VbenInput',
      fieldName: 'id',
      label: 'ID',
      dependencies: {
        show: false,
        triggerFields: ['id'],
      },
    },
    {
      component: 'VbenInput',
      fieldName: 'formLevel',
      label: '表单层级',
      dependencies: {
        show: false,
        triggerFields: ['formLevel'],
      },
    },
    {
      component: 'VbenInput',
      fieldName: 'level_label',
      label: '级别',
      componentProps: {
        disabled: true,
      },
      dependencies: {
        show(values) {
          return Number(values.formLevel) === 2;
        },
        trigger(_values, form) {
          form.setFieldValue('level_label', '子地区');
        },
        triggerFields: ['formLevel'],
      },
    },
    {
      component: 'VbenInput',
      componentProps: {
        placeholder: '请输入名称',
      },
      fieldName: 'name',
      label: '名称',
    },
    {
      component: 'ApiSelect',
      componentProps: {
        placeholder: '请选择父级地区',
        api: getRegionOptionPidApi,
        filterOption: (input: string, option: any) =>
          option?.label.toLowerCase().indexOf(input.toLowerCase()) >= 0,
        showSearch: true,
        afterFetch: (data: { id: number; name: string }[]) => {
          return data.map((item: any) => ({
            label: item.name,
            value: item.id,
          }));
        },
      },
      fieldName: 'pid',
      label: '父级地区',
      dependencies: {
        show(values) {
          return Number(values.formLevel) === 2;
        },
        triggerFields: ['formLevel'],
      },
    },
    {
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入价格',
        class: 'w-full',
        min: 0,
      },
      fieldName: 'express_fee',
      label: '快递费',
    },
  ],
  showDefaultActions: false,
};
