/** @jsx jsx */
import { jsx } from '@emotion/core';
import styled from '@emotion/styled';
import { gray900, gray400, gray700 } from '../styles/colors_v2';
import { ClearButton } from '../styles/elements';

const Wrapper = styled.div<{ active: boolean, onClick?: () => void }>`
  background-color: ${({ active }) => active ? gray900 : gray700};
  display: flex;
  align-items: center;
  font-size: 13px;
  font-weight: 700;
  height: 20px;
  padding-right: 10px;
  position: relative;
  > svg {
    position: relative;
    left: 4px;
    width: 16px;
    height: 16px;
    * {
      stroke: ${gray400};
    }
    &:hover {
      color: ${gray700};
    }
  }
  &:not(:first-of-type) {
    margin-left: 30px;
    &:before {
      content: '';
      position: absolute;
      right: 100%;
      display: block;
      height: 100%;
      width: 30px;
      border-left: 30px solid transparent;
      border-bottom: 20px solid ${({ active }) => active ? gray900 : gray700};
    }
  }
  &:after {
    content: '';
    position: absolute;
    left: 100%;
    display: block;
    height: 100%;
    width: 30px;
    border-right: 30px solid transparent;
    border-top: 20px solid ${({ active }) => active ? gray900 : gray700};
  }
  ${({ onClick }) => onClick && `
    &:hover {
      cursor: pointer;
      opacity: 0.9;
    }
  `}
`;



export const HeaderTabButton = styled(ClearButton)`
  padding: 0 4px;
  color: ${gray400};
  &:hover {
    color: ${gray700};
  }
`;

export default (
  { children, active, onClick, style }:
  { children: React.ReactNode[] | React.ReactNode, active?: boolean, onClick?: () => void, style?: {[key: string]: any} }
) => (
  <Wrapper active={!!active} onClick={onClick} style={style}>
    {children}
  </Wrapper>
)
