"use server";

import { createSessionClient } from "@/lib/appwrite/server";

export interface ThemePrefs {
  theme?: "dark" | "light" | "system";
  colorTheme?: string;
  tweakcnTheme?: string;
  radius?: string;
  sidebarVariant?: "sidebar" | "floating" | "inset";
  sidebarCollapsible?: "offcanvas" | "icon" | "none";
  sidebarSide?: "left" | "right";
}

export async function saveThemePrefsAction(update: Partial<ThemePrefs>): Promise<void> {
  try {
    const { account } = await createSessionClient();
    const existing = await account.getPrefs<Record<string, unknown>>();
    await account.updatePrefs({ ...existing, ...update });
  } catch {
    // best-effort — UI still works without persistence
  }
}
