"use client"

import type { NavGroup } from "@/base/types/navigation"
import {
  AlarmClockIcon,
  AwardIcon,
  BanknoteArrowDownIcon,
  BarChart3Icon,
  BellRingIcon,
  BookIcon,
  BriefcaseBusinessIcon,
  Building2Icon,
  CalendarCheck2Icon,
  CalendarDaysIcon,
  LayoutDashboardIcon,
  ClipboardListIcon,
  UsersIcon,
  CalendarIcon,
  CarIcon,
  ClipboardCheckIcon,
  Clock3Icon,
  ClockIcon,
  GemIcon,
  GitBranchIcon,
  HandCoinsIcon,
  ListIcon,
  ListTodoIcon,
  MegaphoneIcon,
  PackageIcon,
  PhoneCallIcon,
  PlugZapIcon,
  ReceiptIcon,
  ReceiptTextIcon,
  SettingsIcon,
  ShoppingBasketIcon,
  CircleDollarSign,
  StarIcon,
  StoreIcon,
  TimerIcon,
  UserCogIcon,
  WalletIcon,
  WrenchIcon,
  ShoppingCartIcon,
} from "lucide-react"
import Image from "next/image"
import { DashboardLayout } from "@/base/components/layout/dashboard"
import { useAuth } from "@/shared/hooks/use-auth"

