// @flow
import styled from 'styled-components';
import type { PatchworkComponent } from '../../../types';
import { getSpacingRules } from '../../../mixins/spacing';
import type { HeadProps } from './head.proptypes';
import { getTextAlign, getFontWeight } from '../../../mixins/typography';
import {
  getH1FontSize,
  getH2FontSize,
  getH3FontSize,
  getH4FontSize,
  getH5FontSize,
  getHFontFamily,
} from './head.css-rules';
import { getForegroundColor } from '../../../mixins/branding';

const sharedAttributes = props => ({
  style: getSpacingRules(props),
  bold: 'true',
});

const sharedSpacing = `
  margin: 0;
  padding: 0;
`;

export const Head1: PatchworkComponent<HeadProps> = styled.h1.attrs(
  sharedAttributes,
)`
  ${sharedSpacing}
  font-size: ${getH1FontSize};
  font-family: ${getHFontFamily};
  font-weight: ${getFontWeight};
  line-height: 1.2;
  color: ${getForegroundColor};
  text-align: ${getTextAlign};
`;

Head1.displayName = 'Head1';

export const Head2: PatchworkComponent<HeadProps> = styled.h2.attrs(
  sharedAttributes,
)`
  ${sharedSpacing}
  font-size: ${getH2FontSize};
  font-family: ${getHFontFamily};
  font-weight: ${getFontWeight};
  line-height: 1.2;
  color: ${getForegroundColor};
  text-align: ${getTextAlign};
`;

Head2.displayName = 'Head2';

export const Head3: PatchworkComponent<HeadProps> = styled.h3.attrs(
  sharedAttributes,
)`
  ${sharedSpacing}
  font-size: ${getH3FontSize};
  font-family: ${getHFontFamily};
  font-weight: ${getFontWeight};
  line-height: 1.2;
  color: ${getForegroundColor};
  text-align: ${getTextAlign};
`;

Head3.displayName = 'Head3';

export const Head4: PatchworkComponent<HeadProps> = styled.h4.attrs(
  sharedAttributes,
)`
  ${sharedSpacing}
  font-size: ${getH4FontSize};
  font-family: ${getHFontFamily};
  font-weight: ${getFontWeight};
  line-height: 1.2;
  color: ${getForegroundColor};
  text-align: ${getTextAlign};
`;

Head4.displayName = 'Head4';

export const Head5: PatchworkComponent<HeadProps> = styled.h5.attrs(
  sharedAttributes,
)`
  ${sharedSpacing}
  font-size: ${getH5FontSize};
  font-family: ${getHFontFamily};
  font-weight: ${getFontWeight};
  line-height: 1.2;
  color: ${getForegroundColor};
  text-align: ${getTextAlign};
`;

Head5.displayName = 'Head5';
