/* ── Settings Page Helpers ── */ import type { PortalSettings } from "@/lib/storage"; export function formatStorageMB(mb: number): string { if (mb >= 1024) return (mb / 1024).toFixed(0) + " GB"; return mb + " MB"; } export function inputCls(field: string, validation: Record): string { return `w-full rounded-lg bg-surface-900 border ${ validation[field] ? "border-accent-rose/50" : "border-surface-700" } px-3 py-2 text-sm text-surface-200 placeholder:text-surface-500 focus:outline-none focus:border-brand-500 focus:ring-1 focus:ring-brand-500 transition-colors`; } export function validateSettings( form: PortalSettings, ): { valid: boolean; errors: Record } { const errors: Record = {}; let valid = true; if (!form.gatewayUrl.startsWith("http://") && !form.gatewayUrl.startsWith("https://")) { errors.gatewayUrl = "Must start with http:// or https://"; valid = false; } if (form.gatewayUrl.length > 500) { errors.gatewayUrl = "Too long (max 500 chars)"; valid = false; } if (form.apiEndpoint && !form.apiEndpoint.startsWith("/") && !form.apiEndpoint.startsWith("http")) { errors.apiEndpoint = "Must be empty, a path (/…), or a URL"; valid = false; } if (form.storageMax < 1 || form.storageMax > 102400) { errors.storageMax = "Must be 1–102400 MB"; valid = false; } if (form.refreshInterval < 5 || form.refreshInterval > 300) { errors.refreshInterval = "Must be 5–300 seconds"; valid = false; } return { valid, errors }; }