import { cloneElement, type DragEvent, type KeyboardEvent, type MouseEvent, type ReactElement, type UIEvent } from "react"; import { SlidingSelection } from "../../ui/SlidingSelection"; import { DataTable, DataTableBody, DataTableEmpty, DataTableHeader } from "../../ui/DataTable"; import { Dialog } from "../../ui/Dialog"; import { ACCOUNT_COLUMNS, type AccountAddFilter, type AccountAddOption, type AccountRowViewModel } from "./settings-model"; export type AccountWorkspacePanel = "overview" | "rules"; export interface AccountRulesViewModel { providerOrder: readonly string[]; routing: readonly string[]; autoFallback: boolean; rememberCredentials?: boolean; rotationEvents?: readonly { id: string; title: string; detail: string }[]; routingEntries?: readonly { hosterId: string; hosterLabel: string; provider: string; providers: readonly { value: string; label: string }[]; }[]; availableRoutingHosters?: readonly { value: string; label: string }[]; } export interface AccountWorkspaceViewModel { activePanel: AccountWorkspacePanel; rows: readonly AccountRowViewModel[]; selectedIds: readonly string[]; busy: boolean; error?: string; allEnabled?: boolean; statusSort?: "none" | "desc" | "asc"; rules: AccountRulesViewModel; } export interface AccountWorkspaceActions { onPanelChange: (panel: AccountWorkspacePanel) => void; onSelect: (rowId: string) => void; onToggleEnabled: (rowId: string) => void; onEdit: (rowId: string) => void; onContextMenu: (rowId: string, x: number, y: number) => void; onAdd: () => void; onRemoveSelected: () => void; onCheckAll: () => void; onSetAllEnabled?: (enabled: boolean) => void; onStatusSort?: () => void; onMoveProvider?: (index: number, direction: -1 | 1) => void; onProviderDragStart?: (event: DragEvent, index: number) => void; onProviderDragOver?: (event: DragEvent, index: number) => void; onProviderDrop?: (event: DragEvent, index: number) => void; onProviderDragEnd?: () => void; onToggleAutoFallback?: (enabled: boolean) => void; onToggleRememberCredentials?: (enabled: boolean) => void; onRoutingProviderChange?: (hosterId: string, provider: string) => void; onRoutingRemove?: (hosterId: string) => void; onRoutingAdd?: (hosterId: string) => void; } export interface AccountWorkspaceProps { model: AccountWorkspaceViewModel; actions: AccountWorkspaceActions; } export interface AccountDialogField { id: string; label: string; type: "text" | "password" | "number" | "textarea"; value: string; placeholder?: string; help?: string; } export interface AccountAddDialogModel { open: boolean; query: string; filter: AccountAddFilter; options: readonly AccountAddOption[]; selectedOptionId: string | null; fields: readonly AccountDialogField[]; error: string; busy: boolean; } export interface AccountAddDialogActions { onQueryChange: (value: string) => void; onFilterChange: (filter: AccountAddFilter) => void; onOptionSelect: (optionId: string) => void; onFieldChange: (fieldId: string, value: string) => void; onClose: () => void; onSubmit: () => void; } export interface AccountEditDialogModel { open: boolean; hoster: string; mode: string; identity: string; enabled: boolean; fields: readonly AccountDialogField[]; error: string; busy: boolean; } export interface AccountEditDialogActions { onFieldChange: (fieldId: string, value: string) => void; onClose: () => void; onCheck: () => void; onSave: () => void; onRemove: () => void; onToggleEnabled: () => void; } function AccountDialogFields({ fields, onChange }: { fields: readonly AccountDialogField[]; onChange: (fieldId: string, value: string) => void; }): ReactElement { return (
{fields.map((field) => (