import { can, isBusinessIdIn } from "../Utils/helper";
import {
  LayoutDashboard,
  ShoppingCart,
  Package,
  Box,
  ClipboardList,
  FileText,
  Repeat2,
  Undo2,
  Table,
  Ruler,
  Receipt,
  Tag,
  Users,
  UserCog,
  Truck,
  UserPlus,
  Wallet,
  BarChart3,
  TrendingUp,
  Printer,
  Settings,
  Warehouse,
  Store,
  Wrench,
  Recycle,
  PlusCircle,
  List,
  ListOrdered,
  CircleDollarSign,
  Circle,
  Calculator,
  Palette,
  Grid3X3,
  IdCard,
  GitBranch,
  Building2,
  BriefcaseBusiness,
  NotebookTabs,
  Quote,
  AlertCircle,
  Clock3,
  BookOpen,
  Landmark,
  Smartphone,
  CreditCard,
  FileChartColumn,
  GitMerge,
  UserCheck,
  Download,
  CheckCircle2,
  History,
  Key,
  Barcode,
} from "lucide-react";

export const MENU_ICON_MAP = {
  "bx bx-home-alt": LayoutDashboard,
  "bx bxs-cart": ShoppingCart,
  "bx bx-cart": ShoppingCart,
  "bx bx-package": Package,
  "bx bx-box": Box,
  "bx bx-list-ul": List,
  "bx bx-list-plus": ListOrdered,
  "bx bxs-calculator": Calculator,
  "bx bx-table": Table,
  "bx bx-ruler": Ruler,
  "bx bx-receipt": Receipt,
  "bx bx-money": CircleDollarSign,
  "bx bx-money-withdraw": CircleDollarSign,
  "bx bx-dollar-circle": CircleDollarSign,
  "bx bx-purchase-tag": Tag,
  "bx bx-category": Tag,
  "bx bx-category-alt": Grid3X3,
  "bx bx-palette": Palette,
  "bx bx-resize": Box,
  "bx bx-cube": Box,
  "bx bx-user": Users,
  "bx bx-group": Users,
  "bx bxs-user-detail": IdCard,
  "bx bx-user-check": UserCheck,
  "bx bx-user-voice": UserCog,
  "bx bx-sitemap": GitBranch,
  "bx bx-truck": Truck,
  "bx bx-user-plus": UserPlus,
  "bx bx-wallet": Wallet,
  "bx bx-bar-chart": BarChart3,
  "bx bx-line-chart": BarChart3,
  "bx bx-trending-up": TrendingUp,
  "bx bx-printer": Printer,
  "bx bx-cog": Wrench,
  "bx bx-cloud-download": Download,
  "bx bx-store": Store,
  "bx bx-buildings": Building2,
  "bx bx-building": Building2,
  "bx bx-briefcase-alt": BriefcaseBusiness,
  "bx bx-briefcase": BriefcaseBusiness,
  "bx bx-notepad": NotebookTabs,
  "bx bx-quote-left": Quote,
  "bx bx-error": AlertCircle,
  "bx bx-time": Clock3,
  "bx bx-book": BookOpen,
  "bx bxs-bank": Landmark,
  "bx bx-building-house": Building2,
  "bx bx-mobile": Smartphone,
  "bx bx-credit-card": CreditCard,
  "bx bxs-report": FileChartColumn,
  "bx bx-revision": Repeat2,
  "bx bx-transfer": Repeat2,
  "bx bx-undo": Undo2,
  "bx bx-plus-circle": PlusCircle,
  "bx bx-recycle": Recycle,
  "bx bx-file": FileText,
  "bx bx-analyse": FileChartColumn,
  "bx bx-git-merge": GitMerge,
  "bx bx-slider": Settings,
};

