import { globalOption, patternTrim } from '../globalOption';

// 组件公开状态码
export const publishStatusConstant = {
  // 未公开
  UNPUBLISHED: -1,
  // 已公开
  PUBLISHED: 1,
  // 已撤销
  REVOKED: 0,
  // 审批中
  APPROVAL: 2
};
export const publishStatusDict = [
  {
    label: '未公开',
    value: publishStatusConstant.UNPUBLISHED
  },
  {
    label: '未公开',
    value: publishStatusConstant.REVOKED
  },
  {
    label: '已公开',
    value: publishStatusConstant.PUBLISHED
  },
  {
    label: '审批中',
    value: publishStatusConstant.APPROVAL
  }
];
// 组价发布的状态码
export const publicStatus = {
  // 未发布
  UNPUBLISHED: -1,
  UNPUBLISHED1: 0,
  // 已发布
  PUBLISHED: 1,
  // 审核中
  REVIEW: 2,
  // 审核被拒
  REJECTED: 3
};
export const publicStatusDict = [
  {
    label: '未发布',
    value: publicStatus.UNPUBLISHED
  },
  {
    label: '未发布',
    value: publicStatus.UNPUBLISHED1
  },
  {
    label: '已发布',
    value: publicStatus.PUBLISHED
  },
  {
    label: '审核中',
    value: publicStatus.REVIEW
  },
  {
    label: '审核被拒',
    value: publicStatus.REJECTED
  }
];
// 组件基本信息状态字段
export const componentStatusConstant = {
  // 未设计
  DEFAULT: 'default',
  // 设计中
  DESIGN: 'design',
  // 编码中
  CODING: 'coding',
  // 已部署
  DEPLOYED: 'deployed',
  // 已公开
  PUBLISHED: 'published'
};
// 组件所处阶段状态
export const componentStatusDict = [
  {
    label: '未设计',
    value: componentStatusConstant.DEFAULT
  },
  {
    label: '设计中',
    value: componentStatusConstant.DESIGN
  },
  {
    label: '编码中',
    value: componentStatusConstant.CODING
  },
  {
    label: '已部署',
    value: componentStatusConstant.DEPLOYED
  },
  {
    label: '已公开',
    value: componentStatusConstant.PUBLISHED
  }
];
// 组件所处阶段状态
export const componentStatusMap = componentStatusDict.reduce((obj, item) => {
  obj[item.value] = item.label;
  return obj;
}, {});
// 组件类型字典映射
export const componentTypeDict = [
  {
    dictKey: '普通组件',
    dictValue: 'normal'
  },
  {
    dictKey: '监听组件',
    dictValue: 'loop'
  }
];

