<template>
  <div class="panel" :class="{ show }">
    <span class="icon" @click="handlePlayTours" v-if="hasTours">
      <Icon type="play" />
    </span>
    <span class="icon" @click="showScenes = !showScenes" v-if="sceneList.length > 1">
      <Icon type="scene" />
    </span>
    <span class="ctrl" :class="{ show }" @click="show = !show">
      <Icon type="arrows" />
    </span>
  </div>
  <SceneList v-if="showScenes" @close="showScenes = false" @change-scene="changeScene" />
</template>

<script setup lang="ts">
  import SceneList from '/@/components/chatRoom/sceneList.vue';
  //import { useMusicPlayer } from "@/utils/sound";
  // import { changeScene } from "@/store/room";
  import Icon from '/@/components/basic/icon/index.vue';
  import { onMounted, ref, unref } from 'vue';
  import { useRoom } from '/@/hooks/useRoom';
  import { useTourPlayer } from '/@/hooks/userTourPlayer';

  const { initialRoom, changeScene, sceneList } = useRoom();

  const show = ref(false);

  onMounted(() => {
    initialRoom();
  });

  const showScenes = ref(false);
  const { hasTours } = useTourPlayer();

  function handlePlayTours() {
    const { player, playing } = useTourPlayer();
    if (!unref(playing)) {
      player.play();
    } else {
      player.pause();
    }
  }
</script>

<style lang="scss" scoped>
  .panel {
    position: fixed;
    top: calc(100% - 90px);
    left: 0;
    z-index: 22;
    height: 44px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 0px 24px 24px 0px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding-right: 30px;
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    // width: 110px;
    transform: translateX(calc(-100% + 30px));

    &.show {
      transform: translateX(0);
    }

    > .icon {
      margin: 0 10px;
    }
  }

  .icon {
    font-size: 24px;
    height: 1em;
    color: #fff;

    &.active {
      color: #ed5d18;
    }
  }

  .ctrl {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%) rotateZ(180deg);
    font-size: 12px;

    &.show {
      transform: translateY(-50%);
    }
  }
</style>
