import moment from "moment";
import { revertSeconds } from '@/utils/dateUtils'

function timeFormatter(date) {
    if (date === null || date === undefined) {
        return ''
    }
    return moment(date).format('yyyy-MM-DD HH:mm:ss');
}
function formatCellValueTime(row, column, cellValue) {
    if (cellValue === null || cellValue === '') {
        return ''
    }
    try {
        return moment(cellValue).format('yyyy-MM-DD HH:mm:ss')
    }catch {
        return cellValue
    }
}

function dateFormatter(date) {
    if (date === null || date === undefined) {
        return ''
    }
    return moment(date).format('yyyy-MM-DD');
}

function dueFormatter(date) {
    if (date === null || date === undefined) {
        return ''
    }
    return revertSeconds(moment(new Date().getTime()).diff(moment(date), 'seconds'));
}

function taskStatusFormatter(value) {
    switch (value) {
        case 0:
            return '任务新建，待下发'
        case 1:
            return '任务已下发'
        case 2:
            return '任务开始执行'
        case 3:
            return '出库完成'
        case 4:
            return '输送线转运中'
        case 5:
            return '到达拣选站台'
        case 6:
            return '正在拣货'
        case 7:
            return '正在回库'
        case 8:
            return '盘点中'
        case 100:
            return '任务完成'
        case 998:
            return '任务取消'
        case 999:
            return '任务异常'
        default:
            return '未完成'
    }
}

function locationFormatter(locationId) {
    if (locationId === null || locationId == undefined) {
        return ''
    }
    const parts = locationId.split('-');
    if (parts.length === 4) {
        return parts[0] + '排' + parts[1] + '列' + parts[2] + '层' + parts[3] + '深';
      } else if (parts.length === 3) {
        return parts[0] + '排' + parts[1] + '列' + parts[2] + '层';
      } else {
        return '格式错误';
      }
    // const parts = locationId.split('-');
    // return parts[0] + '排' + parts[1] + '列' + parts[2] + '层' + parts[3] + '深度';
    //return locationId.substr(0, 2) + '排' + locationId.substr(2, 2) + '列' + locationId.substr(4, 2) + '层'
}

function kateTaskStatusFormatter(value) {
    switch (value) {
        case 0:
            return '待下发'
        case 1:
            return '已下发'
        case 2:
            return '执行中'
        case 3:
            return '正在拣货'
        case 5:
            return '任务完成'
        default:
            return '异常状态'
    }
}

function pickingStatusFormatter(value) {
    switch (value) {
        case 0:
            return '待拣货'
        case 1:
            return '正在拣货'
        case 2:
            return '拣货完成'
        default:
            return '未拣货'
    }
}

function vehicleStatusFormatter(value) {
    switch (value) {
        case 1:
            return '入库中'
        case 2:
            return '在库中'
        case 3:
            return '出库中'
        default:
            return '异常状态'
    }
}

function kateTaskTypeFormatter(value) {
    switch (value) {
        case 1:
            return '配件'
        case 2:
            return '合件'
        case 3:
            return '紧急'
        case 4:
            return '原包装'
        default:
            return '任务类型异常'
    }
}


export {
    timeFormatter,
    dateFormatter,
    taskStatusFormatter,
    locationFormatter,
    kateTaskStatusFormatter,
    pickingStatusFormatter,
    vehicleStatusFormatter,
    kateTaskTypeFormatter,
    dueFormatter,
    formatCellValueTime
}