<template>
  <el-container class="layout">
    <el-aside width="200px" class="sidebar">
      <div class="logo">Sino MCI</div>
      <el-menu :default-active="$route.path" router>
        <el-menu-item index="/dashboard">
          <span>概览</span>
        </el-menu-item>
        <el-menu-item index="/channel-subject">
          <span>渠道主体</span>
        </el-menu-item>
        <el-menu-item index="/channel-account">
          <span>渠道账号</span>
        </el-menu-item>
        <el-menu-item index="/conversation">
          <span>会话/群聊</span>
        </el-menu-item>
        <el-menu-item index="/person">
          <span>联系人</span>
        </el-menu-item>
        <el-menu-item index="/tag">
          <span>标签</span>
        </el-menu-item>
        <el-menu-item index="/send-record">
          <span>发送记录</span>
        </el-menu-item>
        <el-menu-item index="/inbound-flow">
          <span>入站流程</span>
        </el-menu-item>
        <el-menu-item index="/flow-trace">
          <span>流程追踪</span>
        </el-menu-item>
        <el-menu-item index="/message-test">
          <span>消息测试</span>
        </el-menu-item>
        <el-menu-item v-if="authStore.roleCodes.includes('platform_admin')" index="/tenant-management">
          <span>租户管理</span>
        </el-menu-item>
        <el-menu-item index="/user-management">
          <span>用户管理</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header class="header">
        <span>{{ $route.meta.title || '消息中台' }}</span>
        <div class="header-right">
          <span class="user-info">{{ authStore.tenantCode }} / {{ authStore.username }}</span>
          <el-button type="primary" text @click="handleLogout">退出登录</el-button>
        </div>
      </el-header>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup lang="ts">
import { useRoute, useRouter } from 'vue-router'
import { useAuthStore } from '../stores/auth'

const route = useRoute()
const router = useRouter()
const authStore = useAuthStore()

function handleLogout() {
  authStore.clearAuth()
  router.push('/login')
}
</script>

<style scoped>
.layout {
  height: 100vh;
}
.sidebar {
  background: #fff;
  border-right: 1px solid #e4e7ed;
}
.logo {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: bold;
  border-bottom: 1px solid #e4e7ed;
}
.header {
  background: #fff;
  border-bottom: 1px solid #e4e7ed;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 500;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.user-info {
  color: #606266;
  font-size: 14px;
}
</style>
