<template>
  <!--  BEGIN MAIN CONTAINER  -->
  <!-- <div>112</div> -->
  <div class="relative">
    <!-- sidebar menu overlay -->
    <div class="fixed inset-0 bg-[black]/60 z-50 lg:hidden" :class="{ hidden: !store.state.sidebar }" @click="toggleSidebar"></div>

    <!-- screen loader -->
    <div
      v-show="store.state.isShowMainLoader"
      class="screen_loader fixed inset-0 bg-[#fafafa] dark:bg-[#060818] z-[60] grid place-content-center animate__animated"
    >
      <svg width="64" height="64" viewBox="0 0 135 135" xmlns="http://www.w3.org/2000/svg" fill="#4361ee">
        <path
          d="M67.447 58c5.523 0 10-4.477 10-10s-4.477-10-10-10-10 4.477-10 10 4.477 10 10 10zm9.448 9.447c0 5.523 4.477 10 10 10 5.522 0 10-4.477 10-10s-4.478-10-10-10c-5.523 0-10 4.477-10 10zm-9.448 9.448c-5.523 0-10 4.477-10 10 0 5.522 4.477 10 10 10s10-4.478 10-10c0-5.523-4.477-10-10-10zM58 67.447c0-5.523-4.477-10-10-10s-10 4.477-10 10 4.477 10 10 10 10-4.477 10-10z"
        >
          <animateTransform attributeName="transform" type="rotate" from="0 67 67" to="-360 67 67" dur="2.5s" repeatCount="indefinite" />
        </path>
        <path
          d="M28.19 40.31c6.627 0 12-5.374 12-12 0-6.628-5.373-12-12-12-6.628 0-12 5.372-12 12 0 6.626 5.372 12 12 12zm30.72-19.825c4.686 4.687 12.284 4.687 16.97 0 4.686-4.686 4.686-12.284 0-16.97-4.686-4.687-12.284-4.687-16.97 0-4.687 4.686-4.687 12.284 0 16.97zm35.74 7.705c0 6.627 5.37 12 12 12 6.626 0 12-5.373 12-12 0-6.628-5.374-12-12-12-6.63 0-12 5.372-12 12zm19.822 30.72c-4.686 4.686-4.686 12.284 0 16.97 4.687 4.686 12.285 4.686 16.97 0 4.687-4.686 4.687-12.284 0-16.97-4.685-4.687-12.283-4.687-16.97 0zm-7.704 35.74c-6.627 0-12 5.37-12 12 0 6.626 5.373 12 12 12s12-5.374 12-12c0-6.63-5.373-12-12-12zm-30.72 19.822c-4.686-4.686-12.284-4.686-16.97 0-4.686 4.687-4.686 12.285 0 16.97 4.686 4.687 12.284 4.687 16.97 0 4.687-4.685 4.687-12.283 0-16.97zm-35.74-7.704c0-6.627-5.372-12-12-12-6.626 0-12 5.373-12 12s5.374 12 12 12c6.628 0 12-5.373 12-12zm-19.823-30.72c4.687-4.686 4.687-12.284 0-16.97-4.686-4.686-12.284-4.686-16.97 0-4.687 4.686-4.687 12.284 0 16.97 4.686 4.687 12.284 4.687 16.97 0z"
        >
          <animateTransform attributeName="transform" type="rotate" from="0 67 67" to="360 67 67" dur="8s" repeatCount="indefinite" />
        </path>
      </svg>
    </div>

    <div class="fixed bottom-6 ltr:right-6 rtl:left-6 z-50">
      <template v-if="showTopButton">
        <button
          type="button"
          class="btn btn-outline-primary rounded-full p-2 animate-pulse bg-[#fafafa] dark:bg-[#060818] dark:hover:bg-primary"
          @click="goToTop"
        >
          <svg width="24" height="24" class="h-4 w-4" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
            <path
              opacity="0.5"
              fill-rule="evenodd"
              clip-rule="evenodd"
              d="M12 20.75C12.4142 20.75 12.75 20.4142 12.75 20L12.75 10.75L11.25 10.75L11.25 20C11.25 20.4142 11.5858 20.75 12 20.75Z"
              fill="currentColor"
            />
            <path
              d="M6.00002 10.75C5.69667 10.75 5.4232 10.5673 5.30711 10.287C5.19103 10.0068 5.25519 9.68417 5.46969 9.46967L11.4697 3.46967C11.6103 3.32902 11.8011 3.25 12 3.25C12.1989 3.25 12.3897 3.32902 12.5304 3.46967L18.5304 9.46967C18.7449 9.68417 18.809 10.0068 18.6929 10.287C18.5768 10.5673 18.3034 10.75 18 10.75L6.00002 10.75Z"
              fill="currentColor"
            />
          </svg>
        </button>
      </template>
    </div>

    <!-- BEGIN APP SETTING LAUNCHER -->
    <Setting />
    <!-- END APP SETTING LAUNCHER -->

    <div class="main-container text-black dark:text-white-dark min-h-screen" :class="[store.state.navbar]">
      <!--  BEGIN SIDEBAR  -->
      <Sidebar />
      <!--  END SIDEBAR  -->

      <div class="main-content flex flex-col min-h-screen">
        <!--  BEGIN TOP NAVBAR  -->
        <Header />
        <!--  END TOP NAVBAR  -->

        <!--  BEGIN CONTENT AREA  -->
        <div class="p-4 animation" :class="sidebarShow? 'ml-64':'ml-0'">
          <!--侧边栏 -->
          <div :class="{ 'dark text-white-dark': store.state.semidark }">
            <!-- z-50 top-32-->
            <nav
              class="sidebar  fixed min-h-screen h-full bottom-0 w-[260px] shadow-[5px_0_25px_0_rgba(94,92,154,0.1)] transition-all duration-300"
              :class="sidebarShow? '!left-0':''"
              style="top: 120px"
            >
              <!-- mt-5 -->
              <div class="bg-white dark:bg-[#0e1726] h-full">
                <div class="flex justify-between items-center px-2 py-1"></div>
                <perfect-scrollbar
                  v-if="superMenu == 'super'"
                  :options="{
                    swipeEasing: true,
                    wheelPropagation: false,
                  }"
                  class="h-[calc(100vh-80px)] relative"
                >
                  <ul class="relative font-semibold space-y-0.5 p-4 py-0">
                    <li class="menu nav-item">
                      <button
                        type="button"
                        class="nav-link group w-full"
                        :class="{ active: activeDropdown === 'package' }"
                        @click="activeDropdown === 'package' ? (activeDropdown = null) : (activeDropdown = 'package')"
                      >
                        <div class="flex items-center">
                          <icon-menu-users class="group-hover:!text-primary shrink-0" />

                          <span class="ltr:pl-3 rtl:pr-3 text-black dark:text-[#506690] dark:group-hover:text-white-dark">{{ $t('package') }}</span>
                        </div>
                        <div :class="{ 'rtl:rotate-90 -rotate-90': activeDropdown == 'package' }">
                          <icon-caret-down />
                        </div>
                      </button>
                      <vue-collapsible :isOpen="activeDropdown === 'package'">
                        <ul class="sub-menu text-gray-500">
                          <li>
                            <router-link to="/package/packageList" @click="toggleMobileMenu">{{ $t('packageList') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/package/packagePermissions" @click="toggleMobileMenu">{{ $t('packagePermissions') }}</router-link>
                          </li>
                        </ul>
                      </vue-collapsible>
                      <vue-collapsible :isOpen="activeDropdown === 'package'">
                        <ul class="sub-menu text-gray-500"></ul>
                      </vue-collapsible>
                    </li>
                    <li class="menu nav-item">
                      <button
                        type="button"
                        class="nav-link group w-full"
                        :class="{ active: activeDropdown === 'templateManage' }"
                        @click="activeDropdown === 'templateManage' ? (activeDropdown = null) : (activeDropdown = 'templateManage')"
                      >
                        <div class="flex items-center">
                          <icon-menu-users class="group-hover:!text-primary shrink-0" />

                          <span class="ltr:pl-3 rtl:pr-3 text-black dark:text-[#506690] dark:group-hover:text-white-dark">{{ $t('templateManage') }}</span>
                        </div>
                        <div :class="{ 'rtl:rotate-90 -rotate-90': activeDropdown == 'templateManage' }">
                          <icon-caret-down />
                        </div>
                      </button>
                      <vue-collapsible :isOpen="activeDropdown === 'templateManage'">
                        <ul class="sub-menu text-gray-500">
                          <li>
                            <router-link to="/templateManage/smsTemplate" @click="toggleMobileMenu">{{ $t('smsTemplate') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/templateManage/emailtemplate" @click="toggleMobileMenu">{{ $t('emailtemplate') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/templateManage/accountTemplate" @click="toggleMobileMenu">{{ $t('accountTemplate') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/templateManage/systemMessage" @click="toggleMobileMenu">{{ $t('systemMessage') }}</router-link>
                          </li>
                        </ul>
                      </vue-collapsible>
                      <vue-collapsible :isOpen="activeDropdown === 'package'">
                        <ul class="sub-menu text-gray-500"></ul>
                      </vue-collapsible>
                    </li>
                    <li class="menu nav-item">
                      <button
                        type="button"
                        class="nav-link group w-full"
                        :class="{ active: activeDropdown === 'users' }"
                        @click="activeDropdown === 'users' ? (activeDropdown = null) : (activeDropdown = 'users')"
                      >
                        <div class="flex items-center">
                          <icon-menu-users class="group-hover:!text-primary shrink-0" />

                          <span class="ltr:pl-3 rtl:pr-3 text-black dark:text-[#506690] dark:group-hover:text-white-dark">{{ $t('setting') }}</span>
                        </div>
                        <div :class="{ 'rtl:rotate-90 -rotate-90': activeDropdown == 'users' }">
                          <icon-caret-down />
                        </div>
                      </button>
                      <vue-collapsible :isOpen="activeDropdown === 'users'">
                        <ul class="sub-menu text-gray-500">
                          <li>
                            <router-link to="/setting/companyList" @click="toggleMobileMenu">{{ $t('companyList') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/setting/dicData" @click="toggleMobileMenu">{{ $t('dicData') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/setting/menuManage" @click="toggleMobileMenu">{{ $t('menuManage') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/setting/express" @click="toggleMobileMenu">{{ $t('express') }}</router-link>
                          </li>
                          <!-- express -->
                        </ul>
                      </vue-collapsible>
                      <vue-collapsible :isOpen="activeDropdown === 'users'">
                        <ul class="sub-menu text-gray-500"></ul>
                      </vue-collapsible>
                    </li>
                  </ul>
                </perfect-scrollbar>
                <perfect-scrollbar
                  v-if="superMenu == 'compan'"
                  :options="{
                    swipeEasing: true,
                    wheelPropagation: false,
                  }"
                  class="h-[calc(100vh-80px)] relative"
                >
                  <ul class="relative font-semibold space-y-0.5 p-4 py-0">
                    <li class="menu nav-item">
                      <button
                        type="button"
                        class="nav-link group w-full"
                        :class="{ active: activeDropdown === 'dashboard' }"
                        @click="activeDropdown === 'dashboard' ? (activeDropdown = null) : (activeDropdown = 'dashboard')"
                      >
                        <div class="flex items-center">
                          <!-- <icon-menu-dashboard class="group-hover:!text-primary shrink-0" /> -->
                          <span class="ltr:pl-3 rtl:pr-3 text-black dark:text-[#506690] dark:group-hover:text-white-dark">
                            {{ $t('warehouse') }}
                          </span>
                        </div>
                        <div :class="{ 'rtl:rotate-90 -rotate-90': activeDropdown == 'dashboard' }">
                          <icon-caret-down />
                        </div>
                      </button>
                      <vue-collapsible :isOpen="true"
                        ><!-- -->
                        <ul class="sub-menu text-gray-500">
                          <li>
                            <router-link to="/stock/warehouseList" @click="toggleMobileMenu">{{ $t('warehouseList') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/stock/warehouseLocation" @click="toggleMobileMenu">{{ $t('warehouseLocation') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/stock/goodsLend" @click="toggleMobileMenu">{{ $t('goodsLend') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/stock/goodsTransfer" @click="toggleMobileMenu">{{ $t('goodsTransfer') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/stock/goodsExchange" @click="toggleMobileMenu">{{ $t('goodsExchange') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/stock/goodsOutBound" @click="toggleMobileMenu">{{ $t('goodsOutBound') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/stock/goodsInventory" @click="toggleMobileMenu">{{ $t('goodsInventory') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/stock/goodsInventoryLoss" @click="toggleMobileMenu">{{ $t('goodsInventoryLoss') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/stock/goodsUnderstock" @click="toggleMobileMenu">{{ $t('goodsUnderstock') }}</router-link>
                          </li>
                        </ul>
                      </vue-collapsible>
                    </li>
                    <!--  <li class="menu nav-item">
                      <button
                        type="button"
                        class="nav-link group w-full"
                        :class="{ active: activeDropdown === 'goods' }"
                        @click="activeDropdown === 'goods' ? (activeDropdown = null) : (activeDropdown = 'goods')"
                      >
                        <div class="flex items-center">
                          <icon-menu-users class="group-hover:!text-primary shrink-0" />

                          <span class="ltr:pl-3 rtl:pr-3 text-black dark:text-[#506690] dark:group-hover:text-white-dark">{{ $t('goods') }}</span>
                        </div>
                        <div :class="{ 'rtl:rotate-90 -rotate-90': activeDropdown == 'goods' }">
                          <icon-caret-down />
                        </div>
                      </button>
                      <vue-collapsible :isOpen="activeDropdown === 'goods'">
                        <ul class="sub-menu text-gray-500">
                          <li>
                            <router-link to="/goods/SKUlist" @click="toggleMobileMenu">{{ $t('SKUList') }}</router-link>
                          </li>
                        </ul>
                      </vue-collapsible>
                      <vue-collapsible :isOpen="activeDropdown === 'goods'">
                        <ul class="sub-menu text-gray-500"></ul>
                      </vue-collapsible>
                    </li>
                    <li class="menu nav-item">
                      <button
                        type="button"
                        class="nav-link group w-full"
                        :class="{ active: activeDropdown === 'companyMent' }"
                        @click="activeDropdown === 'companyMent' ? (activeDropdown = null) : (activeDropdown = 'companyMent')"
                      >
                        <div class="flex items-center">
                          <icon-menu-users class="group-hover:!text-primary shrink-0" />

                          <span class="ltr:pl-3 rtl:pr-3 text-black dark:text-[#506690] dark:group-hover:text-white-dark">{{ $t('companyMent') }}</span>
                        </div>
                        <div :class="{ 'rtl:rotate-90 -rotate-90': activeDropdown == 'companyMent' }">
                          <icon-caret-down />
                        </div>
                      </button>
                      <vue-collapsible :isOpen="activeDropdown === 'companyMent'">
                        <ul class="sub-menu text-gray-500">
                          <li>
                            <router-link to="/companyMent/administratorManage" @click="toggleMobileMenu">{{ $t('administratorManage') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/setting/roleManage" @click="toggleMobileMenu">{{ $t('roleManage') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/companyMent/branch" @click="toggleMobileMenu">{{ $t('branch') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/companyMent/configMsg" @click="toggleMobileMenu">{{ $t('configMsg') }}</router-link>
                          </li>
                          <li>
                            <router-link to="/setting/systemLog" @click="toggleMobileMenu">{{ $t('systemLog') }}</router-link>
                          </li>
                        </ul>
                      </vue-collapsible>
                      <vue-collapsible :isOpen="activeDropdown === 'companyMent'">
                        <ul class="sub-menu text-gray-500"></ul>
                      </vue-collapsible>
                    </li> -->
                  </ul>
                </perfect-scrollbar>
              </div>
              <span id="sidebarSwitch" title="Shortcut:S" :style="sidebarShow? '':'left:-12px;'">
                <span class="w" @click="contract" :style="sidebarShow? '':'width:16px;'">
                  <b class="caret caret-left"  v-if="sidebarShow"></b>
                  <b class="caret caret-right"  v-else></b>
                </span>
              </span>
            </nav>
          </div>
          <!-- 页面主体部分 -->
          <router-view></router-view>
        </div>
        <!--  END CONTENT AREA  -->

        <!-- BEGIN FOOTER -->

        <!-- END FOOTER -->
      </div>
      <Footer />
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref, onMounted, computed } from 'vue';
//import Sidebar from '@/components/sidebar/index.vue'
import VueCollapsible from 'vue-height-collapsible/vue3';
import Sidebar from '@/components/layout/Sidebar.vue';
import Header from '@/components/layout/Header.vue';
import Footer from '@/components/layout/Footer.vue';
import Setting from '@/components/ThemeCustomizer.vue';
import appSetting from '@/app-setting';
import IconMenuUsers from '@/components/icon/menu/icon-menu-users.vue';
import IconCaretDown from '@/components/icon/icon-caret-down.vue';
import IconCaretsDown from '@/components/icon/icon-carets-down.vue';
import IconMenuDashboard from '@/components/icon/menu/icon-menu-dashboard.vue';

import store from '@/stores';
const showTopButton = ref(false);
const activeDropdown: any = ref('');
const superMenu = computed(() => store.state.superMenu);
const toggleMobileMenu = () => {
  if (window.innerWidth < 1024) {
    store.dispatch('toggleSidebar');
  }
};
const toggleSidebars = () => {
  store.dispatch('toggleSidebar');
};
onMounted(() => {
  window.onscroll = () => {
    if (document.body.scrollTop > 50 || document.documentElement.scrollTop > 50) {
      showTopButton.value = true;
    } else {
      showTopButton.value = false;
    }
  };

  const eleanimation: any = document.querySelector('.animation');
  eleanimation.addEventListener('animationend', function () {
    appSetting.changeAnimation('remove');
  });
  store.dispatch('toggleMainLoader');
  /*     store.toggleMainLoader(); */
  const selector = document.querySelector('.sidebar ul a[href="' + window.location.pathname + '"]');
  if (selector) {
    selector.classList.add('active');
    const ul: any = selector.closest('ul.sub-menu');
    if (ul) {
      let ele: any = ul.closest('li.menu').querySelectorAll('.nav-link') || [];
      if (ele.length) {
        ele = ele[0];
        setTimeout(() => {
          ele.click();
        });
      }
    }
  }
});

const goToTop = () => {
  document.body.scrollTop = 0;
  document.documentElement.scrollTop = 0;
};
const toggleSidebar = () => {
  store.dispatch('toggleSidebar');
};

const sidebarShow=ref(true)
/* 收缩 */
const contract=()=>{
    sidebarShow.value= !sidebarShow.value
}
/* 展开 */
const expand=()=>{
    sidebarShow.value=true
}

</script>
<style>
#sidebarSwitch {
    position: fixed;
    left: 245px;
    top: 43%;
    z-index: 5;
    display: inline-block;
    width: 30px;
    height: 90px;
    cursor: pointer;
    text-align: center;
}
#sidebarSwitch .w {
    display: inline-block;
    width: 8px;
    text-align: center;
    height: 40px;
    background: #fff;
    margin: 23px 0 0;
    border: 1px solid #ddd;
    border-radius: 5px;
}
#sidebarSwitch .w .caret {
    margin: 17px 0 0;
}
.caret {
  display: inline-block;
  transform: translate(0, -2px) rotate(-45deg);
  width: 5px;
  height: 5px;
  border-left: 1px solid #999;
  border-bottom: 1px solid #999;
  border-top: 0;
  border-right: 0;
  content: '';
}
.caret-left {
  transform: translate(1px, 0) rotate(45deg);
}
.caret-right {
    transform: translate(-1px, 0) rotate(-135deg);
}
</style>
