import {
  IPublicTypeSnippet,
  IPublicModelSettingField,
} from '@alilc/lowcode-types';

const snippets: IPublicTypeSnippet[] = [
  {
    title: '商品选择',
    screenshot: '',
    schema: {
      componentName: 'ProductSelect',
      props: {},
    },
  },
];

const productSelectMeta = {
  snippets,
  componentName: 'ProductSelect',
  title: 'ProductSelect',
  category: '数据展示',
  docUrl: '',
  screenshot: '',
  devMode: 'proCode',
  npm: {
    package: '@pisell/private-materials',
    version: '1.0.1',
    exportName: 'ProductSelect',
    main: 'src/index.tsx',
    destructuring: true,
    subName: '',
  },
  props: [
    {
      title: { label: '数据' },
      type: 'group',
      display: 'block',
      items: [
        {
          name: 'dataSource',
          title: { label: '当前list数据', tip: '当前list数据' },
          setter: ['JsonSetter', 'VariableSetter'],
        },
      ],
    },
    {
      title: { label: '样式' },
      type: 'group',
      display: 'block',
      items: [
        {
          name: 'isSearch',
          title: { label: '开启搜索功能'},
          propType: 'bool',
          setter: 'BoolSetter',
          defaultValue: true,
        },
        {
          name: 'showTab',
          title: { label: '全部商品tab' },
          propType: 'bool',
          setter: 'BoolSetter',
          defaultValue: true,
        },
        {
          type: 'group',
          items: [
            {
              name: 'layout.grid',
              title: { label: '开启栅格', tip: '开启栅格' },
              propType: 'bool',
              setter: 'BoolSetter',
              defaultValue: true,
            },
            {
              name: 'layout.config',
              condition: (target: IPublicModelSettingField) => {
                return target.parent.getPropValue('layout.grid') === true;
              },
              title: { label: '当前选中值', tip: '当前选中值' },
              propType: 'string',
              setter: 'StringSetter',
              defaultValue: '12:12',
            },
          ],
        },
      ],
    },
    {
      title: { label: '商品信息展示' },
      type: 'group',
      display: 'block',
      items: [
        {
          name: 'isProductCover',
          title: { label: '商品图片', tip: '是否展示商品图片' },
          propType: 'bool',
          setter: 'BoolSetter',
          defaultValue: true,
        },
        {
          name: 'imgWidth',
          condition: (target: IPublicModelSettingField) => {
            return target.parent.getPropValue('isProductCover') === true;
          },
          title: { label: '商品图片宽度' },
          propType: 'string',
          setter: 'StringSetter',
          defaultValue: '180px',
        },
        {
          name: 'imgHeight',
          condition: (target: IPublicModelSettingField) => {
            return target.parent.getPropValue('isProductCover') === true;
          },
          title: { label: '商品图片高度' },
          propType: 'string',
          setter: 'StringSetter',
          defaultValue: '126px',
        },
        {
          name: 'isTitle',
          title: { label: '商品名称' },
          propType: 'bool',
          setter: 'BoolSetter',
          defaultValue: true,
        },
          {
          name: 'isSubtitle',
          title: { label: '商品副标题' },
          propType: 'bool',
          setter: 'BoolSetter',
          defaultValue: true,
        },
        {
          name: 'showSpec',
          title: { label: '商品规格' },
          propType: 'bool',
          setter: 'BoolSetter',
          defaultValue: true,
        },
        {
          name: 'isTag',
          title: { label: '商品标签' },
          propType: 'bool',
          setter: 'BoolSetter',
          defaultValue: true,
        },
        {
          name: 'isPrice',
          title: { label: '价格' },
          propType: 'bool',
          setter: 'BoolSetter',
          defaultValue: true,
        },
        {
          name: 'isOriginPrice',
          title: { label: '商品原价' },
          propType: 'bool',
          setter: 'BoolSetter',
          defaultValue: true,
        },
        {
          name: 'showMarketingTag',
          title: { label: '营销标记' },
          propType: 'bool',
          setter: 'BoolSetter',
          defaultValue: true,
        },
        {
          name: 'showRemark',
          title: { label: '商品备注' },
          propType: 'bool',
          setter: 'BoolSetter',
          defaultValue: true,
        },
        {
          name: 'isStock',
          title: { label: '商品库存' },
          propType: 'bool',
          setter: 'BoolSetter',
          defaultValue: true,
        },
      ],
    },
  ],
  configure: {
    supports: {
      style: true,
      events: [
        {
          name: 'onSelectItemChange',
          template:
            "onSelectItemChange(value,${extParams}){\n// 关闭时触发的回调函数\nconsole.log('onChange');}",
        },
      ],
    },
  },
};

export default productSelectMeta;
