import { useState } from "react";
import { investorNotifications } from "@/mocks/dshnInvestor";
import { Container, WCard, cn } from "@/pages/web/WebUI";
import WebPageHeader from "@/pages/web/components/WebPageHeader";

const ICONS: Record<string, { icon: string; tone: string }> = {
  offer: { icon: "ri-hand-coin-line", tone: "bg-accent-100 text-accent-700" },
  deal: { icon: "ri-file-list-3-line", tone: "bg-secondary-100 text-secondary-800" },
  message: { icon: "ri-chat-3-line", tone: "bg-primary-100 text-foreground-800" },
  payment: { icon: "ri-bank-card-line", tone: "bg-danger-100 text-danger-700" },
};

export default function InvNotifications() {
  const [items, setItems] = useState(investorNotifications);
  const unread = items.filter((i) => i.unread).length;

  return (
    <div className="animate-fade-in">
      <WebPageHeader
        title="الإشعارات"
        crumb="الإشعارات"
        desc={unread > 0 ? `${unread} إشعار غير مقروء` : "لا توجد إشعارات جديدة"}
      >
        <button
          type="button"
          onClick={() => setItems((list) => list.map((i) => ({ ...i, unread: false })))}
          className="h-10 px-4 rounded-full bg-background-100 border border-background-200 text-[13px] font-semibold text-foreground-700 hover:border-background-300 cursor-pointer whitespace-nowrap"
        >
          تعليم الكل كمقروء
        </button>
      </WebPageHeader>

      <Container className="py-8 max-w-[820px]">
        <div className="space-y-3">
          {items.map((n) => {
            const meta = ICONS[n.type] ?? ICONS.message;
            return (
              <WCard
                key={n.id}
                onClick={() => setItems((list) => list.map((i) => (i.id === n.id ? { ...i, unread: false } : i)))}
                className={cn("p-4 flex items-start gap-4", n.unread && "bg-accent-50 border-accent-200")}
              >
                <span className={cn("w-11 h-11 rounded-[13px] flex items-center justify-center shrink-0", meta.tone)}>
                  <i className={cn(meta.icon, "text-[20px] leading-none")} />
                </span>
                <div className="flex-1 min-w-0">
                  <p className={cn("text-[13.5px] leading-relaxed", n.unread ? "text-foreground-950 font-medium" : "text-foreground-700")}>
                    {n.text}
                  </p>
                  <p className="text-[11.5px] text-foreground-500 mt-1">{n.time}</p>
                </div>
                {n.unread && <span className="w-2.5 h-2.5 rounded-full bg-accent-700 shrink-0 mt-1.5" />}
              </WCard>
            );
          })}
        </div>
      </Container>
    </div>
  );
}