import { ElMessage } from "element-plus";
import { eStatusOfFilerCertification } from "@/components/ApproveStatus/status";
import { router } from "@/router";
import { deleteAuth } from "@/service/copyrightService";
import { showTip } from "@/components/GlobalMount/api";

export default class Service {
  static instance: Service;
  static getInstance() {
    if (Service.instance) return Service.instance;
    else {
      Service.instance = new Service();
      return Service.instance;
    }
  }

  getOperateListOfFilterStatus() {
    // 待审核:WAITING_CHECK 通过:PASSED 不通过:NOT_PASSED
    return [
      { name: "待审核", value: eStatusOfFilerCertification.WAITING_CHECK },
      { name: "通过", value: eStatusOfFilerCertification.PASSED },
      { name: "不通过", value: eStatusOfFilerCertification.NOT_PASSED },
      { name: "所有状态", value: eStatusOfFilerCertification.ALL },
    ];
  }

  getOperateListOfAction(status: eStatusOfFilerCertification) {
    const seeDetail = {
      name: "查看详情",
      value: "seeDetail",
    };
    const edit = {
      name: "编辑",
      value: "edit",
    };
    const del = {
      name: "删除",
      value: "del",
    };
    if (status === eStatusOfFilerCertification.NOT_PASSED) {
      return [seeDetail, edit, del];
    } else if (status === eStatusOfFilerCertification.PASSED) {
      return [seeDetail];
    } else if (status === eStatusOfFilerCertification.WAITING_CHECK) {
      return [seeDetail];
    }
  }

  handleClickOperateItemOfAction(
    operateValue: string,
    slotProps: any,
    emit: any
  ) {
    if (operateValue === "seeDetail") {
      router.push({
        name: "filingPersonDetail",
        query: {
          id: slotProps.id,
        },
      });
    } else if (operateValue === "edit") {
      emit("edit", {
        id: slotProps.id,
      });
    } else if (operateValue === "del") {
      showTip("此操作将删除该备案人, 是否继续?", async () => {
        const ret = await deleteAuth(slotProps.id);
        if (ret && ret.code === 200) {
          ElMessage.success("删除成功");
          emit("refresh");
        }
      });
    }
  }
}
