<template>
    <div>
      <el-dialog
        v-model="dialogFormVisible"
        width="80%"
        :show-close="false"
        :destroy-on-close="true"
        :modal="false" 
        :lock-scroll="true"
        :before-close="handleClose"
        class="call-dialog" 
      >
        <div class="call-wrapper">
          <!-- 上方头像与状态 -->
          <div class="avatar-section">
            <img class="avatar" :src="avatarUrl" alt="头像" />
            <div class="user-name">{{ userName }}</div>
            <div class="status-text">{{ statusText }}</div>
          </div>
  
          <!-- 底部操作按钮 -->
          <div class="control-section">
            <!-- 呼叫模式 -->
            <template v-if="mode === 'call'">
              <el-button
                v-if="callStatus === 'calling'"
                type="danger"
                round
                class="control-btn hangup"
                @click="hangup"
              >
                挂断
              </el-button>
              <el-button
                v-else
                type="primary"
                round
                class="control-btn call"
                @click="startCall"
              >
                呼叫中...
              </el-button>
            </template>
  
            <!-- 接听模式 -->
            <template v-else>
              <el-button
                type="success"
                round
                class="control-btn accept"
                @click="acceptCall"
              >
                接听
              </el-button>
              <el-button
                type="danger"
                round
                class="control-btn hangup"
                @click="hangup"
              >
                挂断
              </el-button>
            </template>
          </div>
        </div>
      </el-dialog>
    </div>
</template>
  
  <script setup>
  import { ref, computed } from "vue";
  import { ElMessage } from "element-plus";
  
  const props = defineProps({
    mode: { type: String, default: "call" }, // call: 呼叫模式, receive: 接听模式
    avatarUrl: {
      type: String,
      default: "https://cdn-icons-png.flaticon.com/512/1946/1946429.png",
    },
    userName: { type: String, default: "对方用户" },
  });
  
  const dialogFormVisible = ref(false);
  const callStatus = ref("calling"); // calling | active | ended
  
  const statusText = computed(() => {
    if (props.mode === "call") {
      if (callStatus.value === "calling") return "正在呼叫对方...";
      if (callStatus.value === "active") return "通话中";
      return "通话结束";
    } else {
      return callStatus.value === "active" ? "通话中" : "对方来电...";
    }
  });
  
  function startCall() {
    callStatus.value = "active";
    ElMessage.success("开始通话");
  }
  
  function acceptCall() {
    callStatus.value = "active";
    ElMessage.success("已接听");
  }
  
  function hangup() {
    callStatus.value = "ended";
    ElMessage.error("通话已结束");
  }
  
  function handleClose() {
    dialogFormVisible.value = false;
  }
  
  function show() {
    dialogFormVisible.value = true;
  }
  
  defineExpose({
    show,
  });
  </script>
  
  <style scoped> 
  /* ::v-deep .el-dialog__header{ 
    background-color:red;
  } */
  /* 去除 el-dialog 默认样式，让它全屏覆盖且透明 */
  .call-dialog :deep(.el-dialog) {
    background: transparent;
    box-shadow: none;
    padding: 0;
    margin: 0;
    border-radius: 0;
    height: calc(100vh - 30vh);
    width: 100%;
    max-width: none;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .call-dialog :deep(.el-dialog__body) {
    padding: 0;
    height: 100%; 
  }
  
  /* 通话主背景 */
  .call-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    height: calc(100vh - 30vh);
    width: 100%;
    background: linear-gradient(180deg, #0f2027, #203a43, #2c5364);
    color: #fff;
    box-sizing: border-box;
    padding: 80px 0;
    position: relative;
  }
  
  /* 头像部分 */
  .avatar-section {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  
  .avatar {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    border: 6px solid rgba(255, 255, 255, 0.25);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.4);
    object-fit: cover;
    transition: transform 0.3s ease;
  }
  
  .avatar:hover {
    transform: scale(1.05);
  }
  
  .user-name {
    margin-top: 24px;
    font-size: 26px;
    font-weight: 600;
    color: #fff;
  }
  
  .status-text {
    margin-top: 12px;
    font-size: 18px;
    opacity: 0.8;
  }
  
  /* 控制按钮部分 */
  .control-section {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 80px;
  }
  
  .control-btn {
    width: 160px;
    height: 60px;
    font-size: 18px;
    font-weight: 500;
    letter-spacing: 1px;
    transition: all 0.3s ease;
  }
  
  .control-btn:hover {
    transform: scale(1.05);
  }
  
  .control-btn.accept {
    background: linear-gradient(135deg, #00c853, #4caf50);
    color: #fff;
    border: none;
  }
  
  .control-btn.hangup {
    background: linear-gradient(135deg, #ff1744, #d50000);
    color: #fff;
    border: none;
  }
  
  .control-btn.call {
    background: linear-gradient(135deg, #2196f3, #1976d2);
    color: #fff;
    border: none;
  }
  </style>
  