import { CALL_BUSY, CALL_CANCELLED, CALL_ENDED, CALL_INITIATED, CALL_ONGOING, CALL_REJECTED, CALL_UNANSWERED, } from '../shared/constants/UIKitConstants';
import { localize } from '../shared/resources/CometChatLocalize';
export class CallUtils {
    static isInitiator(initiator, loggedInUser) {
        return initiator.getUid() == loggedInUser?.getUid();
    }
    static getCallStatus(message, loggedInUser) {
        try {
            // if (!(message instanceof CometChat.Call)) return '';
            let call = message;
            let callMessageText = '';
            let initiator = (call?.getCallInitiator && call?.getCallInitiator()) || call.getInitiator();
            switch (call.getStatus()) {
                case CALL_INITIATED:
                    if (this.isInitiator(initiator, loggedInUser)) {
                        callMessageText = `${localize(`OUTGOING_CALL`)}`;
                    }
                    else {
                        callMessageText = `${localize(`INCOMING_CALL`)}`;
                    }
                    break;
                case CALL_ONGOING:
                    callMessageText = `${localize(`CALL_ACCEPTED`)}`;
                    break;
                case CALL_ENDED:
                    callMessageText = `${localize(`CALL_ENDED`)}`;
                    break;
                case CALL_UNANSWERED:
                    if (this.isInitiator(initiator, loggedInUser)) {
                        callMessageText = `${localize('UNANSWERED_CALL')}`;
                    }
                    else {
                        callMessageText = `${localize('MISSED_CALL')}`;
                    }
                    break;
                case CALL_CANCELLED:
                    if (this.isInitiator(initiator, loggedInUser)) {
                        callMessageText = `${localize('CANCELLED_CALL')}`;
                    }
                    else {
                        callMessageText = `${localize('MISSED_CALL')}`;
                    }
                    break;
                case CALL_REJECTED:
                    callMessageText = `${localize('CALL_REJECTED')}`;
                    break;
                case CALL_BUSY:
                    if (this.isInitiator(initiator, loggedInUser)) {
                        callMessageText = `${localize('CALL_BUSY')}`;
                    }
                    else {
                        callMessageText = `${localize('MISSED_CALL')}`;
                    }
                    break;
            }
            if (callMessageText == undefined || callMessageText == "undefined")
                console.log(message, loggedInUser);
            return callMessageText;
        }
        catch (e) {
            console.log("__CATCH", e);
            return "";
        }
    }
    static isMissedCall(call, loggedInUser) {
        const callStatus = call.getStatus();
        if (this.isInitiator(call.getInitiator(), loggedInUser)) {
            return callStatus === CALL_UNANSWERED;
        }
        else {
            return [
                CALL_BUSY,
                CALL_UNANSWERED,
                CALL_REJECTED,
                CALL_CANCELLED,
            ].includes(callStatus);
        }
    }
    static convertMinutesToHoursMinutesSeconds(minutes) {
        const hours = Math.floor(minutes / 60);
        const remainingMinutes = Math.floor(minutes % 60);
        const seconds = Math.floor((minutes - Math.floor(minutes)) * 60);
        let hoursString = "";
        let minutesString = "";
        let secondsString = "";
        if (hours > 0) {
            hoursString = `${hours}h`;
        }
        if (remainingMinutes > 0) {
            minutesString = `${remainingMinutes}m`;
        }
        if (seconds >= 0) {
            secondsString = `${seconds}s`;
        }
        return hoursString ? `${hoursString} ${minutesString} ${secondsString}` : minutesString ? `${minutesString} ${secondsString}` : secondsString;
    }
    static convertSecondsToHoursMinutesSeconds(seconds) {
        const hours = Math.floor(seconds / 3600);
        const remainingMinutes = Math.floor((seconds % 3600) / 60);
        const remainingSeconds = Math.floor((seconds % 3600) % 60);
        let hoursString = "";
        let minutesString = "";
        let secondsString = "";
        if (hours > 0) {
            hoursString = `${hours}h`;
        }
        if (remainingMinutes > 0) {
            minutesString = `${remainingMinutes}m`;
        }
        if (remainingSeconds >= 0) {
            secondsString = `${remainingSeconds}s`;
        }
        return hoursString ? `${hoursString} ${minutesString} ${secondsString}` : minutesString ? `${minutesString} ${secondsString}` : secondsString;
    }
}
//# sourceMappingURL=CallUtils.js.map