'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { AlertTriangle, ChevronLeft, ChevronRight, Loader2 } from 'lucide-react';
// ─── Field-type badges ─────────────────────────────────────────────────────
/** Map a field type onto a semantic colour pair (background + text). */
function fieldTypeTone(type) {
    switch (type) {
        case 'email':
        case 'url':
        case 'date':
        case 'number':
            return 'bg-info/10 text-info';
        case 'phone':
        case 'textarea':
            return 'bg-primary/10 text-primary';
        case 'select':
        case 'multiselect':
        case 'radio':
            return 'bg-warning/10 text-warning';
        case 'checkbox':
        case 'consent':
            return 'bg-success/10 text-success';
        case 'file':
            return 'bg-destructive/10 text-destructive';
        default:
            return 'bg-muted text-muted-foreground';
    }
}
const FIELD_TYPE_LABELS = {
    text: 'TEXT',
    email: 'EMAIL',
    phone: 'PHONE',
    textarea: 'TEXTAREA',
    select: 'SELECT',
    multiselect: 'MULTI',
    radio: 'RADIO',
    checkbox: 'CHECKBOX',
    date: 'DATE',
    number: 'NUMBER',
    url: 'URL',
    hidden: 'HIDDEN',
    file: 'FILE',
    consent: 'CONSENT',
    richtext: 'CONTENT',
    divider: 'DIVIDER',
    honeypot: 'HONEYPOT',
};
export function FieldTypeBadge({ type }) {
    return (_jsx("span", { className: `inline-flex items-center rounded-md px-1.5 py-0.5 text-[10px] font-medium tracking-wide uppercase ${fieldTypeTone(type)}`, children: FIELD_TYPE_LABELS[type] ?? type }));
}
// ─── Status badges ─────────────────────────────────────────────────────────
const STATUS_META = {
    active: { label: 'Active', cls: 'bg-success/10 text-success', dot: 'bg-success' },
    draft: { label: 'Draft', cls: 'bg-warning/10 text-warning', dot: 'bg-warning' },
    archived: {
        label: 'Archived',
        cls: 'bg-muted text-muted-foreground',
        dot: 'bg-muted-foreground',
    },
};
export function FormStatusBadge({ status }) {
    const meta = STATUS_META[status] ?? STATUS_META.draft;
    return (_jsxs("span", { className: `inline-flex items-center gap-1.5 rounded-full px-2.5 py-0.5 text-xs font-medium ${meta.cls}`, children: [_jsx("span", { className: `h-1.5 w-1.5 rounded-full ${meta.dot}`, "aria-hidden": true }), meta.label] }));
}
/** Small red count badge for unread submissions. Hidden when count is 0. */
export function UnreadBadge({ count, className = '' }) {
    if (count <= 0)
        return null;
    return (_jsx("span", { className: `bg-destructive text-destructive-foreground inline-flex min-w-5 items-center justify-center rounded-full px-1.5 py-0.5 text-xs font-medium tabular-nums ${className}`, "aria-label": `${count} unread`, children: count > 99 ? '99+' : count }));
}
// ─── Summary chips ───────────────────────────────────────────────────────
export function SummaryChip({ value, label, tone = 'neutral', }) {
    const valueCls = tone === 'success'
        ? 'text-success'
        : tone === 'warning'
            ? 'text-warning'
            : tone === 'destructive'
                ? 'text-destructive'
                : 'text-foreground';
    return (_jsxs("div", { className: "border-border bg-card flex items-baseline gap-1.5 rounded-lg border px-3 py-2", children: [_jsx("span", { className: `text-base font-medium tabular-nums ${valueCls}`, children: value }), _jsx("span", { className: "text-muted-foreground text-sm", children: label })] }));
}
// ─── States ──────────────────────────────────────────────────────────────
export function FormsLoading({ label = 'Loading…' }) {
    return (_jsxs("div", { className: "flex h-64 items-center justify-center", role: "status", "aria-live": "polite", children: [_jsx(Loader2, { className: "text-muted-foreground h-6 w-6 animate-spin", "aria-hidden": true }), _jsx("span", { className: "sr-only", children: label })] }));
}
export function FormsEmptyState({ icon, title, description, action, }) {
    return (_jsxs("div", { className: "border-border flex flex-col items-center justify-center rounded-lg border border-dashed px-6 py-12 text-center", children: [icon && (_jsx("div", { className: "text-muted-foreground mb-3", "aria-hidden": true, children: icon })), _jsx("h3", { className: "text-foreground text-base font-medium", children: title }), description && _jsx("p", { className: "text-muted-foreground mt-1 max-w-md text-sm", children: description }), action && _jsx("div", { className: "mt-4", children: action })] }));
}
export function FormsErrorState({ message, onRetry }) {
    return (_jsxs("div", { className: "border-destructive/30 bg-destructive/5 flex items-center gap-3 rounded-lg border p-3", role: "alert", children: [_jsx(AlertTriangle, { className: "text-destructive h-5 w-5 shrink-0", "aria-hidden": true }), _jsx("span", { className: "text-destructive flex-1 text-sm", children: message }), onRetry && (_jsx("button", { onClick: onRetry, className: "border-border text-foreground hover:bg-accent rounded-md border px-3 py-1 text-sm transition-colors", children: "Retry" }))] }));
}
// ─── Pagination ────────────────────────────────────────────────────────────
/**
 * Return up to 7 page-control entries: a sliding window around the current
 * page with ellipsis markers, so the footer stays narrow on large datasets.
 */
