import dayjs from "dayjs";

const statusName = new Map();

statusName.set(11, "未订舱");
statusName.set(12, "已订舱");

statusName.set(21, "未预装");
statusName.set(22, "预装审核中");
statusName.set(23, "预装审核失败");
statusName.set(24, "预装审核成功");

statusName.set(31, "未派车");
statusName.set(32, "已派车");

statusName.set(41, "未装柜");
statusName.set(42, "装柜中");
statusName.set(43, "已装柜、待封柜");
statusName.set(44, "封柜审核中");
statusName.set(45, "封柜审核失败");
statusName.set(46, "封柜审核成功");

statusName.set(51, "未报关");
statusName.set(52, "报关中");
statusName.set(53, "已报关");

statusName.set(61, "未配船");
statusName.set(62, "已配船");

statusName.set(71, "未提单补料");
statusName.set(72, "已提单补料");

statusName.set(81, "未驳船");
statusName.set(82, "已驳船");

statusName.set(91, "未起运");
statusName.set(92, "已起运");

statusName.set(101, "未上传");
statusName.set(102, "已上传");

statusName.set(111, "未清关文件");
statusName.set(112, "已清关文件");

statusName.set(121, "未到港");
statusName.set(122, "已到港");

statusName.set(131, "未清关");
statusName.set(132, "已清关");

statusName.set(141, "未卸柜");
statusName.set(142, "卸柜中");
statusName.set(143, "卸柜审核中");
statusName.set(144, "卸柜审核失败");
statusName.set(145, "卸柜审核成功");
statusName.set(146, "已卸柜");

statusName.set(151, "未结算");
statusName.set(152, "结算中");
statusName.set(153, "已结算");

