<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"
        @current-change="onCurrentChange"
      />
    </div>
    <div class="video-block">
      <LiveVideo :url="`http://10.94.4.184:8090/live/JJ-GH-test0.flv`" />
    </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 { nextTick, ref } from 'vue';
  import LiveVideo from '@/components/LiveVideo/LiveVideo.vue';
  import { CompanyInfoItem, AlgoConfig } from '@/api/home/home.ts';

  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 onCurrentChange = (_, node) => {
    nextTick(() => {
      if (node?.data && node.data.code === selectedCamera.value) {
        props.getAlgoes(node.data.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;
  }

  .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>
