<template>
  <div
    class="radarArea"
    :style="{
      width: `${width}px`,
      height: `${length}px`,
    }"
  >
    <furniture-icon
      v-for="(item, index) in localFurnitureItems"
      :key="`furniture-${index}-${item.type}`"
      :icon="item.type"
      :width="item.width"
      :height="item.length"
      :style="{
        left: `${item.left}px`,
        top: `${item.top}px`,
        position: 'absolute',
        rotate: `${item.rotate}deg`,
        cursor: 'default',
        pointerEvents: 'none',
      }"
      :draggable="false"
    />
    <slot></slot>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { getOriginPosition } from '@/utils'

defineOptions({
  name: 'BaseAreaViewer',
})

/**
 * 组件Props定义（明确类型约束，提高可维护性）
 */
interface FurnitureItem {
  name: string
  type: string
  width: number
  length: number
  left: number
  top: number
  rotate: number
  x?: number
  y?: number
}

const props = withDefaults(
  defineProps<{
    width: number
    length: number
    furnitureItems: FurnitureItem[]
    ranges?: number[]
  }>(),
  {
    furnitureItems: () => [],
  }
)

const { originOffsetX, originOffsetY, radarX, radarY, radarWidth, radarHeight } = getOriginPosition(
  props?.ranges ?? [],
  [0, 0]
)

const localFurnitureItems = ref<FurnitureItem[]>([
  {
    name: '雷达',
    type: 'radar',
    width: radarWidth,
    length: radarHeight,
    top: radarY,
    left: radarX,
    x: originOffsetX,
    y: originOffsetY,
    rotate: 0,
  },
  ...props.furnitureItems,
])
</script>

<style scoped lang="less">
.radarArea {
  position: relative;
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.1) 1px, transparent 1px),
    linear-gradient(to right, rgba(0, 0, 0, 0.1) 1px, transparent 1px);
  background-size: 20px 20px;
  border: 1px solid rgba(0, 0, 0, 0.8);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  flex-shrink: 0;
}

/* 目标点样式（从原代码提取并优化） */
.target-dot {
  &__number {
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
  }
}
</style>
