<template>
  <div class="TUIBadge-demo">
    <h1 class="page-title">TUIBadge 徽标</h1>
    <p class="page-description">出现在按钮、图标旁的数字或状态标记。</p>

    <!-- Basic Usage -->
    <DemoBlock
      title="基础用法"
      description="展示新消息数量。"
      :code="basicCode"
    >
      <Badge :value="12">
        <TUIButton>消息</TUIButton>
      </Badge>
      <Badge :value="3">
        <TUIButton>评论</TUIButton>
      </Badge>
      <Badge :value="1">
        <TUIButton>回复</TUIButton>
      </Badge>
    </DemoBlock>

    <!-- Max Value -->
    <DemoBlock
      title="最大值"
      description="可自定义最大值，超过最大值会显示 '{max}+'。"
      :code="maxCode"
    >
      <Badge :value="200" :max="99">
        <TUIButton>消息</TUIButton>
      </Badge>
      <Badge :value="100" :max="10">
        <TUIButton>评论</TUIButton>
      </Badge>
    </DemoBlock>

    <!-- Custom Content -->
    <DemoBlock
      title="自定义内容"
      description="可以显示数字以外的文本内容。"
      :code="customCode"
    >
      <Badge value="hot">
        <TUIButton>热门</TUIButton>
      </Badge>
      <Badge value="new">
        <TUIButton>新品</TUIButton>
      </Badge>
    </DemoBlock>

    <!-- Dot -->
    <DemoBlock
      title="小红点"
      description="以红点的形式标注需要关注的内容。"
      :code="dotCode"
    >
      <Badge is-dot>
        <TUIButton>红点提示</TUIButton>
      </Badge>
    </DemoBlock>

    <!-- Different Types -->
    <DemoBlock
      title="不同类型"
      description="通过 type 属性设置不同的颜色类型。"
      :code="typeCode"
    >
      <Badge :value="1" type="primary">
        <TUIButton>主要</TUIButton>
      </Badge>
      <Badge :value="2" type="success">
        <TUIButton>成功</TUIButton>
      </Badge>
      <Badge :value="3" type="warning">
        <TUIButton>警告</TUIButton>
      </Badge>
      <Badge :value="4" type="danger">
        <TUIButton>危险</TUIButton>
      </Badge>
      <Badge :value="5" type="info">
        <TUIButton>信息</TUIButton>
      </Badge>
    </DemoBlock>

    <!-- API Documentation -->
    <section class="api-section">
      <h2>API</h2>

      <!-- Props -->
      <div class="api-table-wrapper">
        <h3>Props</h3>
        <div class="api-table">
          <div class="api-table-header">
            <div class="api-table-cell">属性名</div>
            <div class="api-table-cell">说明</div>
            <div class="api-table-cell">类型</div>
            <div class="api-table-cell">默认值</div>
          </div>
          <div class="api-table-row">
            <div class="api-table-cell">value</div>
            <div class="api-table-cell">显示值</div>
            <div class="api-table-cell">string | number</div>
            <div class="api-table-cell">-</div>
          </div>
          <div class="api-table-row">
            <div class="api-table-cell">max</div>
            <div class="api-table-cell">最大值，超过最大值会显示 {max}+</div>
            <div class="api-table-cell">number</div>
            <div class="api-table-cell">-</div>
          </div>
          <div class="api-table-row">
            <div class="api-table-cell">isDot</div>
            <div class="api-table-cell">显示小红点</div>
            <div class="api-table-cell">boolean</div>
            <div class="api-table-cell">false</div>
          </div>
          <div class="api-table-row">
            <div class="api-table-cell">hidden</div>
            <div class="api-table-cell">隐藏标记</div>
            <div class="api-table-cell">boolean</div>
            <div class="api-table-cell">false</div>
          </div>
          <div class="api-table-row">
            <div class="api-table-cell">type</div>
            <div class="api-table-cell">标记类型</div>
            <div class="api-table-cell">'primary' | 'success' | 'warning' | 'danger' | 'info'</div>
            <div class="api-table-cell">'primary'</div>
          </div>
        </div>
      </div>

      <!-- Slots -->
      <div class="api-table-wrapper">
        <h3>Slots</h3>
        <div class="api-table">
          <div class="api-table-header">
            <div class="api-table-cell">插槽名</div>
            <div class="api-table-cell">说明</div>
          </div>
          <div class="api-table-row">
            <div class="api-table-cell">default</div>
            <div class="api-table-cell">徽标内容</div>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script setup lang="ts">
