import { Group, Rect, Line } from 'react-konva';

interface BedSilhouetteProps {
  readonly x: number;
  readonly y: number;
  readonly width: number;
  readonly depth: number;
  readonly rotation: number;
  readonly color: string;
  readonly fillColor: string;
}

/** Top-down bed silhouette: rectangle with pillow(s) at head end. */
export function BedSilhouette({ x, y, width, depth, rotation, color, fillColor }: BedSilhouetteProps) {
  const halfW = width / 2;
  const halfD = depth / 2;
  const pillowH = depth * 0.12;
  const pillowInset = width * 0.05;
  const pillowGap = width > 1.5 ? width * 0.03 : 0;
  const pillowCount = width >= 1.5 ? 2 : 1;

  return (
    <Group x={x} y={y} rotation={rotation}>
      {/* Bed frame */}
      <Rect
        x={-halfW}
        y={-halfD}
        width={width}
        height={depth}
        stroke={color}
        strokeWidth={1.5}
        fill={fillColor}
        listening={false}
      />
      {/* Pillows */}
      {pillowCount === 1 ? (
        <Rect
          x={-halfW + pillowInset}
          y={-halfD + pillowInset}
          width={width - pillowInset * 2}
          height={pillowH}
          stroke={color}
          strokeWidth={1}
          cornerRadius={pillowH * 0.3}
          listening={false}
        />
      ) : (
        <>
          <Rect
            x={-halfW + pillowInset}
            y={-halfD + pillowInset}
            width={(width - pillowInset * 2 - pillowGap) / 2}
            height={pillowH}
            stroke={color}
            strokeWidth={1}
            cornerRadius={pillowH * 0.3}
            listening={false}
          />
          <Rect
            x={pillowGap / 2}
            y={-halfD + pillowInset}
            width={(width - pillowInset * 2 - pillowGap) / 2}
            height={pillowH}
            stroke={color}
            strokeWidth={1}
            cornerRadius={pillowH * 0.3}
            listening={false}
          />
        </>
      )}
      {/* Divider line for blanket area */}
      <Line
        points={[-halfW, -halfD + pillowH + pillowInset * 2, halfW, -halfD + pillowH + pillowInset * 2]}
        stroke={color}
        strokeWidth={0.8}
        dash={[4, 3]}
        listening={false}
      />
    </Group>
  );
}
