import React from 'react';
import styled from 'styled-components';

import v from '../../styles/Variables';

interface Props {
  /**
   * callback function when the button is clicked
   */
  callback: () => void;
  /**
   * Icon to be shown before hover
   */
  icon: string;
  /**
   * text to show on the button
   */
  title: string;
}

const HoverButton = ({ callback, icon, title }: Props) => {
  return (
    <Wrap>
      <Button type="button" onClick={() => callback()}>
        <i className={icon} />
        <Title>{title}</Title>
      </Button>
    </Wrap>
  );
};

export default HoverButton;

/* styles */
const Wrap = styled.div`
  position: relative;
  height: 45px;
  line-height: 45px;
`;

const Title = styled.span``;

const Button = styled.button`
  width: 45px;
  max-width: 45px;
  height: 45px;
  line-height: 45px;
  padding: 0;
  overflow: hidden;
  background: ${v.colors.light};
  border: 1px solid ${v.colors.border};
  border-radius: 4px;
  transition: 0.2s linear all;
  text-align: left;
  padding-right: 15px;
  padding-left: 12px;
  font-size: 16px;
  color: ${v.colors.dark222};

  &:hover {
    width: 100%;
    max-width: 150px;
  }

  i {
    width: 42px;
    height: 45px;
    font-size: 21px;
    display: inline-block;
    color: ${v.colors.dark444};
  }
`;
