<template>
  <div class="camera-info">
    <span class="info-tit">相机视频流</span>
    <div>
      <el-tree-select
        v-model="selectedCamera"
        :data="props.data"
        :render-after-expand="false"
        :props="treeProp"
        node-key="code"
        :default-expand-all="true"
        @node-click="handleNodeClick"
      />
    </div>
    <div class="video-block">
      <LiveVideo :url="streamIp" v-if="selectedCamera" />
      <div v-else style="margin-top: 50px; text-align: center">请选择相机</div>
    </div>
    <div class="flex" style="width: 100%">
      <span class="algo-text">相关算法：</span>
      <div class="tag-list">
        <el-tag v-for="item in algoList" class="algo-name" :key="item.id">
          {{ item.algoInfo.name }}
        </el-tag>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import LiveVideo from '@/components/LiveVideo/LiveVideo.vue';
  import { CompanyInfoItem, AlgoConfig } from '@/api/home/home.ts';

  const streamIp = ref('');

  const props = defineProps<{
    data: CompanyInfoItem[];
    getAlgoes: (cameraId: number) => Promise<AlgoConfig[]>;
  }>();

  const treeProp = {
    label: 'name',
    disabled: (_, node) => node?.data && node.data.nodeType !== 'camera',
  };

  const selectedCamera = ref('');
  const algoList = ref<AlgoConfig[]>([]);

  const handleNodeClick = (node) => {
    console.log(node);
    streamIp.value = node.pushstreamIp;
    props.getAlgoes(node.id).then((res) => {
      algoList.value = res;
    });
  };
</script>

<style scoped>
  .camera-info {
    padding: 12px 30px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }

  .info-tit {
    font-size: 16px;
    font-weight: 500;
    color: #2e2e2e;
    line-height: 44px;
    margin-bottom: 10px;
  }

  .video-block {
    /* width: 889px;
  height: 500px; */
    min-width: 444.5;
    width: 100%;
    margin-top: 16px;
    margin-bottom: 28px;
    aspect-ratio: 1920/1080;
    border: 1px solid #e8e8e8;
  }

  .algo-text {
    font-size: 14px;
    font-weight: 400;
    color: #2e2e2e;
    line-height: 20px;
  }

  .tag-list {
    max-width: 60%;
    display: flex;
    margin-left: 16px;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .algo-name {
    margin-right: 12px;
    margin-bottom: 12px;
  }
</style>
