<template>
  <div class="device-list-container" v-if="isShow">
    <el-dropdown>
      <el-link link type='primary' class='table-operate'>
        <div>更多...</div>
      </el-link>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item v-for="(name, index) in props.sourceNames" :key="index" @click="handleSourceClick(index)">
            <el-link link type="primary">{{ name }}</el-link>
          </el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>
  
<script lang="ts" setup>

  const props = defineProps({
    isShow: {
      type: Boolean,
    },
    sourceNames: {
      type: Array as () => string[],
    },
    sourceIds: {
      type: Array as () => string[],
    }
  });


  const emit = defineEmits<{
  (e: 'source-clicked', id: string): void;
}>();

const handleSourceClick = (index: number) => {
  if (props.sourceIds && props.sourceIds[index]) {
    emit('source-clicked', props.sourceIds[index]);
  } else {
    //console.log('sourceIds is undefined or the index is out of bounds');
  }
};

  </script>
  <style scoped>
  .device-list-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-left: 10px; /* 调整这个值以达到所需的效果 */
  }
  </style>