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

import { getProductOptionApi } from '#/views/my-gen/product/api';

export const modalFormProps: VbenFormProps = {
  wrapperClass: 'grid-cols-12', // 24栅格,
  commonConfig: {
    formItemClass: 'col-span-12',
    // 所有表单项
    componentProps: {
      class: 'w-full',
    },
  },
  // handleSubmit: onSubmit,
  layout: 'horizontal',
  schema: [
    {
      component: 'VbenInput',
      fieldName: 'id',
      label: 'ID',
      formItemClass: 'col-span-6',
      dependencies: {
        show: false,
        triggerFields: ['id'],
      },
    },
    // 生成的表单字段
    {
      fieldName: 'product_id',
      label: '商品ID',
      component: 'ApiSelect',
      componentProps: {
        api: getProductOptionApi,
        filterOption: (input: string, option: any) => {
          // 自定义过滤逻辑，确保可以根据 name 进行搜索
          return option?.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
        },
        showSearch: true,
        // 菜单接口转options格式
        afterFetch: (data: { id: number; title: string }[]) => {
          return data.map((item: any) => ({
            label: item.title,
            value: item.id,
          }));
        },
      },
      rules: 'required',
    },
    {
      fieldName: 'name',
      label: 'sku名称',
      component: 'VbenInput',
      rules: 'required',
    },
    {
      fieldName: 'cover',
      label: 'sku图片',
      component: 'Avatar',
      rules: 'required',
    },
    {
      fieldName: 'inventory',
      label: '商品库存',
      component: 'InputNumber',
      rules: 'required',
    },
    {
      fieldName: 'price',
      label: '商品单价',
      component: 'InputNumber',
      rules: 'required',
    },
  ],
  showDefaultActions: false,
};

export const productModalFormProps: VbenFormProps = {
  wrapperClass: 'grid-cols-12', // 24栅格,
  commonConfig: {
    formItemClass: 'col-span-12',
    // 所有表单项
    componentProps: {
      class: 'w-full',
    },
  },
  // handleSubmit: onSubmit,
  layout: 'horizontal',
  schema: [
    {
      component: 'VbenInput',
      fieldName: 'id',
      label: 'ID',
      formItemClass: 'col-span-6',
      dependencies: {
        show: false,
        triggerFields: ['id'],
      },
    },
    // 生成的表单字段
    {
      fieldName: 'product_id',
      label: '商品ID',
      component: 'ApiSelect',
      componentProps: {
        api: getProductOptionApi,
        filterOption: (input: string, option: any) => {
          // 自定义过滤逻辑，确保可以根据 name 进行搜索
          return option?.label.toLowerCase().indexOf(input.toLowerCase()) >= 0;
        },
        showSearch: true,
        // 菜单接口转options格式
        afterFetch: (data: { id: number; title: string }[]) => {
          return data.map((item: any) => ({
            label: item.title,
            value: item.id,
          }));
        },
      },
      disabled: true,
      rules: 'required',
    },
    {
      fieldName: 'name',
      label: 'sku名称',
      component: 'VbenInput',
      rules: 'required',
    },
    {
      fieldName: 'cover',
      label: 'sku图片',
      component: 'Avatar',
      rules: 'required',
    },
    {
      fieldName: 'inventory',
      label: '商品库存',
      component: 'InputNumber',
      rules: 'required',
    },
    {
      fieldName: 'price',
      label: '商品单价',
      component: 'InputNumber',
      rules: 'required',
    },
  ],
  showDefaultActions: false,
};
