<template>
  <view class="container">
    <view class="card">
      <view class="card-title">表单交互演示</view>
      <view class="form-item">
        <text class="label">输入内容：</text>
        <input class="input" v-model="inputValue" placeholder="请输入内容" />
      </view>
      <view class="form-item">
        <text class="label">当前输入：</text>
        <text class="value">{{ inputValue || '暂无内容' }}</text>
      </view>
      <button class="primary-btn" @tap="handleSubmit">提交数据</button>
    </view>

    <view class="card">
      <view class="card-title">条件编译演示</view>
      <view class="platform-box">
        <!-- #ifdef MP-WEIXIN -->
        <view class="platform-tag weixin">当前处于：微信小程序</view>
        <!-- #endif -->
        <!-- #ifdef MP-ALIPAY -->
        <view class="platform-tag alipay">当前处于：支付宝小程序</view>
        <!-- #endif -->
        <!-- #ifdef H5 -->
        <view class="platform-tag h5">当前处于：H5 网页</view>
        <!-- #endif -->
        <view class="desc">这里使用了 UniApp 的条件编译功能，不同平台会显示不同的内容。</view>
      </view>
    </view>

    <view class="card">
      <view class="card-title">交互反馈演示</view>
      <view class="btn-group">
        <button class="btn" @tap="showToast">显示提示</button>
        <button class="btn" @tap="showLoading">显示加载</button>
        <button class="btn" @tap="showModal">显示弹窗</button>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const inputValue = ref('')

const handleSubmit = () => {
  if (!inputValue.value) {
    uni.showToast({ title: '请输入内容', icon: 'none' })
    return
  }
  uni.showToast({ title: '提交成功', icon: 'success' })
}

const showToast = () => {
  uni.showToast({ title: '这是一个提示信息' })
}

const showLoading = () => {
  uni.showLoading({ title: '加载中...' })
  setTimeout(() => {
    uni.hideLoading()
  }, 2000)
}

const showModal = () => {
  uni.showModal({
    title: '温馨提示',
    content: '这是一个自定义弹窗内容，用于确认用户操作。',
    confirmText: '确定',
    cancelText: '取消'
  })
}
</script>

<style lang="scss">
.container {
  padding: 30rpx;
  background-color: #f8f8f8;
  min-height: 100vh;
  /* #ifdef H5 */
  padding-top: 50px;
  min-height: calc(100vh - 100px);
  /* #endif */
}

.card {
  background-color: #fff;
  border-radius: 16rpx;
  padding: 30rpx;
  margin-bottom: 30rpx;
  box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.05);
  
  .card-title {
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
    margin-bottom: 30rpx;
    padding-left: 20rpx;
    border-left: 8rpx solid #1890ff;
  }
}

.form-item {
  display: flex;
  align-items: center;
  margin-bottom: 30rpx;
  
  .label {
    font-size: 28rpx;
    color: #666;
    width: 160rpx;
  }
  
  .input {
    flex: 1;
    height: 80rpx;
    border: 1rpx solid #ddd;
    border-radius: 8rpx;
    padding: 0 20rpx;
    font-size: 28rpx;
  }
  
  .value {
    font-size: 28rpx;
    color: #1890ff;
  }
}

.primary-btn {
  background-color: #1890ff;
  color: #fff;
  font-size: 30rpx;
  border-radius: 8rpx;
  height: 80rpx;
  line-height: 80rpx;
}

.platform-box {
  .platform-tag {
    padding: 20rpx;
    border-radius: 8rpx;
    color: #fff;
    font-size: 28rpx;
    text-align: center;
    margin-bottom: 20rpx;
    
    &.weixin { background-color: #07c160; }
    &.alipay { background-color: #1677ff; }
    &.h5 { background-color: #ff4d4f; }
  }
  
  .desc {
    font-size: 24rpx;
    color: #999;
    line-height: 1.6;
  }
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 20rpx;
  
  .btn {
    font-size: 28rpx;
    background-color: #f5f5f5;
    color: #333;
    border: none;
    
    &::after { border: none; }
  }
}
</style>
