"use server";
import React from "react";
import { retrievePageList, retrievePagebyUrl } from "@/apicalls/cookies/token";
import { retrievePage } from "@/components/NavigatePages";
import LeftMenu from "@/components/menu/leftMenu";

export default async function Dashboard({
  searchParams,
}: {
  searchParams: Promise<{ [key: string]: string | undefined }>;
}) {
  const siteUrlsList = (await retrievePageList()) || [];
  const lang = "tr";
  const searchParamsInstance = await searchParams;
  const activePage = "/management/accounting";
  const pageToDirect = await retrievePagebyUrl(activePage);
  const PageComponent = retrievePage(pageToDirect);

  return (
    <>
      <div className="min-h-screen min-w-screen flex h-screen w-screen overflow-hidden">
        {/* Sidebar */}
        <aside className="w-1/4 border-r p-4 overflow-y-auto">
          <LeftMenu
            pageUuidList={siteUrlsList}
            lang={lang}
            searchParams={searchParamsInstance}
            pageSelected={activePage}
          />
        </aside>

        {/* Main Content Area */}
        <div className="flex flex-col w-3/4">
          {/* Sticky Header */}
          <header className="sticky top-0 bg-white shadow-md z-10 p-4 flex justify-between items-center">
            <h1 className="text-2xl font-semibold">{activePage}</h1>
            <div className="flex items-center space-x-4">
              <input
                type="text"
                placeholder="Search..."
                className="border px-3 py-2 rounded-lg"
              />
              <div className="w-10 h-10 bg-gray-300 rounded-full"></div>
            </div>
          </header>
          <PageComponent lang={lang} queryParams={searchParamsInstance} />
        </div>
      </div>
    </>
  );
}
