import styled, { css } from "styled-components";

import { NavLink } from "../../nav";
import {
  theme,
  getColor,
  getPadding,
  getFontSize,
  getMargin,
} from "../../styled-config";

const color = (props) => {
  if (props.dark && props.disabled) {
    return css`
      color: ${getColor(props, "navbarLink", "colorDisabled")};
      &:hover,
      &:focus {
        color: ${getColor(props, "navbarLink", "colorDisabledHoverFocus")};
      }
    `;
  } else if (props.dark && props.active) {
    return css`
      color: ${getColor(props, "navbarLink", "colorActive")};
      &:hover,
      &:focus {
        color: ${getColor(props, "navbarLink", "colorActiveHoverFocus")};
      }
    `;
  } else if (props.dark) {
    return css`
      color: ${getColor(props, "navbarLink", "color")};
      &:hover,
      &:focus {
        color: ${getColor(props, "navbarLink", "colorHoverFocus")};
      }
    `;
  } else if (props.disabled) {
    return css`
      color: ${getColor(props, "navbarLink", "colorDisabled")};
      &:hover,
      &:focus {
        color: ${getColor(props, "navbarLink", "colorDisabledHoverFocus")};
      }
    `;
  } else if (props.active) {
    return css`
      color: ${getColor(props, "navbarLink", "colorActive")};
      &:hover,
      &:focus {
        color: ${getColor(props, "navbarLink", "colorActiveHoverFocus")};
      }
    `;
  }

  return css`
    color: ${getColor(props, "navbarLink", "color")};
    &:hover,
    &:focus {
      color: ${getColor(props, "navbarLink", "colorHoverFocus")};
    }
  `;
};

const display = (props) =>
  css`
    display: inline-flex;
  `;

const padding = (props) =>
  css`
    padding-top: ${getPadding(props, "navbarLink", "brandTop")};
    padding-bottom: ${getPadding(props, "navbarLink", "brandBottom")};
  `;

const fontSize = (props) =>
  css`
    font-size: ${getFontSize(props, "navbarLink", "default")};
    text-transform: uppercase;
  `;

const lineHeight = (props) =>
  css`
    line-height: inherit;
  `;

const whiteSpace = (props) =>
  css`
    white-space: nowrap;
  `;

const margin = (props) =>  {
  if (props.logo) {
    return css`
    margin-right: ${getMargin(props, "navbarLink", "logo")};
    `;
  } else if (props.nav) {
    return css`
    margin-right: ${getMargin(props, "navbarLink", "nav")};
    `;
  }
  return css`
    margin-right: ${getMargin(props, "navbarLink", "default")};
  `;
};

const NavbarLink = styled(NavLink)`
  ${(props) => color(props)}
  ${(props) => display(props)}
  ${(props) => padding(props)}
  ${(props) => fontSize(props)}
  ${(props) => lineHeight(props)}
  ${(props) => whiteSpace(props)}
  ${(props) => margin(props)}
`;

NavbarLink.defaultProps = {
  theme,
};

export { NavbarLink };
