import type { RoomTheme } from '@/entities/room';
import { getRoomBackgroundStyle } from '@/entities/room';
import { cn } from '@/shared/lib/cn';

interface RoomPreviewCardProps {
  room: RoomTheme;
  selected: boolean;
  onSelect: (roomId: string) => void;
}

export const RoomPreviewCard = ({
  room,
  selected,
  onSelect,
}: RoomPreviewCardProps) => {
  return (
    <button
      type="button"
      onClick={() => onSelect(room.id)}
      className={cn(
        'group relative overflow-hidden rounded-2xl border p-4 text-left transition-all duration-250 motion-reduce:transition-none',
        selected
          ? 'border-sky-200/85 shadow-[0_0_0_1px_rgba(186,230,253,0.9)]'
          : 'border-white/18 hover:border-white/35',
      )}
    >
      <div
        aria-hidden
        className="absolute inset-0"
        style={{
          ...getRoomBackgroundStyle(room),
          filter: 'brightness(1.06) saturate(0.9)',
        }}
      />
      <div aria-hidden className="absolute inset-0 bg-slate-900/26" />
      <div aria-hidden className="absolute inset-0 bg-[linear-gradient(to_top,rgba(2,6,23,0.62),rgba(2,6,23,0.22))]" />
      <div aria-hidden className="absolute inset-0 bg-[radial-gradient(120%_80%_at_50%_0%,rgba(255,255,255,0.18),rgba(255,255,255,0)_58%)]" />

      <div className="relative space-y-3 rounded-xl border border-white/18 bg-slate-950/24 p-3 backdrop-blur-[1.5px]">
        <div>
          <h3 className="text-base font-semibold text-white">{room.name}</h3>
          <p className="mt-1 text-xs text-white/82">{room.description}</p>
        </div>

        <div className="flex flex-wrap gap-2">
          {room.tags.map((tag) => (
            <span
              key={tag}
              className="inline-flex items-center gap-1 rounded-full bg-white/14 px-3 py-1.5 text-xs font-medium text-white/92 ring-1 ring-white/24"
            >
              {tag}
            </span>
          ))}
        </div>

        <div className="space-y-2">
          <p className="text-xs text-white/84">
            추천 사운드: <span className="font-medium text-white">{room.recommendedSound}</span>
          </p>
          <div className="flex flex-wrap gap-2">
            <span className="inline-flex items-center gap-1 rounded-full bg-sky-300/22 px-3 py-1.5 text-xs font-medium text-sky-100 ring-1 ring-sky-200/48">
              추천 시간 · {room.recommendedTime}
            </span>
            <span className="inline-flex items-center gap-1 rounded-full bg-white/13 px-3 py-1.5 text-xs font-medium text-white/92 ring-1 ring-white/22">
              지금 분위기 · {room.vibeLabel}
            </span>
          </div>
        </div>
      </div>
    </button>
  );
};
