import { type ComponentType } from 'react' import { useTranslation } from '../../../i18n' import { useIsDark } from '../../../hooks/useIsDark' import { Puzzle, ListChecks, Wallet, FileText, CalendarDays, Globe, Briefcase, Image, Terminal, Link2, Compass, BookOpen, Sparkles, Luggage, Plane, Bookmark, Users, Mountain, CarFront, Settings2, ChevronRight, } from 'lucide-react' import DawarichIcon from '../../../components/shared/DawarichIcon' import AirTrailIcon from '../../../components/shared/AirTrailIcon' import { DOCUMENT_PROVIDER_ICONS } from '../../../components/shared/documentProviderIconMap' import MToggle from '../../components/MToggle' import { type Addon, type CollabFeatures, type ProviderOption, COLLAB_SUB_FEATURES, getAddonLabel, } from '../../../components/Admin/addons/addonModel' import { useAddonManager } from '../../../components/Admin/addons/useAddonManager' import AiSettingsDialog from '../../../components/Admin/addons/AiAdminConfig' import { AI_ADDON_ICONS, type AiAddonId } from '../../../components/Admin/addons/aiAddons' import { useAiAddonTile } from '../../../components/Admin/addons/useAiAddonTile' import { ImmichIcon, SynologyIcon } from '../../../components/Admin/addons/PhotoProviderIcons' import { MAdminCard } from './MAdminUi' import MHintLabel from '../../components/MHintLabel' import WandererMark from '../../../components/Tours/wanderer/WandererMark' import MSkeleton from '../../components/MSkeleton' // Keys are the `icon` column from the addons table; anything unknown falls back to // Puzzle. Users/Sparkles cover collab and llm_parsing, as on the desktop. const ICON_MAP = { ListChecks, Wallet, FileText, CalendarDays, Puzzle, Globe, Briefcase, Image, Terminal, Link2, Compass, BookOpen, Plane, Bookmark, Users, Sparkles, Mountain, // Road trip was seeded as 'Route'; the car says what it is better than a line does. Route: CarFront, Dawarich: DawarichIcon, } const PROVIDER_ICONS: Record> = { immich: ImmichIcon, synologyphotos: SynologyIcon, ...DOCUMENT_PROVIDER_ICONS, } interface AddonIconProps { name: string size?: number /** A switched-off addon greys its icon out, brand marks included. */ enabled?: boolean } function AddonIcon({ name, size = 18, enabled = true }: AddonIconProps) { if (name === 'Dawarich') return // 'Plane' is the icon string airtrail was seeded with, and INSERT OR IGNORE // means every existing install still carries it — so the brand is keyed on // that rather than on a new name no row would ever have. if (name === 'Plane') return const Icon = ICON_MAP[name] || Puzzle return } export default function MAdminAddonManager({ bagTrackingEnabled, onToggleBagTracking, collabFeatures, onToggleCollabFeature }: { bagTrackingEnabled?: boolean; onToggleBagTracking?: () => void; collabFeatures?: CollabFeatures; onToggleCollabFeature?: (key: string) => void }) { const { t } = useTranslation() const dark = useIsDark() const { addons, loading, handleToggle, tripAddons, globalAddons, integrationAddons, aiAddons, providerOptions, documentProviderOptions, toursWanderer, wandererOffered, toggleToursWanderer, mapSwitches, } = useAddonManager() if (loading) { return ( ) } return (
{/* Header */}
{t('admin.addons.title')}
{/* One run of text with the wordmark inside it, so a line break falls between words and never around the logo. */}

{t('admin.addons.subtitleBefore')}{' '} TREK{' '} {t('admin.addons.subtitleAfter')}

{addons.length === 0 ? (

{t('admin.addons.noAddons')}

) : ( <> {/* Trip Addons */} {tripAddons.length > 0 && ( {tripAddons.map((addon, i) => (
{addon.id === 'packing' && addon.enabled && onToggleBagTracking && ( )} {addon.id === 'documents' && addon.enabled && } {addon.id === 'tours' && addon.enabled && ( <> {wandererOffered && ( void toggleToursWanderer()} /> )} {mapSwitches.map(({ key, Icon, titleKey, subtitleKey, enabled, toggle }) => ( void toggle()} /> ))} )} {addon.id === 'collab' && addon.enabled && collabFeatures && onToggleCollabFeature && ( <> {COLLAB_SUB_FEATURES.map(feat => ( onToggleCollabFeature(feat.key)} /> ))} )}
))}
)} {/* Global Addons */} {globalAddons.length > 0 && ( {globalAddons.map((addon, i) => (
{/* Memories providers as sub-items under Journey addon — only while it is on */} {addon.id === 'journey' && addon.enabled && }
))}
)} {/* Integration Addons, headed by the AI ones as one group, as on the desktop */} {(integrationAddons.length > 0 || aiAddons.length > 0) && ( {aiAddons.length > 0 && } {integrationAddons.map((addon, i) => ( ))} )} )}
) } /** Group subheader: small icon + uppercase label, matches the desktop section band. */ function MGroupHead({ icon: Icon, label, hint }: { icon: typeof Briefcase; label: string; hint: string }) { return (
) } interface MAddonRowProps { addon: Addon onToggle: (addon: Addon) => void t: (key: string) => string first?: boolean } /** * Addon row: icon tile, name with its description behind the info mark, MToggle. * No type badge: every row stands under its type's heading already. */ function MAddonRow({ addon, onToggle, t, first }: MAddonRowProps) { const label = getAddonLabel(t, addon) return (
{/* overflow-hidden so a brand mark that fills the slot keeps its rounded corners. */}
onToggle(addon)} />
) } /** A provider shelf under its addon: Journey's photo providers, Documents' document providers. */ function MProviderShelf({ options }: { options: ProviderOption[] }) { return ( <> {options.map(provider => ( ))} ) } interface MSubRowProps { icon?: typeof Luggage providerIcon?: ComponentType<{ size?: number }> title: string subtitle: string enabled: boolean onToggle: () => void } /** Indented sub-feature row (bag tracking, collab features, memory providers). */ function MSubRow({ icon: Icon, providerIcon: ProviderIcon, title, subtitle, enabled, onToggle }: MSubRowProps) { return (
{Icon ? : ProviderIcon ? : null}
) } /** The AI addons as one group: a head row, their switches, and the button to the settings dialog. */ function MAiAddons({ addons, onToggle }: { addons: Addon[]; onToggle: (addon: Addon) => void }) { const { t } = useTranslation() const tile = useAiAddonTile(addons) return (
{tile.enabledCount}/{addons.length}
{addons.map(addon => { const label = getAddonLabel(t, addon) return ( onToggle(addon)} /> ) })} {tile.canSetUp && ( )} {tile.dialogOpen && }
) }