<template>
  <div class="page-wrapper" :class="{ 'footer-space': showFooter && getShowFooter }">
    <div class="mb-3.5 n-layout-page-header" v-if="title || content || $slots.headerContent">
      <el-card shadow="never" class="border-none">
        <template #header>
          <div class="header-title">{{ title }}</div>
        </template>
        {{ content }}
        <slot name="headerContent"></slot>
      </el-card>
    </div>
    <div class="page-wrapper-content" :style="contentStyle" :class="contentClass">
      <slot></slot>
    </div>
    <PageFooter v-if="showFooter && getShowFooter" :style="getFooterWidth">
      <template #left>
        <slot name="leftFooter"></slot>
      </template>
      <template #right>
        <slot name="rightFooter"></slot>
      </template>
    </PageFooter>
  </div>
</template>

<script lang="ts" setup>
  import { computed, useSlots } from 'vue';
  import { basicProps } from './wrapperProps';
  import PageFooter from './PageFooter.vue';
  import { useProjectSetting } from '@/hooks/setting/useProjectSetting';

  const slots = useSlots();
  defineProps({ ...basicProps });

  const { getMenuSetting } = useProjectSetting();

  const getShowFooter = computed(() => slots?.leftFooter || slots?.rightFooter);

  const getFooterWidth = computed(() => {
    const { menuWidth, minMenuWidth, collapsed } = getMenuSetting.value;
    const wh = collapsed ? minMenuWidth : menuWidth;
    return {
      width: `calc(100% - ${wh}px)`,
    };
  });
</script>

<style lang="scss" scoped>
  .page-wrapper {
    .mb-4 {
      margin-bottom: 1rem;
    }
    .header-title {
      font-weight: 700;
      font-size: 16px;
      color: var(--el-text-color-primary);
    }
  }

  .footer-space {
    padding-bottom: 64px;
  }
</style>
