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

/**
 * 实例运行状态
 */
export const runStatusConstant = {
  HEALTHY: 'healthy',
  UNKNOWN: 'unknown',
  RUN: 'run',
  ERROR: 'error',
  STOP: 'stop'
};
export const runStatusDic = [
  {
    label: '可用',
    value: runStatusConstant.HEALTHY,
    color: 'green'
  },
  {
    label: '未知',
    value: runStatusConstant.UNKNOWN,
    color: 'gray'
  },
  {
    // 部署 可停止
    label: '运行',
    value: runStatusConstant.RUN,
    color: 'blue'
  },
  {
    label: '异常',
    value: runStatusConstant.ERROR,
    color: 'orange'
  },
  {
    // 部署 可启用
    label: '停止',
    value: runStatusConstant.STOP,
    color: 'red'
  }
];
export const runStatusMap = runStatusDic.reduce((obj, item) => {
  obj[item.value] = item.label;
  return obj;
}, {});
/**
 * 组件运行状态
 */
export const startStatusConstant = {
  RUN: 'run',
  STOP: 'stop'
};
export const startStatusDic = [
  {
    label: '启用中',
    value: startStatusConstant.RUN
  },
  {
    label: '已下架',
    value: startStatusConstant.STOP
  }
];
export const startStatusMap = startStatusDic.reduce((obj, item) => {
  obj[item.value] = item.label;
  return obj;
}, {});

/**
 * 组件编译状态
 * BUILT_DOING, BUILT_IGNORE,BUILT_DOCKER,BUILT_FAIL
 */
export const compileStatusConstant = {
  BUILT_DOING: 'built-doing',
  BUILT_IGNORE: 'built-ignore',
  BUILT_DOCKER: 'built-docker',
  BUILT_FAIL: 'built-fail',
  // 前端单独使用
  NOT_COMPILED: 'not-compiled',
  get(type) {
    return compileStatusConstant[type] || compileStatusConstant.NOT_COMPILED;
  }
};
export const compileStatusDic = [
  {
    label: '编译中',
    value: compileStatusConstant.BUILT_DOING
  },
  {
    label: '免编译',
    value: compileStatusConstant.BUILT_IGNORE
  },
  {
    label: '已编译',
    value: compileStatusConstant.BUILT_DOCKER
  },
  {
    label: '编译失败',
    value: compileStatusConstant.BUILT_FAIL
  }
];
export const compileStatusMap = startStatusDic.reduce((obj, item) => {
  obj[item.value] = item.label;
  return obj;
}, {});
/**
 * 实例运行类型
 */
