<template>
  <teleport to="body">
    <div
      v-if="visible"
      class="center-card-dialog-overlay"
      :style="{ zIndex: zIndex }"
      @click.self="handleClose"
    >
      <div class="center-card-dialog" :style="dialogStyle">
        <!-- 头部区域 -->
        <div class="dialog-header" @click="handleDetail">
          <div class="header-left">
            <el-icon class="location-icon"><Location /></el-icon>
            <span class="dialog-title">潼南</span>
          </div>
          <el-icon class="arrow-icon"><ArrowRight /></el-icon>
        </div>

        <!-- 内容区域 -->
        <div class="dialog-content">
          <div class="info-item">
            <span class="info-label">人数：</span>
            <span class="info-value">{{ value }}</span>
            <span class="info-unit">人</span>
          </div>
          <div class="info-item">
            <span class="info-label">路段：</span>
            <span class="info-value">{{ roadCount }}</span>
            <span class="info-unit">条</span>
          </div>
        </div>
      </div>
    </div>
  </teleport>
</template>

<script setup>
import { computed } from 'vue';
import { ArrowRight, Location } from '@element-plus/icons-vue';

const props = defineProps({
  visible: {
    type: Boolean,
    default: false,
  },
  value: {
    type: [String, Number],
    default: '',
  },
  roadCount: {
    type: [String, Number],
    default: '128',
  },
  zIndex: {
    type: Number,
    default: 1000,
  },
  width: {
    type: String,
    default: '200px',
  },
});

const emit = defineEmits(['update:visible', 'close', 'detail']);

const dialogStyle = computed(() => ({
  width: props.width,
}));

// 关闭对话框
const handleClose = () => {
  emit('update:visible', false);
  emit('close');
};

// 点击详情
const handleDetail = () => {
  emit('detail');
};
</script>

<style lang="scss" scoped>
// 视频屏幕自适应 - 基于视口宽度动态调整
@function vw($px) {
  @return calc($px / 1920 * 100vw);
}

.center-card-dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.center-card-dialog {
  position: relative;
  background-image: url('../../../assets/MaMap_img/区县弹窗背景@2x.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  min-width: vw(200);
  padding: vw(12) vw(16);

  // 头部区域
  .dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    margin-bottom: vw(8);

    .header-left {
      display: flex;
      align-items: center;
      gap: vw(6);

      .location-icon {
        font-size: vw(16);
        color: #fff;
      }

      .dialog-title {
        font-size: vw(16);
        font-weight: 600;
        color: #fff;
      }
    }

    .arrow-icon {
      font-size: vw(14);
      color: rgba(255, 255, 255, 0.8);
    }
  }

  // 内容区域
  .dialog-content {
    display: flex;
    align-items: center;
    gap: vw(20);

    .info-item {
      display: flex;
      align-items: center;
      gap: vw(4);

      .info-label {
        font-size: vw(13);
        color: rgba(255, 255, 255, 0.8);
      }

      .info-value {
        font-size: vw(14);
        font-weight: 600;
        color: #40a9ff;
      }

      .info-unit {
        font-size: vw(12);
        color: rgba(255, 255, 255, 0.7);
      }
    }
  }
}

// 进入动画
.center-card-dialog-overlay {
  .center-card-dialog {
    animation: dialogIn 0.3s ease-out;
  }
}

@keyframes dialogIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

// 退出动画
.center-card-dialog-overlay.v-leave-active {
  .center-card-dialog {
    animation: dialogOut 0.2s ease-in;
  }
}

@keyframes dialogOut {
  from {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
  to {
    opacity: 0;
    transform: scale(0.9) translateY(-20px);
  }
}
</style>
