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

export const archDict = [
  {
    label: 'x86_64',
    value: 'x86_64',
  },
  {
    label: 'aarch64',
    value: 'aarch64',
  },
];

export const option = {
  ...globalOption,
  height: 'auto',
  calcHeight: 30,
  searchShow: true,
  searchMenuSpan: 6,
  viewBtn: false,
  delBtn: false,
  selection: false,
  header: true,
  addBtn: false,
  editBtn: false,
  updateBtnText: '保 存',
  menuHeaderAlign: 'center',
  column: [
    {
      label: '环境IP',
      prop: 'ip',
      type: 'input',
      overHidden: true,
      span: 12,
      rules: [
        {
          required: true,
          message: '环境IP不能为空',
          trigger: 'blur',
        },
        {
          pattern: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
          message: '请输入正确的IP地址：范围在0.0.0.0-255.255.255.255之间',
          trigger: 'blur',
        },
      ],
    },
    {
      label: 'docker端口',
      prop: 'dockerTcpPort',
      type: 'number',
      labelWidth: 100,
      overHidden: true,
      value: 2375,
      span: 12,
      rules: [
        {
          required: true,
          message: 'docker端口不能为空',
          trigger: 'blur',
        },
        {
          pattern: /^(?:[1-9]\d{0,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/,
          message: 'docker端口只能是1-65535之间',
          trigger: 'blur',
        },
      ],
    },
    {
      label: '环境类型',
      prop: 'type',
      type: 'select',
      overHidden: true,
      search: true,
      span: 12,
      dicUrl: '/api/blade-system/dict/dictionary-tree?code=docker-env',
      props: {
        label: 'dictValue',
        value: 'dictKey',
      },
      rules: [
        {
          required: true,
          message: '环境类型不能为空',
          trigger: 'blur',
        },
      ],
    },
    {
      label: '架构类型',
      prop: 'arch',
      type: 'select',
      overHidden: true,
      search: true,
      span: 12,
      dicData: archDict,
      formSlot: true,
      props: {
        label: 'label',
        value: 'value',
      },
      rules: [
        {
          required: true,
          message: '架构类型不能为空',
          trigger: 'blur',
        },
      ],
    },
    {
      label: '环境别名',
      prop: 'name',
      type: 'input',
      search: true,
      span: 24,
      rules: [
        {
          required: true,
          message: '环境IP不能为空',
          trigger: 'blur',
        },
        patternTrim,
        // 最大50
        {
          max: 50,
          message: '环境别名最大长度不能超过50',
          trigger: 'blur',
        },
      ],
    },
    {
      label: '备注',
      prop: 'description',
      type: 'textarea',
      span: 24,
      rules: [
        {
          max: 200,
          message: '长度不超过200字符',
          trigger: 'blur',
        },
      ],
      overHidden: true,
    },
    {
      label: '实例数量',
      labelWidth: 20,
      span: 24,
      prop: 'instanceCount',
      display: false,
    },
  ],
};
