"use client";
import { useState, useEffect } from "react";
import { useRouter } from "next/navigation";
import { useAuth } from "@/lib/auth";
import { useTheme } from "@/components/ThemeProvider";
import { useTranslation, LOCALES } from "@/lib/i18n";
import type { Locale } from "@/lib/i18n";
export default function SettingsPage() {
const { token, user, logout } = useAuth();
const { theme, toggleTheme } = useTheme();
const { t, locale, setLocale } = useTranslation();
const router = useRouter();
const [notifications, setNotifications] = useState({
push: true,
email: false,
taskReminders: true,
dailySummary: false,
});
const [saved, setSaved] = useState(false);
useEffect(() => {
if (!token) {
router.replace("/login");
}
// Load saved preferences
if (typeof window !== "undefined") {
const savedNotifs = localStorage.getItem("taskteam_notifications");
if (savedNotifs) {
try {
setNotifications(JSON.parse(savedNotifs));
} catch {
// ignore
}
}
}
}, [token, router]);
function handleSave() {
if (typeof window !== "undefined") {
localStorage.setItem("taskteam_notifications", JSON.stringify(notifications));
}
setSaved(true);
setTimeout(() => setSaved(false), 2000);
}
function handleLogout() {
logout();
router.push("/login");
}
if (!token) return null;
return (
{t("settings.title")}
{/* Profile section */}
{t("settings.profile")}
{(user?.name || user?.email || "?").charAt(0).toUpperCase()}
{user?.name || t("settings.user")}
{user?.email}
{/* Install section */}
{t("settings.install") || "Instalace"}
{/* Appearance */}
{t("settings.appearance")}
{/* Theme toggle */}
{theme === "dark" ? (
) : (
)}
{theme === "dark" ? t("settings.dark") : t("settings.light")}
{/* Language */}
{t("settings.language")}
{LOCALES.map((lang) => (
))}
{/* Notifications */}
{t("settings.notifications")}
{[
{ key: "push" as const, label: t("settings.push") },
{ key: "email" as const, label: t("settings.email") },
{ key: "taskReminders" as const, label: t("settings.taskReminders") },
{ key: "dailySummary" as const, label: t("settings.dailySummary") },
].map((item) => (
{item.label}
))}
{/* Save button */}
{/* Logout */}
{/* App info */}
{t("common.appName")} {t("common.appVersion")}
Smazat ucet
Trvale smazat ucet a vsechna data. Tuto akci nelze vratit.
);
}