function pageWindow(current, total) {
    if (total <= 7)
        return Array.from({ length: total }, (_, i) => i + 1);
    const out = [1];
    const start = Math.max(2, current - 1);
    const end = Math.min(total - 1, current + 1);
    if (start > 2)
        out.push('gap');
    for (let i = start; i <= end; i++)
        out.push(i);
    if (end < total - 1)
        out.push('gap');
    out.push(total);
    return out;
}
/**
 * Token-only pagination footer matching the Posts/Pages list styling. Renders
 * a "start–end of total" summary plus prev / numbered / next controls. Hidden
 * when there is a single page of results.
 */
export function FormsPagination({ page, pageSize, total, onPageChange, noun = 'result', label = 'Pagination', }) {
    const totalPages = Math.max(1, Math.ceil(total / pageSize));
    if (totalPages <= 1)
        return null;
    const start = total === 0 ? 0 : (page - 1) * pageSize + 1;
    const end = Math.min(total, page * pageSize);
    return (_jsxs("div", { className: "border-border flex items-center justify-between border-t px-4 py-3 text-sm", children: [_jsxs("span", { className: "text-muted-foreground tabular-nums", children: [start, "\u2013", end, " of ", total, " ", noun, total === 1 ? '' : 's'] }), _jsxs("nav", { className: "flex items-center gap-1", "aria-label": label, children: [_jsx("button", { type: "button", onClick: () => onPageChange(Math.max(1, page - 1)), disabled: page === 1, "aria-label": "Previous page", className: "border-border bg-background text-foreground hover:bg-accent focus-visible:ring-ring inline-flex h-8 w-8 items-center justify-center rounded-md border transition-colors focus-visible:ring-2 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-40", children: _jsx(ChevronLeft, { className: "h-4 w-4", "aria-hidden": true }) }), pageWindow(page, totalPages).map((p, idx) => p === 'gap' ? (_jsx("span", { "aria-hidden": true, className: "text-muted-foreground inline-flex h-8 w-8 items-center justify-center", children: "\u2026" }, `gap-${idx}`)) : (_jsx("button", { type: "button", onClick: () => onPageChange(p), "aria-current": p === page ? 'page' : undefined, className: `focus-visible:ring-ring inline-flex h-8 w-8 items-center justify-center rounded-md text-sm tabular-nums transition-colors focus-visible:ring-2 focus-visible:outline-none ${p === page
                            ? 'bg-primary text-primary-foreground'
                            : 'border-border bg-background text-foreground hover:bg-accent border'}`, children: p }, p))), _jsx("button", { type: "button", onClick: () => onPageChange(Math.min(totalPages, page + 1)), disabled: page === totalPages, "aria-label": "Next page", className: "border-border bg-background text-foreground hover:bg-accent focus-visible:ring-ring inline-flex h-8 w-8 items-center justify-center rounded-md border transition-colors focus-visible:ring-2 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-40", children: _jsx(ChevronRight, { className: "h-4 w-4", "aria-hidden": true }) })] })] }));
}
// ─── Button helpers (token-only) ─────────────────────────────────────────
export const btnPrimary = 'inline-flex items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 text-base font-medium text-primary-foreground transition-colors hover:bg-primary/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60';
export const btnSecondary = 'inline-flex items-center justify-center gap-2 rounded-md border border-border bg-card px-4 py-2 text-base font-medium text-foreground transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60';
export const btnGhostIcon = 'inline-flex items-center justify-center rounded-md p-2 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring';
//# sourceMappingURL=primitives.js.map