import { useCallback, useEffect, useState } from 'react';
import { useDispatch } from 'react-redux';
import { BiHomeSmile, BiBookOpen } from 'react-icons/bi';
import { IoLogoAndroid } from 'react-icons/io5';
import { FiSettings } from 'react-icons/fi';
import { TbReportAnalytics } from 'react-icons/tb';
import { MdOutlineLogout, MdOutlineLogin } from 'react-icons/md';
import { AiOutlineLogin, AiOutlineTransaction } from 'react-icons/ai';
import { TbAppsFilled } from 'react-icons/tb';
import { Messages } from '../../Components/Notifications/Messages.jsx';
import SideMenu from '../../Components/Menu/SideMenu';
import { getItem, getsubItem } from '../../Components/Menu/SideMenu';
import CenterPage from './CenterPage';
import {
  getCompBranchData,
  changeSelectedBranchId,
} from '../../Features/BrachLogin/BranchLogin.js';
import { getSession, sessionStore } from '../../Services/Others';
import { useAuth } from '../../AuthContext.jsx'; // Assuming you have an AuthContext

const subDirectory = import.meta.env.BASE_URL;

const WholesaleAppPage = () => {
  const AppId = getSession('AppId');
  const CompId = getSession('CompId');
  const BranchId = getSession('BranchId');
  const UserId = getSession('UserId');

  const dispatch = useDispatch();

  const [messageType, setMessageType] = useState(null);
  const [messageData, setMessageData] = useState(null);
  const [CompBranchData, setCompBranchData] = useState();
  const [EmpSettingMenu, setEmpSettingMenu] = useState([]);
  const [EmpBookingMenuItem, setEmpBookingMenuItem] = useState([]);
  const [empinfoMenu, setempinfoMenu] = useState([]);
  const [Empprodmenu, setEmpprodmenu] = useState([]);
  const [Emppurchasemenu, setEmppurchasemenu] = useState([]);
  const [Empsalesmenu, setEmpsalesmenu] = useState([]);
  const [EmpfilterReportMenu, setfilterReportMenu] = useState([]);
  const [EmpfilterTransactionMenu, setfilterTransactionMenu] = useState([]);
  const [AndroidApp, setAndroidApp] = useState([]);
  const [SadminUserSettingMenu, setSadminUserSettingMenu] = useState([]);
  const [SadminfilterTransactionMenu, setSadminfilterTransactionMenu] =
    useState([]);
  const [SAdminUserprodmenu, setSAdminUserprodmenu] = useState([]);
  const [SadminUserinfoMenu, setSadminUserinfoMenu] = useState([]);

  const [SadminUserBookingMenuItem, setSadminUserBookingMenuItem] = useState(
    []
  );

  const [SAdminUserAndroidApp, setSAdminUserAndroidApp] = useState([]);
  const [SadminUserpurchasemenu, setSadminUserpurchasemenu] = useState([]);
  const [SadminUsersalesmenu, setSadminUsersalesmenu] = useState([]);
  const [SAdminUserfilterReportMenu, setSAdminUserfilterReportMenu] = useState(
    []
  );
  // const [SadminUserfilterReportMenu, setSadminUserfilterReportMenu] = useState([]);

  const { UserType, Access, SadminuserAccess } = useAuth();
  const onComplete = useCallback(() => {
    setMessageData(null);
    setMessageType(null);
  }, []);
  useEffect(() => {
    if (SadminuserAccess?.length > 0) {
      SAdminuserAccesFilterFun(SadminuserAccess);
    }
  }, [SadminuserAccess]);
  useEffect(() => {
    if (Access?.length > 0) {
      EmpAccesFilterFun(Access);
    }
  }, [Access]);
  useEffect(() => {
    // sessionStore("AppId", 1)
    // sessionStore("BranchId", 127)
    // sessionStore("AppName", "Bakery")
    // sessionStore("CompId", 77)
    // sessionStore("MobileNo", "9972702376")
    // sessionStore("UserType", "Admin")
    // sessionStore("UserId", 1791)
    // sessionStore("userName", "Karthiga")
    // sessionStorage.setItem('auth',"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiOTk3MjcwMjM3NiIsIlBhc3N3b3JkIjoiWkB6MTgxMiIsImF1ZCI6WyJodHRwOi8vMTkyLjE2OC4xLjM3OjgwMTMiLCJodHRwOi8vMTkyLjE2OC4xLjM3OjgwMTIiLCJodHRwOi8vMTkyLjE2OC4xLjM3OjgwMTUiLCJodHRwOi8vMTkyLjE2OC4xLjM3OjgwMTYiLCJodHRwOi8vMTkyLjE2OC4xLjM3OjgwMTQiLCJodHRwOi8vbG9jYWxob3N0OjUzNTU2IiwiaHR0cDovLzE5Mi4xNjguMS4zNzo4MDEzIl0sImV4cCI6MTczNDQ2MjIyMCwiaXNzIjoiaHR0cDovLzE5Mi4xNjguMS4zNzo4MDAxIn0.c6EOfD0TR6oZBtHSq7-Fe4_4_LYXbVaLQ5pfeIqADuk")
    fetchBranchData();
  }, []);

  useEffect(() => {
    fetchBranchData();
  }, [CompId]);
  const SdminASettingmenuItems = [
    getsubItem('Common Master', `${subDirectory}setting/common-master`),
    getsubItem('Customer', `${subDirectory}setting/customer-master`),
  ];

  const SAdminUserBookingMenuItem = [
    // getItem(
    //   'Transaction',
    //   `${subDirectory}app-page/transaction`, <AiOutlineTransaction className="iconsize" />
    // ),
    getItem(
      'Whole Sales',
      `${subDirectory}wholesales`,
      <BiBookOpen className="iconsize" />
    ),
  ];
  const SadminUserinfoitem = [
    getsubItem('Employee', `${subDirectory}setting/employee-master`),
    getsubItem('Shift', `${subDirectory}setting/shift-master`),
    getsubItem('Employee Access', `${subDirectory}setting/employee-access`),
    getsubItem(
      'Employee Screen Rights',
      `${subDirectory}setting/employee-screenrights`
    ),
  ];
  const SadminUserReportMenu = [
    getsubItem('Abstract For Purchase', `${subDirectory}report/sellerabstract`),
    getsubItem('Abstract For Sales', `${subDirectory}report/abstract`),
    getsubItem('Ledger', `${subDirectory}report/ledger`),
  ];

  const SadminUserTransactionMenu = [
    getsubItem('Sales', `${subDirectory}transaction/sales`),
    getsubItem(
      'Payment Received',
      `${subDirectory}transaction/payment-received`
    ),
    getsubItem('Seller Payment', `${subDirectory}transaction/seller-payment`),
  ];

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

  const SadminUserpurchaseReportMenu = [
    getsubItem('Purchase Report', `${subDirectory}report/purchasereport`),
    getsubItem(
      'Purchase Payment',
      `${subDirectory}report/paymentpurchasereport`
    ),
  ];

  const SadminUsersalesReportMenu = [
    getsubItem('Sales Report', `${subDirectory}report/salesreport`),
    getsubItem('Sales Payment', `${subDirectory}report/paymentsalesreport`),
  ];
  // Employee Access start
  const SettingmenuItems = [
    getsubItem('Common Master', `${subDirectory}setting/common-master`),
    getsubItem('Customer', `${subDirectory}setting/customer-master`),
  ];

  const BookingMenuItem = [
    getItem(
      'Whole Sales',
      `${subDirectory}wholesales`,
      <BiBookOpen className="iconsize" />
    ),
  ];

  const empinfoitem = [
    getsubItem('Employee', `${subDirectory}setting/employee-master`),
    getsubItem('Shift', `${subDirectory}setting/shift-master`),
    getsubItem('Employee Access', `${subDirectory}setting/employee-access`),
    getsubItem(
      'Employee Screen Rights',
      `${subDirectory}setting/employee-screenrights`
    ),
  ];
  const prodMenu = [
    getsubItem('Product', `${subDirectory}setting/wholesale-product-master`),
    getsubItem('Seller', `${subDirectory}setting/supplier-master`),
    getsubItem('Product Entry', `${subDirectory}setting/product-entry`),
    // getsubItem('Extra Charges', `${subDirectory}setting/wholesale-extracharges`),
    getsubItem('Preorder', `${subDirectory}setting/wholesale-preorder`),
  ];

  const purchaseReportMenu = [
    getsubItem('Purchase Report', `${subDirectory}report/purchasereport`),
    getsubItem(
      'Purchase Payment',
      `${subDirectory}report/paymentpurchasereport`
    ),
  ];

  const salesReportMenu = [
    getsubItem('Sales Report', `${subDirectory}report/salesreport`),
    getsubItem('Sales Payment', `${subDirectory}report/paymentsalesreport`),
  ];

  const ReportMenu = [
    getsubItem('Abstract For Purchase', `${subDirectory}report/sellerabstract`),
    getsubItem('Abstract For Sales', `${subDirectory}report/abstract`),
    getsubItem('Ledger', `${subDirectory}report/ledger`),
  ];

  const AndroidAppMenuItem = [
    getItem(
      'Android App',
      `${subDirectory}android-app`,
      <IoLogoAndroid className="iconsize" />
    ),
  ];
  const TransactionMenu = [
    getsubItem('Sales', `${subDirectory}transaction/sales`),
    getsubItem(
      'Payment Received',
      `${subDirectory}transaction/payment-received`
    ),
    getsubItem('Seller Payment', `${subDirectory}transaction/seller-payment`),
  ];
  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 indexToSliceFirst = SettingmenuItems?.findIndex(
      (item) => item.label === 'Common Master'
    );

    const indexToSliceSecond = SettingmenuItems?.findIndex(
      (item) => item.label === 'Customer'
    );

    setEmpSettingMenu((prevMenu) => [
      ...prevMenu?.slice(0, indexToSliceFirst),
      ...prodata,
      ...prevMenu?.slice(indexToSliceFirst, indexToSliceSecond),
      ...empdata,
    ]);
  }, [empinfoMenu, Empprodmenu]);
  useEffect(() => {
    const empdata =
      SadminUserinfoMenu.length > 0
        ? [
            getsubItem(
              'Employee Info',
              `${subDirectory}employee`,
              null,
              SadminUserinfoMenu
            ),
          ]
        : [];
    const prodata =
      SAdminUserprodmenu.length > 0
        ? [
            getsubItem(
              'Product Info',
              `${subDirectory}product`,
              null,
              SAdminUserprodmenu
            ),
          ]
        : [];

    const indexToSliceFirst = SettingmenuItems?.findIndex(
      (item) => item.label === 'Common Master'
    );

    const indexToSliceSecond = SettingmenuItems?.findIndex(
      (item) => item.label === 'Customer'
    );

    setSadminUserSettingMenu((prevMenu) => [
      ...prevMenu?.slice(0, indexToSliceFirst),
      ...prodata,
      ...prevMenu?.slice(indexToSliceFirst, indexToSliceSecond),
      ...empdata,
    ]);
  }, [SadminUserinfoMenu, SAdminUserprodmenu]);

  useEffect(() => {
    const purchasedata =
      Emppurchasemenu.length > 0
        ? [
            getsubItem(
              'Purchase Reports',
              `${subDirectory}purchase`,
              null,
              Emppurchasemenu
            ),
          ]
        : [];
    const salesdata =
      Empsalesmenu.length > 0
        ? [
            getsubItem(
              'Sales Reports',
              `${subDirectory}sales`,
              null,
              Empsalesmenu
            ),
          ]
        : [];

    setfilterReportMenu((prevMenu) => {
      const newMenu = new Set([...prevMenu, ...purchasedata, ...salesdata]);
      return Array.from(newMenu);
    });
  }, [Emppurchasemenu, Empsalesmenu]);

  useEffect(() => {
    const purchasedata =
      SadminUserpurchasemenu.length > 0
        ? [
            getsubItem(
              'Purchase Reports',
              `${subDirectory}purchase`,
              null,
              SadminUserpurchasemenu
            ),
          ]
        : [];
    const salesdata =
      SadminUsersalesmenu.length > 0
        ? [
            getsubItem(
              'Sales Reports',
              `${subDirectory}sales`,
              null,
              SadminUsersalesmenu
            ),
          ]
        : [];

    setSAdminUserfilterReportMenu((prevMenu) => {
      const newMenu = new Set([...prevMenu, ...purchasedata, ...salesdata]);
      return Array.from(newMenu);
    });
  }, [SadminUserpurchasemenu, SadminUsersalesmenu]);

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

  const SadminUserfilterMenuItems = (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: SdminASettingmenuItems, setter: setSadminUserSettingMenu },
      {
        items: SAdminUserBookingMenuItem,
        setter: setSadminUserBookingMenuItem,
      },
      { items: SadminUserinfoitem, setter: setSadminUserinfoMenu },
      { items: SadminUserReportMenu, setter: setSAdminUserfilterReportMenu },
      {
        items: SadminUserTransactionMenu,
        setter: setSadminfilterTransactionMenu,
      },
      { items: SadminAndroidAppMenuItem, setter: setSAdminUserAndroidApp },
    ];

    menuConfig.forEach(({ items, setter }) => {
      const filteredMenu = SadminUserfilterMenuItems(items, Access);
      setter(filteredMenu);
    });
    const filterprodMenuItem = SadminUserfilterMenuItems(prodMenu, Access);
    setSAdminUserprodmenu([...filterprodMenuItem]);
    const filterpurchaseMenuItem = SadminUserfilterMenuItems(
      SadminUserpurchaseReportMenu,
      Access
    );
    setSadminUserpurchasemenu([...filterpurchaseMenuItem]);
    const filtersalesMenuItem = SadminUserfilterMenuItems(
      SadminUsersalesReportMenu,
      Access
    );
    setSadminUsersalesmenu([...filtersalesMenuItem]);
  };

  const EmpAccesFilterFun = async (Access) => {
    const menuConfig = [
      { items: SettingmenuItems, setter: setEmpSettingMenu },
      { items: BookingMenuItem, setter: setEmpBookingMenuItem },
      { items: empinfoitem, setter: setempinfoMenu },
      { items: ReportMenu, setter: setfilterReportMenu },
      { items: TransactionMenu, setter: setfilterTransactionMenu },
      { items: AndroidAppMenuItem, setter: setAndroidApp },
    ];

    menuConfig.forEach(({ items, setter }) => {
      const filteredMenu = filterMenuItems(items, Access);
      setter(filteredMenu);
    });
    const filterprodMenuItem = filterMenuItems(prodMenu, Access);
    setEmpprodmenu([...filterprodMenuItem]);
    const filterpurchaseMenuItem = filterMenuItems(purchaseReportMenu, Access);
    setEmppurchasemenu([...filterpurchaseMenuItem]);
    const filtersalesMenuItem = filterMenuItems(salesReportMenu, Access);
    setEmpsalesmenu([...filtersalesMenuItem]);
  };
  // Employee Access END

  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)
          );
        }
      }
    }
  };
  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 />, [
        getsubItem('Config Type', `${subDirectory}setting/config-type`),
        getsubItem('Common Master', `${subDirectory}setting/common-master`),
        getsubItem('Languages', `${subDirectory}setting/languages`),
        getsubItem('Product Info', `${subDirectory}product`, null, [
          getsubItem(
            'Product',
            `${subDirectory}setting/wholesale-product-master`
          ),
          getsubItem('Seller', `${subDirectory}setting/supplier-master`),
          getsubItem('Product Entry', `${subDirectory}setting/product-entry`),
          getsubItem('Preorder', `${subDirectory}setting/wholesale-preorder`),
        ]),
        getsubItem('Customer', `${subDirectory}setting/customer-master`),
        getsubItem('Employee Info', `${subDirectory}employee`, null, [
          getsubItem('Employee', `${subDirectory}setting/employee-master`),
          getsubItem('Shift', `${subDirectory}setting/shift-master`),
          getsubItem(
            'Employee Access',
            `${subDirectory}setting/employee-access`
          ),
          getsubItem(
            'Employee Screen Rights',
            `${subDirectory}setting/employee-screenrights`
          ),
        ]),
      ]),
      getItem(
        'Transaction',
        `${subDirectory}transaction`,
        <AiOutlineTransaction className="iconsize" />,
        [
          getsubItem('Sales', `${subDirectory}transaction/sales`),
          getsubItem(
            'Payment Received',
            `${subDirectory}transaction/payment-received`
          ),
          getsubItem(
            'Seller Payment',
            `${subDirectory}transaction/seller-payment`
          ),
        ]
      ),

      getItem(
        'Whole Sales',
        `${subDirectory}wholesales`,
        <BiBookOpen className="iconsize" />
      ),
      getItem(
        'REPORTS',
        `${subDirectory}reports`,
        <TbReportAnalytics className="iconsize" />,
        [
          getsubItem(
            'Abstract For Purchase',
            `${subDirectory}report/sellerabstract`
          ),
          getsubItem('Abstract For Sales', `${subDirectory}report/abstract`),
          getsubItem('Ledger', `${subDirectory}report/ledger`),
          getsubItem('Purchase Reports', `${subDirectory}purchase`, null, [
            getsubItem(
              'Purchase Report',
              `${subDirectory}report/purchasereport`
            ),
            getsubItem(
              'Purchase Payment',
              `${subDirectory}report/paymentpurchasereport`
            ),
          ]),
          getsubItem('Sales Reports', `${subDirectory}sales`, null, [
            getsubItem('Sales Report', `${subDirectory}report/salesreport`),
            getsubItem(
              'Sales Payment',
              `${subDirectory}report/paymentsalesreport`
            ),
          ]),
        ]
      ),
      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
        ),
      SadminfilterTransactionMenu?.length > 0 &&
        getItem(
          'TRANSACTION',
          `${subDirectory}transaction`,
          <AiOutlineTransaction className="iconsize" />,
          SadminfilterTransactionMenu
        ),
      SadminUserBookingMenuItem?.[0],
      SAdminUserfilterReportMenu?.length > 0 &&
        getItem(
          'REPORTS',
          `${subDirectory}reports`,
          <TbReportAnalytics className="iconsize" />,
          SAdminUserfilterReportMenu
        ),
      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 />, [
        getsubItem('Common Master', `${subDirectory}setting/common-master`),
        getsubItem('Product Info', `${subDirectory}product`, null, [
          getsubItem(
            'Product',
            `${subDirectory}setting/wholesale-product-master`
          ),
          getsubItem('Seller', `${subDirectory}setting/supplier-master`),
          getsubItem('Product Entry', `${subDirectory}setting/product-entry`),
          getsubItem('Preorder', `${subDirectory}setting/wholesale-preorder`),
        ]),

        getsubItem('Customer', `${subDirectory}setting/customer-master`),
        getsubItem('Employee Info', `${subDirectory}employee`, null, [
          getsubItem('Employee', `${subDirectory}setting/employee-master`),
          getsubItem('Shift', `${subDirectory}setting/shift-master`),
          getsubItem(
            'Employee Access',
            `${subDirectory}setting/employee-access`
          ),
          getsubItem(
            'Employee Screen Rights',
            `${subDirectory}setting/employee-screenrights`
          ),
        ]),
      ]),
      getItem(
        'Transaction',
        `${subDirectory}transaction`,
        <AiOutlineTransaction className="iconsize" />,
        [
          getsubItem('Sales', `${subDirectory}transaction/sales`),
          getsubItem(
            'Payment Received',
            `${subDirectory}transaction/payment-received`
          ),
          getsubItem(
            'Seller Payment',
            `${subDirectory}transaction/seller-payment`
          ),
        ]
      ),
      getItem(
        'Whole Sales',
        `${subDirectory}wholesales`,
        <BiBookOpen className="iconsize" />
      ),
      getItem(
        'REPORTS',
        `${subDirectory}reports`,
        <TbReportAnalytics className="iconsize" />,
        [
          getsubItem(
            'Abstract For Purchase',
            `${subDirectory}report/sellerabstract`
          ),
          getsubItem('Abstract For Sales', `${subDirectory}report/abstract`),
          getsubItem('Ledger', `${subDirectory}report/ledger`),

          getsubItem('Purchase Reports', `${subDirectory}purchase`, null, [
            getsubItem(
              'Purchase Report',
              `${subDirectory}report/purchasereport`
            ),
            getsubItem(
              'Purchase Payment',
              `${subDirectory}report/paymentpurchasereport`
            ),
          ]),
          getsubItem('Sales Reports', `${subDirectory}sales`, null, [
            getsubItem('Sales Report', `${subDirectory}report/salesreport`),
            getsubItem(
              'Sales Payment',
              `${subDirectory}report/paymentsalesreport`
            ),
          ]),
        ]
      ),
      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(
        'HOME',
        `${subDirectory}app-page/home`,
        <BiHomeSmile className="iconsize" />
      ),
      EmpSettingMenu?.length > 0 &&
        getItem(
          'SETTINGS',
          `${subDirectory}setting`,
          <FiSettings />,
          EmpSettingMenu
        ),
      EmpfilterTransactionMenu?.length > 0 &&
        getItem(
          'TRANSACTION',
          `${subDirectory}transaction`,
          <AiOutlineTransaction className="iconsize" />,
          EmpfilterTransactionMenu
        ),
      EmpBookingMenuItem?.[0],
      EmpfilterReportMenu?.length > 0 &&
        getItem(
          'REPORTS',
          `${subDirectory}reports`,
          <TbReportAnalytics className="iconsize" />,
          EmpfilterReportMenu
        ),
      AndroidApp?.[0],
      getItem('Sign Out', `${subDirectory}app-page/logout`, <MdOutlineLogout />)
    );
  }

  return (
    <div className="appPage">
      <Messages
        messageType={messageType}
        messageData={messageData}
        onComplete={onComplete}
      />
      <div className="sideNaveParent">
        <div className="paypreLogoDiv"></div>
        <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>
      </div>
      <div className="centerPage">
        <CenterPage />
      </div>
    </div>
  );
};

export default WholesaleAppPage;
