import { FC } from "react";
import { Route, Routes, useLocation } from "react-router-dom";
import { Pages } from "../config/Pages";
import { clx } from "../helpers/utils";
import AccessLogsList from "../pages/accessLogs/AccessLogsList";
import AccessLogsStats from "../pages/accessLogs/AccessLogsStats";
import ErrorLogs from "../pages/accessLogs/ErrorLogs";
import PermissionLogs from "../pages/accessLogs/PermissionLogs";
import AdsList from "../pages/ads/AdsList";
import CreateAds from "../pages/ads/CreateAds";
import UpdateAds from "../pages/ads/Update";
import Create from "../pages/annoncement/Create";
import AnnouncementtList from "../pages/annoncement/List";
import Update from "../pages/annoncement/Update";
import BlogCategory from "../pages/blog/BlogCategory";
import BlogList from "../pages/blog/BlogList";
import Comments from "../pages/blog/Comments";
import CreateBlog from "../pages/blog/CreateBlog";
import UpdateBlog from "../pages/blog/Update";
import CreateBankCard from "../pages/cardBank/Create";
import EditBankCard from "../pages/cardBank/Edit";
import CardBankList from "../pages/cardBank/List";
import CriticismsDetail from "../pages/criticisms/Detail";
import CriticismsList from "../pages/criticisms/List";
import CreateCustomer from "../pages/customer/Create";
import CustomerList from "../pages/customer/List";
import UpdateCustomer from "../pages/customer/Update";
import CreateDiscount from "../pages/discounts/CreateDiscount";
import DiscountsList from "../pages/discounts/DiscountsList";
import UpdateDiscount from "../pages/discounts/UpdateDiscount";
import DkalaGroupIconList from "../pages/dkala/icon/GroupList";
import DkalaIconsList from "../pages/dkala/icon/List";
import DkalaWarningsList from "../pages/dkala/report/List.tsx";
import ShopsList from "../pages/dkala/shop/List.tsx";
import DkalaSmsCountList from "../pages/dkala/shop/SmsCountList.tsx";
import UpdateShop from "../pages/dkala/shop/Update.tsx";
import Domains from "../pages/dmail/Domains.tsx";
import GroupIconList from "../pages/dmenu/icon/GroupList";
import IconsList from "../pages/dmenu/icon/List";
import WarningsList from "../pages/dmenu/report/List.tsx";
import RestaurantsList from "../pages/dmenu/restaurant/List.tsx";
import SmsCountList from "../pages/dmenu/restaurant/SmsCountList.tsx";
import UpdateRestaurant from "../pages/dmenu/restaurant/Update.tsx";
import DpageStickersList from "../pages/dpage/sticker/List";
import ListFeedback from "../pages/feedback/List";
import CreateGuide from "../pages/guide/Create";
import List from "../pages/guide/List";
import UpdateGuide from "../pages/guide/Update.tsx";
import Home from "../pages/home/Home";
import LearningCategory from "../pages/learning/Category";
import CreateLearning from "../pages/learning/Create";
import LearningList from "../pages/learning/List";
import MessageDetail from "../pages/messages/Detail";
import MessagesList from "../pages/messages/List";
import PaymentList from "../pages/payment/List";
import Profile from "../pages/profile/Profile";
import CreateReceipt from "../pages/receipts/Create";
import ReceiptsDetail from "../pages/receipts/Detail";
import ReceiptsList from "../pages/receipts/List";
import CreateReseller from "../pages/reseller/Create.tsx";
import ResellerList from "../pages/reseller/List.tsx";
import Withdraw from "../pages/reseller/Withdraw.tsx";
import AddService from "../pages/service/AddService";
import Category from "../pages/service/Category";
import DetailService from "../pages/service/DetailService";
import ListService from "../pages/service/List";
import MyServices from "../pages/service/MyServices";
import OtherServices from "../pages/service/OtherServices";
import Plans from "../pages/service/Plans";
import Reviews from "../pages/service/Reviews";
import UpdateService from "../pages/service/UpdateService";
import Setting from "../pages/setting/Setting";
import CreateSlider from "../pages/slider/Create";
import SliderList from "../pages/slider/List";
import UpdateSlider from "../pages/slider/Update";
import SubscriptionsList from "../pages/subscriptions/List.tsx";
import CreatePlan from "../pages/support/Create";
import SupportList from "../pages/support/List";
import PlanUsers from "../pages/support/PlanUsers";
import UpdateSupport from "../pages/support/Update";
import CreateProject from "../pages/taskmanager/project/Create.tsx";
import ProjectList from "../pages/taskmanager/project/List.tsx";
import UpdateProject from "../pages/taskmanager/project/Update.tsx";
import Workspace from "../pages/taskmanager/workspace.tsx";
import CreateWorkspace from "../pages/taskmanager/workspace/Create.tsx";
import WorkspaceList from "../pages/taskmanager/workspace/List.tsx";
import UpdateWorkspace from "../pages/taskmanager/workspace/Update.tsx";
import TicketCategory from "../pages/ticket/Category";
import CreateTicket from "../pages/ticket/CreateTicket";
import TicketDetail from "../pages/ticket/Detail";
import TicketList from "../pages/ticket/TicketList";
import TransactionList from "../pages/transaction/List";
import CreateUser from "../pages/users/Create";
import GroupCreate from "../pages/users/GroupCreate";
import GroupList from "../pages/users/GroupList";
import UsersList from "../pages/users/List";
import RoleCreate from "../pages/users/RoleCreate";
import RoleUpdate from "../pages/users/RoleUpdate";
import RolesList from "../pages/users/RolesList";
import UpdateUser from "../pages/users/Update";
import Wallet from "../pages/wallet/Wallet";
import Footer from "../shared/Footer";
import Header from "../shared/Header";
import SideBar from "../shared/SideBar";
import { useSharedStore } from "../shared/store/sharedStore";
// import WarningsList from '../pages/dmenu/reports/List' // TODO: Create this component
const MainRouter: FC = () => {
  const { hasSubMenu } = useSharedStore();
  const { pathname } = useLocation();
  const isWorkspace = pathname.startsWith(Pages.taskmanager.workspace);

  return (
    <div className={clx("overflow-hidden", isWorkspace ? "p-0 xl:p-4" : "p-4")}>
      {!isWorkspace && <SideBar />}
      <Header />
      <div className={clx("flex-1 mt-[68px] xl:mt-[81px]", !isWorkspace && "xl:ms-[269px]", !isWorkspace && hasSubMenu && "xl:ms-[305px]")}>
        <div className={clx("flex flex-col", isWorkspace ? "h-[calc(100dvh-68px)] xl:h-[calc(100dvh-113px)] overflow-hidden" : "overflow-auto h-[calc(100vh-113px)]")}>
          <div className={clx("flex-1 min-h-0", isWorkspace && "overflow-hidden h-full")}>
            <Routes>
              <Route
                path={Pages.dashboard}
                element={<Home />}
              />
              <Route
                path={Pages.services.mine}
                element={<MyServices />}
              />
              <Route
                path={Pages.services.other}
                element={<OtherServices />}
              />
              <Route
                path={Pages.services.detail + ":id"}
                element={<DetailService />}
              />
              <Route
                path={Pages.services.add}
                element={<AddService />}
              />
              <Route
                path={Pages.services.list}
                element={<ListService />}
              />
              <Route
                path={Pages.services.update + ":id"}
                element={<UpdateService />}
              />
              <Route
                path={Pages.services.category}
                element={<Category />}
              />
              <Route
                path={Pages.services.plan + ":id"}
                element={<Plans />}
              />
              <Route
                path={Pages.services.review}
                element={<Reviews />}
              />
              <Route
                path={Pages.ticket.list}
                element={<TicketList />}
              />
              <Route
                path={Pages.ticket.create}
                element={<CreateTicket />}
              />
              <Route
                path={Pages.ticket.category}
                element={<TicketCategory />}
              />
              <Route
                path={Pages.ticket.detail + ":id"}
                element={<TicketDetail />}
              />
              <Route
                path={Pages.ads.list}
                element={<AdsList />}
              />
              <Route
                path={Pages.ads.create}
                element={<CreateAds />}
              />
              <Route
                path={Pages.ads.update + ":id"}
                element={<UpdateAds />}
              />
              <Route
                path={Pages.discount.list}
                element={<DiscountsList />}
              />
              <Route
                path={Pages.discount.create}
                element={<CreateDiscount />}
              />
              <Route
                path={Pages.discount.detail + ":id"}
                element={<UpdateDiscount />}
              />
              <Route
                path={Pages.blog.list}
                element={<BlogList />}
              />
              <Route
                path={Pages.blog.create}
                element={<CreateBlog />}
              />
              <Route
                path={Pages.blog.category}
                element={<BlogCategory />}
              />
              <Route
                path={Pages.blog.detail + ":id"}
                element={<UpdateBlog />}
              />
              <Route
                path={Pages.transactions}
                element={<TransactionList />}
              />
              <Route
                path={Pages.receipts.index}
                element={<ReceiptsList />}
              />
              <Route
                path={Pages.receipts.detail + ":id"}
                element={<ReceiptsDetail />}
              />
              <Route
                path={Pages.receipts.create}
                element={<CreateReceipt />}
              />
              <Route
                path={Pages.announcement.list}
                element={<AnnouncementtList />}
              />
              <Route
                path={Pages.announcement.detail + ":id"}
                element={<Update />}
              />
              <Route
                path={Pages.announcement.create}
                element={<Create />}
              />
              <Route
                path={Pages.criticisms.list}
                element={<CriticismsList />}
              />
              <Route
                path={Pages.criticisms.detail + ":id"}
                element={<CriticismsDetail />}
              />
              <Route
                path={Pages.learning.list}
                element={<LearningList />}
              />
              <Route
                path={Pages.learning.create}
                element={<CreateLearning />}
              />
              <Route
                path={Pages.learning.category}
                element={<LearningCategory />}
              />
              <Route
                path={Pages.setting}
                element={<Setting />}
              />
              <Route
                path={Pages.wallet}
                element={<Wallet />}
              />
              <Route
                path={Pages.profile}
                element={<Profile />}
              />
              <Route
                path={Pages.customer.list}
                element={<CustomerList />}
              />
              <Route
                path={Pages.customer.create}
                element={<CreateCustomer />}
              />
              <Route
                path={Pages.customer.update + ":id"}
                element={<UpdateCustomer />}
              />
              <Route
                path={Pages.messages.list}
                element={<MessagesList />}
              />
              <Route
                path={Pages.messages.detail + ":id"}
                element={<MessageDetail />}
              />
              <Route
                path={Pages.users.list}
                element={<UsersList />}
              />
              <Route
                path={Pages.users.create}
                element={<CreateUser />}
              />
              <Route
                path={Pages.users.detail + ":id"}
                element={<UpdateUser />}
              />
              <Route
                path={Pages.users.roleList}
                element={<RolesList />}
              />
              <Route
                path={Pages.users.roleCreate}
                element={<RoleCreate />}
              />
              <Route
                path={Pages.users.roleUpdate + ":id"}
                element={<RoleUpdate />}
              />
              <Route
                path={Pages.users.groupAdd}
                element={<GroupCreate />}
              />
              <Route
                path={Pages.users.groupList}
                element={<GroupList />}
              />
              <Route
                path={Pages.cardBank.create}
                element={<CreateBankCard />}
              />
              <Route
                path={Pages.cardBank.list}
                element={<CardBankList />}
              />
              <Route
                path={Pages.cardBank.detail + ":id"}
                element={<EditBankCard />}
              />
              <Route
                path={Pages.payment.list}
                element={<PaymentList />}
              />
              <Route
                path={Pages.sliders.create}
                element={<CreateSlider />}
              />
              <Route
                path={Pages.sliders.list}
                element={<SliderList />}
              />
              <Route
                path={Pages.sliders.detail + ":id"}
                element={<UpdateSlider />}
              />
              <Route
                path={Pages.blog.comments}
                element={<Comments />}
              />
              <Route
                path={Pages.support.create}
                element={<CreatePlan />}
              />
              <Route
                path={Pages.support.list}
                element={<SupportList />}
              />
              <Route
                path={Pages.support.detail + ":id"}
                element={<UpdateSupport />}
              />
              <Route
                path={Pages.support.planUsers + ":id"}
                element={<PlanUsers />}
              />
              <Route
                path={Pages.services.guide + ":id"}
                element={<List />}
              />
              <Route
                path={Pages.services.guide + ":id/create"}
                element={<CreateGuide />}
              />
              <Route
                path={Pages.services.guide + ":id/:guideId"}
                element={<UpdateGuide />}
              />
              <Route
                path={Pages.feedback.list}
                element={<ListFeedback />}
              />
              <Route
                path={Pages.accessLogs.list}
                element={<AccessLogsList />}
              />
              <Route
                path={Pages.accessLogs.stats}
                element={<AccessLogsStats />}
              />
              <Route
                path={Pages.accessLogs.errors}
                element={<ErrorLogs />}
              />
              <Route
                path={Pages.accessLogs.permissions}
                element={<PermissionLogs />}
              />

              <Route
                path={Pages.dmenu.icons.list}
                element={<IconsList />}
              />
              <Route
                path={Pages.dmenu.icons.groupList}
                element={<GroupIconList />}
              />
              <Route
                path={Pages.dmenu.warnings.list}
                element={<WarningsList />}
              />
              <Route
                path={Pages.dmenu.restaurants.list}
                element={<RestaurantsList />}
              />
              <Route
                path={Pages.dmenu.restaurants.smsCountList}
                element={<SmsCountList />}
              />
              <Route
                path={Pages.dmenu.restaurants.update + ":id"}
                element={<UpdateRestaurant />}
              />

              <Route
                path={Pages.dkala.icons.list}
                element={<DkalaIconsList />}
              />
              <Route
                path={Pages.dkala.icons.groupList}
                element={<DkalaGroupIconList />}
              />
              <Route
                path={Pages.dkala.warnings.list}
                element={<DkalaWarningsList />}
              />
              <Route
                path={Pages.dkala.shops.list}
                element={<ShopsList />}
              />
              <Route
                path={Pages.dkala.shops.smsCountList}
                element={<DkalaSmsCountList />}
              />
              <Route
                path={Pages.dkala.shops.update + ":id"}
                element={<UpdateShop />}
              />

              <Route
                path={Pages.dpage.stickers.list}
                element={<DpageStickersList />}
              />

              <Route
                path={Pages.subscriptions.list}
                element={<SubscriptionsList />}
              />

              <Route
                path={Pages.dmail.list}
                element={<Domains />}
              />

              <Route
                path={Pages.reseller.list}
                element={<ResellerList />}
              />
              <Route
                path={Pages.reseller.create}
                element={<CreateReseller />}
              />
              <Route
                path={Pages.reseller.withdraw}
                element={<Withdraw />}
              />

              <Route
                path={Pages.taskmanager.workspace + ":slug"}
                element={<Workspace />}
              />
              <Route
                path={Pages.taskmanager.workspaceList}
                element={<WorkspaceList />}
              />
              <Route
                path={Pages.taskmanager.createWorkspace}
                element={<CreateWorkspace />}
              />
              <Route
                path={Pages.taskmanager.updateWorkspace + ":id"}
                element={<UpdateWorkspace />}
              />
              <Route
                path={Pages.taskmanager.createProject}
                element={<CreateProject />}
              />
              <Route
                path={Pages.taskmanager.updateProject + ":id"}
                element={<UpdateProject />}
              />
              <Route
                path={Pages.taskmanager.projectList + ":workspaceId"}
                element={<ProjectList />}
              />
            </Routes>
          </div>
          {!isWorkspace && <div className="h-20 shrink-0 xl:hidden" />}
        </div>
      </div>
      {!isWorkspace && <Footer />}
    </div>
  );
};

export default MainRouter;
