<template>
  <div class="page-wrapper" :class="{ 'footer-space': showFooter && getShowFooter }">
    <div class="mb-4 n-layout-page-header" v-if="title || content || $slots.headerContent">
      <a-card :bordered="false" :title="title">
        {{ content }}
        <slot name="headerContent"></slot>
      </a-card>
    </div>
    <div class="page-wrapper-content" :style="contentStyle" :class="contentClass">
      <slot></slot>
    </div>
    <page-footer v-if="showFooter && getShowFooter" :style="getFooterWidth">
      <template #left>
        <slot name="leftFooter"></slot>
      </template>
      <template #right>
        <slot name="rightFooter"></slot>
      </template>
    </page-footer>
  </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 { getMenuCollapsed, getMenuMinWidth, getMenuWidth } = useProjectSetting();

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

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

<style lang="less" scoped>
  .page-wrapper {
    .mb-4 {
      margin-bottom: 1rem;
    }
  }

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