<template>
  <scroll-view scroll-y class="page-scroll">
    <view :class="['elder-mode-page', elderClass]">
      <view class="elder-mode-card">
        <view class="elder-mode-header">
          <text class="elder-mode-icon">老</text>
          <view class="elder-mode-info">
            <text class="elder-mode-title">长辈模式</text>
            <text class="elder-mode-desc">放大字体和按钮，更易阅读和操作</text>
          </view>
        </view>

        <view class="elder-mode-status">
          <text class="elder-mode-status-text">
            当前状态：{{ uiStore.elderMode ? '已开启' : '已关闭' }}
          </text>
          <view
            :class="['elder-mode-switch', { 'elder-mode-switch--on': uiStore.elderMode }]"
            @tap="handleToggle"
          >
            <view class="elder-mode-switch-thumb" />
          </view>
        </view>
      </view>

      <view class="elder-mode-preview">
        <text class="elder-mode-preview-title">效果预览</text>
        <view class="elder-mode-preview-card">
          <text :class="['elder-mode-preview-sample', { 'elder-mode-preview-sample--large': uiStore.elderMode }]">
            {{ uiStore.elderMode ? '长辈模式字体示例' : '标准模式字体示例' }}
          </text>
          <text class="elder-mode-preview-note">
            {{ uiStore.elderMode ? '字号放大 1.3 倍，间距放大 1.2 倍' : '正常字号和间距' }}
          </text>
        </view>
      </view>
    </view>
  </scroll-view>
</template>

<script setup lang="ts">
import { useUIStore } from '@/stores/ui'
import { useElderClass } from '@/composables/useElderClass'

const uiStore = useUIStore()
const { elderClass } = useElderClass()

function handleToggle() {
  uiStore.toggleElderMode()
  uni.showToast({
    title: uiStore.elderMode ? '已开启长辈模式' : '已关闭长辈模式',
    icon: 'none',
    duration: 1500,
  })
}
</script>

<style lang="scss" scoped>
.page-scroll {
  height: 100vh;
  background: $bg;
}

.elder-mode-page {
  padding: 24px;
}

.elder-mode-card {
  background: $card;
  border-radius: $r;
  padding: 24px;
  box-shadow: $shadow-md;
  margin-bottom: 20px;
}

.elder-mode-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.elder-mode-icon {
  width: 48px;
  height: 48px;
  border-radius: $r-sm;
  background: $acc-l;
  @include flex-center;
  font-size: var(--tk-font-body);
  font-weight: 700;
  color: $acc;
  flex-shrink: 0;
}

.elder-mode-info {
  flex: 1;
}

.elder-mode-title {
  font-size: var(--tk-font-body-sm);
  font-weight: 700;
  color: $tx;
  display: block;
  margin-bottom: 4px;
}

.elder-mode-desc {
  font-size: var(--tk-font-cap);
  color: var(--tk-text-secondary);
}

.elder-mode-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 0;
  border-top: 1px solid $bd-l;
}

.elder-mode-status-text {
  font-size: var(--tk-font-cap);
  color: $tx2;
}

.elder-mode-switch {
  width: 52px;
  height: 30px;
  border-radius: $r-pill;
  background: $bd;
  position: relative;
  transition: background 0.25s;
  transition: background 0.25s;

  &--on {
    background: $acc;
  }
}

.elder-mode-switch-thumb {
  width: 26px;
  height: 26px;
  border-radius: $r-pill;
  background: $card;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.25s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);

  .elder-mode-switch--on & {
    transform: translateX(22px);
  }
}

.elder-mode-preview {
  margin-top: 4px;
}

.elder-mode-preview-title {
  font-size: var(--tk-font-cap);
  font-weight: 600;
  color: $tx2;
  display: block;
  margin-bottom: 10px;
  padding-left: 4px;
}

.elder-mode-preview-card {
  background: $card;
  border-radius: $r;
  padding: 20px;
  box-shadow: $shadow-sm;
}

.elder-mode-preview-sample {
  font-size: var(--tk-font-body-sm);
  color: $tx;
  display: block;
  margin-bottom: 8px;
  transition: font-size 0.25s;

  &--large {
    font-size: var(--tk-font-body);
  }
}

.elder-mode-preview-note {
  font-size: var(--tk-font-cap);
  color: var(--tk-text-secondary);
}
</style>
