import VersionApi, { type addRequest } from "@/api/system/version";
import type { IModalConfig } from "@/components/CURD/types";

const modalConfig: IModalConfig<addRequest> = {
  pageName: "sys:user",
  dialog: {
    title: "新增版本",
    width: 800,
    draggable: true,
  },
  form: {
    labelWidth: 140,
  },
  formAction: function (data) {
    return VersionApi.add({ ...data, url: typeof data.url === "string" ? data.url : data.url[0] });
  },
  beforeSubmit(data) {
    console.log("提交之前处理", data);
  },
  formItems: [
    {
      label: "渠道",
      prop: "source",
      rules: [{ required: true, message: "请选择渠道", trigger: "blur" }],
      type: "select",
      attrs: {
        placeholder: "请选择渠道",
      },
      options: [],
    },
    {
      label: "类型",
      prop: "type",
      rules: [{ required: true, message: "请选择类型", trigger: "blur" }],
      type: "select",
      attrs: {
        placeholder: "请选择类型",
      },
      col: {
        xs: 24,
        sm: 12,
      },
      options: [],
    },
    {
      type: "input",
      label: "版本号",
      prop: "version",
      rules: [{ required: true, message: "请输入版本号", trigger: "blur" }],
      attrs: {
        placeholder: "请输入版本号",
      },
    },
    {
      type: "radio",
      label: "是否强制更新",
      prop: "isForce",
      rules: [{ required: true, message: "请输入版本号", trigger: "blur" }],
      attrs: {
        placeholder: "请输入版本号",
      },
      initialValue: 0,
      options: [],
    },
    {
      type: "textarea",
      label: "更新提示内容",
      prop: "message",
      rules: [{ required: true, message: "请输入更新提示内容", trigger: "blur" }],
      attrs: {
        placeholder: "请输入更新提示内容",
      },
    },
    {
      type: "custom",
      label: "版本文件",
      prop: "url",
      rules: [{ required: true, message: "请上传版本文件", trigger: "blur" }],
      attrs: {
        placeholder: "请上传版本文件",
      },
      initialValue: [],
    },
  ],
};

// 如果有异步数据会修改配置的，推荐用reactive包裹，而纯静态配置的可以直接导出
export default reactive(modalConfig);
