<template>
  <div class="guns-layout">
    <div class="guns-layout-content">
      <div class="guns-layout">
        <div class="guns-layout-content-header portal-config-header">
          <a-space :size="16">
            <span class="back-btn" @click="back">
              <left-outlined />
              <span>返回</span>
            </span>
            <a-divider type="vertical" />
            <a-tabs v-model:activeKey="activeKey" class="devops-tabs">
              <a-tab-pane key="new" tab="新闻" />
              <a-tab-pane key="carousel" tab="轮播图" />
              <a-tab-pane key="app" tab="应用链接" />
              <a-tab-pane key="effective" tab="生效范围" />
              <a-tab-pane key="permission" tab="管理权限" />
            </a-tabs>
          </a-space>
        </div>
        <div class="guns-layout-content-application" v-if="designId">
          <div class="content-mian">
            <div class="content-mian-body">
              <div class="table-content">
                <newConfig v-if="activeKey == 'new'" :designId="designId" />
                <carouselConfig v-if="activeKey == 'carousel'" :designId="designId" />
                <appConfig v-if="activeKey == 'app'" :designId="designId" />
                <effectiveConfig v-if="activeKey == 'effective'" :designId="designId" />
                <permissionConfig v-if="activeKey == 'permission'" :designId="designId" />
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { useRoute, useRouter } from 'vue-router';
import { ref, onMounted, defineAsyncComponent } from 'vue';

const newConfig = defineAsyncComponent(() => import('./new/index.vue'));
const carouselConfig = defineAsyncComponent(() => import('./carousel/index.vue'));
const appConfig = defineAsyncComponent(() => import('./app/index.vue'));
const effectiveConfig = defineAsyncComponent(() => import('./effective/index.vue'));
const permissionConfig = defineAsyncComponent(() => import('./permission/index.vue'));

const route = useRoute();
const router = useRouter();

const designId = ref('');

const activeKey = ref('');

onMounted(() => {
  const { id, type } = route.query;
  if (!(id || type)) return back();
  designId.value = id;
  activeKey.value = type || 'new';
});

// 返回
const back = () => {
  router.push('/portal/backend/config');
};
</script>

<style scoped lang="less">
.back-btn {
  cursor: pointer;
  font-size: 16px;
  color: #60666b;
  font-weight: 400;

  .anticon {
    font-size: 14px;
    margin-right: 4px;
    color: #60666b;
  }
}
.ant-divider {
  border-left: 1.5px solid #c5cfd1;
}
.portal-config-header {
  height: auto !important;
  border-bottom: 1px solid rgba(197, 207, 209, 0.4);
  margin-bottom: 0 !important;
  padding-bottom: 12px;
}
</style>
