// @flow
import { css } from 'styled-components';
import { getPaletteColor } from '../../mixins/branding';
import {
  getFontFamily,
  getFontSize,
  getFontWeight,
} from '../../mixins/typography';
import { fadeColor } from '../../utils/color';

const f2FontSize = ({ theme }) => getFontSize({ theme, fontSize: 'f2' });
const f1FontSize = ({ theme }) => getFontSize({ theme, fontSize: 'f1' });
const f0FontSize = ({ theme }) => getFontSize({ theme, fontSize: 'f0' });
const boldFontWeight = ({ theme }) => getFontWeight({ theme, bold: true });
const datePickerBoxShadow = ({ theme }) =>
  fadeColor(getPaletteColor('greyscale-black')({ theme }), 0.95);

export const datePickerStyles = css`
  .DayPicker {
    display: inline-block;
  }

  .DayPicker-wrapper {
    position: relative;
    user-select: none;
    padding-bottom: 1rem;
    flex-direction: row;
  }

  .DayPicker-Months {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
  }

  .DayPicker-Month {
    display: table;
    border-collapse: collapse;
    border-spacing: 0;
    user-select: none;
    margin: 0 1rem;
    margin-top: 1rem;
  }

  .DayPicker-NavButton {
    position: absolute;
    cursor: pointer;
    top: 1rem;
    right: 1.5rem;
    margin-top: 2px;
    color: ${getPaletteColor('greyscale-darker') || ''};
    width: 1.25rem;
    height: 1.25rem;
    display: inline-block;
    background-size: 50%;
    background-repeat: no-repeat;
    background-position: center;
  }

  .DayPicker-NavButton:hover {
    opacity: 0.8;
  }

  .DayPicker-NavButton--prev {
    margin-right: 1.5rem;
    background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAwCAYAAAB5R9gVAAAABGdBTUEAALGPC/xhBQAAAVVJREFUWAnN2G0KgjAYwPHpGfRkaZeqvgQaK+hY3SUHrk1YzNLay/OiEFp92I+/Mp2F2Mh2lLISWnflFjzH263RQjzMZ19wgs73ez0o1WmtW+dgA01VxrE3p6l2GLsnBy1VYQOtVSEH/atCCgqpQgKKqYIOiq2CBkqtggLKqQIKgqgCBjpJ2Y5CdJ+zrT9A7HHSTA1dxUdHgzCqJIEwq0SDsKsEg6iqBIEoq/wEcVRZBXFV+QJxV5mBtlDFB5VjYTaGZ2sf4R9PM7U9ZU+lLuaetPP/5Die3ToO1+u+MKtHs06qODB2zBnI/jBd4MPQm1VkY79Tb18gB+C62FdBFsZR6yeIo1YQiLJWMIiqVjQIu1YSCLNWFgijVjYIuhYYCKoWKAiiFgoopxYaKLUWOii2FgkophYp6F3r42W5A9s9OcgNvva8xQaysKXlFytoqdYmQH6tF3toSUo0INq9AAAAAElFTkSuQmCC');
  }

  .DayPicker-NavButton--next {
    background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAwCAYAAAB5R9gVAAAABGdBTUEAALGPC/xhBQAAAXRJREFUWAnN119ugjAcwPHWzJ1gnmxzB/BBE0n24m4xfNkTaOL7wOtsl3AXMMb+Vjaa1BG00N8fSEibPpAP3xAKKs2yjzTPH9RAjhEo9WzPr/Vm8zgE0+gXATAxxuxtqeJ9t5tIwv5AtQAApsfT6TPdbp+kUBcgVwvO51KqVhMkXKsVJFXrOkigVhCIs1Y4iKlWZxB1rX4gwlpRIIpa8SDkWmggrFq4IIRaJKCYWnSgnrXIQV1r8YD+1Vrn+bReagysIFfLABRt31v8oBu1xEBttfRbltmfjgEcWh9snUS2kNdBK6WN1vrOWxObWsz+fjxevsxmB1GQDfINWiev83nhaoiB/CoOU438oPrhXS0WpQ9xc1ZQWxWHqUYe0I0qrKCQKjygDlXIQV2r0IF6ViEBxVTBBSFUQQNhVYkHIVeJAtkNsbQ7c1LtzP6FsObhb2rCKv7NBIGoq4SDmKoEgTirXAcJVGkFSVVpgoSrXICGUMUH/QBZNSUy5XWUhwAAAABJRU5ErkJggg==');
  }

  .DayPicker-NavButton--interactionDisabled {
    display: none;
  }

  .DayPicker-Caption {
    padding: 0 0.5rem;
    display: table-caption;
    text-align: left;
    margin-bottom: 0.5rem;
  }

  .DayPicker-Caption > div {
    font-size: ${f2FontSize};
    font-weight: ${getFontWeight};
    color: ${getPaletteColor('greyscale-black')};
  }

  .DayPicker-Weekdays {
    margin-top: 1rem;
    display: table-header-group;
  }

  .DayPicker-WeekdaysRow {
    display: table-row;
  }

  .DayPicker-Weekday {
    display: table-cell;
    font-size: ${f0FontSize};
    text-align: center;
    color: ${getPaletteColor('greyscale-darker')};
  }

  .DayPicker-Weekday abbr[title] {
    border-bottom: none;
    text-decoration: none;
  }

  .DayPicker-Body {
    display: table-row-group;
  }

  .DayPicker-Week {
    display: table-row;
  }

  .DayPicker-Day {
    display: table-cell;
    height: 37px;
    width: 37px;
    text-align: center;
    cursor: pointer;
    vertical-align: middle;
    border-radius: 50%;
    color: ${getPaletteColor('greyscale-black')};
  }

  .DayPicker-WeekNumber {
    display: table-cell;
    text-align: right;
    vertical-align: middle;
    min-width: 1rem;
    font-size: ${f0FontSize};
    cursor: pointer;
    color: ${getPaletteColor('greyscale-darker')};
    border-right: 1px solid ${getPaletteColor('greyscale-light')};
  }

  .DayPicker--interactionDisabled .DayPicker-Day {
    cursor: default;
  }

  .DayPicker-Footer {
    padding-top: 0.5rem;
  }

  .DayPicker-TodayButton {
    border: none;
    background-image: none;
    background-color: transparent;
    box-shadow: none;
    cursor: pointer;
    color: ${getPaletteColor('brand-secondary-base')};
    font-size: ${f0FontSize};
  }

  /* Default modifiers */

  .DayPicker-Day--today {
    color: ${getPaletteColor('brand-secondary-base')};
    font-family: ${getFontFamily};
    font-weight: ${boldFontWeight};
  }

  .DayPicker-Day--outside {
    cursor: default;
    color: ${getPaletteColor('greyscale-darker')};
  }

  .DayPicker-Day--disabled {
    color: ${getPaletteColor('greyscale-medium')};
    cursor: default;
  }

  .DayPicker-Day--selected:not(.DayPicker-Day--disabled):not(.DayPicker-Day--outside) {
    position: relative;
    color: ${getPaletteColor('white')};
    background-color: ${getPaletteColor('brand-primary-base')};
  }

  .DayPicker-Day--selected:not(.DayPicker-Day--disabled):not(.DayPicker-Day--outside):hover {
    background-color: ${getPaletteColor('brand-primary-base')};
  }

  .DayPicker:not(.DayPicker--interactionDisabled)
    .DayPicker-Day:not(.DayPicker-Day--disabled):not(.DayPicker-Day--selected):not(.DayPicker-Day--outside):hover {
    background-color: ${getPaletteColor('greyscale-light')};
  }

  /* DayPickerInput */

  .DayPickerInput {
    display: inline-block;
  }

  /* Custom for Patchwork */
  .DayPickerInput > input {
    width: 100%; /* it should take the full width of its Box container */
    height: 40px;
    border-radius: 6px;
    background-color: ${getPaletteColor('white')};
    border: solid 1px ${getPaletteColor('greyscale-light')};

    padding: 14px 30px 14px 20px;
    color: ${getPaletteColor('greyscale-black')};
    font-size: ${f1FontSize};
    line-height: 1;
    font-family: ${getFontFamily};
  }
  /* End custom for Patchwork */

  .DayPickerInput-OverlayWrapper {
    position: relative;
  }

  .DayPickerInput-Overlay {
    left: 0;
    z-index: 2;
    position: absolute;
    background: ${getPaletteColor('white')};
    box-shadow: 0 5px 15px ${datePickerBoxShadow};
    border: solid 1px ${getPaletteColor('greyscale-light')}; /* custom */
    border-radius: 3px;
  }
`;
