<template>
  <div class="position-relative">
    <div ref="map3dContainer"></div>
    <!-- 操作按钮面板 -->
    <div class="map-operation-panel">
      <button :loading="loading" @click="drawerVisible = true" class="btn">老空区永久密闭列表</button>
      <button :loading="loading" @click="emit('close')" class="btn ml-5px">返回列表</button>
    </div>

    <SideDrawer v-model:open="drawerVisible" :mineCode="mineCode" :getContainer="() => map3dContainer" />
  </div>
</template>

<script lang="ts" setup>
  import { onMounted, ref } from 'vue';
  // 直接导入app.ts中导出的方法
  import { initMap2d } from '../app';
  // import { message } from 'ant-design-vue';
  // 导入侧边弹框组件
  import SideDrawer from './SideDrawer.vue';

  const props = defineProps<{
    mineCode: string;
    wjId: string;
  }>();

  const emit = defineEmits(['close']);

  // 定义弹框显隐状态
  const drawerVisible = ref(false);
  const map3dContainer = ref<HTMLElement>();
  const loading = ref(false);

  // 初始化地图（确保先加载地图，再调用其他方法）
  onMounted(() => {
    // nextTick(async () => {
    loading.value = true;
    initMap2d(map3dContainer.value!, {
      wjId: props.wjId as string,
    }).finally(() => {
      loading.value = false;
    });
    // });
  });
</script>

<style scoped>
  #map3dContainer {
    position: absolute;
    background: transparent;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
  }

  /* 操作面板样式 */
  .map-operation-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 999;
    display: flex;
    gap: 8px;
  }

  .btn {
    padding: 8px 12px;
    background: #409eff;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
  }

  .btn:hover {
    background: #66b1ff;
  }
</style>
