<template>
  <div  class="go-title-03">
    <div class="flex ai-c jc-sb max-w navsbox">
      <div class="flex navsli ai-c jc-c" v-for="(item,index) in navsArr" :class="index==navsIndex?'navsliactive':''" @click="navsClick(item,index)">
        {{ item.label }}
        <span class="navsNum" v-if="item.value!=0">{{item.value}}</span>
      </div>
    </div>
    <div class="flex column sectionBox">
      <div class="mt-1 sectionLi" v-for="(item,index) in sectionDatas" @click="handlerFireDetail(item)">
        <div class="flex jc-sb">
          <div class="titleText">{{item.describe}}</div>
          <div class="mr-2 desStyle">{{item.degreeType}}</div>
        </div>
        <div class="flex mt-1 ai-c">
          <img class="mr-1" src="@/assets/images/chart/equipment/address.png" />
          <div class="numStyle" :title="item.address">{{item.address}}</div>
        </div>
        <div class="flex mt-1 ai-c">
          <img class="mr-1 timeicon" src="@/assets/images/chart/equipment/time.png" />
          <div class="numStyle">{{item.reportTime}}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { PropType, toRefs, ref,onMounted } from 'vue'
import { CreateComponentType } from '@/packages/index.d'
import { useChartDataFetch } from '@/hooks';
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore';
import * as mars3d from "mars3d";
import { EventBus } from '@/utils/eventBus';

import { eventHandlerHook } from '@/hooks/eventHandler.hook';
const chartEditStore = useChartEditStore();

const props = defineProps({
  chartConfig: {
    type: Object as PropType<CreateComponentType>,
    required: true
  }
})

const navsIndex = ref(0)
const { w, h } = toRefs(props.chartConfig.attr)
const {
  navsArr,
  navsSize,
  navsColor,
  navsCheckSize,
  navsCheckColor,
  navsCheckBackground,
  navsBackground,
  titleSize,
  titleColor,
  sectionDatas,
  desColor,
  desSize,
  datasColor,
  datasSize
} = toRefs(props.chartConfig.option)



 const navsClick = function(item,index){
  navsIndex.value = index
  props.chartConfig.request.requestSQLContent.sql = item.sql
  useChartDataFetch(props.chartConfig, useChartEditStore, (resData: any) => {
      props.chartConfig.option.sectionDatas = resData
  })
 }
 // 数据callback处理（预览时触发）
useChartDataFetch(props.chartConfig, useChartEditStore, (resData: any[]) => {
  props.chartConfig.option.sectionDatas = resData;
});


onMounted(()=>{
  // 加载火点
  setTimeout(function(){
    handlerLoadFirePoint(sectionDatas.value);
  },5000)
})

// 加载火点信息
const handlerLoadFirePoint = (points:[])=>{

  points?.forEach((item,index)=>{
    let graphicOptions = {
      id:item.id,
      attr:item,
      position: [parseFloat(item.lng), parseFloat(item.lat)],
      style: {
        image: "/public/map/fire.png",
        clampToGround: true,
        scale: 0.8,
        label: {
          text: item.title,
          font_size: 12,
          color: "#ffffff",
          pixelOffsetY: -36,
          distanceDisplayCondition: true,
          distanceDisplayCondition_far: 500000,
          distanceDisplayCondition_near: 0,
        },
      },
      popup: 'all',
      // `<div class="marsTiltPanel marsTiltPanel-theme-red" style="font-size:12px;">
      //     <div class="marsTiltPanel-wrap">
      //         <div class="area">
      //             <div class="arrow-lt"></div>
      //             <div class="b-t"></div>
      //             <div class="b-r"></div>
      //             <div class="b-b"></div>
      //             <div class="b-l"></div>
      //             <div class="arrow-rb"></div>
      //             <div class="label-wrap">
      //                 <div class="title">火点信息</div>
      //                 <div class="label-content">
      //                     <div class="data-li">
      //                         <div class="data-label">火点地址：${item.position}</div>
      //                     </div>
      //                     <div class="data-li">
      //                         <div class="data-label">上报时间：</div>
      //                         <div class="data-value"><span id="lablYeWei"  class="label-num">2025-2-11 12:00:00</span><span class="label-unit"></span>
      //                         </div>
      //                     </div>
      //                 </div>
      //             </div>
      //         </div>
      //         <div class="b-t-l"></div>
      //         <div class="b-b-r"></div>
      //     </div>
      //     <div class="arrow" ></div>
      // </div>`,
      popupOptions: {
        offsetY: -30,
        template: "{content}",
        horizontalOrigin: "Cesium.HorizontalOrigin.LEFT",
        verticalOrigin: "Cesium.VerticalOrigin.CENTER",
      },
    }

    let graphic = new mars3d.graphic.BillboardEntity(graphicOptions);
    window.graphicLayer.addGraphic(graphic);
  })
  
  window.graphicLayer.on(mars3d.EventType.click,function(e){
      handlerFireDetail(e.graphic.options.attr)
  })

}

