'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useId, useState } from 'react';
import { Loader2 } from 'lucide-react';
import { MAX_CONCURRENT_SESSION_OPTIONS } from '@actuate-media/cms-core/security-center';
import { ConfirmDangerousSettingDialog } from './components.js';
import { SecurityCard, StatusRow } from './securityPrimitives.js';
function sessionsLabel(n) {
    return n === 0 ? 'Unlimited' : String(n);
}
export function SessionPolicyCard({ form, setField, canEdit, sessionMaxAgeHours, activeSessions, revokeState, onRevokeAll, }) {
    const headingId = useId();
    const maxId = useId();
    const [confirmRevoke, setConfirmRevoke] = useState(false);
    const maxAgeDays = Math.round(sessionMaxAgeHours / 24);
    return (_jsxs(SecurityCard, { headingId: headingId, title: "Session Policy", description: "Control how many sessions an account can hold and revoke active sessions.", children: [_jsx("div", { className: "space-y-4", children: _jsxs("div", { className: "flex items-center justify-between gap-4", children: [_jsxs("label", { htmlFor: maxId, className: "flex-1", children: [_jsx("span", { className: "text-foreground text-base font-medium", children: "Maximum concurrent sessions" }), _jsx("p", { className: "text-muted-foreground mt-0.5 text-sm", children: "Oldest sessions are signed out when a user exceeds this. Choose Unlimited to disable the cap." })] }), _jsx("select", { id: maxId, value: form.maxConcurrentSessions, disabled: !canEdit, onChange: (e) => setField('maxConcurrentSessions', Number(e.target.value)), className: "border-border bg-input-background text-foreground focus-visible:ring-ring rounded-md border px-3 py-2 text-sm focus-visible:ring-2 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50", children: MAX_CONCURRENT_SESSION_OPTIONS.map((n) => (_jsx("option", { value: n, children: sessionsLabel(n) }, n))) })] }) }), _jsxs("div", { className: "border-border mt-4 space-y-2 border-t pt-4", children: [_jsx(StatusRow, { status: "pass", label: "Active admin sessions", value: String(activeSessions) }), _jsx(StatusRow, { status: "pass", label: "Maximum session age", value: `${maxAgeDays} day${maxAgeDays === 1 ? '' : 's'}` }), _jsx(StatusRow, { status: "pass", label: "Revoke sessions on password change", value: "Enabled" })] }), _jsxs("div", { className: "border-border mt-4 flex items-center justify-between gap-3 border-t pt-4", children: [_jsxs("div", { children: [_jsx("p", { className: "text-foreground text-sm font-medium", children: "Revoke other sessions" }), _jsx("p", { className: "text-muted-foreground text-sm", children: "Sign out every session except this one. Useful after a suspected compromise." }), revokeState === 'done' && (_jsx("p", { className: "text-success mt-1 text-sm", "aria-live": "polite", children: "Other sessions revoked." })), revokeState === 'error' && (_jsx("p", { className: "text-destructive mt-1 text-sm", "aria-live": "polite", children: "Could not revoke sessions. Try again." }))] }), _jsxs("button", { type: "button", disabled: !canEdit || revokeState === 'working', onClick: () => setConfirmRevoke(true), className: "border-border text-foreground hover:bg-accent inline-flex shrink-0 items-center gap-2 rounded-md border px-3 py-2 text-sm font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50", children: [revokeState === 'working' && (_jsx(Loader2, { size: 15, className: "animate-spin", "aria-hidden": "true" })), "Revoke other sessions"] })] }), _jsx(ConfirmDangerousSettingDialog, { open: confirmRevoke, title: "Revoke all other sessions?", description: "Every active session except your current one will be signed out immediately. Those users (and your other devices) will need to sign in again.", confirmLabel: "Revoke sessions", onConfirm: () => {
                    setConfirmRevoke(false);
                    onRevokeAll();
                }, onCancel: () => setConfirmRevoke(false) })] }));
}
//# sourceMappingURL=SessionPolicyCard.js.map