import { userInfosStore } from "../../store/store";
import { getConnectionId } from "../../utils/func";
export const getPriorityConfig = (priority) => {
    const configs = {
        low: { label: 'ต่ำ', color: 'bg-blue-400' },
        medium: { label: 'กลาง', color: 'bg-yellow-400' },
        high: { label: 'สูง', color: 'bg-red-400' },
    };
    return configs[priority];
};
export const formatTimeRemaining = (dueDate, status) => {
    if (status === 'closed')
        return '';
    const now = new Date();
    const due = new Date(dueDate);
    const diffMs = due.getTime() - now.getTime();
    const diffMins = Math.floor(diffMs / (1000 * 60));
    const diffHours = Math.floor(diffMins / 60);
    const diffDays = Math.floor(diffHours / 24);
    if (diffDays > 0)
        return `(${diffDays}d)`;
    if (diffHours > 0)
        return `(${diffHours}:${String(diffMins % 60).padStart(2, '0')})`;
    if (diffMins > 0)
        return `(${diffMins}m)`;
    return '(overdue)';
};
export const getBusinessUser = (connectionItem) => {
    const connectionId = getConnectionId(connectionItem);
    const userInfo = userInfosStore.get(connectionId);
    const zdeskBusinessId = connectionItem.type === 'zwiz' ? connectionItem.bot_id : '';
    const businessUser = userInfo?.userProfile.business_users.find(user => user.business_id === zdeskBusinessId);
    return businessUser;
};