const menuConfig = {
  menu_items: [
    {
      id: "dashboard",
      label: "Dashboard",
      icon: LayoutDashboard,
      permission: "deshbord_view",
      route: "dashboard",
      type: "single",
      order: 1,
    },
    {
      id: "approval_inbox",
      label: "Approval Inbox",
      icon: CheckCircle2,
      route: "approvals.inbox",
      type: "single",
      permission: "approval_inbox_view",
      order: 2,
    },
    {
      id: "sales_pos",
      label: "Sales Management",
      icon: ShoppingCart,
      type: "group",
      order: 3,
      permission_group: [
        "pos_view",
        "sales_view",
        "customer_collection_view",
        "requsition_view"
      ],
      children: [
        {
          label: "Sales Invoice",
          route: "pos.index",
          permission: "pos_view",
          icon: Calculator,
        },
        {
          label: "Table Setup",
          route: "table-setup.index",
          permission: "table_setup_view",
          icon: Table,

        },
        {
          label: "All Sales Records",
          route: "sales.index",
          permission: "sales_view",
          icon: List,
        },
        {
          label: "Sales Requisition",
          route: "shop-requisition.index",
          permission: "requsition_view",
          icon: Repeat2,
        },
        {
          label: "Sales Return List",
          route: "sales.return",
          permission: "sales_return",
          icon: Repeat2,
        },
        {
          label: "Direct Product Return",
          route: "direct.return",
          permission: "sales_direct_return",
          icon: Undo2,
        },
        {
          label: "Customer Advance Payment",
          route: "customer-advance-payment.index",
          permission: "customer_collection_view",
          icon: CircleDollarSign,
        },
        {
          label: "Customer Due Collection",
          route: "due.collection",
          permission: "customer_collection_view",
          icon: CircleDollarSign,
        },
      ],
    },
    {
      id: "inventory",
      label: "Inventory Management",
      icon: Package,
      type: "group",
      order: 4,
      permission_group: [
        "warehoue_view",
        "warehoue_setup_view",
        "shop_warehouse_view",
        "adjustment_view",
        // "requsition_view",
        "product_shiping_view",
      ],
      children: [
        {
          label: "Warehouse/Shop Setup",
          route: "warehouse.index",
          permission: "warehoue_setup_view",
          icon: Wrench,
        },
        {
          label: "Manage Warehouse Stock",
          route: "warehouse-store.index",
          permission: "warehoue_view",
          icon: Box,
        },
        {
          label: "Add Opening Stock",
          route: "warehouse-opening.index",
          permission: "warehoue_view",
          icon: PlusCircle,
        },
        {
          label: "Transfer Stock",
          route: "warehouse-transfer.index",
          permission: "warehoue_view",
          icon: Repeat2,
        },
        {
          label: "Damage Product Entry",
          route: "damage.index",
          permission: "damage_view",
          icon: Repeat2,
        },
        {
          label: "Stock Adjustment",
          route: "stock-adjustment.index",
          permission: "adjustment_view",
          icon: Repeat2,
        },

        {
          label: "Requisition Received",
          route: "shipment.received",
          permission: "product_received_view",
          icon: Repeat2,
        },
        {
          label: "Shipment Products",
          route: "shipment-product.index",
          permission: "product_shiping_view",
          icon: Repeat2,
        },
        {
          label: "Used Product",
          route: "used-product.index",
          icon: Recycle,
        },
      ],
    },
    {
      id: "purchase",
      label: "Purchase Management",
      icon: ShoppingCart,
      type: "group",
      order: 3,
      permission_group: ["purchase_maker_view", "purchase_view", "lc_module_view", "purchase_return_view", "purchase_direct_return_view", "purchase_payment_view"],
      children: [
        {
          label: "Create Purchase Order",
          route: "purchase-makers.index",
          permission: "purchase_maker_view",
          icon: ListOrdered,
        },
        {
          label: () => can("for_labware") ? "Purchase Record" : "Purchase Invoice",
          route: "purchase.index",
          permission: "purchase_view",
          icon: List,
        },
        {
          label: () => can("for_labware") ? "Import module" : "LC Module (Import Costing)",
          route: "lc-module.index",
          permission: "lc_module_view",
          icon: Receipt,
        },
        {
          label: "Purchase Return List",
          route: "purchase.return",
          permission: "purchase_return_view",
          icon: Repeat2,
        },
        {
          label: "Direct Purchase Return",
          route: "direct.purchase.return",
          permission: "purchase_direct_return",
          icon: Undo2,
        },
        {
          label: "Supplier Payment Records",
          route: "purchase.payment.view",
          permission: "purchase_payment_view",
          icon: CircleDollarSign,
        },
      ],
    },

    {
      id: "products",
      label: "Product Configuration",
      icon: Box,
      type: "group",
      order: 1,
      permission_group: [
        "category_view",
        "unit_view",
        "brand_view",
        "product_type_view",
        "product_view",
        "shelf_view",
        "model_view",
        "origin_view",
        "color_view",
        "size_view",
        "barcode_view",
        "product_view",
        "product_type_view",
        "product_type_view",
      ],
      children: [
        {
          label: "Product List",
          route: "product.index",
          permission: "product_view",
          icon: List,
        },
        {
          label: "Product Categories",
          route: "category.index",
          permission: "category_view",
          icon: Tag,
        },
        {
          label: "Measurement Units",
          route: "unit.index",
          permission: "unit_view",
          icon: Ruler,
        },
        {
          label: "Product Sizes",
          route: "size.index",
          icon: Box,
          permission: "size_view",
        },
        {
          label: "Product Brands",
          route: "brand.index",
          permission: "brand_view",
          icon: Tag,
          permission: "brand_view",
        },

        {
          label: "Product Types",
          route: "product-type.index",
          permission: "product_type_view",
          icon: Grid3X3,
          permission: "product_type_view",
        },
        {
          label: "Product Colors",
          route: "color.index",
          permission: "color_view",
          icon: Palette,

        },

        {
          label: "Shelf No",
          route: "shelf.index",
          icon: Box,
          permission: "shelf_view",
        },
        {
          label: "Product Models",
          route: "model.index",
          icon: Box,
          permission: "model_view",
        },
        {
          label: "Product Origins",
          route: "origin.index",
          icon: Box,
          permission: "origin_view",
        },
        {
          label: "Barcode Generator",
          route: "barcode.index",
          permission: "barcode_view",
          icon: Barcode,
        },

      ],
    },

    {
      id: "party_setup",
      label: "Business Contacts",
      icon: IdCard,
      type: "group",
      order: 1,
      permission_group: [
        "supplier_view",
        "customer_retailer_view",
        "customer_branch_view",
        "category_view",
        "unit_view",
        "brand_view",
        "product_view",
        "sales_person_view",
        "department_view",
        "designation_view",
      ],

      children: [
        {
          label: () => can('for_labware') ? 'Company Directory' : "Customers & Retailers Directory",
          route: "customer.index",
          permission: "customer_retailer_view",
          icon: Users,
        },
        {
          label: "Customer Branches",
          route: "customer.branches.index",
          permission: "customer_branch_view",
          icon: GitBranch,
        },
        {
          label: "Sales Persons Directory",
          route: "sales-person.index",
          permission: "sales_person_view",
          icon: Users,
        },
        {
          label: () => can("for_labware") ? "Shipper Directory" : "Suppliers Directory",
          route: "supplier.index",
          permission: "supplier_view",
          icon: Building2,
        },
        {
          label: "Departments",
          route: "department.index",
          permission: "department_view",
          icon: Building2,
          visibility: () => isBusinessIdIn([8]),
        },
        {
          label: "Designations",
          route: "designation.index",
          permission: "designation_view",
          icon: BriefcaseBusiness,
          visibility: () => isBusinessIdIn([8]),
        },
        {
          label: "C&F Directory",
          route: "cnf.index",
          permission: "cnf_view",
          icon: Truck,
        },
        // {
        //     label: "Customer Opening Balances",
        //     route: "customer-opening.index",
        //     permission: "customer_retailer_opening_view",
        //     icon: "bx bx-wallet",
        // },
      ],
    },

    {
      id: "employee",
      label: "Employee Management",
      icon: IdCard,
      type: "group",
      order: 5,
      permission_group: [
        "employee_setup_view",
        "employee_salary_view",

      ],
      children: [
        {
          label: "Employee Setup",
          route: "employee-setup.index",
          permission: "employee_setup_view",
          icon: UserPlus,
        },

        {
          label: "Employee Salary",
          route: "employee-salary.index",
          permission: "employee_salary_view",
          icon: CircleDollarSign,
        },
        {
          label: "Departments",
          route: "department.index",
          permission: "department_view",
          icon: Building2,
          visibility: () => isBusinessIdIn([9]),
        },
        {
          label: "Designations",
          route: "designation.index",
          permission: "designation_view",
          icon: BriefcaseBusiness,
          visibility: () => isBusinessIdIn([9]),
        },
      ],
    },

    {
      id: "quotation_management",
      label: "Quotation Management",
      icon: NotebookTabs,
      type: "group",
      order: 6,
      permission_group: ["quotation_type_view"],
      children: [
        {
          label: "Quotation Types",
          route: "quotation-type.index",
          permission: "quotation_type_view",
          icon: Grid3X3,
        },

        {
          label: "Product Quotation",
          route: "product-quotation.index",
          icon: Quote,
        },
        {
          label: "Product Quotation Settings",
          route: "product_cotation_setting.index",
          icon: Quote,
        },
      ],
    },

    {
      id: "work_order",
      label: "Work Order",
      icon: BriefcaseBusiness,
      type: "group",
      order: 6,
      permission_group: ["work_order_view"],
      children: [
        {
          label: "Work Order List",
          route: "work-order.index",
          icon: List,
          permission: "work_order_view",
        },
        {
          label: "Work Order Merger",
          route: "work-order.merge",
          icon: GitMerge,
          permission: "work_order_view",
        },
      ],
    },

    {
      id: "finance",
      label: "Finance",
      icon: CircleDollarSign,
      type: "group",
      order: 6,
      children: [
        {
          id: "income_expense",
          label: "Income & Expense",
          icon: CircleDollarSign,
          type: "group",
          permission_group: ["expanse_category_view", "expanse_view"],
          children: [
            {
              label: "Transactions",
              route: "expance.index",
              permission: "expanse_view",
              icon: Repeat2,
            },
            {
              label: "Categories",
              route: "expance-category.index",
              permission: "expanse_category_view",
              icon: Tag,
            },
          ],
        },
        {
          id: "banking",
          label: "Banking",
          icon: Landmark,
          type: "group",
          permission: "transfer_view",
          children: [
            {
              label: "Bank Accounts",
              route: "bank.index",
              icon: Building2,
            },
            {
              label: "Mobile Banking",
              route: "mobilebank.index",
              icon: Smartphone,
            },
          ],
        },
        {
          id: "loan_setup",
          label: "Loan Setup",
          icon: CreditCard,
          type: "group",
          permission_group: ["loan_provider_view", "loan_type_view"],
          children: [
            {
              label: "Loan Providers",
              route: "loan-provider.index",
              permission: "loan_provider_view",
              icon: Building2,
            },
            {
              label: "Loan Types",
              route: "loan-type.index",
              permission: "loan_type_view",
              icon: ListOrdered,
            },
            {
              label: "Loan Taken Entry",
              route: "loan-entry.index",
              permission: "loan_entry_view",
              icon: Wallet,
            },
          ],
        },
      ],
    },
    {
      id: "reports",
      label: "Reports & Analytics",
      icon: FileChartColumn,
      type: "group",
      order: 7,
      permission_group: [
        "sales_summary",
        "sales_details",
        "sales_return_report",
        "discount_report",
        "purchase_summary",
        "purchase_details",
        "purchase_return",
        "current_stock_position",
        "opening_stock",
        "product_report",
        "warehouse_transfer_report",
        "damage_report",
        "expiredReportView",
        "current_stock_position",
        "requisition_client_report",
        "income_statement",
        "expense",
        "daily_khata",
        "customer_due_summary",
        "customer_payment_details",
        "customer_opening",
        "customer_ledger_report",
        "supplier_due_summary",
        "supplier_opening",
        "supplier_ledger_report",
        "supplier_payment_history",
        "sales_person_salary_view",
        "company_due_summary",
        "company_opening",
        "company_ledger_report",
        "company_payment_history",
      ],
      children: [
        {
          id: "sales_reports",
          label: "Sales Reports",
          type: "group",
          icon: ShoppingCart,
          children: [
            {
              label: "Sales Summary Report",
              route: "salsereport.index",
              permission: "sales_summary",
              icon: List,
            },
            {
              label: "Detailed Sales Report",
              route: "SalesDetalisReport",
              permission: "sales_details",
              icon: FileText,
            },
            {
              label: "Sales Return Report",
              route: "salse.return.report",
              permission: "sales_return_report",
              icon: Repeat2,
            },
            {
              label: "Sales Discount Report",
              route: "SalesDiscountReport",
              permission: "discount_report",
              icon: Tag,
            },
          ],
        },
        {
          id: "purchase_reports",
          label: "Purchase Reports",
          type: "group",
          icon: ShoppingCart,
          children: [
            {
              label: "Purchase Summary Report",
              route: "purchase.summary",
              permission: "purchase_summary",
              icon: List,
            },
            {
              label: "Detailed Purchase Report",
              route: "purchase.details",
              permission: "purchase_details",
              icon: FileText,
            },
            {
              label: "Purchase Return Report",
              route: "purchase.return.report",
              permission: "purchase_return",
              icon: Repeat2,
            },
          ],
        },
        {
          id: "inventory_reports",
          label: "Inventory Reports",
          type: "group",
          icon: Box,
          children: [
            {
              label: "Current Stock Position",
              route: "stock.position.report",
              permission: "current_stock_position",
              icon: Box,
            },
            {
              label: "Opening Stock Report",
              route: "opening.stock.position.report",
              permission: "opening_stock",
              icon: PlusCircle,
            },
            {
              label: "Product-wise Stock Report",
              route: "product.report",
              permission: "product_report",
              icon: Package,
            },
            {
              label: "Warehouse Transfer Report",
              route: "warehouse.transfer.report",
              permission: "warehouse_transfer_report",
              icon: Repeat2,
            },
            {
              label: "Damaged Product Report",
              route: "damage.report",
              permission: "damage_report",
              icon: AlertCircle,
            },
            {
              label: "Expired Product Report",
              route: "expire.report",
              permission: "expiredReportView",
              icon: Clock3,
            },
            {
              label: "Comprehensive Inventory Ledger Report",
              route: "inventory.ledger.report",
              permission: "current_stock_position",
              icon: BookOpen,
            },
          ],
        },
        {
          id: "requisition_reports",
          label: "Requisition Reports",
          type: "group",
          icon: FileText,
          children: [
            {
              label: "Requisition Client Report",
              route: "requisition.client.report",
              permission: "sales_details",
              icon: UserCheck,
            },
          ],
        },
        {
          id: "financial_reports",
          label: "Financial Reports",
          type: "group",
          icon: CircleDollarSign,
          children: [
            {
              label: "Income Statement Report",
              route: "income.report",
              permission: "income_statement",
              icon: TrendingUp,
            },
            {
              label: "Income & Expense Summary",
              route: "expenses.report",
              permission: "expense",
              icon: CircleDollarSign,
            },
            {
              label: "Daily Ledger (Khata)",
              route: "daily.khata.report",
              permission: "daily_khata",
              icon: BookOpen,
            },
          ],
        },
        {
          id: "customer_reports",
          label: "Customer Reports",
          type: "group",
          icon: Users,
          children: [
            {
              label: "Customer Due Summary",
              route: "customer.due.summary.report",
              permission: "client_retailer_due_summary",
              icon: Users,
            },
            {
              label: "Customer Payment History",
              route: "customer.payment.details.report",
              permission: "client_retailer_payment_details",
              icon: CircleDollarSign,
            },
            {
              label: "Customer Opening Balances",
              route: "customer.opening.report",
              permission: "client_retailer_opening",
              icon: Wallet,
            },
            {
              label: "Customer Ledger Report",
              route: "customer.ledger.report",
              permission: "customer_ledger_report",
              icon: Wallet,
            },
          ],
        },
        {
          id: "supplier_reports",
          label: " Supplier Reports",
          type: "group",
          icon: Users,
          children: [
            {
              label: "Supplier Due Summary",
              route: "supplier.due.report",
              permission: "company_due_summary",
              icon: Building2,
            },
            {
              label: "Supplier Opening Balances",
              route: "supplier.opening.report",
              permission: "company_opening",
              icon: Wallet,
            },
            {
              label: "Supplier Ledger Report",
              route: "supplier.ledger.report",
              permission: "supplier_ledger_report",
              icon: Wallet,
            },
            {
              label: "Supplier Payment History",
              route: "supplier.payment.history",
              permission: "supplier_ledger_report",
              icon: CircleDollarSign,
            },
          ],
        },
        {
          id: "sales_person_reports",
          label: "Sales Person Reports",
          type: "group",
          icon: Users,
          permission_group: ["sales_person_salary_view"],
          children: [
            {
              label: "Sales Person Salary ",
              route: "sales.person.salary.report",
              permission: "sales_person_salary_view",
              icon: Building2,
            },
          ],
        },
        {
          id: "activity_log",
          label: "Activity Log",
          type: "group",
          icon: History,
          children: [
            {
              label: "User Activity History",
              route: "user.activity.report",
              permission: "company_due_summary",
              icon: Building2,
            },
          ],
        },
      ],
    },
    {
      id: "settings",
      label: "Settings",
      icon: Settings,
      type: "group",
      order: 8,
      children: [
        {
          id: "user_management",
          label: "User Management",
          type: "group",
          icon: Users,
          permission: "role_view",
          children: [
            {
              label: "Users",
              route: "user.index",
              icon: Users,
            },
            {
              label: "Roles & Permissions",
              route: "role.index",
              icon: Key,
            },
          ],
        },
        {
          id: "system_settings",
          label: "System Settings",
          type: "group",
          icon: Settings,
          permission: "setting_view",
          children: [

            {
              label: "General Settings",
              route: "setting.general",
              icon: Settings,
            },
            {
              label: "System Update",
              route: "system-update.index",
              icon: Download,
            },

          ],
        },
      ],
    },
  ],
};

export default menuConfig;
