'use client';

import { useState, useEffect } from 'react';
import { Switch } from '@/components/ui/switch';

export default function AdminSettings() {
  const [demoActive, setDemoActive] = useState(true);

  useEffect(() => {
    const state = localStorage.getItem('demo_banner_disabled') !== 'true';
    setDemoActive(state);
  }, []);

  const toggleDemo = (checked: boolean) => {
    setDemoActive(checked);
    localStorage.setItem('demo_banner_disabled', (!checked).toString());
    // Event feuern, damit andere Tabs/Komponenten sofort updaten
    window.dispatchEvent(new Event('storage_demo_changed'));
  };

  return (
    <div className="p-6 max-w-xl mx-auto text-slate-900 dark:text-white">
      <h1 className="text-2xl font-bold mb-6">Admin Einstellungen</h1>
      <div className="flex items-center justify-between p-4 bg-slate-100 dark:bg-white/5 rounded-xl border border-slate-200 dark:border-white/10">
        <div>
          <p className="font-medium text-slate-900 dark:text-white">Demo-Warnmeldungen</p>
          <p className="text-xs text-slate-500 dark:text-slate-400">Schaltet gelbe Banner ein oder aus.</p>
        </div>
        <Switch checked={demoActive} onCheckedChange={toggleDemo} />
      </div>
    </div>
  );
}
