"use client"; import { AlertTriangle, Check, ChevronRight, Copy, Download, Eye, EyeOff, Info, } from "@/components/icons/platform-icons"; import { SETTINGS_BADGE_SURFACE } from "@/modules/settings/components/panel/surface"; import type { ControlAvailability } from "@/modules/settings/components/panel/types"; import { createContext, useContext, useState, type ChangeEvent, type ReactNode, } from "react"; const ControlAvailabilityContext = createContext({ disabled: false, }); export function ControlAvailabilityProvider({ value, children, }: { value: ControlAvailability; children: ReactNode; }) { return ( {children} ); } export function useControlAvailability( overrideDisabled?: boolean, overrideReason?: string, ) { const context = useContext(ControlAvailabilityContext); const disabled = overrideDisabled !== undefined ? overrideDisabled : Boolean(context.disabled); const disabledReason = overrideReason !== undefined ? overrideReason : disabled ? context.disabledReason : undefined; return { disabled, disabledReason, }; } export function ControlDisabledHint({ text }: { text?: string }) { if (!text) return null; return {text}; } export function Toggle({ enabled, onToggle, label, description, disabled, disabledReason, }: { enabled: boolean; onToggle: () => void; label: string; description?: string; disabled?: boolean; disabledReason?: string; }) { const availability = useControlAvailability(disabled, disabledReason); return (
{label} {description ? ( {description} ) : null}
); } export function SettingsInput({ label, value, placeholder, type = "text", onChange, readOnly, copyable, description, disabled, disabledReason, }: { label: string; value: string; placeholder?: string; type?: string; onChange?: (value: string) => void; readOnly?: boolean; copyable?: boolean; description?: string; disabled?: boolean; disabledReason?: string; }) { const [showPassword, setShowPassword] = useState(false); const [copied, setCopied] = useState(false); const isPassword = type === "password"; const availability = useControlAvailability(disabled, disabledReason); const isReadOnly = readOnly || availability.disabled || !onChange; return (
{description ? ( {description} ) : null}
{ if (!onChange || isReadOnly || availability.disabled) return; onChange(event.target.value); }} className="h-8 w-full rounded-lg border border-glass-border bg-background/55 px-3 text-xs text-foreground placeholder:text-muted-foreground/60 transition-all focus:border-primary/40 focus:outline-none read-only:opacity-60 disabled:cursor-not-allowed disabled:opacity-50" /> {isPassword ? ( ) : null}
{copyable ? ( ) : null}
); } export function SettingsSelect({ label, value, options, description, onChange, disabled, disabledReason, }: { label: string; value: string; options: readonly string[]; description?: string; onChange?: (value: string) => void; disabled?: boolean; disabledReason?: string; }) { const availability = useControlAvailability(disabled, disabledReason); return (
{description ? ( {description} ) : null}
); } export function SectionDivider({ title }: { title: string }) { return (
{title}
); } export function InfoBanner({ text, variant = "info", }: { text: string; variant?: "info" | "warning"; }) { return (
{variant === "warning" ? ( ) : ( )} {text}
); } export function StorageBar({ label, detail, pct, color, }: { label: string; detail: string; pct: number; color: string; }) { const safePct = Number.isFinite(pct) ? Math.max(0, Math.min(pct, 100)) : 0; return (
{label} {detail}
); } export function formatStorageSize(bytes: number | null | undefined) { if ( bytes === null || bytes === undefined || !Number.isFinite(bytes) || bytes < 0 ) { return "--"; } if (bytes < 1024 ** 2) { return `${Math.round(bytes / 1024)} KB`; } if (bytes < 1024 ** 3) { return `${(bytes / 1024 ** 2).toFixed(1)} MB`; } if (bytes < 1024 ** 4) { return `${(bytes / 1024 ** 3).toFixed(1)} GB`; } return `${(bytes / 1024 ** 4).toFixed(1)} TB`; } export function UserRow({ name, role, email, lastActive, avatarColor, }: { name: string; role: string; email: string; lastActive: string; avatarColor: string; }) { return (
{name.charAt(0).toUpperCase()}
{name} {role}
{email}
{lastActive}
); } export function BackupRow({ date, size, type, status, actionLabel, onAction, actionDisabled, }: { date: string; size: string; type: string; status: "completed" | "failed" | "in-progress"; actionLabel?: string; onAction?: () => void; actionDisabled?: boolean; }) { return (
{type}
{date} - {size}
{actionLabel && onAction ? ( ) : ( )}
); }