// 表格参数
export const option = {
  ...globalOption,
  height: 'auto',
  calcHeight: 30,
  tip: false,
  searchShow: true,
  searchMenuSpan: 6,
  viewBtn: true,
  delBtn: false,
  selection: false,
  dialogClickModal: false,
  labelWidth: '100',
  menuWidth: 500,
  menuHeaderAlign: 'center',
  header: true,
  addBtn: true,
  editBtn: false,
  updateBtnText: '保 存',
  addBtnText: '新增组件',
  addBtnIcon: 'none',
  column: [
    {
      label: '组件名称',
      prop: 'name',
      type: 'input',
      width: 150,
      placeholder: '请输入组件名称',
      rules: [
        {
          required: true,
          message: '组件名称不能为空',
          trigger: 'blur'
        },
        {
          pattern: /^[\u4e00-\u9fa5a-zA-Z0-9_-]+$/,
          message: '组件名称只能为中文、字母、数字、"-"、"_"组成'
        },
        patternTrim,
        { max: 50, message: '组件名称最长为50字符' }
      ]
    },
    {
      label: '组件标识',
      prop: 'projectId',
      type: 'input',
      width: 200,
      overHidden: true,
      placeholder: '请输入组件标识',
      editDisabled: true,
      rules: [
        { required: true, message: '组件标识不能为空' },
        {
          pattern: /^([a-z][a-z0-9]*[_-]?)+$/,
          message: '组件标识由小写字母、数字、"-"、"_"组成，以小写字母开头，且“-”、"_"后第一个字符需为小写字母'
        },
        { max: 30, message: '组件标识最长为30个字符' },
        patternTrim
      ]
    },
    {
      label: '分类',
      prop: 'componentClassify',
      type: 'select',
      placeholder: '请选择分类',
      width: 200,
      dicUrl: '/api/blade-system/dict-biz/dictionary-tree?code=component_classify',
      props: {
        label: 'dictValue',
        value: 'dictKey'
      },
      rules: [{ required: true, message: '分类不能为空' }]
    },
    {
      label: '创建人',
      prop: 'createUserName',
      type: 'input',
      display: false,
      overHidden: true,
      editDisabled: false,
      width: 180,
      hide: false
    },
    {
      label: '代码语言',
      prop: 'codeLanguage',
      type: 'select',
      dicUrl: '/api/blade-system/dict/dictionary?code=language_type',
      value: 'Java',
      editDisabled: true,
      width: 150,
      placeholder: '请选择代码语言',
      props: {
        label: 'dictValue',
        value: 'dictKey'
      },
      rules: [{ required: true, message: '代码语言不能为空' }]
    },
    {
      label: '标签',
      prop: 'tags',
      type: 'select',
      remote: true,
      multiple: true,
      allowCreate: true,
      filterable: true,
      placeholder: '请选择标签',
      width: 200,
      dicUrl: '/api/blade-isdp/componentBase/tags',
      hide: true
    },
    {
      label: '组件类型',
      prop: 'type',
      type: 'select',
      dicData: componentTypeDict,
      value: 'normal',
      editDisabled: true,
      width: 150,
      placeholder: '请选择组件类型',
      props: {
        label: 'dictKey',
        value: 'dictValue'
      },
      rules: [{ required: true, message: '组件类型不能为空' }]
    },
    {
      label: '图标',
      prop: 'logoUrl',
      type: 'upload',
      hide: true,
      listType: 'picture-card',
      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: 'desc',
      type: 'textarea',
      overHidden: true,
      placeholder: '请输入描述',
      formSlot: true,
      hide: true,
      minRows: 2,
      maxLen: 100,
      span: 24
    },
    {
      label: '组件状态',
      prop: 'componentStatus',
      type: 'input',
      display: false,
      width: 100,
      dicData: componentStatusDict
    },
    {
      label: '创建部门',
      prop: 'createDept',
      type: 'input',
      display: false,
      hide: true
    },
    {
      label: '创建时间',
      prop: 'createTime',
      type: 'input',
      hide: true,
      display: false
    },
    {
      label: '发布状态',
      prop: 'publicStatus',
      type: 'input',
      width: 90,
      dicData: [
        {
          label: '未发布',
          value: publicStatus.UNPUBLISHED
        },
        {
          label: '未发布',
          value: publicStatus.UNPUBLISHED1
        },
        {
          label: '已发布',
          value: publicStatus.PUBLISHED
        },
        {
          label: '审核中',
          value: publicStatus.REVIEW
        },
        {
          label: '审核被拒',
          value: publicStatus.REJECTED
        }
      ],
      display: false
    },
    {
      label: '公开状态',
      prop: 'publishStatus',
      type: 'input',
      width: 90,
      dicData: [
        {
          label: '未公开',
          value: publishStatusConstant.UNPUBLISHED
        },
        {
          label: '未公开',
          value: publishStatusConstant.REVOKED
        },
        {
          label: '已公开',
          value: publishStatusConstant.PUBLISHED
        },
        {
          label: '审批中',
          value: publishStatusConstant.APPROVAL
        }
      ],
      display: false
    },
    {
      label: '修改人',
      prop: 'updateUser',
      type: 'input',
      display: false,
      hide: true
    },
    {
      label: '修改时间',
      prop: 'updateTime',
      type: 'input',
      width: 130,
      display: false
    },
    {
      label: '是否已删除',
      prop: 'isDeleted',
      type: 'input',
      display: false,
      hide: true
    }
  ]
};

