<template>
  <section class="map-container" ref="mapWrapperRef">
    <AirQuality class="air-quality block-box" />
    <Weather class="weather block-box" />
    <Numbox class="num-box block-box" />
    <Tabber class="tabber-box" />
    <Norm class="block-box nomr-box" />
    <section class="map">
      <charts :options="mapOption" ref="mapChartRef" class="mapChart" />
    </section>
  </section>
</template>

<script setup lang="ts">
import AirQuality from './airQuality.vue'
import Weather from './weather.vue'
import Numbox from './numbox.vue'
import Tabber from './tabber.vue'
import Norm from './norm.vue'

let observer: Nullable<ResizeObserver> = null
const mapWrapperRef = ref()

const mapChartRef = ref()

const mapOption = ref({
  geo: [
    {
      map: 'yx',
      layoutCenter: ['50%', '50%'],
      layoutSize: '80%',
      itemStyle: {
        areaColor: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 1,
          y2: 0,
          colorStops: [
            {
              offset: 0,
              color: '#01996A'
            },
            {
              offset: 1,
              color: '#00553B'
            }
          ]
        },
        borderColor: '#34F6BA'
      },
      zlevel: 0
    },
    {
      map: 'yx',
      layoutCenter: ['50%', '51%'],
      layoutSize: '80%',
      itemStyle: {
        areaColor: '#002C1F',
        borderColor: 'transparent'
      },
      zlevel: -1
    },
    {
      map: 'yx',
      layoutCenter: ['50%', '51%'],
      layoutSize: '80%',
      itemStyle: {
        areaColor: '#078B63',
        borderColor: 'transparent'
      },
      zlevel: -2
    },
    {
      map: 'yx',
      layoutCenter: ['50%', '52%'],
      layoutSize: '80%',
      itemStyle: {
        areaColor: '#002C1F',
        borderColor: 'transparent',
        shadowBlur: 20,
        shadowColor: '#000',
        shadowOffsetX: 0,
        shadowOffsetY: 0
      },
      zlevel: -3
    }
  ]
})

const handlerResize = () => {
  unref(mapChartRef).resizeHandler()
}



onMounted(() => {
  observer = new ResizeObserver(handlerResize)
  observer.observe(mapWrapperRef.value)
})

onUnmounted(() => {
  observer?.disconnect()
})
</script>

<style scoped lang="scss">
.map-container {
  position: relative;
  width: 100%;
  height: 100%;
  &::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url('@/assets/imgs/screen/mapborder.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    //animation: rotate 5s linear infinite;
  }
  &::after {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url('@/assets/imgs/screen/mapCricle.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    //animation: rotate 5s linear infinite;
  }
  .map {
    position: absolute;
    inset: 0;
    display: flex;
    flex-flow: column nowrap;
    padding: 12px;
  }
  .air-quality {
    position: absolute;
    left: 12px;
    top: 0;
  }
  .nomr-box {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
  }
  .weather {
    position: absolute;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
  }
  .num-box {
    position: absolute;
    right: 12px;
    top: 0;
  }
  .tabber-box {
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    z-index: 2;
  }
  .block-box {
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(3px);
    z-index: 2;
  }
}
@keyframes rotate {
  from {
    transform: rotateX(0deg) rotateZ(0);
  }
  50% {
    transform: rotateX(-30deg) rotateZ(30deg);
  }
  to {
    transform: rotateX(0deg) rotateZ(0deg);
  }
}
</style>
