<template>
  <view class="page">
    <view class="header-hero" :style="{ paddingTop: statusBarHeight + 'px' }">
      <view class="top-bar">
        <view class="top-left" @click="goBack">
          <AppIcon name="chevronLeft" size="sm" color="white" />
        </view>
        <view class="top-center">
          <text class="page-title">{{ t('support.title') }}</text>
          <LocationPicker />
        </view>
        <view class="top-right" @click="isMenuOpen = true">
          <AppIcon name="menu" size="sm" color="white" />
        </view>
      </view>
    </view>

    <view class="content">
      <text class="section-label section-label-first">Contact Us</text>

      <view class="contact-card" @click="callSupport">
        <view class="cc-icon green">
          <AppIcon name="phone" size="sm" color="green" />
        </view>
        <view class="cc-body">
          <text class="cc-title">{{ t('support.phone') }}</text>
          <text class="cc-value">1-800-SUPPORT</text>
          <text class="cc-hint">Available 24/7</text>
        </view>
        <view class="cc-arrow">
          <AppIcon name="chevronRight" size="sm" color="gray" />
        </view>
      </view>

      <view class="contact-card">
        <view class="cc-icon blue">
          <AppIcon name="mail" size="sm" color="blue" />
        </view>
        <view class="cc-body">
          <text class="cc-title">{{ t('support.email') }}</text>
          <text class="cc-value">support@medvantage.com</text>
          <text class="cc-hint">Response within 24 hours</text>
        </view>
        <view class="cc-arrow">
          <AppIcon name="chevronRight" size="sm" color="gray" />
        </view>
      </view>

      <text class="section-label">Resources</text>

      <view class="res-group">
        <view class="res-item">
          <view class="res-icon">
            <AppIcon name="fileText" size="sm" color="blue" />
          </view>
          <view class="res-body">
            <text class="res-title">{{ t('support.userGuide') }}</text>
            <text class="res-desc">Complete guide to using the app</text>
          </view>
          <AppIcon name="chevronRight" size="sm" color="gray" />
        </view>
        <view class="res-divider" />
        <view class="res-item">
          <view class="res-icon">
            <AppIcon name="eye" size="sm" color="purple" />
          </view>
          <view class="res-body">
            <text class="res-title">Video Tutorials</text>
            <text class="res-desc">Step-by-step video instructions</text>
          </view>
          <AppIcon name="chevronRight" size="sm" color="gray" />
        </view>
        <view class="res-divider" />
        <view class="res-item">
          <view class="res-icon">
            <AppIcon name="help" size="sm" color="orange" />
          </view>
          <view class="res-body">
            <text class="res-title">{{ t('support.faq') }}</text>
            <text class="res-desc">Frequently asked questions</text>
          </view>
          <AppIcon name="chevronRight" size="sm" color="gray" />
        </view>
      </view>

      <view class="emergency-card">
        <view class="emergency-header">
          <view class="emergency-icon-box">
            <AppIcon name="alert" size="sm" color="red" />
          </view>
          <view class="emergency-texts">
            <text class="emergency-title">Emergency Support</text>
            <text class="emergency-desc">For urgent food safety issues or critical system problems</text>
          </view>
        </view>
        <view class="emergency-btn" @click="callEmergency">
          <AppIcon name="phone" size="sm" color="white" />
          <text class="emergency-btn-text">Call Emergency Support</text>
        </view>
      </view>

      <view class="version-card">
        <view class="ver-row">
          <text class="ver-label">App Version</text>
          <text class="ver-value">1.0.0</text>
        </view>
        <view class="ver-divider" />
        <view class="ver-row">
          <text class="ver-label">Build Number</text>
          <text class="ver-value">2024.02.001</text>
        </view>
      </view>
    </view>

    <SideMenu v-model="isMenuOpen" />
  </view>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
import AppIcon from '../../components/AppIcon.vue'
import SideMenu from '../../components/SideMenu.vue'
import LocationPicker from '../../components/LocationPicker.vue'
import { getStatusBarHeight } from '../../utils/statusBar'

const { t } = useI18n()
const statusBarHeight = getStatusBarHeight()
const isMenuOpen = ref(false)

const goBack = () => {
  const pages = getCurrentPages()
  if (pages.length > 1) {
    uni.navigateBack()
  } else {
    uni.redirectTo({ url: '/pages/index/index' })
  }
}