import { Badge, TUIButton } from '@/components';
import DemoBlock from './components/DemoBlock.vue';

// Code examples
const basicCode = `<template>
  <Badge :value="12">
    <TUIButton>消息</TUIButton>
  </Badge>
  <Badge :value="3">
    <TUIButton>评论</TUIButton>
  </Badge>
</template>`;

const maxCode = `<template>
  <Badge :value="200" :max="99">
    <TUIButton>消息</TUIButton>
  </Badge>
</template>`;

const customCode = `<template>
  <Badge value="hot">
    <TUIButton>热门</TUIButton>
  </Badge>
  <Badge value="new">
    <TUIButton>新品</TUIButton>
  </Badge>
</template>`;

const dotCode = `<template>
  <Badge is-dot>
    <TUIButton>红点提示</TUIButton>
  </Badge>
</template>`;

const typeCode = `<template>
  <Badge :value="1" type="primary">
    <TUIButton>主要</TUIButton>
  </Badge>
  <Badge :value="2" type="success">
    <TUIButton>成功</TUIButton>
  </Badge>
  <Badge :value="3" type="warning">
    <TUIButton>警告</TUIButton>
  </Badge>
</template>`;
</script>

<style scoped lang="scss">
.TUIBadge-demo {
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
  box-sizing: border-box;
  overflow-x: hidden;

  @media (max-width: 768px) {
    padding: 16px;
  }
}

.page-title {
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 600;
  color: var(--text-color-primary, #303133);
}

.page-description {
  margin: 0 0 32px;
  font-size: 14px;
  color: var(--text-color-secondary, #606266);
  line-height: 1.6;
}

// API Documentation
.api-section {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--stroke-color-primary, #e4e7ed);

  h2 {
    margin: 0 0 24px;
    font-size: 22px;
    font-weight: 600;
    color: var(--text-color-primary, #303133);
  }

  h3 {
    margin: 24px 0 12px;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-color-secondary, #606266);
  }
}

.api-table-wrapper {
  margin-bottom: 24px;
}

.api-table {
  border: 1px solid var(--stroke-color-primary, #e4e7ed);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-color-operate, #fff);

  .api-table-header {
    display: flex;
    background: var(--bg-color-default, #fafafa);
    border-bottom: 1px solid var(--stroke-color-primary, #e4e7ed);
    font-weight: 600;
    color: var(--text-color-secondary, #606266);
  }

  .api-table-row {
    display: flex;
    border-bottom: 1px solid var(--stroke-color-secondary, #ebeef5);

    &:last-child {
      border-bottom: none;
    }

    &:hover {
      background-color: var(--list-color-hover, #f5f7fa);
    }
  }

  .api-table-cell {
    flex: 1;
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-color-primary, #303133);

    &:first-child {
      flex: 0.8;
      font-weight: 500;
      color: var(--text-color-link, #409eff);
    }

    &:nth-child(2) {
      flex: 1.4;
    }

    &:nth-child(3) {
      flex: 1.2;
      color: var(--text-color-warning, #e6a23c);
      font-family: 'Monaco', 'Menlo', monospace;
      font-size: 13px;
    }

    &:last-child {
      flex: 0.6;
      color: var(--text-color-tertiary, #909399);
    }
  }
}
</style>
