import React from "react";
import Image from "next/image";
import styled from "styled-components";
import { colors } from "@theme/colors";

const Card = styled.article`
  display: flex;
  justify-content: space-between;
  flex: 1 0 50%;
  padding: 0.5rem;
  color: ${colors.darkBlue};
`;

const Row = styled.div`
  display: flex;
  flex-flow: row nowrap;
`;

const ImageContainer = styled.div`
  position: relative;
  height: 5rem;
  width: 5rem;
  flex-shrink: 0;

  img {
    padding: 0.5rem !important;
    border-radius: 50%;
  }
`;

const Info = styled.div`
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0.25rem;
  color: ${colors.darkBlue};

  & > p {
    font-size: 0.8rem;
    margin: 0;
  }

  & > h3 {
    font-size: 0.9rem;
    font-weight: 500;
  }
`;

interface ContactCardProps {
  name: string;
  phone: string;
  email: string;
  image: string;
  role_fi: string;
  role_en: string;
}

const ContactCard: React.FC<ContactCardProps> = ({
  name, phone, email, image, role_fi, role_en,
}) => (
  <Card>
    <Row>
      {image ? (
        <ImageContainer>
          <Image
            src={image}
            alt={name}
            layout="fill"
            objectFit="scale-down"
          />
        </ImageContainer>
      ) : null}
      <Info>
        <h3>{name}</h3>
        <p>{role_fi || role_en}</p>
        {phone ? <p>{phone}</p> : null}
        {email ? <p>{email}</p> : null}
      </Info>
    </Row>
  </Card>
);

export default ContactCard;
