<!--
@description: 未安装 Versatile 时，使用 KPC 原生组件组合购买/创建页面布局。
@source-reference: @ksyun-internal/versatile LayoutContent
-->
<script setup lang="ts">
import { ref } from 'vue';
import {
  Body,
  Button,
  Header,
  Icon,
  Layout,
  Spin,
  Tab,
  Tabs,
} from '@king-design/vue';

const activeTab = ref('basic');
const submitting = ref(false);

function openDocumentation(): void {
  window.open(
    'https://docs.ksyun.com',
    '_blank',
    'noopener,noreferrer',
  );
}
</script>

<template>
  <Layout class="purchase-page">
    <Header class="purchase-header" theme="light" :height="64">
      <div class="purchase-inner header-inner">
        <span class="page-title">创建云服务器</span>
        <Button
          class="doc-button"
          type="link"
          @click="openDocumentation"
        >
          <Icon class="k-icon-paper" />
          <span>相关文档</span>
        </Button>
      </div>
    </Header>

    <div class="tabs-bar">
      <div class="purchase-inner">
        <Tabs v-model="activeTab">
          <Tab value="basic">基础配置</Tab>
          <Tab value="confirm">确认配置</Tab>
        </Tabs>
      </div>
    </div>

    <Body class="purchase-body">
      <main class="purchase-inner purchase-content">
        <div v-if="activeTab === 'basic'">配置区块</div>
        <div v-else>配置确认</div>
      </main>
    </Body>

    <footer class="purchase-footer">
      <div class="purchase-inner footer-inner">
        <div class="footer-summary">
          <Button>配置明细</Button>
          <Spin v-if="submitting" size="small" />
        </div>
        <Button
          type="warning"
          size="large"
          :disabled="submitting"
        >
          立即购买
        </Button>
      </div>
    </footer>
  </Layout>
</template>

<style scoped>
.purchase-page {
  min-height: 100vh;
  background: #f5f7fa;
}

.purchase-inner {
  width: min(1200px, calc(100% - 48px));
  margin: 0 auto;
}

.purchase-header {
  box-sizing: border-box;
  padding: 0;
}

.header-inner,
.footer-inner,
.footer-summary {
  display: flex;
  align-items: center;
}

.header-inner,
.footer-inner {
  height: 100%;
  justify-content: space-between;
}

.page-title {
  color: #151b1e;
  font-size: 20px;
  font-weight: 500;
}

.doc-button {
  padding: 0 !important;
  line-height: 1;
}

.tabs-bar {
  background: #fff;
}

.purchase-body {
  box-sizing: border-box;
  flex: 1;
  padding: 24px 0;
  background: #f5f7fa;
}

.purchase-content {
  box-sizing: border-box;
  min-height: 360px;
  padding: 16px;
  background: #fff;
}

.purchase-footer {
  position: sticky;
  z-index: 10;
  bottom: 0;
  box-sizing: border-box;
  padding: 24px 0;
  background: #fff;
  box-shadow: 0 -2px 8px rgb(31 35 41 / 8%);
}

.footer-summary {
  gap: 8px;
}

@media (max-width: 768px) {
  .purchase-inner {
    width: calc(100% - 32px);
  }
}
</style>