const callSupport = () => {
  uni.makePhoneCall({ phoneNumber: '18005877678' })
}

const callEmergency = () => {
  uni.makePhoneCall({ phoneNumber: '18005877678' })
}
</script>

<style scoped>
.page {
  min-height: 100vh;
  background: #f9fafb;
}

.header-hero {
  background: linear-gradient(135deg, var(--theme-primary), var(--theme-primary-dark));
  padding: 16rpx 32rpx 24rpx;
}

.top-bar {
  height: 96rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.top-left,
.top-right {
  width: 64rpx;
  height: 64rpx;
  border-radius: 999rpx;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
}

.top-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.page-title {
  font-size: 34rpx;
  font-weight: 600;
  color: #fff;
}

.content {
  padding: 32rpx;
}

.section-label {
  font-size: 28rpx;
  font-weight: 600;
  color: #6b7280;
  display: block;
  margin-bottom: 16rpx;
  margin-top: 28rpx;
}

.section-label-first {
  margin-top: 0;
}

.contact-card {
  background: #fff;
  padding: 28rpx 32rpx;
  border-radius: 20rpx;
  margin-bottom: 16rpx;
  display: flex;
  align-items: center;
  gap: 24rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
}

.cc-icon {
  width: 72rpx;
  height: 72rpx;
  border-radius: 18rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cc-icon.green {
  background: #f0fdf4;
}

.cc-icon.blue {
  background: #eff6ff;
}

.cc-body {
  flex: 1;
  min-width: 0;
}

.cc-title {
  font-size: 30rpx;
  font-weight: 600;
  color: #111827;
  display: block;
  margin-bottom: 4rpx;
}

.cc-value {
  font-size: 28rpx;
  color: var(--theme-primary);
  display: block;
  margin-bottom: 4rpx;
  font-weight: 500;
}

.cc-hint {
  font-size: 24rpx;
  color: #9ca3af;
}

.cc-arrow {
  flex-shrink: 0;
  opacity: 0.5;
}

.res-group {
  background: #fff;
  border-radius: 20rpx;
  padding: 0 32rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
  margin-bottom: 28rpx;
}

.res-item {
  display: flex;
  align-items: center;
  gap: 20rpx;
  padding: 28rpx 0;
}

.res-divider {
  height: 1rpx;
  background: #f3f4f6;
}

.res-icon {
  width: 56rpx;
  height: 56rpx;
  border-radius: 14rpx;
  background: #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.res-body {
  flex: 1;
  min-width: 0;
}

.res-title {
  font-size: 30rpx;
  font-weight: 600;
  color: #111827;
  display: block;
  margin-bottom: 4rpx;
}

.res-desc {
  font-size: 26rpx;
  color: #6b7280;
}

.emergency-card {
  padding: 32rpx;
  background: #fef2f2;
  border: 1rpx solid #fecaca;
  border-radius: 20rpx;
  margin-bottom: 24rpx;
}

.emergency-header {
  display: flex;
  align-items: flex-start;
  gap: 20rpx;
  margin-bottom: 24rpx;
}

.emergency-icon-box {
  width: 56rpx;
  height: 56rpx;
  border-radius: 14rpx;
  background: rgba(220, 38, 38, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.emergency-texts {
  flex: 1;
  min-width: 0;
}

.emergency-title {
  font-size: 30rpx;
  font-weight: 700;
  color: #991b1b;
  display: block;
  margin-bottom: 6rpx;
}

.emergency-desc {
  font-size: 26rpx;
  color: #b91c1c;
  line-height: 1.5;
}

.emergency-btn {
  width: 100%;
  height: 88rpx;
  background: #dc2626;
  border-radius: 14rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12rpx;
}

.emergency-btn-text {
  font-size: 28rpx;
  font-weight: 600;
  color: #fff;
  line-height: 1;
}

.version-card {
  background: #fff;
  border-radius: 20rpx;
  padding: 0 32rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
}

.ver-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24rpx 0;
}

.ver-divider {
  height: 1rpx;
  background: #f3f4f6;
}

.ver-label {
  font-size: 28rpx;
  color: #6b7280;
}

.ver-value {
  font-size: 28rpx;
  font-weight: 600;
  color: #111827;
}
</style>
