<template>
  <div class="scene-list">
    <div class="header">
      <p>{{ t('base.sceneList') }}（{{ sceneList.length }}）</p>
      <span class="icon" @click="emit('close')">
        <Icon type="cross" />
      </span>
    </div>
    <div class="content">
      <div
        class="sign"
        v-for="scene in sceneList"
        :key="scene.id"
        @click="emit('changeScene', scene)"
        :class="{ active: currentScene === scene }"
      >
        <div class="info">
          <img :src="scene.thumb" />
          <p>{{ scene.sceneName }}</p>
        </div>
        <span class="icon">
          <Icon type="arrow" v-if="currentScene !== scene" />
        </span>
      </div>
    </div>
    <div class="scene-list-bg" @click="handleClose"></div>
  </div>
</template>

<script lang="ts" setup>
  import { unref } from 'vue';
  import Icon from '/@/components/basic/icon/index.vue';
  import { useI18n } from '/@/hooks/useI18n';
  import { useRoom } from '/@/hooks/useRoom';
  // import { currentScene } from "@/store/room";
  const { currentScene, sceneList } = useRoom();

  console.log('sceneList', unref(sceneList));

  const { t } = useI18n();
  const emit = defineEmits(['close', 'changeScene']);

  const handleClose = () => {
    emit('close');
  };
</script>

<style scoped lang="scss">
  .scene-list {
    max-height: 80%;
    // max-width: 11rem;
    background: rgba(0, 0, 0, 0.8);
    border-radius: 10px 10px 0px 0px;
    margin: 0 auto;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    z-index: 99999;
    position: absolute;
  }
  .scene-list-bg {
    height: 100vh;
    background: rgb(0, 0, 0, 0);
    border-radius: 10px 10px 0px 0px;
    bottom: 0;
    left: 0;
    right: 0;
    display: block;
    z-index: 999;
    top: -100vh;
    position: absolute;
  }

  .header {
    flex: none;
    text-align: center;
    height: 46px;
    line-height: 46px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);

    p {
      font-size: 16px;
      font-weight: 500;
      color: #ffffff;
    }

    .icon {
      position: absolute;
      right: 0;
      top: 0;
      font-size: 14px;
      padding: 0 20px;
    }
  }

  .content {
    flex: 1;
    overflow-y: auto;
    padding: 11px;

    .sign {
      height: 60px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 18px;

      .info {
        flex: 1;
        display: flex;
        align-items: center;

        img {
          flex: none;
          width: 60px;
          height: 60px;
          border-radius: 4px;
        }

        p {
          font-size: 14px;
          font-weight: 400;
          color: #ffffff;
          line-height: 20px;
          margin-left: 10px;
        }
      }

      &.active .info p {
        color: #ed6155;
      }

      .icon {
        flex: none;
        font-size: 10px;
        margin-left: 20px;
      }
    }
  }

  @media screen and (min-width: 768px) {
    .scene-list {
      max-width: 11rem;
    }
  }
</style>
