<template>
  <div class="week-analyze">
    <div class="analyze-header">
      <h3>本周综合表现分析</h3>
      <p class="analyze-subtitle">基于本周销售数据的综合分析报告</p>
    </div>
    
    <div class="analyze-content">
      <!-- 周期表现概览 -->
      <div class="performance-overview">
        <div class="overview-card">
          <div class="card-icon">
            <svg width="24" height="24" viewBox="0 0 24 24" fill="none">
              <path d="M12 2L15.09 8.26L22 9L17 14L18.18 21L12 17.77L5.82 21L7 14L2 9L8.91 8.26L12 2Z" fill="#FFD700"/>
            </svg>
          </div>
          <div class="card-content">
            <h4>综合评分</h4>
            <div class="score">{{ overallScore }}<span class="score-unit">/100</span></div>
            <div class="score-trend" :class="scoreTrend.type">
              {{ scoreTrend.text }}
            </div>
          </div>
        </div>
        
        <div class="overview-card">
          <div class="card-icon">
            <svg width="24" height="24" viewBox="0 0 24 24" fill="none">
              <path d="M16 6L18.29 8.29L13.41 13.17L9.41 9.17L2 16.59L3.41 18L9.41 12L13.41 16L19.71 9.71L22 12V6H16Z" fill="#4CAF50"/>
            </svg>
          </div>
          <div class="card-content">
            <h4>目标完成率</h4>
            <div class="score">{{ targetCompletion }}<span class="score-unit">%</span></div>
            <div class="progress-bar">
              <div class="progress-fill" :style="{ width: targetCompletion + '%' }"></div>
            </div>
          </div>
        </div>
        
        <div class="overview-card">
          <div class="card-icon">
            <svg width="24" height="24" viewBox="0 0 24 24" fill="none">
              <path d="M12 2C6.48 2 2 6.48 2 12S6.48 22 12 22 22 17.52 22 12 17.52 2 12 2ZM13 17H11V15H13V17ZM13 13H11V7H13V13Z" fill="#FF9800"/>
            </svg>
          </div>
          <div class="card-content">
            <h4>改进建议</h4>
            <div class="suggestions-count">{{ suggestions.length }}项</div>
            <div class="suggestions-preview">{{ suggestions[0]?.title || '暂无建议' }}</div>
          </div>
        </div>
      </div>
      
      <!-- 详细分析 -->
      <div class="detailed-analysis">
        <div class="analysis-section">
          <h4>关键指标表现</h4>
          <div class="metrics-grid">
            <div v-for="metric in keyMetrics" :key="metric.name" class="metric-item">
              <div class="metric-header">
                <span class="metric-name">{{ metric.name }}</span>
                <span class="metric-trend" :class="metric.trend">
                  {{ metric.trendText }}
                </span>
              </div>
              <div class="metric-value">
                <span class="current-value">{{ metric.current }}</span>
                <span class="target-value">/ {{ metric.target }}</span>
              </div>
              <div class="metric-progress">
                <div class="progress-bar">
                  <div class="progress-fill" :style="{ width: (metric.current / metric.target * 100) + '%' }"></div>
                </div>
                <span class="progress-text">{{ Math.round(metric.current / metric.target * 100) }}%</span>
              </div>
            </div>
          </div>
        </div>
        
        <div class="analysis-section">
          <h4>改进建议</h4>
          <div class="suggestions-list">
            <div v-for="suggestion in suggestions" :key="suggestion.id" class="suggestion-item">
              <div class="suggestion-priority" :class="suggestion.priority"></div>
              <div class="suggestion-content">
                <h5>{{ suggestion.title }}</h5>
                <p>{{ suggestion.description }}</p>
                <div class="suggestion-actions">
                  <span class="action-tag" v-for="action in suggestion.actions" :key="action">{{ action }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'

// Props
const props = defineProps({
  weekData: {
    type: Object,
    default: () => ({})
  }
})

// 响应式数据
const overallScore = ref(78)
const targetCompletion = ref(65)

const scoreTrend = computed(() => {
  const score = overallScore.value
  if (score >= 80) {
    return { type: 'positive', text: '表现优秀' }
  } else if (score >= 60) {
    return { type: 'neutral', text: '表现良好' }
  } else {
    return { type: 'negative', text: '需要改进' }
  }
})

const keyMetrics = ref([
  {
    name: '通话量',
    current: 85,
    target: 100,
    trend: 'positive',
    trendText: '↗ +12%'
  },
  {
    name: '接通率',
    current: 68,
    target: 80,
    trend: 'neutral',
    trendText: '→ 持平'
  },
  {
    name: '转化率',
    current: 12,
    target: 15,
    trend: 'negative',
    trendText: '↘ -3%'
  },
  {
    name: '客户满意度',
    current: 4.2,
    target: 4.5,
    trend: 'positive',
    trendText: '↗ +0.2'
  }
])

const suggestions = ref([
  {
    id: 1,
    title: '提升通话转化率',
    description: '当前转化率低于目标，建议优化话术和跟进策略',
    priority: 'high',
    actions: ['话术优化', '跟进策略', '客户画像分析']
  },
  {
    id: 2,
    title: '增加客户互动频次',
    description: '客户响应时间较长，建议增加主动联系频次',
    priority: 'medium',
    actions: ['主动联系', '内容营销', '社群运营']
  },
  {
    id: 3,
    title: '优化时间管理',
    description: '通话时长分布不均，建议优化时间分配',
    priority: 'low',
    actions: ['时间规划', '效率工具', '任务优先级']
  }
])

// 生命周期
onMounted(() => {
  // 可以在这里根据传入的数据计算分析结果
  console.log('WeekAnalize组件已挂载', props.weekData)
})
</script>

<style scoped>
.week-analyze {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.analyze-header {
  margin-bottom: 24px;
}

.analyze-header h3 {
  font-size: 20px;
  font-weight: 600;
  color: #1a1a1a;
  margin: 0 0 8px 0;
}

.analyze-subtitle {
  color: #666;
  font-size: 14px;
  margin: 0;
}

.performance-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.overview-card {
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px solid #e9ecef;
}

.card-icon {
  width: 48px;
  height: 48px;
  background: #fff;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.card-content h4 {
  font-size: 14px;
  color: #666;
  margin: 0 0 8px 0;
  font-weight: 500;
}

.score {
  font-size: 28px;
  font-weight: 700;
  color: #1a1a1a;
  line-height: 1;
}

.score-unit {
  font-size: 16px;
  color: #666;
  font-weight: 400;
}

.score-trend {
  font-size: 12px;
  margin-top: 4px;
}

.score-trend.positive {
  color: #4CAF50;
}

.score-trend.neutral {
  color: #FF9800;
}

.score-trend.negative {
  color: #f44336;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: #e9ecef;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4CAF50 0%, #8BC34A 100%);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.suggestions-count {
  font-size: 24px;
  font-weight: 700;
  color: #FF9800;
  line-height: 1;
}

.suggestions-preview {
  font-size: 12px;
  color: #666;
  margin-top: 4px;
}

.detailed-analysis {
  display: grid;
  gap: 32px;
}

.analysis-section h4 {
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
  margin: 0 0 16px 0;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.metric-item {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 16px;
  border: 1px solid #e9ecef;
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.metric-name {
  font-size: 14px;
  color: #1a1a1a;
  font-weight: 500;
}

.metric-trend {
  font-size: 12px;
  font-weight: 500;
}

.metric-trend.positive {
  color: #4CAF50;
}

.metric-trend.neutral {
  color: #FF9800;
}

.metric-trend.negative {
  color: #f44336;
}

.metric-value {
  margin-bottom: 8px;
}

.current-value {
  font-size: 20px;
  font-weight: 700;
  color: #1a1a1a;
}

.target-value {
  font-size: 14px;
  color: #666;
  margin-left: 4px;
}

.metric-progress {
  display: flex;
  align-items: center;
  gap: 8px;
}

.metric-progress .progress-bar {
  flex: 1;
  margin: 0;
}

.progress-text {
  font-size: 12px;
  color: #666;
  min-width: 35px;
  text-align: right;
}

.suggestions-list {
  display: grid;
  gap: 16px;
}

.suggestion-item {
  display: flex;
  gap: 12px;
  padding: 16px;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e9ecef;
}

.suggestion-priority {
  width: 4px;
  border-radius: 2px;
  flex-shrink: 0;
}

.suggestion-priority.high {
  background: #f44336;
}

.suggestion-priority.medium {
  background: #FF9800;
}

.suggestion-priority.low {
  background: #4CAF50;
}

.suggestion-content h5 {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a1a;
  margin: 0 0 8px 0;
}

.suggestion-content p {
  font-size: 13px;
  color: #666;
  margin: 0 0 12px 0;
  line-height: 1.4;
}

.suggestion-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.action-tag {
  background: #e3f2fd;
  color: #1976d2;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 12px;
  font-weight: 500;
}

@media (max-width: 768px) {
  .week-analyze {
    padding: 16px;
  }
  
  .performance-overview {
    grid-template-columns: 1fr;
  }
  
  .metrics-grid {
    grid-template-columns: 1fr;
  }
  
  .overview-card {
    padding: 16px;
  }
}
</style>