import { useCallback, useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { BiHomeSmile, BiBookOpen } from 'react-icons/bi';
import { FcSelfServiceKiosk } from 'react-icons/fc';
import { FiSettings } from 'react-icons/fi';
import { GiExitDoor } from "react-icons/gi";
import { TbReportAnalytics } from 'react-icons/tb';
import { MdOutlineLogout, MdOutlineLogin } from 'react-icons/md';
import { AiOutlineLogin } from 'react-icons/ai';
import { TbAppsFilled } from 'react-icons/tb';
import { IoLogoAndroid } from 'react-icons/io5';
import SideMenu from '../../Components/Menu/SideMenu';
import SideMenuPozo from '../../Components/Menu/SideMenuPozo';
import CenterPage from './CenterPage';
import { getItem, getsubItem } from '../../Components/Menu/SideMenu';
import {
  getSession,
  sessionStore,
  encryptedValuesUrlFun,
} from '../../Services/Others';
import '../../styles/AppPage/AppPage.scss';
import {
  getCompBranchData,
  changeSelectedBranchId,
  GenerateLogout,
  ApplicationPreferences,
  globalBranchType,
} from '../../Features/BrachLogin/BranchLogin.js';
import { useLocation } from 'react-router-dom';
import { Messages } from '../../Components/Notifications/Messages.jsx';
import { getCustomerDisplayWindow } from '../../Features/customerDisplayWindow/customerDisplayWindow.js';
import { changepreOrder } from '../../Features/BookingScreen/PreOrder/PreOrder.js';
import { useAuth } from '../../AuthContext.jsx'; // Assuming you have an AuthContext
import {
  gettableData,
  preferencechangeStatus,
  settingDataSelector,
} from '../../Features/PreferenceMaster/PreferenceMaster.js';

const subDirectory = import.meta.env.BASE_URL;
const commonDirectory = import.meta.env.COMMON_BASE_URL;

const AppPage = () => {
  const dispatch = useDispatch();
  const location = useLocation();

  const AppId = getSession('AppId');
  const CompId = getSession('CompId');
  const BranchId = getSession('BranchId');
  const UserId = getSession('UserId');
  const [collapse, setCollapse] = useState(false);
  const {
    UserType,
    Access,
    SadminuserAccess,
    Advance,
    ProORAdvance,
    featureaddDetails,
  } = useAuth();
  // Retrieve user details
  const DineInStatus = useSelector(preferencechangeStatus);
  const iswarehouse = useSelector(globalBranchType);
  console.log(SadminuserAccess, 'SadminuserAccess');
  const SettingData = useSelector(settingDataSelector);
  const appPreferences = useSelector(ApplicationPreferences);
  const bookingTypePreference = appPreferences?.find(
    (preference) => preference?.PreferredCatName === 'Booking Type'
  )?.PreferenceCatDetails;
  const dinePreference = bookingTypePreference?.find(
    (type) =>
      type?.PreferredSubCatName?.toLowerCase() === 'dine in' &&
      type?.PreferredStatus === 'Y'
  );
  console.log(dinePreference,"dinePreference")
  const takeAwayPreference = bookingTypePreference?.find(
    (type) =>
      type?.PreferredSubCatName?.toLowerCase() === 'take away' &&
      type?.PreferredStatus === 'Y'
  );
  const [CompBranchData, setCompBranchData] = useState();
  const [messageType, setMessageType] = useState(null);
  const [messageData, setMessageData] = useState(null);
  const [EmpSettingMenu, setEmpSettingMenu] = useState([]);
  const [EmpfilterReportMenu, setfilterReportMenu] = useState([]);
  const [EmpBookingMenuItem, setEmpBookingMenuItem] = useState([]);
  const [EmpKioskMenuItem, setEmpKioskMenuItem] = useState([]);
  const [empinfoMenu, setempinfoMenu] = useState([]);
  const [offemenu, setofferMenu] = useState([]);
  const [payMenu, setPayMenu] = useState([]);
  const [CancelMenu, setCancelMenu] = useState([]);
  const [SalesMenu, setSalesMenu] = useState([]);
  const [AndroidApp, setAndroidApp] = useState([]);
  const [Empprodmenu, setEmpprodmenu] = useState([]);
  const [SadminUserSettingMenu, setSadminUserEmpSettingMenu] = useState([]);
  const [SadminUserfilterReportMenu, setSadminUserfilterReportMenu] = useState(
    []
  );
  const [SadminUserBookingMenuItem, setSadminUserBookingMenuItem] = useState(
    []
  );
  const [SadminUserKioskMenuItem, setSadminUserKioskMenuItem] = useState([]);
  const [SadminUserinfoMenu, setSadminUserinfoMenu] = useState([]);
  const [SadminUseroffemenu, setSadminUserofferMenu] = useState([]);
  const [SadminUserpayMenu, setSadminUserPayMenu] = useState([]);
  const [SadminUserCancelMenu, setSadminUserCancelMenu] = useState([]);
  const [SadminUserSalesMenu, setSadminUserSalesMenu] = useState([]);
  const [SadminUserAndroidApp, setSadminUserAndroidApp] = useState([]);
  const [SadminUserprodmenu, setSadminUserEmpprodmenu] = useState([]);
  const [DineinData, setDineinData] = useState(false);
  const [EstimateData, setEstimateData] = useState(false);

  useEffect(() => {
    fetchBranchData();
    clearCustomerDisplay();
  }, []);

  const onComplete = useCallback(() => {
    setMessageData(null);
    setMessageType(null);
  }, []);

  useEffect(() => {
    fetchBranchData();
  }, [CompId]);

  useEffect(() => {
    updateSelectedMenuItem();
  }, [location.pathname]);

  useEffect(() => {
    if (Access?.length > 0) {
      EmpAccesFilterFun(Access);
    }
  }, [Access, SettingData, SadminuserAccess]);
  useEffect(() => {
    if (SadminuserAccess?.length > 0) {
      SAdminuserAccesFilterFun(SadminuserAccess);
    }
  }, [SadminuserAccess, SettingData, Access]);

  useEffect(() => {
    if (SettingData?.length === 0) {
      Dinein();
    } else {
      const SettingValueData = SettingData?.find(
        (e) => e.AppId === AppId
      )?.SettingDtlDetails?.some(
        (e) => e.SettingIdName === 'DineIn' && e.SettingValue === 'Y'
      );
      if (SettingValueData) {
        setDineinData(true);
      } else {
        setDineinData(false);
      }
      const EstimateValueData = SettingData?.find(
        (e) => e.AppId === AppId
      )?.SettingDtlDetails?.some(
        (e) => e.SettingIdName === 'Estimation' && e.SettingValue === 'Y'
      );
      if (EstimateValueData) {
        setEstimateData(true);
      } else {
        setEstimateData(false);
      }
    }
  }, [BranchId]);

  useEffect(() => {
    Dinein();
  }, [DineInStatus]);

  useEffect(() => {
    const empdata =
      empinfoMenu.length > 0
        ? [
            getsubItem(
              'Employee Info',
              `${subDirectory}employee`,
              null,
              empinfoMenu
            ),
          ]
        : [];
    const prodata =
      Empprodmenu.length > 0
        ? [
            getsubItem(
              'Product Info',
              `${subDirectory}product`,
              null,
              Empprodmenu
            ),
          ]
        : [];
    const offermenu =
      offemenu.length > 0
        ? [getsubItem('Offer', `${subDirectory}offer`, null, offemenu)]
        : [];
    const PaymentMenu =
      payMenu.length > 0
        ? [getsubItem('Payment', `${subDirectory}Payment`, null, payMenu)]
        : [];
    const salesMenu =
      SalesMenu.length > 0
        ? [
            getsubItem(
              'Sales Layout',
              `${subDirectory}saleslayouts`,
              null,
              SalesMenu
            ),
          ]
        : [];
    const cancelMenus =
      CancelMenu.length > 0
        ? [
            getsubItem(
              'Cancel / Reschedule',
              `${subDirectory}cancelReschedule`,
              null,
              CancelMenu
            ),
          ]
        : [];
    const indexToSliceFirst = SuperAdminUserSettingmenuItems?.findIndex(
      (item) => item.label === 'Preference'
    );

    const indexToSliceSecond = SuperAdminUserSettingmenuItems?.findIndex(
      (item) => item.label === 'Extra Charges'
    );
    setEmpSettingMenu((prevMenu) => [
      ...prevMenu.slice(0, indexToSliceFirst),
      ...prodata,
      ...prevMenu.slice(indexToSliceFirst, indexToSliceSecond),
      ...empdata,
      ...offermenu,
      ...salesMenu,
      ...prevMenu.slice(indexToSliceSecond),
      ...PaymentMenu,
      ...cancelMenus,
    ]);
  }, [empinfoMenu, Empprodmenu]);

  useEffect(() => {
    const Sdminuserdata =
      SadminUserinfoMenu.length > 0
        ? [
            getsubItem(
              'Employee Info',
              `${subDirectory}employee`,
              null,
              SadminUserinfoMenu
            ),
          ]
        : [];
    const Sdminuserprodata =
      SadminUserprodmenu.length > 0
        ? [
            getsubItem(
              'Product Info',
              `${subDirectory}product`,
              null,
              SadminUserprodmenu
            ),
          ]
        : [];
    const Sdminuseroffermenu =
      SadminUseroffemenu.length > 0
        ? [
            getsubItem(
              'Offer',
              `${subDirectory}offer`,
              null,
              SadminUseroffemenu
            ),
          ]
        : [];
    const SdminuserPaymentMenu =
      SadminUserpayMenu.length > 0
        ? [
            getsubItem(
              'Payment',
              `${subDirectory}Payment`,
              null,
              SadminUserpayMenu
            ),
          ]
        : [];
    const SdminusersalesMenu =
      SadminUserSalesMenu.length > 0 && !iswarehouse
        ? [
            getsubItem(
              'Sales Layout',
              `${subDirectory}saleslayouts`,
              null,
              SadminUserSalesMenu
            ),
          ]
        : [];
    const SdminusercancelMenus =
      SadminUserCancelMenu.length > 0 && !iswarehouse
        ? [
            getsubItem(
              'Cancel / Reschedule',
              `${subDirectory}cancelReschedule`,
              null,
              SadminUserCancelMenu
            ),
          ]
        : [];
    const indexToSliceFirst = SuperAdminUserSettingmenuItems?.findIndex(
      (item) => item.label === 'Common Master'
    );

    const indexToSliceSecond = SuperAdminUserSettingmenuItems?.findIndex(
      (item) => item.label === 'Extra Charges'
    );
    setSadminUserEmpSettingMenu((SdminuserprevMenu) => [
      ...SdminuserprevMenu.slice(0, indexToSliceFirst),
      ...Sdminuserprodata,
      ...SdminuserprevMenu.slice(indexToSliceFirst, indexToSliceSecond),
      ...Sdminuserdata,
      ...Sdminuseroffermenu,
      ...SdminusersalesMenu,
      ...SdminuserprevMenu.slice(indexToSliceSecond),
      ...SdminuserPaymentMenu,
      ...SdminusercancelMenus,
    ]);
  }, [SadminUserinfoMenu, SadminUserprodmenu]);

  const Dinein = async () => {
    if (AppId && CompId && BranchId) {
      let DineinData = {
        AppId: AppId,
        CompId: CompId,
        BranchId: BranchId,
      };
      const response = await dispatch(gettableData(DineinData)).unwrap();
      if (response?.data?.statusCode === 1) {
        const SettingValueData = response?.data?.data
          ?.find((e) => e.AppId === AppId)
          ?.SettingDtlDetails?.some(
            (e) => e.SettingIdName === 'DineIn' && e.SettingValue === 'Y'
          );
        if (SettingValueData) {
          setDineinData(true);
        } else {
          setDineinData(false);
        }
        const EstimateValueData = response?.data?.data
          ?.find((e) => e.AppId === AppId)
          ?.SettingDtlDetails?.some(
            (e) => e.SettingIdName === 'Estimation' && e.SettingValue === 'Y'
          );
        if (EstimateValueData) {
          setEstimateData(true);
        } else {
          setEstimateData(false);
        }
      } else {
        setDineinData(false);
        setEstimateData(false);
      }
    }
  };

  const updateSelectedMenuItem = () => {
    const path = location.pathname;
    let key = 'home'; // Default key
    if (path.includes('/home')) key = 'home';
    else if (path.includes('/setting')) key = 'setting';
  };

  const clearCustomerDisplay = async () => {
    await dispatch(changepreOrder(false));
    const customerDisplayWindow = getCustomerDisplayWindow();
    if (customerDisplayWindow && !customerDisplayWindow.closed) {
      const updatedRemovedData = {
        userData: [],
        ExtraCharges: [],
        paymentMethod: 'Cash',
        type: 'remove',
        keyValue: 'customer',
      };
      customerDisplayWindow.postMessage(updatedRemovedData, '*');
    } else {
      console.error(
        'Customer display window is not available or has been closed.'
      );
    }
  };

  const fetchBranchData = async () => {
    if (
      getSession('UserType') === 'Super Admin' ||
      getSession('UserType') === 'Super Admin User'
    ) {
      const response = await dispatch(
        getCompBranchData({ CompId: CompId, AppId: AppId })
      ).unwrap();
      if (response?.data?.statusCode === 1) {
        setCompBranchData(response?.data?.data);
        if (response?.data?.data?.length == 1) {
          await sessionStore('BranchId', response?.data?.data?.[0]?.BrId);
          await dispatch(
            changeSelectedBranchId(response?.data?.data?.[0]?.BrId)
          );
        }
      }
    } else if (
      getSession('UserType') === 'Admin' ||
      getSession('UserType') === 'Admin User'
    ) {
      const response = await dispatch(
        getCompBranchData({ AppId: AppId, UserId: UserId, CompId: CompId })
      ).unwrap();
      if (response?.data?.statusCode === 1) {
        setCompBranchData(response?.data?.data);
        if (response?.data?.data?.length == 1) {
          await sessionStore('BranchId', response?.data?.data?.[0]?.BrId);
          await dispatch(
            changeSelectedBranchId(response?.data?.data?.[0]?.BrId)
          );
        }
      }
    }
  };

  // Super Admin User Menu

  //***************************** */

  const SuperAdminUserInfoitem = !iswarehouse
    ? [
    getsubItem('Shift', `${subDirectory}setting/shift-master`),
    getsubItem('Employee', `${subDirectory}setting/employee-master`),
    getsubItem(
      'Commission / Incentive',
      `${subDirectory}setting/commission-or-incentive-master`
    ),
    getsubItem('Employee Access', `${subDirectory}setting/employee-access`),
      getsubItem('TableMapping', `${subDirectory}setting/TableMapping`),
    ]
    : [];

  const SadminUserPurchaseMenuItem = [
    getsubItem('Purchase Order', `${subDirectory}setting/purchase-order`),
    getsubItem('Purchase Entry', `${subDirectory}setting/purchase-entry/new`),
    getsubItem('Purchase Return', `${subDirectory}setting/purchase-return`),
  ];

  const SadminUserprodMenu = [
    getsubItem('Sales Quotation', `${subDirectory}setting/sales-quotation`),
    getsubItem(
      'Delivery Challan Info',
      `${subDirectory}setting/delivery-challan`,
      null,
      [
        getsubItem(
          'Delivery Challan',
          `${subDirectory}setting/delivery-challan`
        ),
        getsubItem(
          'DC to Invoice',
          `${subDirectory}setting/delivery-challan-to-invoice`
        ),
      ]
    ),
    getsubItem('Product', `${subDirectory}setting/product-master`),
    getsubItem('Image Bulk Upload', `${subDirectory}setting/image-bulk-upload`),
    getsubItem('Supplier', `${subDirectory}setting/supplier`, null, [
      getsubItem('Supplier Master', `${subDirectory}setting/supplier-master`),
      getsubItem(
        'Supplier Product Mapping',
        `${subDirectory}setting/supplierproductmapping-master`
      ),
    ]),
    getsubItem('Price Change', `${subDirectory}setting/price-change`),
    !iswarehouse &&
    getsubItem(
      'Product Catalogue',
      `${subDirectory}setting/product-catalogue`
    ),
    !iswarehouse &&
    getsubItem(
      'Counter Category Mapping',
      `${subDirectory}setting/counter-category-mapping`
    ),
  ];

  const SuperAdminUserpayMentMenu = !iswarehouse
    ? [
    getsubItem('Payment Details', `${subDirectory}setting/payment-details`),
    getsubItem('Payment Options', `${subDirectory}setting/payment-options`),
    getsubItem(
      'Payment Device Access',
      `${subDirectory}setting/payment-device-access`
    ),
    getsubItem(
      'Payment Received',
      `${subDirectory}setting/payment-received-retail`
    ),
    ]
    : [];

  const SuperAdminUsersalesMenuList = [
    getsubItem('UI Component', `${subDirectory}saleslayouts/component-master`),
    getsubItem(
      'Barcode Component',
      `${subDirectory}saleslayouts/barcode-master`
    ),
    getsubItem(
      'Kiosk Component',
      `${subDirectory}saleslayouts/kiosk-component`
    ),
    getsubItem('Theme Creation', `${subDirectory}saleslayouts/theme-creation`),
    getsubItem('Sales Setup', `${subDirectory}saleslayouts/sales-selection`),
    getsubItem('Print Setup', `${subDirectory}saleslayouts/print-selection`),
    getsubItem('Kiosk Setup', `${subDirectory}saleslayouts/kiosk-selection`),
    getsubItem(
      'Barcode / Qr Setup',
      `${subDirectory}saleslayouts/barcode-qr-selection`
    ),
  ];

  const SuperAdminUserSettingmenuItems = !iswarehouse
    ? [
    getsubItem('Config Type', `${subDirectory}setting/config-type`),
    getsubItem('Common Master', `${subDirectory}setting/common-master`),
    getsubItem('Preference', `${subDirectory}setting/preference`),
    DineinData && dinePreference
      ? getsubItem('Dine In', `${subDirectory}setting/dinein-master`)
      : '',
    getsubItem('Tax', `${subDirectory}setting/admin-tax`),
    getsubItem('Customer', `${subDirectory}setting/customer-master`),
    getsubItem('Extra Charges', `${subDirectory}setting/extra-charges`),
    getsubItem(
      'Exchange and Return policy',
      `${subDirectory}setting/Exchange-Return-policy`,
      null,
      [
        getsubItem(
          'Exchange and Return policy',
          `${subDirectory}setting/Exchange-Return-policy`
        ),
        getsubItem(
          'Map Products',
          `${subDirectory}setting/Exchange-Return-policy`
        ),
      ]
    ),
    getsubItem('Create Ticket', `${subDirectory}setting/create-ticket`),
    ]
    : [];
  const ComboMenu = [
    getsubItem('Combo Product', `${subDirectory}setting/combo-master`),
    getsubItem('Combo Price', `${subDirectory}setting/combo-offer-master`),
  ];

  const SuperAdminUserofferMenu = !iswarehouse
    ? [
    getsubItem('Offer', `${subDirectory}setting/offer`),
    getsubItem('Item Wise Offer', `${subDirectory}setting/item-wise`),
    getsubItem('Sales Wise Offer', `${subDirectory}setting/sales-wise`),
      getsubItem(
        'Quantity Wise Offer',
        `${subDirectory}setting/quantity-wise`
      ),
      getsubItem(
        'Buy X and Get X or Y',
        `${subDirectory}setting/buyone-getone`
      ),
    getsubItem('Loyalty Cards', `${subDirectory}setting/loyalty-point`),
    getsubItem('Bundle Offer', `${subDirectory}setting/bundle-offer`),
    getsubItem('Coupon Wise Offer', `${subDirectory}setting/coupon`),
    getsubItem('Promo Code', `${subDirectory}setting/promo-code`),
    getsubItem('Offer Code', `${subDirectory}setting/offer-code`),
    getsubItem(
      'Free Products/Purchase',
      `${subDirectory}setting/free-product/purchase`,
      null,
      [
        getsubItem(
          'Free Product Info',
          `${subDirectory}setting/free-product-master`
        ),
        getsubItem(
          'Free Purchase Info',
          `${subDirectory}setting/free-purchase`,
          null,
          [
            getsubItem(
              'Free Purchase Order',
              `${subDirectory}setting/free-purchase-order`
            ),
            getsubItem(
              'Free Purchase Entry',
              `${subDirectory}setting/free-purchase-entry`
            ),
            getsubItem(
              'Free Purchase Return',
              `${subDirectory}setting/free-purchase-return`
            ),
          ]
        ),
      ]
    ),
    ]
    : [];

  const SuperAdminUserCancelMenuList = !iswarehouse
    ? [
    getsubItem(
      'Cancel Applicable Products',
      `${subDirectory}setting/cancel-applicable-product`
    ),
    getsubItem(
      'Cancellation and Reschedule Rules',
      `${subDirectory}setting/cancel-reschedule-rules`
    ),
    getsubItem(
      'Cancel Payment Change',
      `${subDirectory}setting/cancel-paymentchange`
    ),
    getsubItem(
      'Cancel Unpaid Device Orders',
      `${subDirectory}setting/cancel-pendingpayment`
    ),
      getsubItem(
        'Sales Bill Cancel',
        `${subDirectory}setting/sales-bill-cancel`
      ),
    getsubItem(
      'Sales Bill Product Return',
      `${subDirectory}setting/sales-bill-product-return`
    ),
    ]
    : [];

  const SuperAdminUserReportMenu = !iswarehouse
    ? [
    DineinData && dinePreference
      ? getsubItem('KOT', `${subDirectory}report/kot`)
      : '',
    getsubItem(
      'Tip Amount Settlement',
      `${subDirectory}report/tipamountsettlementlist`
    ),
      getsubItem(
        'PublicQrCode',
        `${subDirectory}report/PublicQrCode`
      ),
    getsubItem(
      'Empoloyee Settlement',
      `${subDirectory}report/EmployeeSettlement`
    ),
    getsubItem(
      'Date Wise Sales Report',
      `${subDirectory}report/datewisereport`
    ),
    getsubItem(
      'Item Wise Sales Report',
      `${subDirectory}report/itemwisereport`
    ),
    EstimateData
      ? getsubItem('Estimate', `${subDirectory}report/`, null, [
          getsubItem(
            'Item Wise Report',
            `${subDirectory}report/estimateitemwisereport`
          ),
          getsubItem(
            'Date Wise Report',
            `${subDirectory}report/estimatedatewisereport`
          ),
        ])
      : '',

    getsubItem('Revenue', `${subDirectory}report/revenu`, null, [
      // getsubItem('Revenue Date Wise Report', `${subDirectory}report/revenuedatewisereport`),
      getsubItem(
        'Revenue Item  Wise Report',
        `${subDirectory}report/revenueitemWisereport`
      ),
    ]),

    getsubItem('Ledger', `${subDirectory}report/ledgerreport`),
      getsubItem(
        'Reprint',
        `${subDirectory}report/reprintreasonreport`
      ),
    ]
    : [];
  const SuperAdminUserBookingMenuItem = !iswarehouse
    ? [
    getItem(
      'Sales',
      `${subDirectory}sales`,
      <BiBookOpen className="iconsize" />
    ),
    getItem(
      'Kiosk Sales',
      `${subDirectory}kiosksales`,
      <FcSelfServiceKiosk className="iconsize" />
    ),
    ]
    : [];

  const SuperAdminUserkioskMenuItem = [
    getItem(
      'Kiosk Sales',
      `${subDirectory}kiosksales`,
      <FcSelfServiceKiosk className="iconsize" />
    ),
  ];

  const SuperAdminUserAndroidAppMenuItem = !iswarehouse
    ? [
    getItem(
      'Android App',
      `${subDirectory}android-app`,
      <IoLogoAndroid className="iconsize" />
    ),
    ]
    : [];

  const filterSadminUserMenuItems = (menu, configList) => {
    return menu?.filter((item) => {
      const config = configList?.find(
        (config) => config.MenuName === item?.label && config.ReadAccess === 'Y'
      );
      return config;
    });
  };

  const SAdminuserAccesFilterFun = async (Access) => {
    const menuConfig = [
      {
        items: SuperAdminUserSettingmenuItems,
        setter: setSadminUserEmpSettingMenu,
      },
      { items: SuperAdminUsersalesMenuList, setter: setSadminUserSalesMenu },
      {
        items: SuperAdminUserReportMenu,
        setter: setSadminUserfilterReportMenu,
      },
      {
        items: SuperAdminUserBookingMenuItem,
        setter: setSadminUserBookingMenuItem,
      },
      {
        items: SuperAdminUserkioskMenuItem,
        setter: setSadminUserKioskMenuItem,
      },
      { items: SuperAdminUserInfoitem, setter: setSadminUserinfoMenu },
      { items: SuperAdminUserpayMentMenu, setter: setSadminUserPayMenu },
      { items: SuperAdminUserCancelMenuList, setter: setSadminUserCancelMenu },
      {
        items: SuperAdminUserAndroidAppMenuItem,
        setter: setSadminUserAndroidApp,
      },
    ];

    menuConfig.forEach(({ items, setter }) => {
      const filteredMenu = filterSadminUserMenuItems(items, Access);
      setter(filteredMenu);
    });
    const filterComboMenuItem = filterSadminUserMenuItems(ComboMenu, Access);
    const filterOfferMenuItem = filterSadminUserMenuItems(
      SuperAdminUserofferMenu,
      Access
    );
    const filterprodMenuItem = filterSadminUserMenuItems(
      SadminUserprodMenu,
      Access
    );
    const filterPurchaseinfoMenuItem = filterSadminUserMenuItems(
      SadminUserPurchaseMenuItem,
      Access
    );
    const indexToSliceFirst = SadminUserprodMenu?.findIndex(
      (item) => item.label === 'Product'
    );
    setSadminUserEmpprodmenu([
      ...filterprodMenuItem.slice(0, indexToSliceFirst + 1),
      ...(filterPurchaseinfoMenuItem.length > 0
        ? [
            getsubItem(
              'Purchase',
              `${subDirectory}purchase`,
              null,
              filterPurchaseinfoMenuItem
            ),
          ]
        : []),
      ...filterprodMenuItem.slice(indexToSliceFirst + 1),
    ]);
    setSadminUserofferMenu([
      ...filterOfferMenuItem.slice(0, indexToSliceFirst + 1),
      ...(filterComboMenuItem && filterComboMenuItem?.length > 0
        ? [
            getsubItem(
              'Combo Pack',
              `${subDirectory}setting/combopack`,
              null,
              filterComboMenuItem
            ),
          ]
        : []),
    ]);
  };

  //***************************** */

  // Employee Menu

  //***************************** */

  const empinfoitem = [
    getsubItem('Shift', `${subDirectory}setting/shift-master`),
    getsubItem('Employee', `${subDirectory}setting/employee-master`),
    getsubItem('Employee Access', `${subDirectory}setting/employee-access`),
    getsubItem('TableMapping', `${subDirectory}setting/TableMapping`),
  ];

  const PurchaseMenuItem = [
    getsubItem('Purchase Order', `${subDirectory}setting/purchase-order`),
    getsubItem('Purchase Entry', `${subDirectory}setting/purchase-entry/new`),
    getsubItem('Purchase Return', `${subDirectory}setting/purchase-return`),
  ];

  const prodMenu = [
    getsubItem('Sales Quotation', `${subDirectory}setting/sales-quotation`),
    getsubItem(
      'Delivery Challan Info',
      `${subDirectory}setting/delivery-challan`,
      null,
      [
        getsubItem(
          'Delivery Challan',
          `${subDirectory}setting/delivery-challan`
        ),
        getsubItem(
          'DC to Invoice',
          `${subDirectory}setting/delivery-challan-to-invoice`
        ),
      ]
    ),
    getsubItem('Product', `${subDirectory}setting/product-master`),
    getsubItem('Image Bulk Upload', `${subDirectory}setting/image-bulk-upload`),
    getsubItem('Supplier', `${subDirectory}setting/supplier`, null, [
      getsubItem('Supplier Master', `${subDirectory}setting/supplier-master`),
      getsubItem(
        'Supplier Product Mapping',
        `${subDirectory}setting/supplierproductmapping-master`
      ),
    ]),
    getsubItem('Price Change', `${subDirectory}setting/price-change`),
    ProORAdvance ||
    featureaddDetails?.find(
      (item) => item?.FeatureAddonName?.toLowerCase() === 'catalog'
    )
      ? getsubItem(
          'Product Catalogue',
          `${subDirectory}setting/product-catalogue`
        )
      : '',
    getsubItem(
      'Counter Category Mapping',
      `${subDirectory}setting/counter-category-mapping`
    ),
  ];

  const payMentMenu = [
    getsubItem('Payment Details', `${subDirectory}setting/payment-details`),
    getsubItem('Payment Options', `${subDirectory}setting/payment-options`),
    getsubItem(
      'Payment Device Access',
      `${subDirectory}setting/payment-device-access`
    ),
    getsubItem(
      'Payment Received',
      `${subDirectory}setting/payment-received-retail`
    ),
  ];

  const salesMenuList = [
    (Advance ||
      Boolean(
        featureaddDetails?.find(
          (item) =>
            item?.FeatureAddonName?.toLowerCase() === 'customized template'
        )
      )) &&
      getsubItem('Sales Setup', `${subDirectory}saleslayouts/sales-selection`),
    (Advance ||
      Boolean(
        featureaddDetails?.find(
          (item) =>
            item?.FeatureAddonName?.toLowerCase() === 'customized template'
        )
      )) &&
      getsubItem('Print Setup', `${subDirectory}saleslayouts/print-selection`),
    featureaddDetails?.find(
      (item) => item?.FeatureAddonName?.toLowerCase() === 'kiosk sales'
    ) &&
    
      getsubItem('Kiosk Setup', `${subDirectory}saleslayouts/kiosk-selection`),
    Advance ||
    featureaddDetails?.find(
      (item) => item?.FeatureAddonName?.toLowerCase() === 'customized template'
    )
      ? getsubItem(
          'Barcode / Qr Setup',
          `${subDirectory}saleslayouts/barcode-qr-selection`
        )
      : '',
  ];
  const SettingmenuItems = [
    getsubItem('Common Master', `${subDirectory}setting/common-master`),
    getsubItem('Preference', `${subDirectory}setting/preference`),
    DineinData && dinePreference
      ? getsubItem('Dine In', `${subDirectory}setting/dinein-master`)
      : '',
    getsubItem('Tax', `${subDirectory}setting/admin-tax`),
    getsubItem('Customer', `${subDirectory}setting/customer-master`),
    getsubItem('Extra Charges', `${subDirectory}setting/extra-charges`),
    getsubItem(
      'Exchange and Return policy',
      `${subDirectory}setting/Exchange-Return-policy`,
      null,
      [
        getsubItem(
          'Exchange and Return policy',
          `${subDirectory}setting/Exchange-Return-policy`
        ),
        getsubItem(
          'Map Products',
          `${subDirectory}setting/Exchange-Return-policy`
        ),
      ]
    ),
    getsubItem('Create Ticket', `${subDirectory}setting/create-ticket`),
  ];

  const offerMenu = [
    getsubItem('Offer', `${subDirectory}setting/offer`),
    getsubItem('Item Wise Offer', `${subDirectory}setting/item-wise`),
    getsubItem('Sales Wise Offer', `${subDirectory}setting/sales-wise`),
    getsubItem('Quantity Wise Offer', `${subDirectory}setting/quantity-wise`),
    getsubItem('Buy X and Get X or Y', `${subDirectory}setting/buyone-getone`),
    getsubItem('Loyalty Cards', `${subDirectory}setting/loyalty-point`),
    getsubItem('Bundle Offer', `${subDirectory}setting/bundle-offer`),
    getsubItem('Coupon Wise Offer', `${subDirectory}setting/coupon`),
    getsubItem('Promo Code', `${subDirectory}setting/promo-code`),
    getsubItem('Offer Code', `${subDirectory}setting/offer-code`),
    getsubItem(
      'Free Products/Purchase',
      `${subDirectory}setting/free-product/purchase`,
      null,
      [
        getsubItem(
          'Free Product Info',
          `${subDirectory}setting/free-product-master`
        ),
        getsubItem(
          'Free Purchase Info',
          `${subDirectory}setting/free-purchase`,
          null,
          [
            getsubItem(
              'Free Purchase Order',
              `${subDirectory}setting/free-purchase-order`
            ),
            getsubItem(
              'Free Purchase Entry',
              `${subDirectory}setting/free-purchase-entry`
            ),
            getsubItem(
              'Free Purchase Return',
              `${subDirectory}setting/free-purchase-return`
            ),
          ]
        ),
      ]
    ),
  ];

  const CancelMenuList = [
    getsubItem(
      'Cancel Applicable Products',
      `${subDirectory}setting/cancel-applicable-product`
    ),
    getsubItem(
      'Cancellation and Reschedule Rules',
      `${subDirectory}setting/cancel-reschedule-rules`
    ),
    getsubItem(
      'Cancel Payment Change',
      `${subDirectory}setting/cancel-paymentchange`
    ),
    getsubItem(
      'Cancel Unpaid Device Orders',
      `${subDirectory}setting/cancel-pendingpayment`
    ),
    getsubItem('Sales Bill Cancel', `${subDirectory}setting/sales-bill-cancel`),
    getsubItem(
      'Sales Bill Product Return',
      `${subDirectory}setting/sales-bill-product-return`
    ),
  ];

  const ReportMenu = [
    getsubItem(
      'Tip Amount Settlement',
      `${subDirectory}report/tipamountsettlementlist`
    ),
    getsubItem(
      'Empoloyee Settlement',
      `${subDirectory}report/EmployeeSettlement`
    ),
    getsubItem(
      'PublicQrCode',
      `${subDirectory}report/PublicQrCode`
    ),
    DineinData && dinePreference
      ? getsubItem('KOT', `${subDirectory}report/kot`)
      : '',
    getsubItem(
      'Date Wise Sales Report',
      `${subDirectory}report/datewisereport`
    ),
    getsubItem(
      'Item Wise Sales Report',
      `${subDirectory}report/itemwisereport`
    ),
    EstimateData
      ? getsubItem('Estimate', `${subDirectory}report/`, null, [
          getsubItem(
            'Item Wise Report',
            `${subDirectory}report/estimateitemwisereport`
          ),
          getsubItem(
            'Date Wise Report',
            `${subDirectory}report/estimatedatewisereport`
          ),
        ])
      : '',
    getsubItem('Revenue', `${subDirectory}report/revenu`, null, [
      // getsubItem('Revenue Date Wise Report', `${subDirectory}report/revenuedatewisereport`),
      getsubItem(
        'Revenue Item  Wise Report',
        `${subDirectory}report/revenueitemWisereport`
      ),
    ]),
    getsubItem('Ledger', `${subDirectory}report/ledgerreport`),
    getsubItem('Reprint', `${subDirectory}report/reprintreasonreport`),
  ];

  const BookingMenuItem = [
    getItem(
      'Sales',
      `${subDirectory}sales`,
      <BiBookOpen className="iconsize" />
    ),
    featureaddDetails?.find(
      (item) => item?.FeatureAddonName?.toLowerCase() === 'kiosk sales'
    )
      ? getItem(
          'Kiosk Sales',
          `${subDirectory}kiosksales`,
          <FcSelfServiceKiosk className="iconsize" />
        )
      : '',
  ];
  const kioskMenuItem = [
    featureaddDetails?.find(
      (item) => item?.FeatureAddonName?.toLowerCase() === 'kiosk sales'
    )
      ? getItem(
          'Kiosk Sales',
          `${subDirectory}kiosksales`,
          <FcSelfServiceKiosk className="iconsize" />
        )
      : '',
  ];

  const AndroidAppMenuItem = [
    getItem(
      'Android App',
      `${subDirectory}android-app`,
      <IoLogoAndroid className="iconsize" />
    ),
  ];

  const filterMenuItems = (menu, configList) => {
    return menu?.filter((item) => {
      const config = configList?.find(
        (config) =>
          config.ConfigName === item?.label && config.ReadAccess === 'Y'
      );
      return config;
    });
  };

  const EmpAccesFilterFun = async (Access) => {
    const menuConfig = [
      { items: SettingmenuItems, setter: setEmpSettingMenu },
      { items: salesMenuList, setter: setSalesMenu },
      { items: ReportMenu, setter: setfilterReportMenu },
      { items: BookingMenuItem, setter: setEmpBookingMenuItem },
      { items: kioskMenuItem, setter: setEmpKioskMenuItem },
      { items: empinfoitem, setter: setempinfoMenu },
      // { items: offerMenu, setter: setofferMenu },
      { items: payMentMenu, setter: setPayMenu },
      { items: CancelMenuList, setter: setCancelMenu },
      { items: AndroidAppMenuItem, setter: setAndroidApp },
    ];

    menuConfig.forEach(({ items, setter }) => {
      const filteredMenu = filterMenuItems(items, Access);
      setter(filteredMenu);
    });
    const filterEmpComboMenuItem = filterMenuItems(ComboMenu, Access);
    const filterEmpOfferMenuItem = filterMenuItems(offerMenu, Access);
    const filterprodMenuItem = filterMenuItems(prodMenu, Access);
    const filterPurchaseinfoMenuItem = filterMenuItems(
      PurchaseMenuItem,
      Access
    );
    const indexToSliceFirst = SadminUserprodMenu?.findIndex(
      (item) => item.label === 'Product'
    );
    setEmpprodmenu([
      ...filterprodMenuItem.slice(0, indexToSliceFirst + 1),
      ...(filterPurchaseinfoMenuItem.length > 0
        ? [
            getsubItem(
              'Purchase',
              `${subDirectory}purchase`,
              null,
              filterPurchaseinfoMenuItem
            ),
          ]
        : []),
      ...filterprodMenuItem.slice(indexToSliceFirst + 1),
    ]);
    setofferMenu([
      ...filterEmpOfferMenuItem.slice(0, indexToSliceFirst + 1),
      ...(filterEmpComboMenuItem && filterEmpComboMenuItem?.length > 0
        ? [
            getsubItem(
              'Combo Pack',
              `${subDirectory}setting/combopack`,
              null,
              filterEmpComboMenuItem
            ),
          ]
        : []),
    ]);
  };

  //***************************** */

  const items = [];
  if (BranchId === null || BranchId === '' || BranchId === undefined) {
    if (getSession('UserType') === 'Super Admin') {
      items.push(
        getItem(
          'Apps',
          `${subDirectory}app-page/redirect-apps`,
          <TbAppsFilled className="iconsize" />
        ),
        getItem(
          'HOME',
          `${subDirectory}app-page/home`,
          <BiHomeSmile className="iconsize" />
        ),
        getItem(
          'Branch Signin',
          `${subDirectory}app-page/branch-login`,
          <MdOutlineLogin />
        ),
        getItem(
          'Back To Branches',
          `${subDirectory}app-page/branch-all`,
          <AiOutlineLogin />
        ),
        getItem(
          'Sign Out',
          `${subDirectory}app-page/logout`,
          <MdOutlineLogout />
        )
      );
    } else if (getSession('UserType') === 'Super Admin User') {
      items.push(
        getItem(
          'Apps',
          `${subDirectory}app-page/redirect-apps`,
          <TbAppsFilled className="iconsize" />
        ),
        // getItem('HOME', `${subDirectory}app-page/home`, <BiHomeSmile className="iconsize" />),
        getItem(
          'Branch Signin',
          `${subDirectory}app-page/branch-login`,
          <MdOutlineLogin />
        ),
        getItem(
          'Sign Out',
          `${subDirectory}app-page/logout`,
          <MdOutlineLogout />
        )
      );
    } else if (
      getSession('UserType') === 'Admin' ||
      getSession('UserType') === 'Admin User'
    ) {
      items.push(
        getItem(
          'Apps',
          `${subDirectory}app-page/redirect-apps`,
          <TbAppsFilled className="iconsize" />
        ),
        getItem(
          'HOME',
          `${subDirectory}app-page/home`,
          <BiHomeSmile className="iconsize" />
        ),
        getItem(
          'Branch Signin',
          `${subDirectory}app-page/branch-login`,
          <MdOutlineLogin />
        ),
        getItem(
          'Sign Out',
          `${subDirectory}app-page/logout`,
          <MdOutlineLogout />
        )
      );
    }
  }
  if (UserType === 'Super Admin' && BranchId) {
    items.push(
      getItem(
        'APPS',
        `${subDirectory}app-page/redirect-apps`,
        <TbAppsFilled className="iconsize" />
      ),
      getItem(
        'HOME',
        `${subDirectory}app-page/home`,
        <BiHomeSmile className="iconsize" />
      ),
      getItem('SETTINGS', `${subDirectory}setting`, <FiSettings />, [
        !iswarehouse &&
        getsubItem('Config Type', `${subDirectory}setting/config-type`),
        !iswarehouse &&
        getsubItem('Common Master', `${subDirectory}setting/common-master`),
        !iswarehouse &&
        getsubItem('Preference', `${subDirectory}setting/preference`),
        DineinData && dinePreference && !iswarehouse
          ? getsubItem('Dinein', `${subDirectory}setting/dinein-master`)
          : '',
        !iswarehouse && getsubItem('Tax', `${subDirectory}setting/admin-tax`),
        getsubItem('Product Info', `${subDirectory}product`, null, [
          getsubItem('Product', `${subDirectory}setting/product-master`),
          getsubItem(
            'Image Bulk Upload',
            `${subDirectory}setting/image-bulk-upload`
          ),
          getsubItem('Purchase', `${subDirectory}purchase`, null, [
            getsubItem(
              'Purchase Order',
              `${subDirectory}setting/purchase-order/new`
            ),
            getsubItem(
              'Purchase Entry',
              `${subDirectory}setting/purchase-entry/new`
            ),
            getsubItem(
              'Purchase Return',
              `${subDirectory}setting/purchase-return`
            ),
          ]),
          !iswarehouse &&
          getsubItem(
            'sales Quotation',
            `${subDirectory}setting/sales-quotation`
          ),
          getsubItem(
            'Delivery Challan Info',
            `${subDirectory}setting/delivery-challan`,
            null,
            [
              getsubItem(
                'Delivery Challan',
                `${subDirectory}setting/delivery-challan`
              ),
              getsubItem(
                'DC to Invoice',
                `${subDirectory}setting/delivery-challan-to-invoice`
              ),
            ]
          ),
          getsubItem('Supplier', `${subDirectory}setting/supplier`, null, [
            getsubItem(
              'Supplier Master',
              `${subDirectory}setting/supplier-master`
            ),
            getsubItem(
              'Supplier Product Mapping',
              `${subDirectory}setting/supplierproductmapping-master`
            ),
          ]),
          !iswarehouse &&
          getsubItem('Price Change', `${subDirectory}setting/price-change`),
          !iswarehouse &&
          getsubItem(
            'Product Catalogue',
            `${subDirectory}setting/product-catalogue`
          ),
          !iswarehouse &&
          getsubItem(
            'Counter Category Mapping',
            `${subDirectory}setting/counter-category-mapping`
          ),
        ]),
        !iswarehouse &&
        getsubItem('Other Services', `${subDirectory}setting/other-services`),

        !iswarehouse &&
        getsubItem('Store', `${subDirectory}store`, null, [
          !iswarehouse &&
          getsubItem(
            'Custom Product',
            `${subDirectory}setting/custom-product`
          ),
          !iswarehouse &&
          getsubItem(
            'Material Issue to Production',
            `${subDirectory}setting/storeto-production`
          ),
          !iswarehouse &&
          getsubItem(
            'Ready-For-Sale',
            `${subDirectory}setting/readyfor-sale`
          ),
        ]),

        !iswarehouse &&
        getsubItem('Customer', `${subDirectory}setting/customer-master`),
        !iswarehouse &&
        getsubItem('Employee Info', `${subDirectory}employee`, null, [
          getsubItem('Shift', `${subDirectory}setting/shift-master`),
          getsubItem('Employee', `${subDirectory}setting/employee-master`),
          getsubItem(
            'Commission / Incentive',
            `${subDirectory}setting/commission-or-incentive-master`
          ),
          getsubItem(
            'Employee Access',
            `${subDirectory}setting/employee-access`
          ),
          getsubItem('TableMapping', `${subDirectory}setting/TableMapping`),
        ]),
        !iswarehouse &&
        getsubItem('offer', `${subDirectory}offer`, null, [
          getsubItem('Offer', `${subDirectory}setting/offer`),
          getsubItem('Item Wise Offer', `${subDirectory}setting/item-wise`),
          getsubItem('Sales Wise Offer', `${subDirectory}setting/sales-wise`),
          getsubItem(
            'Quantity Wise Offer',
            `${subDirectory}setting/quantity-wise`
          ),
          getsubItem(
            'Buy X and Get X or Y',
            `${subDirectory}setting/buyone-getone`
          ),
          getsubItem('Loyalty Cards', `${subDirectory}setting/loyalty-point`),
          getsubItem('Bundle Offer', `${subDirectory}setting/bundle-offer`),
          getsubItem('Coupon Wise Offer', `${subDirectory}setting/coupon`),
          getsubItem('Promo Code', `${subDirectory}setting/promo-code`),
          getsubItem('Offer Code', `${subDirectory}setting/offer-code`),
          getsubItem('Combo Pack', `${subDirectory}setting/combopack`, null, [
            getsubItem(
              'Combo Product',
              `${subDirectory}setting/combo-master`
            ),
            getsubItem(
              'Combo Price',
              `${subDirectory}setting/combo-offer-master`
            ),
          ]),
          getsubItem(
            'Free Products/Purchase',
            `${subDirectory}setting/free-product/purchase`,
            null,
            [
              getsubItem(
                'Free Product Info',
                `${subDirectory}setting/free-product-master`
              ),
              getsubItem(
                'Free Purchase Info',
                `${subDirectory}setting/free-purchase`,
                null,
                [
                  getsubItem(
                    'Free Purchase Order',
                    `${subDirectory}setting/free-purchase-order`
                  ),
                  getsubItem(
                    'Free Purchase Entry',
                    `${subDirectory}setting/free-purchase-entry`
                  ),
                  getsubItem(
                    'Free Purchase Return',
                    `${subDirectory}setting/free-purchase-return`
                  ),
                ]
              ),
            ]
          ),
        ]),
        !iswarehouse &&
        getsubItem('Sales Layout', `${subDirectory}saleslayouts`, null, [
          getsubItem(
            'UI Component',
            `${subDirectory}saleslayouts/component-master`
          ),
          getsubItem(
            'Kiosk Component',
            `${subDirectory}saleslayouts/kiosk-component`
          ),
          getsubItem(
            'Barcode Component',
            `${subDirectory}saleslayouts/barcode-master`
          ),
          getsubItem(
            'Theme Creation',
            `${subDirectory}saleslayouts/theme-creation`
          ),
          getsubItem(
            'Sales Setup',
            `${subDirectory}saleslayouts/sales-selection`
          ),
          getsubItem(
            'Print Setup',
            `${subDirectory}saleslayouts/print-selection`
          ),
            getsubItem(
              'Kiosk Setup',
              `${subDirectory}saleslayouts/kiosk-selection`
            ),
          getsubItem(
            'Barcode / Qr Setup',
            `${subDirectory}saleslayouts/barcode-qr-selection`
          ),
        ]),
        !iswarehouse &&
        getsubItem('Payment', '', null, [
          getsubItem(
            'Payment details',
            `${subDirectory}setting/payment-details`
          ),
          getsubItem(
            'Payment options',
            `${subDirectory}setting/payment-options`
          ),
          getsubItem(
            'Payment Device Access',
            `${subDirectory}setting/payment-device-access`
          ),
          getsubItem(
            'Payment Received',
            `${subDirectory}setting/payment-received-retail`
          ),
        ]),
        !iswarehouse &&
        getsubItem('Extra Charges', `${subDirectory}setting/extra-charges`),
        !iswarehouse &&
        getsubItem(
          'Exchange and Return policy',
          `${subDirectory}setting/Exchange-Return-policy`,
          null,
          [
            getsubItem(
              'Exchange and Return policy',
              `${subDirectory}setting/Exchange-Return-policy`
            ),
            getsubItem(
              'Map Products',
              `${subDirectory}setting/Exchange-Return-policy`
            ),
          ]
        ),
        !iswarehouse &&
        getsubItem(
          'Cancel / Reschedule',
          `${subDirectory}cancelReschedule`,
          null,
          [
            getsubItem(
              'Cancel Applicable Product',
              `${subDirectory}setting/cancel-applicable-product`
            ),
            getsubItem(
              'Cancellation and Reschedule Rules',
              `${subDirectory}setting/cancel-reschedule-rules`
            ),
            getsubItem(
              'Cancel / Payment Change',
              `${subDirectory}setting/cancel-paymentchange`
            ),
            getsubItem(
              'Cancel Unpaid Device Orders',
              `${subDirectory}setting/cancel-pendingpayment`
            ),
            getsubItem(
              'Sales Bill Cancel',
              `${subDirectory}setting/sales-bill-cancel`
            ),
            getsubItem(
              'Sales Bill Product Return',
              `${subDirectory}setting/sales-bill-product-return`
            ),
          ]
        ),
        !iswarehouse &&
        getsubItem('Create Ticket', `${subDirectory}setting/create-ticket`),
      ]),

      !iswarehouse &&
      getItem(
        'Sales',
        `${subDirectory}sales`,
        <BiBookOpen className="iconsize" />
      ),
      !iswarehouse &&
      getItem(
        'Kiosk Sales',
        `${subDirectory}kiosksales`,
        <FcSelfServiceKiosk className="iconsize" />
      ),
      !iswarehouse &&
      getItem(
        'REPORTS',
        `${subDirectory}reports`,
        <TbReportAnalytics className="iconsize" />,
        [
          getsubItem(
            'Tip Amount Settlement',
            `${subDirectory}report/tipamountsettlementlist`
          ),
          getsubItem(
            'Empoloyee Settlement',
            `${subDirectory}report/EmployeeSettlement`
          ),
          getsubItem(
            'PublicQrCode',
            `${subDirectory}report/PublicQrCode`
          ),
          DineinData && dinePreference
            ? getsubItem('KOT', `${subDirectory}report/kot`)
            : '',
          getsubItem(
            'Date Wise Sales Report',
            `${subDirectory}report/datewisereport`
          ),
          getsubItem(
            'Item Wise Sales Report',
            `${subDirectory}report/itemwisereport`
          ),
          getsubItem('Ledger', `${subDirectory}report/ledgerreport`),
          getsubItem(
            'Reprint',
            `${subDirectory}report/reprintreasonreport`
          ),
          EstimateData
            ? getsubItem('Estimate', `${subDirectory}report/`, null, [
                getsubItem(
                  'Item Wise Report',
                  `${subDirectory}report/estimateitemwisereport`
                ),
                getsubItem(
                  'Date Wise Report',
                  `${subDirectory}report/estimatedatewisereport`
                ),
              ])
            : '',

          getsubItem('Revenue', `${subDirectory}report/revenu`, null, [
            // getsubItem('Revenue Date Wise Report', `${subDirectory}report/revenuedatewisereport`),
            getsubItem(
              'Revenue Item  Wise Report',
              `${subDirectory}report/revenueitemWisereport`
            ),
          ]),
        ]
      ),
      !iswarehouse &&
      getItem(
        'Android App',
        `${subDirectory}android-app`,
        <IoLogoAndroid className="iconsize" />
      ),
      CompBranchData?.length > 1 &&
        getItem(
          'Back to Signin',
          `${subDirectory}app-page/back-to-login`,
          <MdOutlineLogin />
        ),
      getItem(
        'Back To Branches',
        `${subDirectory}app-page/branch-all`,
        <AiOutlineLogin />
      ),
      getItem('Sign Out', `${subDirectory}app-page/logout`, <MdOutlineLogout />)
    );
  } else if (UserType === 'Super Admin User' && BranchId) {
    items.push(
      getItem(
        'APPS',
        `${subDirectory}app-page/redirect-apps`,
        <TbAppsFilled className="iconsize" />
      ),
      getItem(
        'HOME',
        `${subDirectory}app-page/home`,
        <BiHomeSmile className="iconsize" />
      ),
      SadminUserSettingMenu?.length > 0 &&
        getItem(
          'SETTINGS',
          `${subDirectory}setting`,
          <FiSettings />,
          SadminUserSettingMenu
        ),
      !iswarehouse && SadminUserBookingMenuItem?.[0],
      !iswarehouse && SadminUserKioskMenuItem?.[0],
      SadminUserfilterReportMenu?.length > 0 &&
      !iswarehouse &&
        getItem(
          'REPORTS',
          `${subDirectory}reports`,
          <TbReportAnalytics className="iconsize" />,
          SadminUserfilterReportMenu
        ),
      CompBranchData?.length > 1 &&
        getItem(
          'Back to Signin',
          `${subDirectory}app-page/back-to-login`,
          <MdOutlineLogin />
        ),
      SadminUserAndroidApp?.[0],
      getItem('Sign Out', `${subDirectory}app-page/logout`, <MdOutlineLogout />)
    );
  } else if ((UserType === 'Admin' || UserType === 'Admin User') && BranchId) {
    items.push(
      getItem(
        'APPS',
        `${subDirectory}app-page/redirect-apps`,
        <TbAppsFilled className="iconsize" />
      ),
      getItem(
        'HOME',
        `${subDirectory}app-page/home`,
        <BiHomeSmile className="iconsize" />
      ),
      getItem('SETTINGS', `${subDirectory}setting`, <FiSettings />, [
        !iswarehouse &&
        getsubItem('Common Master', `${subDirectory}setting/common-master`),
        !iswarehouse &&
        getsubItem('Preference', `${subDirectory}setting/preference`),
        DineinData && dinePreference && !iswarehouse
          ? getsubItem('Dinein', `${subDirectory}setting/dinein-master`)
          : '',
        !iswarehouse && getsubItem('Tax', `${subDirectory}setting/admin-tax`),
        getsubItem('Product Info', `${subDirectory}product`, null, [
          getsubItem('Product', `${subDirectory}setting/product-master`),
          getsubItem(
            'Image Bulk Upload',
            `${subDirectory}setting/image-bulk-upload`
          ),
          getsubItem('Purchase', `${subDirectory}purchase`, null, [
            getsubItem(
              'Purchase Order',
              `${subDirectory}setting/purchase-order/new`
            ),
            getsubItem(
              'Purchase Entry',
              `${subDirectory}setting/purchase-entry/new`
            ),
            getsubItem(
              'Purchase Return',
              `${subDirectory}setting/purchase-return`
            ),
          ]),
          !iswarehouse &&
          getsubItem(
            'Sales Quotation',
            `${subDirectory}setting/sales-quotation`
          ),
          getsubItem(
            'Delivery Challan Info',
            `${subDirectory}setting/delivery-challan`,
            null,
            [
              getsubItem(
                'Delivery Challan',
                `${subDirectory}setting/delivery-challan`
              ),
              getsubItem(
                'DC to Invoice',
                `${subDirectory}setting/delivery-challan-to-invoice`
              ),
            ]
          ),
          getsubItem('Supplier', `${subDirectory}setting/supplier`, null, [
            getsubItem(
              'Supplier Master',
              `${subDirectory}setting/supplier-master`
            ),
            getsubItem(
              'Supplier Product Mapping',
              `${subDirectory}setting/supplierproductmapping-master`
            ),
          ]),
          !iswarehouse &&
          getsubItem('Price Change', `${subDirectory}setting/price-change`),
          (ProORAdvance ||
          featureaddDetails?.find(
            (item) => item?.FeatureAddonName?.toLowerCase() === 'catalog'
            )) &&
            !iswarehouse
            ? getsubItem(
                'Product Catalogue',
                `${subDirectory}setting/product-catalogue`
              )
            : '',
          !iswarehouse &&
          getsubItem(
            'Counter Category Mapping',
            `${subDirectory}setting/counter-category-mapping`
          ),
        ]),
        !iswarehouse &&
        getsubItem('Other Services', `${subDirectory}setting/other-services`),

        !iswarehouse &&
        getsubItem('Store', `${subDirectory}store`, null, [
          getsubItem(
            'Custom Product',
            `${subDirectory}setting/custom-product`
          ),
          getsubItem(
            'Material Issue to Production',
            `${subDirectory}setting/storeto-production`
          ),
          getsubItem(
            'Ready-For-Sale',
            `${subDirectory}setting/readyfor-sale`
          ),
        ]),

        !iswarehouse &&
        getsubItem('Customer', `${subDirectory}setting/customer-master`),
        !iswarehouse &&
        getsubItem('Employee Info', `${subDirectory}employee`, null, [
          getsubItem('Shift', `${subDirectory}setting/shift-master`),
          getsubItem('Employee', `${subDirectory}setting/employee-master`),
          getsubItem(
            'Commission / Incentive',
            `${subDirectory}setting/commission-or-incentive-master`
          ),
          getsubItem(
            'Employee Access',
            `${subDirectory}setting/employee-access`
          ),
          getsubItem('TableMapping', `${subDirectory}setting/TableMapping`),
        ]),
        !iswarehouse &&
        getsubItem('offer', `${subDirectory}offer`, null, [
          getsubItem('Offer', `${subDirectory}setting/offer`),
          getsubItem('Item Wise Offer', `${subDirectory}setting/item-wise`),
          getsubItem('Sales Wise Offer', `${subDirectory}setting/sales-wise`),
          getsubItem(
            'Quantity Wise Offer',
            `${subDirectory}setting/quantity-wise`
          ),
          getsubItem(
            'Buy X and Get X or Y',
            `${subDirectory}setting/buyone-getone`
          ),
          getsubItem('Loyalty Cards', `${subDirectory}setting/loyalty-point`),
          getsubItem('Bundle Offer', `${subDirectory}setting/bundle-offer`),
          getsubItem('Coupon Wise Offer', `${subDirectory}setting/coupon`),
          getsubItem('Promo Code', `${subDirectory}setting/promo-code`),
          getsubItem('Offer Code', `${subDirectory}setting/offer-code`),
          getsubItem('Combo Pack', `${subDirectory}setting/combopack`, null, [
            getsubItem('Combo Product', `${subDirectory}setting/combo-master`),
            getsubItem(
              'Combo Price ',
              `${subDirectory}setting/combo-offer-master`
            ),
          ]),
          getsubItem(
            'Free Product/Purchase',
            `${subDirectory}setting/free-product/purchase`,
            null,
            [
              getsubItem(
                'Free Product Info',
                `${subDirectory}setting/free-product-master`
              ),
              getsubItem(
                'Free Purchase Info',
                `${subDirectory}setting/free-purchase`,
                null,
                [
                  getsubItem(
                    'Free Purchase Order',
                    `${subDirectory}setting/free-purchase-order`
                  ),
                  getsubItem(
                    'Free Purchase Entry',
                    `${subDirectory}setting/free-purchase-entry`
                  ),
                  getsubItem(
                    'Free Purchase Return',
                    `${subDirectory}setting/free-purchase-return`
                  ),
                ]
              ),
            ]
          ),
        ]),
        (Advance ||
        featureaddDetails?.find(
          (item) =>
            item?.FeatureAddonName?.toLowerCase() === 'customized template'
          )) &&
          !iswarehouse
          ? getsubItem(
              'Sales Setup',
              `${subDirectory}saleslayouts/sales-selection`
            )
          : '',
        (Advance ||
        featureaddDetails?.find(
          (item) =>
            item?.FeatureAddonName?.toLowerCase() === 'customized template'
          )) &&
          !iswarehouse
          ? getsubItem(
              'Print Setup',
              `${subDirectory}saleslayouts/print-selection`
            )
          : '',
        featureaddDetails?.find(
          (item) => item?.FeatureAddonName?.toLowerCase() === 'kiosk sales'
        ) &&
          !iswarehouse
          ? getsubItem(
              'Kiosk Setup',
              `${subDirectory}saleslayouts/kiosk-selection`
            )
          : '',
        (Advance ||
        featureaddDetails?.find(
          (item) =>
            item?.FeatureAddonName?.toLowerCase() === 'customized template'
          )) &&
          !iswarehouse
          ? getsubItem(
              'Barcode / Qr Setup',
              `${subDirectory}saleslayouts/barcode-qr-selection`
            )
          : '',
        !iswarehouse &&
        getsubItem('Payment', '', null, [
          getsubItem(
            'Payment details',
            `${subDirectory}setting/payment-details`
          ),
          getsubItem(
            'Payment options',
            `${subDirectory}setting/payment-options`
          ),
          // Writed by sree
          featureaddDetails?.find(
            (item) =>
              item?.FeatureAddonName?.toLowerCase() ===
              'payment device access'
          ) &&
            getsubItem(
              'Payment Device Access',
              `${subDirectory}setting/payment-device-access`
            ),

          getsubItem(
            'Payment Received',
            `${subDirectory}setting/payment-received-retail`
          ),
        ]),
        !iswarehouse &&
        getsubItem('Extra Charges', `${subDirectory}setting/extra-charges`),
        !iswarehouse &&
        getsubItem(
          'Exchange and Return policy',
          `${subDirectory}setting/Exchange-Return-policy`,
          null,
          [
            getsubItem(
              'Exchange and Return policy',
              `${subDirectory}setting/Exchange-Return-policy`
            ),
            getsubItem(
              'Exchange Return Mapping',
              `${subDirectory}setting/exchange-return-mapping`
            ),
          ]
        ),
        !iswarehouse &&
        getsubItem(
          'Cancel / Reschedule',
          `${subDirectory}cancelReschedule`,
          null,
          [
            getsubItem(
              'Cancel Applicable Product',
              `${subDirectory}setting/cancel-applicable-product`
            ),
            getsubItem(
              'Cancellation and Reschedule Rules',
              `${subDirectory}setting/cancel-reschedule-rules`
            ),
            getsubItem(
              'Cancel / Payment Change',
              `${subDirectory}setting/cancel-paymentchange`
            ),
            getsubItem(
              'Cancel Unpaid Device Orders',
              `${subDirectory}setting/cancel-pendingpayment`
            ),
            getsubItem(
              'Sales Bill Cancel',
              `${subDirectory}setting/sales-bill-cancel`
            ),
            getsubItem(
              'Sales Bill Product Return',
              `${subDirectory}setting/sales-bill-product-return`
            ),
          ]
        ),
        !iswarehouse &&
        getsubItem('Create Ticket', `${subDirectory}setting/create-ticket`),
      ]),

      !iswarehouse &&
      getItem(
        'Sales',
        `${subDirectory}sales`,
        <BiBookOpen className="iconsize" />
      ),
      featureaddDetails?.find(
        (item) => item?.FeatureAddonName?.toLowerCase() === 'kiosk sales'
      ) && !iswarehouse
        ? getItem(
            'Kiosk Sales',
            `${subDirectory}kiosksales`,
            <FcSelfServiceKiosk className="iconsize" />
          )
        : '',

      !iswarehouse &&
      getItem(
        'REPORTS',
        `${subDirectory}reports`,
        <TbReportAnalytics className="iconsize" />,
        [
          getsubItem(
                      'Tip Amount Settlement',
                      `${subDirectory}report/tipamountsettlementlist`
                    ),
                     getsubItem(
                                'Empoloyee Settlement',
                                `${subDirectory}report/EmployeeSettlement`
                              ),
          getsubItem(
            'PublicQrCode',
            `${subDirectory}report/PublicQrCode`
          ),
          DineinData && dinePreference
            ? 
            getsubItem('KOT', `${subDirectory}report/kot`)
            : '',
          getsubItem(
            'Date Wise Sales Report',
            `${subDirectory}report/datewisereport`
          ),
          getsubItem(
            'Item Wise Sales Report',
            `${subDirectory}report/itemwisereport`
          ),
          getsubItem('Ledger', `${subDirectory}report/ledgerreport`),
          EstimateData
            ? getsubItem('Estimate', `${subDirectory}report/`, null, [
                getsubItem(
                  'Item Wise Report',
                  `${subDirectory}report/estimateitemwisereport`
                ),
                getsubItem(
                  'Date Wise Report',
                  `${subDirectory}report/estimatedatewisereport`
                ),
              ])
            : '',

          getsubItem('Revenue', `${subDirectory}report/revenu`, null, [
            // getsubItem('Revenue Date Wise Report', `${subDirectory}report/revenuedatewisereport`),
            getsubItem(
              'Revenue Item  Wise Report',
              `${subDirectory}report/revenueitemWisereport`
            ),
          ]),

          getsubItem(
            'Reprint',
            `${subDirectory}report/reprintreasonreport`
          ),
        ]
      ),
      !iswarehouse &&
      getItem(
        'Android App',
        `${subDirectory}android-app`,
        <IoLogoAndroid className="iconsize" />
      ),
      CompBranchData?.length > 1 &&
        getItem(
          'Back to Signin',
          `${subDirectory}app-page/back-to-login`,
          <MdOutlineLogin />
        ),
      getItem('Sign Out', `${subDirectory}app-page/logout`, <MdOutlineLogout />)
    );
  } else if (UserType === 'Employee' && BranchId) {
    items.push(
      getItem(
        'APPS',
        `${subDirectory}app-page/redirect-apps`,
        <TbAppsFilled className="iconsize" />
      ),
      getItem(
        'HOME',
        `${subDirectory}app-page/home`,
        <BiHomeSmile className="iconsize" />
      ),
      getItem(
        'Employee Relieve',
        `${subDirectory}app-page/relieve-request`,
        <GiExitDoor className="iconsize" />
      ),
      EmpSettingMenu?.length > 0 &&
        getItem(
          'SETTINGS',
          `${subDirectory}setting`,
          <FiSettings />,
          EmpSettingMenu
        ),
      EmpBookingMenuItem?.[0],
      EmpKioskMenuItem?.[0],
      EmpfilterReportMenu?.length > 0 &&
        getItem(
          'REPORTS',
          `${subDirectory}reports`,
          <TbReportAnalytics className="iconsize" />,
          EmpfilterReportMenu
        ),
      AndroidApp?.[0],
      CompBranchData?.length > 1 &&
        getItem(
          'Back to Signin',
          `${subDirectory}app-page/back-to-login`,
          <MdOutlineLogin />
        ),
      getItem('Sign Out', `${subDirectory}app-page/logout`, <MdOutlineLogout />)
    );
  }

  const isCurrentPath = location.pathname === `${subDirectory}app-page/home`;

  return (
    <div className="appPage">
      <Messages
        messageType={messageType}
        messageData={messageData}
        onComplete={onComplete}
      />
      <div className="sideNaveParent">
        <div className="paypreLogoDiv"></div>
        {!isCurrentPath ? (
          <SideMenu items={items} mode={'vertical'} theme={'light'}>
            {items?.map((item) =>
              item?.type === 'group' ? (
                <Menu.Item
                  key={item.key}
                  aria-expanded={item.ariaExpanded}
                  style={item.alignLeft ? { textAlign: 'left' } : null}
                >
                  {item?.label}
                </Menu.Item>
              ) : null
            )}
          </SideMenu>
        ) : (
          <SideMenuPozo items={items} collapse={collapse} />
        )}
      </div>

      <div className={isCurrentPath ? 'centerPages' : 'centerPage'}>
        <CenterPage collapse={collapse} setCollapse={setCollapse} />
      </div>
    </div>
  );
};

export default AppPage;
