<template>
    <div class="voice-call-overlay">
      <div class="call-container">
        <img class="avatar" :src="user.avatar" />
        <div class="nickname">{{ user.nickname }}</div>
        <div class="call-status">{{ callStatus }}</div>
        <div class="call-duration" v-if="callStatus === '通话中'">{{ callDuration }}</div>
        <button class="hangup-button" @click="hangup">挂断</button>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ref, onMounted, onBeforeUnmount } from 'vue';
  const props = defineProps({
    user: {
      type: Object,
      required: true
    }
  });
  const emit = defineEmits(['hangup']);
  
  const callStatus = ref('正在呼叫...');
  const callDuration = ref('00:00');
  let timer = null;
  
  const startCallTimer = () => {
    let seconds = 0;
    timer = setInterval(() => {
      seconds++;
      const m = String(Math.floor(seconds / 60)).padStart(2, '0');
      const s = String(seconds % 60).padStart(2, '0');
      callDuration.value = `${m}:${s}`;
    }, 1000);
  };
  
  const hangup = () => {
    emit('hangup');
  };
  
  onMounted(() => {
    // 模拟3秒后进入通话状态
    setTimeout(() => {
      callStatus.value = '通话中';
      startCallTimer();
    }, 3000);
  });
  
  onBeforeUnmount(() => {
    clearInterval(timer);
  });
  </script>
  
  <style scoped>
  .voice-call-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #000;
    color: #fff;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  
  .call-container {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  
  .avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    margin-bottom: 20px;
  }
  
  .nickname {
    font-size: 20px;
    margin-bottom: 10px;
  }
  
  .call-status {
    font-size: 16px;
    margin-bottom: 5px;
  }
  
  .call-duration {
    font-size: 16px;
    margin-bottom: 20px;
  }
  
  .hangup-button {
    background-color: red;
    border: none;
    padding: 12px 30px;
    color: white;
    border-radius: 24px;
    font-size: 16px;
  }
  </style>
  