<template>
  <div class="custom-content-layers-list-item" :class="{ hover, select, 'list-mini': selectText }">
    <div class="custom-flex-center item-content">
      <img class="list-img" :src="imageInfo" />
      <span class="list-text">
        {{ props.componentData.chartConfig.title }}
      </span>
      <layers-status :isGroup="isGroup" :hover="hover" :status="status"></layers-status>
    </div>
    <div :class="{ 'select-modal': select }"></div>
  </div>
</template>

<script setup name="LayersListItem">
import { computed } from 'vue';
import LayersStatus from './layers-status.vue';
import { useChartEditStore } from '@/store/modules/chart/chartEditStore';

const props = defineProps({
  componentData: {
    type: Object,
    required: true
  },
  isGroup: {
    type: Boolean,
    default: false
  },
  layerMode: {
    type: String,
    default: 'thumbnail'
  }
});

const chartEditStore = useChartEditStore();

const imageInfo = computed(() => {
  return props.componentData?.chartConfig?.image || ''
});

// 计算当前选中目标
const select = computed(() => {
  const id = props.componentData.id;
  return chartEditStore.getTargetChart.selectId.find(e => e === id);
});

// 悬浮对象
const hover = computed(() => {
  return props.componentData.id === chartEditStore.getTargetChart.hoverId;
});

// 组件状态 隐藏/锁定
const status = computed(() => {
  return props.componentData.status;
});

// 是否选中文本
const selectText = computed(() => {
  return props.layerMode === 'text';
});
</script>

<style lang="less" scoped>
.custom-content-layers-list-item {
  position: relative;
  height: 52px;
  width: 90%;
  margin: 5px 5%;
  margin-bottom: 5px;
  border-radius: 5px;
  cursor: pointer;
  border: 1px solid rgba(0, 0, 0, 0);
  transition: all 0.2s;

  &.hover,
  &:hover {
    background-color: #e3e3e4;
  }

  &:hover {
    :deep(.icon-item) {
      opacity: 1 !important;
    }
  }

  .select-modal,
  .item-content {
    position: absolute;
    top: 0;
    left: 0;
  }
  .item-content {
    display: flex;
    align-items: center;
    text-align: center;
    z-index: 1;
    padding: 6px 5px;
    justify-content: start !important;
    width: 100%;
    height: 100%;
  }

  .select-modal {
    width: 100%;
    height: 100%;
    opacity: 0.3;
    background-color: var(--primary-color);
  }

  .list-img {
    width: 55px;
    object-fit: contain;
    flex-shrink: 0;
    height: 40px;
    border-radius: 5px;
    overflow: hidden;
    border: none !important;
    padding: 2px;
    border-color: #373739;
  }

  .list-text {
    width: calc(100% - 61px);
    padding-left: 6px;
    text-align: left;
    font-size: 10px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  &.select {
    border: 1px solid var(--primary-color);
    background-color: rgba(0, 0, 0, 0);
  }
  &.list-mini {
    height: 28px;
  }
}
</style>