const seaBaseData = () => {
  return [
    [
      {
        title: "订舱",
        imgSrc: {
          start: require("@/assets/images/shipping/dc-start.png"),
          end: require("@/assets/images/shipping/dc-end.png"),
        },
        type: "booking", // 类型
        /**
         * 订舱状态：11、未订舱；12、已订舱
         */
        voName: "bookSeaInfo", // 订舱对象vo
        keyName: "bkStatus",
        status: {
          start: [11],
          wait: [],
          end: [12],
        },
      },
    ],
    [
      {
        title: "预装",
        imgSrc: {
          start: require("@/assets/images/shipping/yz-start.png"),
          wait: require("@/assets/images/shipping/yz-wait.png"),
          end: require("@/assets/images/shipping/yz-end.png"),
        },
        type: "preinstall",
        /**
         * 预装状态：21、未预装；22、预装审核中；23、预装审核失败；24、预装审核成功
         */
        voName: "preInstallInfo",
        keyName: "prStatus",
        status: {
          start: [21],
          wait: [22, 23],
          end: [24],
        },
      },
      {
        title: "拖车",
        imgSrc: {
          start: require("@/assets/images/shipping/tc-start.png"),
          wait: require("@/assets/images/shipping/tc-wait.png"),
          end: require("@/assets/images/shipping/tc-end.png"),
        },
        type: "trailer",
        /**
         * 拖车状态：31、未派车；32、已派车
         */
        voName: "trailerInfo",
        keyName: "tlStatus",
        status: {
          start: [31],
          wait: [],
          end: [32],
        },
      },
      {
        title: "AGENT",
        imgSrc: {
          start: require("@/assets/images/shipping/agent-start.png"),
          wait: require("@/assets/images/shipping/agent-wait.png"),
          end: require("@/assets/images/shipping/agent-end.png"),
        },
        type: "agent",
        voName: "agentInfo",
        currStatus: "start",
      },
    ],
    [
      {
        title: "装柜",
        imgSrc: {
          start: require("@/assets/images/shipping/zg-start.png"),
          wait: require("@/assets/images/shipping/zg-wait.png"),
          end: require("@/assets/images/shipping/zg-end.png"),
        },
        type: "cabinet",
        /**
         * 装柜状态：41、未装柜；42、装柜中；43、已装柜、待封柜；44、封柜审核中；45、封柜审核失败；46、封柜审核成功
         */
        voName: "cabinetInfo",
        keyName: "ldStatus",
        status: {
          start: [41],
          wait: [42, 43, 44, 45],
          end: [46],
        },
      },
    ],
    [
      {
        title: "报关",
        imgSrc: {
          start: require("@/assets/images/shipping/bg-start.png"),
          wait: require("@/assets/images/shipping/bg-wait.png"),
          end: require("@/assets/images/shipping/bg-end.png"),
        },
        type: "cusDeclaration",
        voName: "customsInfo",
        /**
         *报关状态：51、未报关；52、报关中；53、已报关
         */
        keyName: "dcStatus",
        status: {
          start: [51],
          wait: [52],
          end: [53],
        },
      },
      {
        title: "配船",
        imgSrc: {
          start: require("@/assets/images/shipping/pc-start.png"),
          wait: require("@/assets/images/shipping/pc-wait.png"),
          end: require("@/assets/images/shipping/pc-end.png"),
        },
        type: "ship",
        /**
         * 配船状态：61、未配船；62、已配船
         */
        voName: "shipConfigInfo",
        keyName: "saStatus",
        status: {
          start: [61],
          wait: [],
          end: [62],
        },
      },
      {
        title: "提单补料",
        imgSrc: {
          start: require("@/assets/images/shipping/tdcl-start.png"),
          wait: require("@/assets/images/shipping/tdcl-wait.png"),
          end: require("@/assets/images/shipping/tdcl-end.png"),
        },
        type: "subMaterial",
        /**
         * 提单补料状态：71、未提单补料；72、已提单补料
         */
        voName: "ladingBillInfo",
        keyName: "blStatus",
        status: {
          start: [71],
          wait: [],
          end: [72],
        },
      },
    ],
    [
      {
        title: "驳船",
        imgSrc: {
          start: require("@/assets/images/shipping/bc-start.png"),
          wait: require("@/assets/images/shipping/bc-wait.png"),
          end: require("@/assets/images/shipping/bc-end.png"),
        },
        type: "barge",
        /**
         * 驳船状态：81、未驳船；82、已驳船
         */
        voName: "bargeInfo",
        keyName: "bgStatus",
        status: {
          start: [81],
          wait: [],
          end: [82],
        },
      },
    ],
    [
      {
        title: "起运",
        imgSrc: {
          start: require("@/assets/images/shipping/qy-start.png"),
          wait: require("@/assets/images/shipping/qy-wait.png"),
          end: require("@/assets/images/shipping/qy-end.png"),
        },
        type: "departure",
        /**
         * 起运状态：91、未起运；92、已起运
         */
        voName: "shippingInfo",
        keyName: "dtStatus",
        status: {
          start: [91],
          wait: [],
          end: [92],
        },
      },
    ],
    [
      {
        title: "提单Copy",
        imgSrc: {
          start: require("@/assets/images/shipping/tdcopy-start.png"),
          wait: require("@/assets/images/shipping/tdcopy-wait.png"),
          end: require("@/assets/images/shipping/tdcopy-end.png"),
        },
        type: "blCopy",
        /**
         * 提单COPY状态：101、未上传；102、已上传
         */
        voName: "ladingCopyInfo",
        keyName: "cpStatus",
        status: {
          start: [101],
          wait: [],
          end: [102],
        },
      },
      {
        type: "clrDocument",
        imgSrc: {
          start: require("@/assets/images/shipping/qg-start.png"),
          wait: require("@/assets/images/shipping/qg-wait.png"),
          end: require("@/assets/images/shipping/qg-end.png"),
        },
        title: "清关文件",
        /**
         * 清关文件状态：111、未清关文件；112、已清关文件
         */
        voName: "clearanceDocInfo",
        keyName: "cdStatus",
        status: {
          start: [111],
          wait: [],
          end: [112],
        },
      },
    ],
    [
      {
        title: "到港",
        imgSrc: {
          start: require("@/assets/images/shipping/dg-start.png"),
          wait: require("@/assets/images/shipping/dg-wait.png"),
          end: require("@/assets/images/shipping/dg-end.png"),
        },
        type: "arrival",
        /**
         * 到港状态：121、未到港；112、已到港
         */
        voName: "arrivalInfo",
        keyName: "apStatus",
        status: {
          start: [121],
          wait: [],
          end: [122],
        },
      },
    ],
    [
      {
        title: "清关",
        imgSrc: {
          start: require("@/assets/images/shipping/qg-start.png"),
          wait: require("@/assets/images/shipping/qg-wait.png"),
          end: require("@/assets/images/shipping/qg-end.png"),
        },
        type: "cusClearance",
        /**
         * 清关状态：131、未清关；132、已清关
         */
        voName: "clearanceInfo",
        keyName: "clStatus",
        status: {
          start: [131],
          wait: [],
          end: [132],
        },
      },
    ],
    [
      {
        title: "卸柜",
        imgSrc: {
          start: require("@/assets/images/shipping/xg-start.png"),
          wait: require("@/assets/images/shipping/xg-wait.png"),
          end: require("@/assets/images/shipping/xg-end.png"),
        },
        type: "unloading",
        /**
         * 卸柜状态：141、未卸柜；142、卸柜中；143、卸柜审核中；144、卸柜审核失败；145、卸柜审核成功；146、已卸柜
         */
        voName: "cabinetUnloadInfo",
        keyName: "ulStatus",
        status: {
          start: [141],
          wait: [142, 143, 144, 145],
          end: [146],
        },
      },
    ],
    [
      {
        title: "结算",
        imgSrc: {
          start: require("@/assets/images/shipping/js-start.png"),
          wait: require("@/assets/images/shipping/js-wait.png"),
          end: require("@/assets/images/shipping/js-end.png"),
        },
        type: "settlement",
        /**
         * 结算状态：151、未结算；152、结算中；153、已结算
         */
        voName: "settlementInfo",
        keyName: "slStatus",
        status: {
          start: [151],
          wait: [152],
          end: [153],
        },
      },
    ],
  ];
};

