function isLinkedAwaitingSelfChat(status) {
    return (status.enabled === true &&
        status.provider === 'whatsapp' &&
        !status.lastError &&
        !status.qrText &&
        !status.pairedChatId);
}
export function describePhoneStatusTransitionForCli(previousStatus, nextStatus) {
    if (previousStatus.provider === 'whatsapp' &&
        previousStatus.qrText &&
        isLinkedAwaitingSelfChat(nextStatus)) {
        return 'WhatsApp linked. Open Message yourself in WhatsApp and send a message there to finish connecting Shorty.';
    }
    if (!previousStatus.pairedChatId &&
        nextStatus.pairedChatId &&
        nextStatus.provider === 'whatsapp') {
        if (nextStatus.currentDesktopIsActiveTarget === false && nextStatus.activeDesktopLabel) {
            return `WhatsApp self-chat connected. Phone prompts currently route to ${nextStatus.activeDesktopLabel}. Run /shorty whatsapp here to take over.`;
        }
        return 'WhatsApp self-chat connected. Phone prompts and approvals now route to this desktop.';
    }
    return null;
}
export async function withPhoneStatusNotifications(phoneManager, onInfo, run) {
    const unsubscribe = phoneManager.subscribe((status, previousStatus) => {
        const info = describePhoneStatusTransitionForCli(previousStatus, status);
        if (info) {
            onInfo(info);
        }
    });
    try {
        return await run();
    }
    finally {
        unsubscribe();
    }
}
//# sourceMappingURL=phone-status-notifications.js.map