<template>
  <div class="head no-events">
    <div class="left">
      <div class="logo">
        <img  src="@/assets/img/logo-horizontal.png" width="180" height="40" />
      </div>
      <GardenMenu @changeGarden="changeGarden" @handleChange="selectOrganAndArea" ></GardenMenu>
    </div>
    <div class="center">
      <div class="title">飞鸟智慧果园管理平台</div>
    </div>
    <div class="right">
      <div class="weather" v-if="weather">
        <!--      <embed :src="weather.icon" fill="red" type="image/svg+xml" style="width: 40px;height:40px;" />-->
        <img src="@/assets/img/ty.png" width="16" height="16" />   晴
      </div>
      <div class="nowDate" :key="nowDateKey">
        {{dateFormat("YYYY/mm/dd",new Date())}} {{getWeek()}} {{getMoment()}} {{dateFormat("HH:MM:SS",new Date())}}
      </div>
      <div class="logout yse-events">
        <img src="@/assets/img/user.png" width="14" height="16" />
        <el-dropdown @command="handleCommand">
            <span class="ve_nav_dropdown">
                管理员
                <el-icon>
                    <arrow-down-bold />
                </el-icon>
            </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item :command="{ name: 'Login' }">
                退出登录
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>



  </div>
</template>

<script setup>
import {Search} from '@element-plus/icons-vue'
import {dateFormat,getWeek,getMoment,isDayOrNight} from '@/common/commonMethods.js'
import {base_img_url} from '@/api/config.js'
import {inject, onMounted, ref} from "vue"
import {useStore} from "vuex";
import {wktCastGeom,fit} from "@/common/ol_common.js"
import {useRouter} from "vue-router";
import Back from "./components/Back";
import GardenMenu from "./components/GardenMenu";

let emit = defineEmits(["goBack","selectOrganAndArea","changeGarden"])
let props = defineProps({
  menuType:{
    type:String,
    value : ""
  },
  title:{
    type:String,
    value : ""
  },
  hideZnxy:{
    type:Boolean,
    value : false
  }
})

const store = useStore();
const state = store.state;
const userId = store.getters.userinfo.userId;
const router = useRouter();
const backRef = ref(null)
const cityMenuRef = ref(null)
const weather = ref(null);
const nowDateKey = ref(0)
const dayOrNight = ref(1)
const tabIndex = ref(1)
async function initWeather(){
  let {code,data} = await VE_API.system.weather();
  weather.value = data.daily[0];
}

function selectOrganAndArea(data){
  emit("selectOrganAndArea", data)
}
function changeGarden(){
  emit("changeGarden")
}
onMounted(async ()=>{
  // initWeather()
})

/**
 * 返回按钮的事件
 */
function goBack(){
  emit("goBack")
}

function keyPlus(){
  dayOrNight.value = isDayOrNight();
  nowDateKey.value = nowDateKey.value + 1;
  if(weather.value){
    weather.value.icon = dayOrNight.value ?
        (base_img_url+"weather/"+weather.value.iconDay + ".svg") :
        (base_img_url+"weather/"+weather.value.iconNight + ".svg");

    weather.value.text = dayOrNight.value ? weather.value.textDay : weather.value.textNight;
  }
  setTimeout(keyPlus,1000)
}
keyPlus();

const handleCommand =  (command) => {
  router.push(command)
};

defineExpose({})
</script>


<style lang="scss" scoped>
.head{
  position: absolute;
  z-index: 3;
  width:100%;
  height: 80px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  .left{
    height: 100%;
    display: flex;
    width: 25%;
    .logo{
      width: 225px;
      height: 100%;
      display: flex;
      flex-direction: column-reverse;
      align-items: center;
    }
  }
  .center{
    width: 50%;
    text-align: center;
    .title{
      width: 100%;
      text-align: center;
      height: 50px;
      font-size: 36px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #5EFCFF;
      line-height: 50px;
      letter-spacing: 1px;
      background: linear-gradient(180deg, #5CF2FF 0%, #6CFFD7 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;

    }
  }

  .right{
    height: 100%;
    width: 25%;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: flex-end;
    background-image: url(@/assets/img/input_bg2.png);
    background-repeat: no-repeat;
    background-size: 100% 13px;
    background-position: 0 100%;
    padding-bottom: 5px;
    box-sizing: border-box;
    color: #F4F4F4;
    font-family: PingFangSC-Medium, PingFang SC;
    font-size: 14px;
    .weather{
      flex-grow:1;
      text-align: right;
    }
    .nowDate{
      text-align: left;
      flex-grow:20;
      padding-left: 10px;
    }
    .logout{
      flex-grow:1;
      display: flex;
      flex-direction: row;
      justify-content: space-around;
      align-items: center;
      text-align: right;
      box-sizing: border-box;
      padding-right:20px ;
    }
  }
}
</style>