const constantDict = {
  // 配船状态
  saExmtStatus: [
    {
      value: "1",
      label: "免配",
    },
    {
      value: "2",
      label: "已配",
    },
  ],
  // 驳船
  bgExmtStatus: [
    {
      value: "1",
      label: "无驳船",
    },
    {
      value: "2",
      label: "有驳船",
    },
  ],
  // 出单方式
  billingMethod: [
    {
      value: "1",
      label: "电放",
    },
    {
      value: "2",
      label: "正本",
    },
  ],
  // 是否有文件
  isFile: [
    {
      value: "1",
      label: "无需",
    },
    {
      value: "2",
      label: "已做",
    },
  ],
};

function formatStringNumber(obj, keys) {
  for (const [key, value] of Object.entries(obj)) {
    if (keys.includes(key) && !Number.isNaN(Number(value))) {
      obj[key] = Number(value);
    }
  }
  return obj;
}

function formatNumberString(obj, keys) {
  for (const [key, value] of Object.entries(obj)) {
    if (keys.includes(key) && value) {
      obj[key] = String(value);
    }
  }
  return obj;
}

function formatDateStr(obj, keys, format = "YYYY-MM-DD") {
  for (const [key, value] of Object.entries(obj)) {
    if (keys.includes(key) && dayjs(value).isValid()) {
      obj[key] = dayjs(value).format(format);
    }
  }
  return obj;
}

export const fileTypes = [
  "doc",
  "xls",
  "ppt",
  "txt",
  "pdf",
  "png",
  "jpg",
  "jpeg",
];

export {
  statusName,
  seaBaseData,
  constantDict,
  formatStringNumber,
  formatDateStr,
  formatNumberString,
};
