<template>
  <admin-layout
    :page-title="pageTitle"
    @menu-change="handleMenuChange"
  >
    <!-- 环境管理页面 -->
    <env-management
      v-if="currentPage === 'env'"
      ref="envManagement"
    />

    <!-- 生成周报页面 -->
    <weekly-report
      v-else-if="currentPage === 'weekly-report'"
      ref="weeklyReport"
    />

    <!-- JIRA 工时查询页面 -->
    <jira-worklog
      v-else-if="currentPage === 'worklog'"
      ref="jiraWorklog"
    />

    <!-- 消息同步页面 -->
    <message-sync
      v-else-if="currentPage === 'message-sync'"
      ref="messageSync"
    />

    <!-- 事件消费者同步页面 -->
    <event-consumer-sync
      v-else-if="currentPage === 'event-consumer-sync'"
      ref="eventConsumerSync"
    />

    <!-- 消息分发异常查询页面 -->
    <message-dispatch
      v-else-if="currentPage === 'message-dispatch'"
      ref="messageDispatch"
    />

    <!-- 系统设置页面 -->
    <system-settings v-else-if="currentPage === 'settings'" />

    <!-- 操作日志页面 -->
    <div v-else-if="currentPage === 'logs'" class="bg-white rounded-xl shadow-sm border border-gray-200 p-8">
      <div class="text-center py-12">
        <svg class="w-16 h-16 text-gray-300 mx-auto mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
          <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 17v-2m3 2v-4m3 4v-6m2 10H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
        </svg>
        <h3 class="text-lg font-medium text-gray-900 mb-2">操作日志</h3>
        <p class="text-gray-500">此功能正在开发中...</p>
      </div>
    </div>
  </admin-layout>
</template>

<script>
import AdminLayout from './AdminLayout.vue';
import EnvManagement from '../env/EnvManagement.vue';
import WeeklyReport from '../jira/WeeklyReport.vue';
import JiraWorklog from '../jira/JiraWorklog.vue';
import MessageSync from '../message-sync/MessageSync.vue';
import EventConsumerSync from '../message-sync/EventConsumerSync.vue';
import MessageDispatch from '../message-sync/MessageDispatch.vue';
import SystemSettings from './SystemSettings.vue';

export default {
  name: 'AdminDashboard',
  components: {
    AdminLayout,
    EnvManagement,
    WeeklyReport,
    JiraWorklog,
    MessageSync,
    EventConsumerSync,
    MessageDispatch,
    SystemSettings
  },
  data() {
    return {
      currentPage: 'env',
      pageTitle: '环境配置管理'
    }
  },
  mounted() {
    console.log('AdminDashboard mounted');

    // 根据 URL 路径设置初始页面
    this.setCurrentPageFromPath();
  },
  methods: {
    handleMenuChange(menu) {
      this.currentPage = menu;

      // 更新页面标题
      const titles = {
        'env': '环境配置管理',
        'weekly-report': '生成周报',
        'worklog': 'JIRA 工时查询',
        'message-sync': '消息同步',
        'event-consumer-sync': '事件消费者同步对比',
        'message-dispatch': '消息分发异常查询',
        'settings': '系统设置',
        'logs': '操作日志'
      };

      this.pageTitle = titles[menu] || '环境配置管理';
    },

    setCurrentPageFromPath() {
      const path = window.location.pathname;
      let page = 'env'; // 默认页面

      if (path === '/') {
        page = 'env';
      } else if (path === '/weekly-report') {
        page = 'weekly-report';
      } else if (path === '/worklog') {
        page = 'worklog';
      } else if (path === '/message-sync') {
        page = 'message-sync';
      } else if (path === '/event-consumer-sync') {
        page = 'event-consumer-sync';
      } else if (path === '/message-dispatch') {
        page = 'message-dispatch';
      } else if (path === '/settings') {
        page = 'settings';
      } else if (path === '/logs') {
        page = 'logs';
      }

      this.currentPage = page;
      this.handleMenuChange(page);
    }
  }
}
</script>

<style scoped>
/* 主应用样式 */
</style>
