import { h } from "./dom.js";
import { icon, spinner } from "./icons.js";
import { statusIcon, statusLabel } from "./status.js";
export function pageHeader(title, description, actions) {
return h(
"header",
{ class: "page-header" },
h("div", null, h("h1", null, title), h("p", null, description)),
actions && actions.length ? h("div", { class: "page-actions" }, actions) : null,
);
}
export function loading() {
return h(
"div",
{ class: "loading" },
spinner(24),
h("span", null, "Reading local configuration…"),
);
}
export function loadFailure(onRetry, onDiagnostics) {
return h(
"section",
{ class: "load-failure" },
icon("circle-x", 24),
h("h1", null, "Configuration could not be read"),
h(
"p",
null,
"GitBound has stopped before offering any write actions. Fix the reported error, then retry.",
),
h(
"div",
{ class: "button-row" },
h(
"button",
{ class: "primary", onClick: () => void onRetry() },
icon("refresh-cw", 16),
"Retry",
),
h(
"button",
{ class: "secondary", onClick: onDiagnostics },
icon("monitor-cog", 16),
"Open diagnostics",
),
),
);
}
export function statusGlyph(status) {
return icon(statusIcon(status), 15);
}
export function badge(status, text) {
return h("span", { class: `badge ${status}` }, statusGlyph(status), text ?? statusLabel(status));
}
export function initials(name) {
const parts = String(name ?? "").trim().split(/\s+/).filter(Boolean);
if (parts.length === 0) return "–";
if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();
return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
}
export function relativeTime(iso) {
const then = Date.parse(iso ?? "");
if (Number.isNaN(then)) return "—";
const seconds = Math.round((Date.now() - then) / 1000);
if (seconds < 60) return "just now";
const minutes = Math.round(seconds / 60);
if (minutes < 60) return `${minutes} min ago`;
const hours = Math.round(minutes / 60);
if (hours < 24) return `${hours} h ago`;
const days = Math.round(hours / 24);
if (days < 30) return `${days} d ago`;
return new Date(then).toLocaleDateString();
}
export function displayPath(path) {
if (typeof path !== "string") return "";
if (path.startsWith("\\\\?\\UNC\\")) return "\\\\" + path.slice(8);
if (path.startsWith("\\\\?\\")) return path.slice(4);
return path;
}