import React, { useEffect, useState } from "react"; import { Box, Button, Checkbox, FormControl, FormControlLabel, InputLabel, MenuItem, Paper, Select, Tab, Tabs, Typography, } from "@mui/material"; import { useNavigate } from "react-router-dom"; import { JobTableColumns } from "./JobTable"; import ImportExportJobs from "./ImportExportJobs"; import RulesSettingsCard from "./RulesSettingsCard"; import BackupCard from "./BackupCard"; import QuickCaptureCard from "./QuickCaptureCard"; import AiUsageCard from "./AiUsageCard"; import AiPrivacySettingsCard from "./AiPrivacySettingsCard"; import { ThemeModePref } from "../themePrefs"; import { useI18n } from "../i18n/I18nProvider"; interface Props { pageSize: 15 | 20 | 25; onPageSizeChange: (n: 15 | 20 | 25) => void; columns: JobTableColumns; onColumnsChange: (next: JobTableColumns) => void; themeMode: ThemeModePref; onThemeModeChange: (v: ThemeModePref) => void; } function TabPanel({ value, index, children }: { value: number; index: number; children: React.ReactNode }) { if (value !== index) return null; return {children}; } function SectionCard({ title, subtitle, children }: { title: string; subtitle?: string; children: React.ReactNode }) { return ( {title} {subtitle ? {subtitle} : } {children} ); } const NOTIFICATION_PREFS_KEY = "settings.notificationPrefs"; type NotificationPrefs = { emailFollowUpReminders: boolean; emailGhostedJobAlerts: boolean; inAppReminderHighlights: boolean; }; function loadNotificationPrefs(): NotificationPrefs { try { const raw = window.localStorage.getItem(NOTIFICATION_PREFS_KEY); if (!raw) { return { emailFollowUpReminders: true, emailGhostedJobAlerts: true, inAppReminderHighlights: true, }; } return { emailFollowUpReminders: true, emailGhostedJobAlerts: true, inAppReminderHighlights: true, ...JSON.parse(raw), }; } catch { return { emailFollowUpReminders: true, emailGhostedJobAlerts: true, inAppReminderHighlights: true, }; } } export default function SettingsView({ pageSize, onPageSizeChange, columns, onColumnsChange, themeMode, onThemeModeChange, }: Props) { const navigate = useNavigate(); const [tab, setTab] = useState(0); const { language, setLanguage, t } = useI18n(); const [notificationPrefs, setNotificationPrefs] = useState(() => loadNotificationPrefs()); useEffect(() => { window.localStorage.setItem(NOTIFICATION_PREFS_KEY, JSON.stringify(notificationPrefs)); }, [notificationPrefs]); return ( {t("settingsTitle")} {t("settingsSubtitle")} setTab(v)} variant="scrollable" scrollButtons="auto" allowScrollButtonsMobile sx={{ mb: 1 }}> {t("settingsTheme")} {t("settingsPreferredLanguage")} {t("settingsPagination")} {t("settingsRowsPerPage")} {t("settingsColumns")} {( [ ["status", t("settingsColumnStatus")], ["dateApplied", t("settingsColumnDateApplied")], ["daysSince", t("settingsColumnDays")], ["jobUrl", t("settingsColumnJobUrl")], ] as const ).map(([key, label]) => ( onColumnsChange({ ...columns, [key]: !columns[key] })} />} label={label} /> ))} setNotificationPrefs((prev) => ({ ...prev, emailFollowUpReminders: e.target.checked }))} />} label={t("settingsNotificationsFollowUpReminders")} /> setNotificationPrefs((prev) => ({ ...prev, emailGhostedJobAlerts: e.target.checked }))} />} label={t("settingsNotificationsGhostedJobs")} /> setNotificationPrefs((prev) => ({ ...prev, inAppReminderHighlights: e.target.checked }))} />} label={t("settingsNotificationsInAppReminders")} /> {t("settingsNotificationsDelivery")} ); }