export const runTypeConstant = {
  LOCAL: 0,
  ONLINE: 1
};
export const runTypeDic = [
  {
    label: '本地运行',
    value: runTypeConstant.LOCAL
  },
  {
    label: '线上运行',
    value: runTypeConstant.ONLINE
  }
];
export const option = {
  ...globalOption,
  height: '300',
  calcHeight: 30,
  tip: false,
  searchShow: false,
  header: false,
  viewBtn: false,
  delBtn: false,
  index: true,
  menuWidth: 300,
  addBtn: false,
  editBtn: false,
  submitText: '修改',
  emptyText: '暂无数据',
  span: 24,
  column: [
    {
      label: 'id',
      prop: 'id',
      hide: true,
      display: false
    },
    {
      label: '标识',
      prop: 'identifier',
      type: 'input',
      overHidden: true,
      display: false
    },
    {
      label: '实例名称',
      prop: 'name',
      type: 'input',
      overHidden: true,
      rules: [
        { required: true, message: '必须填写实例名称' },
        { max: 50, message: '实例名称不能超过50字符' }
      ]
    },
    {
      label: '运行类型',
      prop: 'runType',
      type: 'input',
      width: 80,
      display: false,
      dicData: runTypeDic
    },
    {
      label: '运行状态',
      prop: 'runStatus',
      type: 'input',
      width: 80,
      dicData: runStatusDic,
      display: false,
      slot: true
    },
    {
      label: '创建时间',
      prop: 'createTime',
      type: 'input',
      // width: 160,
      display: false
    },
    {
      label: '实例描述',
      prop: 'description',
      type: 'textarea',
      hide: true,
      minRows: 3,
      span: 24
    }
  ]
};
export const instanceOption = {
  ...globalOption,
  calcHeight: 'auto',
  // height: '300',
  // calcHeight: 30,
  tip: false,
  searchShow: false,
  header: false,
  viewBtn: false,
  delBtn: false,
  index: true,
  menuWidth: 350,
  addBtn: false,
  editBtn: false,
  submitText: '修改',
  emptyText: '取消',
  span: 24,
  column: [
    ...option.column,
    {
      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 * 10,
      accept: 'image/png, image/jpeg, image/jpg'
      // tip: '图片尺寸不超过300*300像素，大小限制为1mb以内',
      // rules: [{
      //   required: true,
      //   message: "请输入图片地址",
      //   trigger: "blur"
      // }]
    }
  ]
};
export const envConfigOption = {
  ...globalOption,
  height: 300,
  calcHeight: 30,
  tip: false,
  searchShow: false,
  addBtn: false,
  addRowBtn: false,
  cellBtn: false,
  index: true,
  menuWidth: 80,
  editBtn: false,
  delBtn: false,
  column: [
    {
      label: '启动项名称',
      prop: 'name',
      placeholder: '启动项名称',
      formSlot: true,
      rules: [
        { required: true, message: '启动项名称不能为空' },
        { max: 50, message: '启动项名称最长为50字符' }
      ],
      width: 120,
      span: 24,
      cell: true
    },
    {
      label: '参数名（key）',
      prop: 'key',
      formSlot: true,
      rules: [
        { required: true, message: '请输入参数名（key）' },
        { max: 50, message: '参数名（key）最长为50字符' }
      ],
      span: 24,
      cell: true
    },
    {
      label: '配置值',
      prop: 'value',
      span: 24,
      formSlot: true,
      rules: [{ max: 200, message: '配置值最长为200字符' }],
      cell: true
    },
    {
      label: '描述说明',
      prop: 'desc',
      type: 'input',
      formSlot: true,
      span: 24,
      rules: [{ max: 200, message: '描述说明最长为200字符' }],
      cell: true
    }
    // {
    //   label: "配置类型",
    //   prop: "unmodifiable",
    //   value: false,
    //   width: 80,
    //   dicData: [
    //     {
    //       label: "自定义配置",
    //       value: false
    //     },
    //     {
    //       label: "必须配置",
    //       value: true
    //     }
    //   ]
    // },
  ]
};
export const addInstanceOption = {
  ...globalOption,
  submitBtn: false,
  emptyBtn: false,
  column: [
    {
      label: '部署环境',
      prop: 'environment',
      type: 'select',
      value: 'docker-env-prod',
      // disabled: true,
      dicData: [],
      rules: [{ required: true, message: '请选择环境变量' }],
      overHidden: true
    },
    {
      label: '主机',
      prop: 'deployEnvId',
      type: 'select',
      value: '',
      props: {
        label: 'name',
        value: 'id',
        desc: 'ip'
      },
      rules: [{ required: true, message: '请输入主机' }],
      overHidden: true
    },
    {
      label: 'CPU核数',
      prop: 'cpuCount',
      type: 'slider',
      step: 1,
      min: 1,
      max: 12,
      showStops: true,
      marks: [1, 4, 8].reduce((obj, pre) => {
        obj[pre] = pre + '核';
        return obj;
      }, {})
    },
    // {
    //   label: "容器名称",
    //   prop: "containerName",
    //   tip: "为空时自动生成",
    //   rules: [
    //     { min: 1, max: 63, message: "容器名称长度为1-63个字符" },
    //     patternTrim,
    //   ],
    // },
    {
      label: '是否使用GPU',
      prop: 'useGpu',
      type: 'switch',
      labelWidth: 100,
      value: false,
      dicData: [
        { label: '否', value: false },
        { label: '是', value: true }
      ]
    },
    {
      label: '最大内存',
      prop: 'memory',
      type: 'slider',
      step: 64,
      min: 64,
      max: 8192,
      formSlot: true,
      span: 24,
      marks: {
        64: '64MB',
        1024: '1GB',
        2048: '2GB',
        4096: '4GB',
        6144: '6GB'
      },
      showStops: true
    },
    // 网络模式 选择框
    {
      label: '网络模式',
      prop: 'networkType',
      type: 'select',
      span: 6,
      value: 'bridge',
      dicData: [
        {
          label: '桥接模式',
          value: 'bridge'
        },
        {
          label: '主机模式',
          value: 'host'
        },
        {
          label: '禁用网络',
          value: 'null'
        }
      ],
      rules: [{ required: true, message: '请选择网络模式' }],
      overHidden: true
    },
    // 网卡
    {
      label: '网卡',
      prop: 'networkMode',
      type: 'select',
      value: 'bridge',
      span: 9,
      overHidden: true,
      rules: [{ required: true, message: '请选择网卡' }]
    },
    // ip
    {
      label: 'IP',
      prop: 'ipv4Address',
      type: 'input',
      formSlot: true,
      value: '',
      overHidden: true,
      span: 9
    },
    {
      label: '端口映射',
      prop: 'ports',
      type: 'dynamic',
      span: 24,
      children: {
        height: 120,
        column: [
          {
            label: '主机端口',
            prop: 'hostPort',
            type: 'number',
            value: '80',
            max: 65535,
            rules: [{ required: true, message: '请输入主机端口' }]
          },
          {
            label: '容器端口',
            prop: 'containerPort',
            type: 'number',
            max: 65535,
            rules: [{ required: true, message: '请输入容器端口' }]
          },
          {
            label: '备注',
            prop: 'remake',
            type: 'input',
            value: ''
          }
        ]
      }
    },
    {
      label: '目录挂载',
      prop: 'volumes',
      type: 'dynamic',
      span: 24,
      children: {
        height: 170,
        column: [
          {
            label: '主机路径',
            prop: 'hostPath',
            type: 'input',
            value: '',
            rules: [{ required: true, message: '请输入主机路径' }, patternTrim]
          },
          {
            label: '容器路径',
            prop: 'containerPath',
            type: 'input',
            value: '',
            rules: [{ required: true, message: '请输入容器路径' }, patternTrim]
          },
          {
            label: '备注',
            prop: 'remake',
            type: 'input'
          }
        ]
      }
    },
    {
      // 设备挂载
      label: '设备挂载',
      prop: 'devices',
      type: 'dynamic',
      span: 24,
      children: {
        height: 120,
        column: [
          {
            label: '主机路径',
            prop: 'hostPath',
            type: 'input',
            value: '',
            rules: [{ required: true, message: '请输入主机路径' }, patternTrim]
          },
          {
            label: '容器路径',
            prop: 'containerPath',
            type: 'input',
            value: '',
            rules: [{ required: true, message: '请输入容器路径' }, patternTrim]
          },
          {
            label: '权限',
            prop: 'permissions',
            type: 'select',
            value: 'rwm',
            dicData: [
              { value: 'rwm', label: 'rwm' },
              { value: 'rw', label: 'rw' },
              { value: 'r', label: 'r' }
            ],
            rules: [{ required: true, message: '请输入权限' }]
          },
          {
            label: '备注',
            prop: 'remake',
            type: 'input',
            value: ''
          }
        ]
      }
    },
    // 重启策略
    {
      label: '重启策略',
      prop: 'restartPolicy',
      type: 'select',
      span: 6,
      display: false,
      hide: true,
      value: 'always',
      dicData: [
        {
          label: '始终',
          value: 'always'
        },
        {
          label: '失败',
          value: 'on-failure'
        },
        {
          label: '无',
          value: 'no'
        }
      ],
      overHidden: true
    }
  ]
};
