import { SETTINGS_SECTIONS, type SettingsSectionDef, type SettingsSectionId } from "@umt/contracts"; import { Bot, FolderTree, KeyRound, type LucideIcon, Monitor, Server, Shield, Tags, Tv, UserCog, Zap, } from "lucide-react"; import type { ReactNode } from "react"; import { AccountSection } from "./account.tsx"; import { AgentSection } from "./agent.tsx"; import { ApiKeysSection } from "./api-keys.tsx"; import { AutomationSection } from "./automation.tsx"; import { DownloadersSection, MediaServersSection } from "./instances.tsx"; import { InterfaceSection } from "./interface.tsx"; import { LibrarySection } from "./library.tsx"; import { MetadataSection } from "./metadata.tsx"; import { SitesSection } from "./sites.tsx"; // 设置分区:文案与字段归属在 contracts 的 SETTINGS_SECTIONS,这里只挂图标与渲染 const UI: Record ReactNode }> = { automation: { icon: Zap, render: () => }, sites: { icon: UserCog, render: () => }, downloaders: { icon: Server, render: () => }, library: { icon: FolderTree, render: () => }, "media-servers": { icon: Tv, render: () => }, metadata: { icon: Tags, render: () => }, agent: { icon: Bot, render: () => }, "api-keys": { icon: KeyRound, render: () => }, interface: { icon: Monitor, render: () => }, account: { icon: Shield, render: () => }, }; export type SectionView = SettingsSectionDef & { icon: LucideIcon; render: () => ReactNode }; export const SECTIONS: SectionView[] = SETTINGS_SECTIONS.map((s) => ({ ...s, ...UI[s.id] })); /** URL hash:`#<分区>` 或 `#<分区>/<节>`;不认识的落到默认分区 */ export function parseSettingsHash(hash: string): { section: SectionView; anchor: string | null } { const [id, anchor] = decodeURIComponent(hash.replace(/^#/, "")).split("/"); const section = SECTIONS.find((s) => s.id === id) ?? (SECTIONS[0] as SectionView); return { section, anchor: section.id === id && anchor ? anchor : null }; } export const settingsHash = (section: string, anchor?: string | null) => `#${section}${anchor ? `/${anchor}` : ""}`;