<template>
  <div :class="$style['container']">
    <div class="header">
      <div class="title">
        <header2
          ref="headerref"
          :width="'100%'"
          :height="'150px'"
          :title="t('messages.InPlantProducts')"
          :titleTip="titleTip"
          :typeFun="['AbnormalData','time']"
          :alarmType="['inplant']"
        ></header2>
        <!-- <div class="tip" style="display: flex;"> 
            <span class="tipspan"><div class="red"></div><span class="tipstring">网关离线</span></span>
            <span class="tipspan"><div class="blue"></div> <span class="tipstring">网关在线</span></span>
          </div> -->
      </div>
    </div>

    <div class="content" ref="Acontent">
      <el-row>
        <el-col :span="24">
          <top :width="size.oWidth" :height="size.oHeight"></top>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <bottom :width="size.oWidth" :height="size.oHeight * 3"></bottom>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, onUnmounted, reactive, ref } from "vue";
import top from "./content/top.vue";
import bottom from "./content/bottom.vue";
//   import contentRight from './content/right.vue'
import header2 from "@/components/headerBox/header2.vue";
//   import useNowTime from '@/hook/nowTime'
import { connectWebsocket, closeWebsocket } from "@/utils/websocket";
import { useInPlantProductsStore } from "@/store/module/InPlantProducts";

import { calcWH } from "@/components/ts/selfAdaption";
import { useI18n } from 'vue-i18n'
let {t} = useI18n();
// import { ElRow, ElCol } from "element-plus";
const store = useInPlantProductsStore();
let Acontent = ref();
let headerref=ref()
let time = ref(null);
let titleTip = [
  {
    color: "rgb(32, 174, 197)",
    name: t('messages.onLine'),
  },
  {
    color: "rgb(228, 57, 97)",
    name: t('messages.offline'),
  },
];

let size = reactive({
  oWidth: 0,
  oHeight: 0,
});
function WH(div: HTMLElement) {
  let a = calcWH(div.offsetHeight, div.offsetWidth, 4, 1, 0);
  size.oWidth = a.oWidth;
  size.oHeight = a.oHeight;
}
//
function getWebsocket(val) {
  headerref.value.HeadergetWebsocket(val)
  try {
    let data = JSON.parse(val);
    if (data.type == "gatewayCrops") {
      if(!store.gatewayOfCorps) return
      store.changegatewayOfCorps(data.msg)
      // store.changenoise(data.msg)
    }
    if(data.type=="DeviceInPlant"){
      console.log(data.msg);
      store.changeDevList(data.msg)
    }
  } catch (err) {}
}
function errWebsocket(val) {
  headerref.value?headerref.value.HeadererrWebsocket(val):''
  // console.log(val);
}

onMounted(() => {
  let contentBox = Acontent.value;
  // let Timedombox=Timedom.value
  window.document.title = t('messages.InPlantProducts');
  WH(contentBox);
  window.addEventListener("resize", () => {
    if (time.value) {
      clearTimeout(time.value);
      time.value = null;
    }
    time.value = setTimeout(() => {
      WH(contentBox);
    }, 1000);
  });
  connectWebsocket(null, null, getWebsocket, errWebsocket);
});

onUnmounted(() => {
  closeWebsocket();
  clearTimeout(time);
});
</script>

<style module>
.container {
  height: 1080px;
  width: 1920px;
  color: #20aec5;
  background-color: #100c2a;
}
</style>

<style scoped>
.title {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}
.title > h1 {
  font-size: 30px;
  position: absolute;
  top: 10px;
}
.header {
  position: relative;
}
.header p {
  position: absolute;
  right: 50px;
  bottom: 20px;
  font-size: 20px;
}
.content {
  width: 100%;
  --header: 150px;
  height: calc(1080px - var(--header));
}

</style>

<style>
body {

  /* --content:calc(100vh - var(--header)) */
  overflow: hidden !important;
  -ms-overflow-style: none; /* IE + Edge */
  scrollbar-width: none; /* Firefox */
}
body::-webkit-scrollbar {
  display: none;
}
</style>
