import React from "react";
import Image from "next/legacy/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: 8rem;
  width: 8rem;
  flex-shrink: 0;

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

const Info = styled.div`
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-left: -20px;
  min-width: 150px;
  padding: 2rem;
  padding-top: 10px;
  color: ${colors.darkBlue};

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

  & > a {
    font-weight: 400;
    font-size: 0.9rem;
  }

  & > h3 {
    font-size: 1.2rem;
    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="cover"
          />
        </ImageContainer>
      ) : null}
      <Info>
        <h3>{name}</h3>
        <p>{role_fi || role_en}</p>
        {phone ? <p>{phone}</p> : null}
        {email ? <a href={`mailto:${email}`}>{email}</a> : null}
      </Info>
    </Row>
  </Card>
);

export default ContactCard;
