import { Outlet, useLocation } from "react-router-dom";
import Sidebar from "./sidebar";
import Header from "./header";

export default function Layout() {
  const location = useLocation();
  const path = location.pathname;

  // لیست الگوهایی که باید هدر نشون داده بشه
  const headerPaths = [
    "/management",
    "/management/",
    "/management/cafes",
    "/edit-cafe",
    "/edit-cafe/",
    "/cafe",
    "/cafes",
    "/admin",
  ];

  // بررسی: اگر هرکدوم از الگوها داخل path بود، هدر نمایش داده میشه
  const showHeader = headerPaths.some(
    (p) => path.startsWith(p) || path.includes(p)
  );

  return (
    <div className="flex flex-row h-screen bg-[#FDF8F4]">
      <div className="fixed right-0 top-0 bottom-0 z-40">
        <Sidebar />
      </div>

      <div className="flex-1 flex flex-col mr-[220px] h-screen">
        {showHeader && <Header title="مدیریت کافه‌ها" />}

        <main className="flex-1 overflow-y-auto p-6 bg-[#FDF8F4] pt-[80px]">
          <Outlet />
        </main>
      </div>
    </div>
  );
}
