import {getStatusTag} from "utils/statusUtils/Base";
import * as DateUtils from "utils/DateUtils";

const confirm = { color: "#1D8735", eng: "Pass for printing", cht: "可以付印", cn: "可以付印" } // was #22a13f
const unable = { color: "#d9372b", eng: "Re-proofing", cht: "未能付印", cn: "未能付印" } // unchanged
const timeOut = { color: "#797674", eng: "Proofing timed out. Please apply again", cht: "校對回覆逾時，請重新申請", cn: "校对回复逾时，请重新申请" } // was #8a8784
const pendingReply = { color: "#9D6C27", eng: "Proofing reply pending", cht: "校對待覆", cn: "校对待复" } // was #f5a83d
const cancel = { color: "#000", textColor: "#fff", eng: "Cancelled", cht: "已取消", cn: "已取消" } // unchanged

export function getStatus_Cht(params) {
    let status = getStatus(params);
    return getStatusTag({color: status.color, textColor:status.textColor, text:status.cht })
}

export function getStatus_Eng(params) {
    let status = getStatus(params);
    return getStatusTag({color: status.color, textColor:status.textColor, text:status.eng})
}

export function getStatus_Cn(params) {
    let status = getStatus(params);
    return getStatusTag({color: status.color, textColor:status.textColor, text:status.cn })
}


export function getStatusText_Cht(params) {
    let status = getStatus(params);
    return {text:status.cht,status:status.eng}
}

export function getStatusText_Eng(params) {
    let status = getStatus(params);
    return {text:status.eng,status:status.eng}
}

function getStatus(params) {
    // console.log(params)
    let replyDate = params.row?params.row.replyDate:params.replyDate;
    let action = params.row?params.row.action:params.action;
    let proofPaymentDeadline = params.row?params.row.proofPaymentDeadline:params.proofPaymentDeadline;
    let isCancelled = params.row?params.row.cancelled:params.cancelled;
    
    if(isCancelled) return cancel;
    
    // console.log(replyDate)
    if(replyDate){
        return action?confirm:unable;
    }else{
        return isOverTime(proofPaymentDeadline)? timeOut: pendingReply;
    }
}

const isOverTime = (proofPaymentDeadline) => {
    if (!proofPaymentDeadline) return true;
    proofPaymentDeadline = DateUtils.convertToDate(proofPaymentDeadline);
    let current = new Date();
    return current.getTime() > proofPaymentDeadline.getTime();
}

