<template>
  <div class="TUISwitch-demo">
    <h1 class="page-title">TUISwitch 开关</h1>
    <p class="page-description">表示两种相互对立的状态间的切换。</p>

    <!-- Basic Usage -->
    <DemoBlock
      title="基础用法"
      description="绑定 v-model 到一个 Boolean 类型的变量。"
      :code="basicCode"
    >
      <TUISwitch v-model="value1" />
      <span class="value-text">当前值: {{ value1 }}</span>
    </DemoBlock>

    <!-- Disabled -->
    <DemoBlock
      title="禁用状态"
      description="设置 disabled 属性禁用开关。"
      :code="disabledCode"
    >
      <TUISwitch v-model="value2" disabled />
      <TUISwitch v-model="value3" disabled />
    </DemoBlock>

    <!-- Different Sizes -->
    <DemoBlock
      title="不同尺寸"
      description="通过 size 属性设置开关的大小。"
      :code="sizeCode"
    >
      <TUISwitch v-model="value4" size="large" />
      <TUISwitch v-model="value4" size="medium" />
      <TUISwitch v-model="value4" size="small" />
    </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">modelValue / v-model</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">disabled</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">loading</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">size</div>
            <div class="api-table-cell">开关尺寸</div>
            <div class="api-table-cell">'large' | 'medium' | 'small'</div>
            <div class="api-table-cell">'medium'</div>
          </div>
          <div class="api-table-row">
            <div class="api-table-cell">width</div>
            <div class="api-table-cell">开关宽度</div>
            <div class="api-table-cell">number | string</div>
            <div class="api-table-cell">-</div>
          </div>
        </div>
      </div>

      <!-- Events -->
      <div class="api-table-wrapper">
        <h3>Events</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>
          <div class="api-table-row">
            <div class="api-table-cell">update:modelValue</div>
            <div class="api-table-cell">值更新时触发</div>
            <div class="api-table-cell">(value: boolean) => void</div>
          </div>
          <div class="api-table-row">
            <div class="api-table-cell">change</div>
            <div class="api-table-cell">值改变时触发</div>
            <div class="api-table-cell">(value: boolean) => void</div>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

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

const value1 = ref(false);
const value2 = ref(true);
const value3 = ref(false);
const value4 = ref(true);

// Code examples
const basicCode = `<template>
  <TUISwitch v-model="value" />
</template>

<script setup>
import { ref } from 'vue';
const value = ref(false);
<\/script>`;

const disabledCode = `<template>
  <TUISwitch v-model="value1" disabled />
  <TUISwitch v-model="value2" disabled />
</template>`;

const sizeCode = `<template>
  <TUISwitch v-model="value" size="large" />
  <TUISwitch v-model="value" size="medium" />
  <TUISwitch v-model="value" size="small" />
</template>`;
</script>

<style scoped lang="scss">
.TUISwitch-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;
}

.value-text {
  margin-left: 12px;
  font-size: 14px;
  color: var(--text-color-secondary, #606266);
}

// 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>