const navGroups: NavGroup[] = [
  {
    items: [
      {
        title: "Dashboard",
        href: "/",
        icon: <LayoutDashboardIcon />,
      },
      {
        title: "Job Cards",
        href: "/sales/workorder/list",
        icon: <ClipboardListIcon />,
      },
      {
        title: "Customer & Vehicles",
        href: "/customer_vehicles",
        icon: <UsersIcon />,
      },
      {
        title: "Reports",
        href: "/reports",
        icon: <BarChart3Icon />,
      },
    ],
  },
  {
    label: "Management",
    items: [
      {
        title: "Calendars",
        href: "/calendars",
        icon: <CalendarIcon />,
        items: [
          { title: "Work Schedule", href: "/calendar/work_schedule/list", icon: <Clock3Icon /> },
          { title: "Appointments", href: "/calendar/appointment/list", icon: <CalendarCheck2Icon /> },
        ],
      },
      {
        title: "Sales",
        href: "/sales",
        icon: <CircleDollarSign />,
        items: [
          { title: "Customers", href: "/sales/customers", icon: <UsersIcon /> },
          { title: "Vehicles", href: "/sales/vehicles", icon: <CarIcon /> },
          { title: "Inspections", href: "/sales/inspections", icon: <ClipboardCheckIcon /> },
          { title: "Estimates", href: "/sales/estimate", icon: <ReceiptTextIcon /> },
          { title: "Job Cards", href: "/sales/workorder/list", icon: <ClipboardListIcon /> },
          { title: "Invoices", href: "/sales/invoice", icon: <ReceiptIcon /> },
          { title: "Payments Received", href: "/sales/payment_received", icon: <HandCoinsIcon /> },
          { title: "Credit Notes", href: "/sales/credit_notes", icon: <ReceiptTextIcon /> },
        ],
      },
      {
        title: "Purchases",
        href: "/purchases",
        icon: <ShoppingCartIcon />,
        items: [
          { title: "Vendors", href: "/purchase/vendor", icon: <StoreIcon /> },
          { title: "Expenses", href: "/purchase/expense", icon: <WalletIcon /> },
          { title: "Purchase Orders", href: "/purchase/purchase_order", icon: <ShoppingBasketIcon /> },
          { title: "Bills", href: "/purchase/bill", icon: <ReceiptIcon /> },
          { title: "Payments Made", href: "/purchase/payments_made", icon: <BanknoteArrowDownIcon /> },
          { title: "Vendor Credits", href: "/purchase/vendor_credit", icon: <ReceiptTextIcon /> },
        ],
      },
      {
        title: "CRM",
        href: "/crm",
        icon: <BriefcaseBusinessIcon />,
        items: [
          { title: "Leads", href: "/crm/leads/list", icon: <GemIcon /> },
          { title: "Calls", href: "/crm/calls_follow_up/list", icon: <PhoneCallIcon /> },
          { title: "Tasks", href: "/crm/tasks/list", icon: <ListTodoIcon /> },
        ],
      },
      {
        title: "Marketing",
        href: "/marketing",
        icon: <MegaphoneIcon />,
        items: [
          { title: "Service Reminders", href: "/marketing/service_reminder/list", icon: <AlarmClockIcon /> },
          { title: "Rating & Reviews", href: "/marketing/rating_review", icon: <StarIcon /> },
          { title: "Google Business Reviews", href: "/marketing/google_rating_review", icon: <AwardIcon /> },
        ],
      },
      {
        title: "Accountants",
        href: "/accountants",
        icon: <BookIcon />,
        items: [
          { title: "Manual Journals", href: "/accountants/manual_journal", icon: <BookIcon /> },
          { title: "Chart of Accounts", href: "/accountants/chart_of_account", icon: <GitBranchIcon /> },
        ],
      },
      {
        title: "Employees",
        href: "/productivity",
        icon: <UserCogIcon />,
        items: [
          { title: "Employees", href: "/productivity/employees", icon: <UsersIcon /> },
          { title: "Time Clocks", href: "/productivity/time_clocks", icon: <TimerIcon /> },
          { title: "Time Sheets", href: "/productivity/timesheet", icon: <ClockIcon /> },
          { title: "Payroll", href: "/productivity/payroll", icon: <WalletIcon /> },
          { title: "Payments Made", href: "/productivity/employee_payments_made", icon: <HandCoinsIcon /> },
          { title: "Shop Calendars", href: "/productivity/shop_calendars", icon: <CalendarDaysIcon /> },
          { title: "Shop Timing", href: "/productivity/shop_timings", icon: <Clock3Icon /> },
          { title: "Holidays", href: "/productivity/holidays", icon: <CalendarIcon /> },
        ],
      },
      {
        title: "Items",
        href: "/items",
        icon: <PackageIcon />,
        items: [
          { title: "Services", href: "/items/services", icon: <WrenchIcon /> },
          { title: "Parts", href: "/items/parts", icon: <WrenchIcon /> },
          { title: "Expense Item", href: "/items/expense_item", icon: <WalletIcon /> },
          { title: "Service Group", href: "/items/service_group", icon: <PackageIcon /> },
          { title: "Inspections", href: "/items/inspection", icon: <ClipboardCheckIcon /> },
          { title: "Inventory Adjustments", href: "/items/adjustment", icon: <ListIcon /> },
        ],
      },
      {
        title: "Settings",
        href: "/setting",
        icon: <SettingsIcon />,
        items: [
          { title: "Company", href: "/setting/company", icon: <Building2Icon /> },
          { title: "Shop Types", href: "/setting/shop_type", icon: <CarIcon /> },
          { title: "Tax & Rates", href: "/setting/tax_rates", icon: <ReceiptTextIcon /> },
          { title: "Configurations", href: "/setting/configurations/preferences/sales", icon: <SettingsIcon /> },
          { title: "Templates", href: "/setting/templates", icon: <ClipboardListIcon /> },
          { title: "Integrations", href: "/setting/integrations/providers", icon: <PlugZapIcon /> },
          { title: "Master", href: "/setting/master/body_type", icon: <ListIcon /> },
        ],
      },
    ],
  },
]

function Logo() {
  return (
    <div className="flex items-center gap-2">
        <Image alt="Logo" src={'/assets/logo.png'} height={200} width={200}/>
    </div>
  )
}

export default function AuthenticatedLayout({
  children,
}: {
  children: React.ReactNode
}) {
  const { user } = useAuth()

  const userInfo = user
    ? {
        name: user.name,
        email: user.email,
        initials: user.name.charAt(0).toUpperCase(),
      }
    : undefined

  return (
    <DashboardLayout navGroups={navGroups} logo={<Logo />} user={userInfo}>
      {children}
    </DashboardLayout>
  )
}

