import { globalOption, patternTrim } from '../globalOption';
import { componentBaseTagsUrl } from '@/api/isdp/componentBase';

export const releaseMaping = {
  0: {
    label: '未公开',
    type: 'info',
  },
  '-1': {
    label: '未公开',
    type: 'info',
  },
  1: {
    label: '已公开',
    type: 'success',
  },
};

export const option = {
  ...globalOption,
  height: 'auto',
  calcHeight: 30,
  tip: false,
  searchShow: true,
  searchSpan: 5,
  searchMenuSpan: 4,
  menuWidth: 120,
  viewBtn: true,
  delBtn: false,
  selection: false,
  header: false,
  editBtn: false,
  column: [
    {
      label: '组件名称',
      prop: 'name',
      type: 'input',
      overHidden: true,
      search: true,
      placeholder: '请输入组件名称',
      rules: [
        {
          required: true,
          message: '组件名称不能为空',
          trigger: 'blur',
        },
        patternTrim,
        { max: 20, message: '组件名称最长为20字符' },
      ],
    },
    {
      label: '项目名',
      prop: 'identifier',
      type: 'input',
      overHidden: true,
      search: true,
      placeholder: '请输入项目名',
      rules: [
        { required: true, message: '项目名不能为空' },
        {
          pattern: /^([a-z][a-z0-9]*[_-]?)+$/,
          message: '项目名由小写字母、数字、"-"、"_"组成，以小写字母开头，且“-”、"_"后第一个字符需为小写字母',
        },
        { max: 30, message: '项目名最长为30个字符' },
        patternTrim,
      ],
    },
    {
      label: '版本号',
      prop: 'version',
      type: 'input',
      overHidden: true,
      disabled: true,
      value: 'v1',
      width: 60,
      span: 6,
      rules: [
        {
          required: true,
          message: '请输入组件版本号',
          trigger: 'blur',
        },
        // {
        //   pattern: /^\d+(\.\d+){0,3}$/,
        //   message: "版本只能是由数字组成的x.x或x.x.x格式",
        //   trigger: "blur"
        // },
        { max: 20, message: '版本号最长为20字符' },
      ],
    },
    {
      label: '分类',
      prop: 'componentClassify',
      type: 'select',
      placeholder: '请选择分类',
      search: true,
      dicUrl: '/api/blade-system/dict-biz/dictionary-tree?code=component_classify',
      props: {
        label: 'dictValue',
        value: 'dictKey',
      },
      span: 9,
      rules: [{ required: true, message: '分类不能为空' }],
      // search: true,
    },
    {
      label: '代码语言',
      prop: 'codeLanguage',
      type: 'select',
      search: true,
      dicUrl: '/api/blade-system/dict/dictionary?code=language_type',
      value: 'Java',
      width: 70,
      span: 9,
      placeholder: '请选择代码语言',
      props: {
        label: 'dictValue',
        value: 'dictKey',
      },
      rules: [{ required: true, message: '代码语言不能为空' }],
    },
    {
      label: '标签',
      prop: 'tags',
      type: 'select',
      remote: true,
      multiple: true,
      allowCreate: true,
      filterable: true,
      placeholder: '请选择标签',
      span: 24,
      dicUrl: componentBaseTagsUrl,
      hide: true,
    },
    {
      label: '描述',
      prop: 'desc',
      type: 'textarea',
      overHidden: true,
      placeholder: '请输入描述',
      minRows: 2,
      maxLen: 100,
      rules: [{ max: 200, message: '最长为200个字符' }],
      span: 24,
    },
    {
      label: '图标',
      prop: 'logoUrl',
      type: 'upload',
      hide: true,
      listType: 'picture-img',
      action: '/api/blade-isdp/fileSystem/fileUpload',
      propsHttp: {
        res: 'data',
        url: 'link',
      },
      fileType: 'img',
      limit: 1,
      fileSize: 1024,
      accept: 'image/png, image/jpeg, image/jpg',
      tip: '图片尺寸不超过300*300像素，大小限制为1mb以内',
    },
    {
      label: '公开状态',
      prop: 'publishStatus',
      type: 'input',
      slot: true,
      display: false,
      width: 90,
    },
    {
      label: '修改时间',
      prop: 'updateTime',
      type: 'input',
      width: 130,
      display: false,
    },
  ],
};
