"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Header = Header;
const jsx_runtime_1 = require("react/jsx-runtime");
const ink_1 = require("ink");
const NavigationContext_1 = require("../state/NavigationContext");
const TrelloContext_1 = require("../state/TrelloContext");
function Header() {
    const { state: navState, config } = (0, NavigationContext_1.useNavigation)();
    const { state: trelloState } = (0, TrelloContext_1.useTrello)();
    let title = "Trello CLI";
    let visibleInfo = "";
    if (navState.view === "board" && trelloState.currentBoard) {
        if (navState.mode !== "normal") {
            // Show breadcrumb: Board / List / Card Title
            const currentList = trelloState.lists[navState.selectedListIndex];
            const cards = currentList
                ? trelloState.cardsByList[currentList.id] || []
                : [];
            const card = cards[navState.selectedCardIndex];
            const parts = [trelloState.currentBoard.name];
            if (currentList)
                parts.push(currentList.name);
            if (card)
                parts.push(card.name);
            title = parts.join(" / ");
        }
        else {
            title = trelloState.currentBoard.name;
            const listCount = trelloState.lists.length;
            if (listCount > 0) {
                visibleInfo = ` (${listCount} lists)`;
            }
        }
    }
    else if (navState.view === "my-cards") {
        title = "My Assigned Cards";
    }
    return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { borderStyle: "single", borderBottom: true, borderTop: false, borderLeft: false, borderRight: false, paddingX: 1, justifyContent: "space-between", children: [(0, jsx_runtime_1.jsxs)(ink_1.Text, { bold: true, color: config.theme.primary, children: [title, (0, jsx_runtime_1.jsx)(ink_1.Text, { color: config.theme.muted, children: visibleInfo })] }), (0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [trelloState.loading && ((0, jsx_runtime_1.jsx)(ink_1.Text, { color: config.theme.warning, children: " Loading... " })), trelloState.error && ((0, jsx_runtime_1.jsxs)(ink_1.Text, { color: config.theme.error, children: [" ", trelloState.error, " "] })), navState.statusMessage && ((0, jsx_runtime_1.jsxs)(ink_1.Text, { color: config.theme.accent, children: [" ", navState.statusMessage, " "] })), trelloState.lastSynced && !trelloState.loading && ((0, jsx_runtime_1.jsxs)(ink_1.Text, { color: config.theme.muted, children: [" ", "Synced ", formatTimeSince(trelloState.lastSynced), " "] }))] })] }));
}
function formatTimeSince(date) {
    const seconds = Math.floor((Date.now() - date.getTime()) / 1000);
    if (seconds < 60)
        return "just now";
    if (seconds < 3600)
        return `${Math.floor(seconds / 60)}m ago`;
    return `${Math.floor(seconds / 3600)}h ago`;
}
