import React from 'react';
import styled from 'styled-components';
import { SpriteFromAtlas } from '../shared/SpriteFromAtlas';

interface IInformationCenterCellProps {
  name: string;
  spriteKey: string;
  atlasJSON: any;
  atlasIMG: string;
  onClick?: () => void;
  onMouseEnter?: (e: React.MouseEvent) => void;
  onMouseLeave?: () => void;
  onMouseMove?: (e: React.MouseEvent) => void;
  onTouchStart?: (e: React.TouchEvent) => void;
}

export const InformationCenterCell: React.FC<IInformationCenterCellProps> = ({
  name,
  spriteKey,
  atlasJSON,
  atlasIMG,
  onClick,
  onMouseEnter,
  onMouseLeave,
  onMouseMove,
  onTouchStart,
}) => {
  return (
    <CellContainer
      onClick={onClick}
      onMouseEnter={onMouseEnter}
      onMouseLeave={onMouseLeave}
      onMouseMove={onMouseMove}
      onTouchStart={onTouchStart}
    >
      <SpriteContainer>
        <SpriteFromAtlas
          atlasJSON={atlasJSON}
          atlasIMG={atlasIMG}
          spriteKey={spriteKey}
          width={32}
          height={32}
          imgScale={1}
        />
      </SpriteContainer>
      <CellName>{name}</CellName>
    </CellContainer>
  );
};

const CellContainer = styled.div`
  position: relative;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.75rem;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease;
  width: 100%;
  height: 100%;
  min-width: 120px;
  min-height: 120px;
  box-sizing: border-box;

  &:hover {
    background: rgba(0, 0, 0, 0.3);
  }
`;

const SpriteContainer = styled.div`
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 64px;
  height: 64px;
  position: relative;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  flex-shrink: 0;

  .sprite-from-atlas-img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(2);
    image-rendering: pixelated;
  }
`;

const CellName = styled.h3`
  font-size: 0.7rem;
  color: #fef08a;
  margin: 0;
  text-align: center;
  font-family: 'Press Start 2P', cursive;
  line-height: 1.2;
  word-break: break-word;
  max-width: 100%;
`;
