"use client";

import { Sidebar } from "@/components/dashboard/Sidebar";
import { cn } from "@/lib/utils";
import { Search } from "lucide-react";
import { motion } from "framer-motion";
import { GlobalSearch } from "@/components/dashboard/GlobalSearch";
import { NotificationCenter } from "@/components/dashboard/NotificationCenter";
import { UserMenuDropdown } from "@/components/dashboard/UserMenuDropdown";
import { DashboardFooter } from "@/components/layout/DashboardFooter";

interface DashboardLayoutProps {
    children: React.ReactNode;
    role?: "candidate" | "employer" | "admin";
    user?: any;
}

export function DashboardLayout({ children, role = "employer", user }: DashboardLayoutProps) {
    return (
        <div className="flex flex-col md:flex-row bg-[#f5f7fa] min-h-screen w-full">
            {/* Sidebar */}
            <Sidebar
                role={role}
                user={user}
            />

            {/* Main Content Area */}
            <div className="flex-1 flex flex-col min-h-screen transition-all duration-300 bg-white md:rounded-tl-2xl border-l border-t border-slate-200 overflow-hidden">
                {/* Header */}
                <header className="sticky top-0 z-30 flex h-16 items-center justify-between border-b border-slate-200 bg-white/80 px-4 md:px-8 shadow-sm backdrop-blur-md">
                    <div className="flex items-center gap-4">
                        {/* Search Bar (Desktop) */}
                        <div className="hidden md:flex items-center relative group w-full max-w-md">
                            <GlobalSearch />
                        </div>
                    </div>

                    <div className="flex items-center gap-2 md:gap-4">
                        {/* Mobile Search Icon */}
                        <button className="md:hidden p-2 rounded-full text-slate-500 hover:bg-slate-100 transition-colors">
                            <Search className="h-5 w-5" />
                        </button>

                        {/* Notifications */}
                        <NotificationCenter />

                        <div className="h-6 w-px bg-slate-200 hidden sm:block mx-1"></div>

                        {/* User Profile */}
                        <UserMenuDropdown user={user} role={role} />
                    </div>
                </header>

                {/* Main Content */}
                <main className="flex-1 overflow-y-auto overflow-x-hidden p-4 md:p-8 shrink-0">
                    <motion.div
                        initial={{ opacity: 0, y: 10 }}
                        animate={{ opacity: 1, y: 0 }}
                        transition={{ duration: 0.4, ease: "easeOut" }}
                        className="mx-auto max-w-7xl h-full"
                    >
                        {children}
                    </motion.div>
                </main>
                <DashboardFooter />
            </div>
        </div>
    );
}
