import { useState } from "react";
import { useApp } from "@/pages/app/AppContext";
import { BackHeader, cn } from "@/pages/app/components/ui";

interface SettingRow {
  id: string;
  label: string;
  desc: string;
}

const ROWS: SettingRow[] = [
  { id: "orders", label: "إشعارات الطلبات", desc: "تنبيه عند وصول طلب مدفوع جديد" },
  { id: "negotiations", label: "إشعارات التفاوض", desc: "تنبيه عند وصول طلب تفاوض جديد" },
  { id: "chats", label: "إشعارات المحادثات", desc: "تنبيه عند وصول رسالة جديدة" },
  { id: "promo", label: "الإشعارات الترويجية", desc: "عروض ونصائح من دشن" },
];

export default function BizSettings() {
  const { goBack } = useApp();
  const [on, setOn] = useState<Record<string, boolean>>({
    orders: true,
    negotiations: true,
    chats: true,
    promo: false,
  });

  const toggle = (id: string) => setOn((s) => ({ ...s, [id]: !s[id] }));

  return (
    <div className="min-h-full bg-background-50 pb-6">
      <BackHeader title="الإعدادات" onBack={goBack} />

      <div className="px-4 py-5 space-y-3">
        <div className="rounded-[20px] bg-background-100 border border-background-200 overflow-hidden divide-y divide-background-200">
          {ROWS.map((r) => (
            <div key={r.id} className="flex items-center gap-3 px-4 py-3.5">
              <div className="flex-1 min-w-0">
                <p className="text-[13.5px] font-medium text-foreground-950">{r.label}</p>
                <p className="text-[11.5px] text-foreground-600 mt-0.5">{r.desc}</p>
              </div>
              <button
                type="button"
                onClick={() => toggle(r.id)}
                aria-label={r.label}
                className={cn(
                  "relative w-[48px] h-[28px] rounded-full shrink-0 transition-colors cursor-pointer",
                  on[r.id] ? "bg-accent-500" : "bg-background-300",
                )}
              >
                <span
                  className={cn(
                    "absolute top-1 w-[20px] h-[20px] rounded-full bg-background-50 transition-all",
                    on[r.id] ? "right-1" : "right-[26px]",
                  )}
                />
              </button>
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}