import { Alert, Button, Group, Modal, NumberInput, Stack, Switch, Text, } from "@mantine/core"; import { useForm } from "@mantine/form"; import { notifications } from "@mantine/notifications"; import { IconInfoCircle } from "@tabler/icons-react"; import { usePubSub } from "create-pubsub/react"; import { useState } from "react"; import { useSearchHistory } from "../../hooks/useSearchHistory"; import { addLogEntry } from "../../modules/logEntries"; import { settingsPubSub } from "../../modules/pubSub"; interface HistorySettingsProps { onClose?: () => void; } export default function HistorySettings({ onClose }: HistorySettingsProps) { const [settings, setSettings] = usePubSub(settingsPubSub); const { recentSearches, clearAll } = useSearchHistory(); const [showClearConfirm, setShowClearConfirm] = useState(false); const form = useForm({ initialValues: { enableHistory: settings.enableHistory, historyMaxEntries: settings.historyMaxEntries, historyAutoCleanup: settings.historyAutoCleanup, historyRetentionDays: settings.historyRetentionDays, }, onValuesChange: (values) => { setSettings({ ...settings, ...values, }); }, }); const handleClearHistory = async () => { try { await clearAll(); setShowClearConfirm(false); notifications.show({ title: "History Cleared", message: "All search history has been cleared", color: "blue", }); addLogEntry("User cleared all search history"); } catch (_) { notifications.show({ title: "Clear Failed", message: "Failed to clear history. Please try again.", color: "red", }); } }; return ( <> {form.values.enableHistory && ( <> {form.values.historyAutoCleanup && ( )} {onClose && ( )} )} setShowClearConfirm(false)} title="Clear Search History" centered > }> This action will permanently delete all {recentSearches.length}{" "} search entries. This cannot be undone. Are you sure you want to clear your entire search history? ); }