<script setup>
import { Layout } from 'ant-design-vue';
import Navbar from './components/navbar';
import SiderBar from './components/siderBar';

import { useAppStore } from '@/stores';
import { useSidebarStore } from '@/stores/modules/side-bar';
import { useResponsive } from '@/hooks';
import JoinModal from '@/components/join-modal.vue';
import { getQueryParam } from '@/utils/helper';
import { useUserStore } from '@/stores';

import { ref, onMounted, computed } from 'vue';
import { useRoute } from 'vue-router';

const joinEnterpriseVisible = ref(false);
const joinModalRef = ref(null);
const appStore = useAppStore();
const sidebarStore = useSidebarStore();
const userStore = useUserStore();
const router = useRouter();
const route = useRoute();

useResponsive(true);

const showSider = computed(() => {
  return  !route.meta?.hideSidebar;
});

const collapsed = computed(() => {
  return sidebarStore.menuCollapse;
});

onMounted(() => {
  checkHasInviteCode();
});
const setCollapsed = (val) => {
  appStore.updateSettings({ menuCollapse: val });
};

const checkHasInviteCode = () => {
  const inviteCode = getQueryParam('invite_code');
  if (userStore.isLogin && inviteCode) {
    joinEnterpriseVisible.value = true;
    joinModalRef.value?.getEnterprise?.();
  }
};
</script>

<template>
  <Layout :class="['layout-wrap', { mobile: appStore.hideMenu }]" class="h-full flex flex-col w-full">
    <JoinModal v-model:visible="joinEnterpriseVisible" ref="joinModalRef" />
    <Layout.Header class="layout-header-wrap">
      <Navbar />
    </Layout.Header>
    <Layout class="flex layout-content-wrap">
      <Layout.Sider
        v-if="showSider"
        v-model="collapsed"
        :width="sidebarStore.sidebarWidth"
        collapsible
        trigger
        @collapse="setCollapsed"
      >
        <section class="menu-wrapper">
          <SiderBar />
        </section>
      </Layout.Sider>
      <Layout class="flex-1 layout-content">
        <div class="px-24px py-16px">
          <layout-page />
        </div>
      </Layout>
    </Layout>
  </Layout>
</template>

<style scoped lang="scss">
.layout-wrap {
  font-family: inherit;
  background: transparent;
  min-width: 1200px;
  .layout-header-wrap {
    background: transparent;
    height: $navbar-height;
    line-height: $navbar-height;
    padding-inline: inherit;
    color: inherit;
  }
  .layout-content-wrap {
    height: 100%;
    background: transparent;
    min-height: calc(100vh - $navbar-height);
    :deep(.ant-layout-sider) {
      background: none;
      box-shadow: none;
      padding-bottom: 0;
      .ant-layout-sider-trigger {
        display: none;
      }
      .ant-layout-sider-children {
        overflow: hidden;
      }
      .arco-menu-inner {
        overflow: hidden;
        padding: 16px !important;
      }
      .menu-wrapper {
        height: 100%;
        overflow: auto;
        overflow-x: hidden;
        :deep(.arco-menu) {
          ::-webkit-scrollbar {
            width: 12px;
            height: 4px;
          }
          ::-webkit-scrollbar-thumb {
            border: 4px solid transparent;
            background-clip: padding-box;
            border-radius: 7px;
            background-color: var(--color-text-4);
          }
          ::-webkit-scrollbar-thumb:hover {
            background-color: var(--color-text-3);
          }
        }
      }
    }
    .layout-content {
      height: 100%;
      overflow-y: scroll;
      overflow-x: auto;
      background: transparent;
      transition: padding 0.2s cubic-bezier(0.34, 0.69, 0.1, 1);
    }
  }
}
</style>
