<script setup>
import { storeToRefs } from 'pinia';
import useVoiceStore from "@/store/modules/voice";

const voiceStore = useVoiceStore();
const { callDialing, callTime, isMakingCall, telephoneNumber } = storeToRefs(voiceStore);

// 切换展示窗口
const handleToggle = () => {
  voiceStore.noiceBarVisibleState = false;
  voiceStore.noiceBoxVisibleState = true;
}

// 挂断电话
const handleCallDisconnected = () => {
  voiceStore.onCallDisconnected();
}

// 接听电话
const handleCallAnswered = () => {
  voiceStore.onCallAnswered();
}

</script>

<template>
  <div class="tel-notice-bar_view flex items-center justify-between" :style="{ top: voiceStore.noiceBarVisibleState ? '10px' : '-88px' }">
    <div class="notice-left flex items-center justify-center">
      <div class="avatar-box">
        <div class="circle1"></div>
        <div class="circle2"></div>
        <div class="circle3"></div>
        <div class="circle4">
          <img src="@/assets/images/tools/icon-avatar-call.svg" alt="">
        </div>
      </div>

      <ul class="pl-[20px]">
        <li class="text-[14px] text-[#7B7B7D] space-x-[4px]">
          <span>黑龙江</span>
          <span>牡丹江</span>
        </li>
        <li class="text-[18px] font-bold">
          <span>{{ telephoneNumber }}</span>
        </li>
      </ul>
    </div>
    
    <div class="notice-center text-[14px]" style="color: rgba(255, 255, 255, 0.6)" v-show="callDialing">
      <span>通话中：</span>
      <span>{{ callTime }}</span>
    </div>

    <div class="notice-right flex">
      <ul class="flex items-center space-x-[12px]">
        <li class="icon-off" @click="handleCallDisconnected"></li>
        <li class="icon-on" @click="handleCallAnswered" v-show="!callDialing && !isMakingCall"></li>
        <li class="icon-toggle" @click="handleToggle"></li>
      </ul>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.tel-notice-bar_view {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  width: 600px;
  height: 88px;
  padding: 0 24px;
  background: #000;
  z-index: 1100;
  border-radius: 8px;
  color: #fff;
  transition: top ease-out .5s;

  .notice-left .avatar-box {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 100% 100%;
    background: linear-gradient(180deg, #656565 0%, #2F2F2F 100%);
    
    .circle1,
    .circle2,
    .circle3 {
      position: absolute;
      width: 30px;
      height: 30px;
      background: rgba(137, 142, 254, 0);
      border: 1px solid rgba(255, 255, 255, 0.60);
      border-radius: 999px;
    }

    .circle1,
    .circle2,
    .circle3 {
      animation-name: circleChange;
      animation-duration: 3s;
      animation-iteration-count: infinite;
      animation-timing-function: linear;
    }

    .circle1 {
      animation-delay: 0.5s;
    }

    .circle2 {
      animation-delay: 1.5s;
    }

    .circle3 {
      animation-delay: 2.5s;
    }

    @keyframes circleChange {
      0% {
        transform: scale(1.5);
        opacity: 0.75;
      }

      100% {
        transform: scale(2.5);
        opacity: 0.05;
      }
    }

    .circle4 {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 11111;
      width: 100%;
      height: 100%;
      border-radius: 100% 100%;
      background: linear-gradient(180deg, #656565 0%, #2F2F2F 100%);
    }
  }

  .notice-right {

    .icon-off,
    .icon-on {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      cursor: pointer;
    }

    .icon-off {
      background: url("@/assets/images/tools/icon-phone-on.svg") center center no-repeat;
    }

    .icon-on {
      background: url("@/assets/images/tools/icon-phone-off.svg") center center no-repeat;
    }

    .icon-toggle {
      width: 24px;
      height: 24px;
      background: url("@/assets/images/tools/icon-toggle.svg") center center no-repeat;
      cursor: pointer;
    }
  }
}

</style>