import { useState } from "react";
import { useWeb } from "../WebContext";
import { Container, cn } from "../WebUI";
import { BoOverview, BoBusiness, BoProducts, BoOpportunities } from "./bo/BoSectionsA";
import {
  BoInvestRequests,
  BoOrders,
  BoNegotiations,
  BoChats,
  BoPartnerships,
  BoEarnings,
  BoCommission,
  BoNotifications,
  BoProfile,
} from "./bo/BoSectionsB";

const SECTIONS = [
  { key: "overview", label: "نظرة عامة", icon: "ri-dashboard-line" },
  { key: "business", label: "إدارة المنشأة", icon: "ri-store-3-line" },
  { key: "products", label: "إدارة المنتجات", icon: "ri-shopping-bag-3-line" },
  { key: "opportunities", label: "فرص الاستثمار", icon: "ri-line-chart-line" },
  { key: "investRequests", label: "طلبات الاستثمار", icon: "ri-file-user-line" },
  { key: "orders", label: "الطلبات المدفوعة", icon: "ri-file-list-3-line" },
  { key: "negotiations", label: "طلبات التفاوض", icon: "ri-chat-3-line" },
  { key: "chats", label: "المحادثات", icon: "ri-message-3-line" },
  { key: "partnerships", label: "الشراكات", icon: "ri-links-line" },
  { key: "earnings", label: "الأرباح والسحب", icon: "ri-money-dollar-circle-line" },
  { key: "commission", label: "تسوية العمولات", icon: "ri-exchange-line" },
  { key: "notifications", label: "الإشعارات", icon: "ri-notification-3-line" },
  { key: "profile", label: "الحساب الشخصي", icon: "ri-user-3-line" },
];

export default function BoDashboard() {
  const { params } = useWeb();
  const [section, setSection] = useState(params.section ?? "overview");

  return (
    <div className="animate-fade-in bg-background-50 min-h-screen">
      <Container className="py-8">
        <div className="flex flex-col lg:flex-row gap-8 items-start">
          <div className="flex-1 min-w-0 w-full order-2 lg:order-1">
            {section === "overview" && <BoOverview onSection={setSection} />}
            {section === "business" && <BoBusiness />}
            {section === "products" && <BoProducts />}
            {section === "opportunities" && <BoOpportunities />}
            {section === "investRequests" && <BoInvestRequests />}
            {section === "orders" && <BoOrders />}
            {section === "negotiations" && <BoNegotiations />}
            {section === "chats" && <BoChats />}
            {section === "partnerships" && <BoPartnerships />}
            {section === "earnings" && <BoEarnings />}
            {section === "commission" && <BoCommission />}
            {section === "notifications" && <BoNotifications />}
            {section === "profile" && <BoProfile />}
          </div>

          <aside className="w-full lg:w-[264px] shrink-0 order-1 lg:order-2 ">
            <div className="bg-background-100 border border-background-200 rounded-[20px] p-2.5">
              <p className="text-[12px] font-bold text-foreground-500 px-3 py-2">لوحة تحكم المنشأة</p>
              {SECTIONS.map((s) => (
                <button
                  key={s.key}
                  type="button"
                  onClick={() => setSection(s.key)}
                  className={cn(
                    "w-full flex items-center gap-2.5 h-10 px-3 rounded-[12px] text-[13.5px] font-medium cursor-pointer transition-colors",
                    section === s.key ? "bg-primary-500 text-background-50" : "text-foreground-700 hover:bg-background-200",
                  )}
                >
                  <i className={cn(s.icon, "text-[17px] leading-none")} />
                  {s.label}
                </button>
              ))}
            </div>
          </aside>
        </div>
      </Container>
    </div>
  );
}