// 查看详情
const handlerFireDetail = (item) => { 
  
  // 显示弹窗
  eventHandlerHook(
    chartEditStore.getComponentList,
    props.chartConfig.events.interactConfigEvents,
    'click',
    item
  );

  // 更新详情弹窗信息
  let bindEvents = props.chartConfig.events.interactConfigEvents
  
  console.log("bindEvents",bindEvents);
  for(let i=0;i<bindEvents.length;i++){
      for(let j=0;j<bindEvents[i].movementList.length;j++){
        EventBus.emit(bindEvents[i].movementList[j].elementId[j]+"dataupdate",item);
      }
  }
  let graphic =  window.graphicLayer.getGraphicById(item.id);

  if(graphic){
    window.globalMap.flyToGraphic(graphic,{radius:300});
  }

}


</script>

<style lang="scss" scoped>
@include go('title-03') {
  height: v-bind('h');
  position: relative;
  padding-top:10px;
  scrollbar-width: none;
  -ms-overflow-style: none;
  .max-w{
    width: 100%;
  }
  .column{
    flex-direction: column;
  }
  .flex{
    display: flex;
  }
  .jc-sb{
    justify-content: space-between;
  }
  .jc-sa{
    justify-content: space-around;
  }
  .jc-c{
    justify-content: center;
  }
  .ai-c{
    align-items: center;
  }
  .img{
    width: 148px;
    height: 16px;
  }
  .navsbox{
    width: 92%;
    margin-left: 4%;
    height: 28px;
    background: v-bind('navsBackground');
    border-radius: 1px;
    border: 1px solid #4FE985;
    margin-bottom: 13px;
    display: flex;
  }
  .navsli{
    flex: 1;
    height: 25px;
    color: v-bind('navsColor');
    font-size: v-bind('navsSize+"px"');
    cursor: pointer;
    position: relative;
  }
  .navsNum{
    background: #F91B1B;
    width: 20px;
    height: 20px;
    border-radius: 20px;
    text-align: center;
    line-height:20px;
    color: #fff;
    font-size: 8px;
    position: absolute;
    left: 60%;
    top: 0;
    margin-top: -10px;
  }
  .navsliactive{
    color: v-bind('navsCheckColor');
    font-size: v-bind('navsCheckSize+"px"');
    background: v-bind('navsCheckBackground');
  }
  .sectionBox{
    width: 92%;
    height: calc(100% - 40px);
    margin-left: 4%;
    overflow: auto;
    img{
      width: 21px;
      height: 21px;
    }
    .timeicon{
      width: 15px;
      height: 15px;
      margin-left: 3px;
    }
  }
  .sectionLi{
    padding: 9px 12px;
    height: 104px;
    background: url('@/assets/images/chart/equipment/sectionbg.png');
    background-size: 100% 100%;
  }
  .titleText{
    color: v-bind('titleColor');
    font-size: v-bind('titleSize+"px"');
  }
  .dataStyle{
    font-size: 14px;
    color: #CBE7CD;
  }
  .numStyle{
    color: v-bind('datasColor');
    font-size: v-bind('datasSize+"px"');
    white-space: nowrap;
    overflow: hidden;      /* 隐藏溢出内容 :ml-search[overflow] */
    text-overflow: ellipsis;
  }
  .desStyle{
    color: v-bind('desColor');
    font-size: v-bind('desSize+"px"');
  }
  .desImg{
    margin-right: 10px;
  }
  .mr-2{
    margin-right: 20px;
  }
  .mr-1{
    margin-right: 6px;
  }
  .mt-1{
    margin-top: 8px;
  }
}
</style>
