import type { PlaceContribState } from '@trek/shared'; import { HeartHandshake, Undo2 } from 'lucide-react'; import { useTranslation } from '../../i18n'; import type { TranslationFn } from '../../types'; import { SettingsCard, StatusPill } from '../Settings/settingsKit'; import ToggleSwitch from '../Settings/ToggleSwitch'; import ConfirmDialog from '../shared/ConfirmDialog'; import { fs } from '../shared/DialogShell'; import { FigureBadge } from '../Tours/paddle/FigureBadge'; import PlaceContribLog from './PlaceContribLog'; import { contribNote, fieldEntries, fieldLabel, type ContribStatus } from './placeContribModel'; import PlaceContribPrompt from './PlaceContribPrompt'; import { usePlaceContribPanel } from './usePlaceContribPanel'; const PILL_TONE: Record = { active: 'success', paused: 'warning', off: 'neutral', unavailable: 'neutral', }; function Figures({ state, t }: { state: PlaceContribState; t: TranslationFn }) { const { locale } = useTranslation(); const number = new Intl.NumberFormat(locale); const last = state.lastSuccessDay ? new Intl.DateTimeFormat(locale, { day: 'numeric', month: 'short' }).format( new Date(`${state.lastSuccessDay}T12:00:00`) ) : t('admin.contribute.never'); return (
); } /** * Sharing place details with the TREK Places API, inside the TREK API card: * one switch for the installation, one per field, the transmission log and the * way to take everything back. Turning it on for the first time opens the same * prompt an admin gets on the first visit, so an agreement always comes from it. */ export default function PlaceContribPanel({ hideWhenSwitchedOff = false }: { hideWhenSwitchedOff?: boolean } = {}) { const { t } = useTranslation(); const panel = usePlaceContribPanel({ hideWhenSwitchedOff }); const { contrib, state, status, on, confirm, setConfirm, toggleField, withdraw } = panel; if (panel.hidden || !state || !status) return null; return ( {t(`admin.contribute.status.${status}`)}} hint={contribNote(t, state)} action={ } bodyClassName="flex flex-col gap-3 p-4" > {on && ( <>
    {fieldEntries(state.consent.fields).map(([field, on]) => (
  • {fieldLabel(t, field)} toggleField(field)} />
  • ))}
)} {panel.showLog && (
{/* A plain section head: the settings fold nothing away. */}
{t('admin.contribute.log.title')}
)} {panel.showPrompt && } setConfirm(null)} onConfirm={panel.switchOff} title={t('admin.contribute.offTitle')} message={t('admin.contribute.offMessage')} confirmLabel={t('admin.contribute.offConfirm')} /> setConfirm(null)} onConfirm={withdraw} title={t('admin.contribute.withdrawTitle')} message={t('admin.contribute.withdrawMessage')} confirmLabel={t('admin.contribute.withdraw')} danger />
); }