<template>
  <view class="help-container">
    <!-- 常见问题 -->
    <view class="faq-section">
      <view 
        v-for="(item, index) in faqList"
        :key="index"
        class="collapse-item"
      >
        <view 
          class="collapse-header"
          @click="toggleCollapse(index)"
        >
          <text class="collapse-title">{{ $t(item.question) }}</text>
          <text class="collapse-icon" :class="{ 'active': activeIndex === index }">▼</text>
        </view>
        <view 
          class="collapse-content"
          :class="{ 'show': activeIndex === index }"
        >
          <view class="answer-content">
            <text class="answer-text">{{ $t(item.answer) }}</text>
          </view>
        </view>
      </view>
    </view>

    <!-- 联系客服 -->
    <view class="contact-card">
      <view class="contact-title">{{ $t('help.contactUs') }}</view>
      <view class="contact-content">
        <view class="contact-item">
          <text class="label">{{ $t('help.phone') }}</text>
          <text class="value" @click="makePhoneCall">{{ customerPhone }}</text>
        </view>
        <view class="contact-item">
          <text class="label">{{ $t('help.workingHours') }}</text>
          <text class="value">{{ $t('help.workingHoursValue') }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { HELP_CONTENT } from '@/constants/help'
import { getCustomerPhone } from '@/util/index.js'
import { useI18n } from '@/utils/i18n.js'

const { t } = useI18n()

const faqList = ref(HELP_CONTENT.FAQ_LIST)
const customerPhone = ref(HELP_CONTENT.CONTACT.PHONE.VALUE)
const activeIndex = ref(null)

onLoad(() => {
  uni.setNavigationBarTitle({
    title: t('help.title')
  })
  customerPhone.value = getCustomerPhone()
})

const toggleCollapse = (index) => {
  if (activeIndex.value === index) {
    activeIndex.value = null
  } else {
    activeIndex.value = index
  }
}

const makePhoneCall = () => {
  uni.makePhoneCall({
    phoneNumber: customerPhone.value
  })
}
</script>

<style lang="scss" scoped>
.help-container {
  min-height: 100vh;
  background: #f8f8f8;
  padding: 30rpx;

  .faq-section {
    background: #fff;
    border-radius: 20rpx;
    margin-bottom: 30rpx;
    box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.04);
    overflow: hidden;

    .collapse-item {
      border-bottom: 1rpx solid #f0f0f0;
      
      &:last-child {
        border-bottom: none;
      }

      .collapse-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 30rpx;
        cursor: pointer;
        transition: background-color 0.2s;

        &:active {
          background-color: #f5f5f5;
        }

        .collapse-title {
          flex: 1;
          font-size: 30rpx;
          color: #333;
          font-weight: 500;
          line-height: 1.5;
        }

        .collapse-icon {
          margin-left: 20rpx;
          font-size: 24rpx;
          color: #999;
          transition: transform 0.3s;
          transform: rotate(0deg);

          &.active {
            transform: rotate(180deg);
          }
        }
      }

      .collapse-content {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease-out;

        &.show {
          max-height: 2000rpx;
          transition: max-height 0.3s ease-in;
        }

        .answer-content {
          padding: 20rpx 30rpx 30rpx;
          background: #f9f9f9;
          
          .answer-text {
            font-size: 28rpx;
            color: #666;
            line-height: 1.8;
            display: block;
          }
        }
      }
    }
  }

  .contact-card {
    background: #fff;
    border-radius: 20rpx;
    padding: 30rpx;
    box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.04);

    .contact-title {
      position: relative;
      z-index: 4;
      display: inline-block;
      font-size: 32rpx;
      color: #333;
      font-weight: 500;
      margin-bottom: 20rpx;
      padding-bottom: 8rpx;
      width: fit-content;

      &::after {
        z-index: -1;
        content: '';
        position: absolute;
        left: 0;
        bottom: 8rpx;
        width: 88%;
        height: 16rpx;
        border-radius: 20rpx;
        background: #07C160;
      }
    }

    .contact-content {
      .contact-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 20rpx 0;
        
        .label {
          font-size: 28rpx;
          color: #666;
        }

        .value {
          font-size: 28rpx;
          color: #333;
          font-weight: 500;

          &:active {
            opacity: 0.7;
          }
        }
      }
    }
  }
}
</style> 