export const operateOption = {
  ...globalOption,
  height: '400',
  calcHeight: 30,
  tip: false,
  searchShow: false,
  selection: false,
  dialogClickModal: false,
  header: false,
  delBtn: true,
  viewBtn: false,
  dialogWidth: '55%',
  menuWidth: 100,
  saveBtn: false,
  cancelBtn: false,
  editBtn: true,
  editBtnIcon: 'none',
  delBtnIcon: 'none',
  column: [
    {
      label: '接口名称',
      prop: 'ident',
      type: 'input',
      placeholder: '请输入名称',
      rules: [
        { required: true, message: '名称不能为空' },
        { pattern: /^[a-z][a-zA-Z0-9]*$/, message: '名称符需要为首字母小写的驼峰命名法' },
        { max: 20, message: '名称最长为20个字符' },
        patternTrim
      ]
    },
    {
      label: '描述',
      prop: 'desc',
      type: 'textarea',
      placeholder: '请输入描述',
      hide: true,
      overHidden: true,
      minRows: 2,
      rules: [{ max: 200, message: '最长为200个字符' }, patternTrim],
      span: 24
    },
    {
      label: '输入参数',
      prop: 'parameters',
      type: 'input',
      span: 24,
      formSlot: true,
      overHidden: true,
      value: [],
      slot: true
    },
    {
      label: '输出参数',
      prop: 'responses',
      type: 'input',
      span: 24,
      formSlot: true,
      overHidden: true,
      value: [],
      slot: true
    }
  ]
};

export const baseConfigOption = {
  ...globalOption,
  addBtn: false,
  addRowBtn: true,
  menu: true,
  cellBtn: false,
  editBtn: false,
  delBtn: false,
  dialogWidth: '40%',
  menuWidth: '80',
  column: [
    {
      label: '启动项名称',
      prop: 'name',
      placeholder: '启动项名称',
      width: '150px',
      rules: [{ required: true, message: '启动项名称不能为空' }, {
        max: 50,
        message: '启动项名称最长为50字符'
      }, patternTrim],
      cell: true,
      span: 24
    },
    {
      label: '参数名（key）',
      prop: 'key',
      input: 'input',
      width: '200px',
      rules: [{ required: true, message: '请输入参数名（key）' }, {
        max: 50,
        message: '参数名（key）最长为50字符'
      }, patternTrim],
      cell: true,
      span: 24
    },
    {
      label: '默认值',
      prop: 'value',
      width: '200px',
      span: 24,
      cell: true,
      rules: [{ max: 200, message: '默认值最长为200字符' }, patternTrim]
    },
    {
      label: '描述说明',
      prop: 'desc',
      overHidden: true,
      span: 24,
      cell: true,
      rules: [{ max: 200, message: '描述说明最长为200字符' }, patternTrim]
    }
  ]
};

export const baseDisplayToEntity = (row) => {
  row.desc = row.desc || '';
  row.tags = row.tags || [];
  row.logoUrl = row.logoUrl || '';
  return row;
};

export const baseEntityToDisplay = (row) => {
  row.desc = row.desc || '';
  row.logoUrl = row.logoUrl || '';
  row.tags = row.tags || [];
  return row;
};

export const toolbars = {
  bold: true, // 粗体
  italic: true, // 斜体
  header: true, // 标题
  underline: true, // 下划线
  strikethrough: true, // 中划线
  mark: true, // 标记
  superscript: true, // 上角标
  subscript: true, // 下角标
  quote: true, // 引用
  ol: true, // 有序列表
  ul: true, // 无序列表
  link: true, // 链接
  imagelink: true, // 图片链接
  code: true, // code
  table: true, // 表格
  fullscreen: true, // 全屏编辑
  readmodel: true, // 沉浸式阅读
  htmlcode: true, // 展示html源码
  help: false, // 帮助
  /* 1.3.5 */
  undo: true, // 上一步
  redo: true, // 下一步
  trash: true, // 清空
  save: false, // 保存（触发events中的save事件）
  /* 1.4.2 */
  navigation: true, // 导航目录
  /* 2.1.8 */
  alignleft: true, // 左对齐
  aligncenter: true, // 居中
  alignright: true, // 右对齐
  /* 2.2.1 */
  subfield: true, // 单双栏模式
  preview: true // 预览
};
