<template>
  <div class="page-layout">
    <!-- 页面头部 -->
    <div class="page-header" v-if="showHeader">
      <div class="page-header-content">
        <div class="page-title">
          <h1>{{ pageTitle }}</h1>
          <p class="page-description" v-if="pageDescription">{{ pageDescription }}</p>
        </div>
        
        <!-- 页面操作按钮 -->
        <div class="page-actions" v-if="$slots.actions">
          <slot name="actions"></slot>
        </div>
      </div>
    </div>
    
    <!-- 页面内容 -->
    <div class="page-content">
      <router-view />
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { useRoute } from 'vue-router';

// Props
interface Props {
  showHeader?: boolean;
  title?: string;
  description?: string;
}

const props = withDefaults(defineProps<Props>(), {
  showHeader: true
});

// Composition API
const route = useRoute();

// 计算属性
const pageTitle = computed(() => {
  return props.title || route.meta?.title || '';
});

const pageDescription = computed(() => {
  return props.description || route.meta?.description || '';
});
</script>

<style lang="scss" scoped>
.page-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.page-header {
  background: white;
  border-bottom: 1px solid #e8e8e8;
  padding: 16px 0;
  margin-bottom: 16px;
}

.page-header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.page-title {
  flex: 1;
  
  h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    color: #333;
    line-height: 1.2;
  }
  
  .page-description {
    margin: 8px 0 0 0;
    color: #666;
    font-size: 14px;
    line-height: 1.4;
  }
}

.page-actions {
  flex-shrink: 0;
  margin-left: 16px;
}

.page-content {
  flex: 1;
  overflow: hidden;
}
</style>
