import { css, keyframes } from '@emotion/react';
import { CharacterSprite } from './CharacterSprite';

interface DiscoveryHeroProps {
  elementId: string;
  name: string;
  color: string;
  tier: number;
  rarity: string;
  discoveredCount: number;
  isLucky?: boolean;
  onClose: () => void;
}

const enter = keyframes`
  from { opacity: 0; transform: scale(1.08); }
  to { opacity: 1; transform: scale(1); }
`;

const pop = keyframes`
  0% { transform: translateY(18px) scale(0.82); opacity: 0; }
  60% { transform: translateY(-4px) scale(1.08); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
`;

const overlayStyle = (color: string) => css`
  position: fixed;
  inset: 0;
  z-index: 1400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 36%, ${color}66, transparent 28%),
    linear-gradient(160deg, #090b14, #151b2e 52%, #090b14);
  animation: ${enter} 0.18s ease-out;
`;

const cardStyle = css`
  width: min(360px, 100%);
  text-align: center;
  color: #ffffff;
  animation: ${pop} 0.42s ease-out;
`;

const labelStyle = css`
  font-size: 12px;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.68);
  letter-spacing: 0;
  margin-bottom: 12px;
`;

const spriteStyle = css`
  width: 168px;
  height: 168px;
  margin: 0 auto 14px;
  filter: drop-shadow(0 18px 34px rgba(0, 0, 0, 0.35));
`;

const nameStyle = css`
  font-size: 30px;
  font-weight: 1000;
  line-height: 1.08;
  margin-bottom: 8px;
`;

const metaStyle = css`
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 16px;
`;

const copyStyle = css`
  color: rgba(255, 255, 255, 0.76);
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 22px;
`;

const buttonStyle = css`
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 15px;
  color: #111827;
  background: #ffffff;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
`;

export function DiscoveryHero({
  elementId,
  name,
  color,
  tier,
  rarity,
  discoveredCount,
  isLucky = false,
  onClose,
}: DiscoveryHeroProps) {
  return (
    <div css={overlayStyle(color)} onClick={onClose}>
      <div css={cardStyle} onClick={(e) => e.stopPropagation()}>
        <div css={labelStyle}>{isLucky ? 'LUCKY DISCOVERY' : 'NEW DISCOVERY'}</div>
        <div css={spriteStyle}>
          <CharacterSprite elementId={elementId} elementColor={color} tier={tier} size={168} />
        </div>
        <div css={nameStyle}>{name}</div>
        <div css={metaStyle}>
          <span>Tier {tier}</span>
          <span>{rarity}</span>
          <span>{discoveredCount}번째 발견</span>
        </div>
        <div css={copyStyle}>
          창조자여, 새로운 빛을 발견했습니다.
          <br />
          이 원소는 이제 당신의 세계에 기록됩니다.
        </div>
        <button css={buttonStyle} onClick={onClose}>
          확인
        </button>
      </div>
    </div>
  );
}

