<template>
  <div class="TUISlider-demo">
    <h1 class="page-title">TUISlider 滑块</h1>
    <p class="page-description">通过拖动滑块在一个固定区间内进行选择。</p>

    <!-- Basic Usage -->
    <DemoBlock
      title="基础用法"
      description="在拖动滑块时，显示当前值。"
      :code="basicCode"
    >
      <div class="slider-wrapper">
        <TUISlider v-model="value1" />
        <span class="value-text">当前值: {{ value1 }}</span>
      </div>
    </DemoBlock>

    <!-- Disabled -->
    <DemoBlock
      title="禁用状态"
      description="设置 disabled 属性禁用滑块。"
      :code="disabledCode"
    >
      <div class="slider-wrapper">
        <TUISlider v-model="value2" disabled />
      </div>
    </DemoBlock>

    <!-- Step -->
    <DemoBlock
      title="离散值"
      description="通过 step 属性设置步长。"
      :code="stepCode"
    >
      <div class="slider-wrapper">
        <TUISlider v-model="value3" :step="10" />
        <span class="value-text">步长: 10, 当前值: {{ value3 }}</span>
      </div>
    </DemoBlock>

    <!-- Marks -->
    <DemoBlock
      title="显示标记"
      description="通过 marks 属性显示标记点。"
      :code="marksCode"
    >
      <div class="slider-wrapper slider-wrapper--marks">
        <TUISlider v-model="value4" :marks="marks" :step="10" />
      </div>
    </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">number</div>
            <div class="api-table-cell">0</div>
          </div>
          <div class="api-table-row">
            <div class="api-table-cell">min</div>
            <div class="api-table-cell">最小值</div>
            <div class="api-table-cell">number</div>
            <div class="api-table-cell">0</div>
          </div>
          <div class="api-table-row">
            <div class="api-table-cell">max</div>
            <div class="api-table-cell">最大值</div>
            <div class="api-table-cell">number</div>
            <div class="api-table-cell">100</div>
          </div>
          <div class="api-table-row">
            <div class="api-table-cell">step</div>
            <div class="api-table-cell">步长</div>
            <div class="api-table-cell">number</div>
            <div class="api-table-cell">1</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">marks</div>
            <div class="api-table-cell">标记点</div>
            <div class="api-table-cell">Record&lt;number, string&gt;</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: number) => 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: number) => void</div>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

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

const value1 = ref(30);
const value2 = ref(50);
const value3 = ref(20);
const value4 = ref(30);

const marks = {
  0: '0°C',
  20: '20°C',
  40: '40°C',
  60: '60°C',
  80: '80°C',
  100: '100°C',
};

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

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

const disabledCode = `<template>
  <TUISlider v-model="value" disabled />
</template>`;

const stepCode = `<template>
  <TUISlider v-model="value" :step="10" />
</template>`;

const marksCode = `<template>
  <TUISlider v-model="value" :marks="marks" :step="10" />
</template>

<script setup>
const marks = {
  0: '0°C',
  20: '20°C',
  40: '40°C',
  60: '60°C',
  80: '80°C',
  100: '100°C',
};
<\/script>`;
</script>

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

.slider-wrapper {
  width: 100%;
  max-width: 400px;
  display: flex;
  align-items: center;
  gap: 16px;

  &--marks {
    padding-bottom: 24px;
  }
}

.value-text {
  font-size: 14px;
  color: var(--text-color-secondary, #606266);
  white-space: nowrap;
}

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