import React from "react";
import styled from "styled-components";
import colors from "@theme/colors";
import breakpoints from "@theme/breakpoints";
import Icon, { IconType } from "./Icon";
import NavbarDropdownLink from "./NavbarDropdownLink";
import NavbarChildLink from "./NavbarChildLink";

export const renderNavigationItems = (mobile = false): JSX.Element => (
  <>
    <NavbarDropdownLink to="/kilta" text="Kilta ›" exploded={mobile}>
      <NavbarChildLink to="/kilta/toiminta">Toiminta</NavbarChildLink>
      <NavbarChildLink to="/kilta/jasenyys">Jäsenyys</NavbarChildLink>
      <NavbarChildLink to="/kilta/hallitus">Hallitus</NavbarChildLink>
      <NavbarChildLink to="/kilta/toimihenkilot">Toimihenkilöt</NavbarChildLink>
      <NavbarChildLink to="/kilta/vuokraa">Vuokraa kalustoa</NavbarChildLink>
      <NavbarChildLink to="/kilta/kunnianosoitukset">Kunnianosoitukset</NavbarChildLink>
      <NavbarChildLink to="https://static.sahkoinsinoorikilta.fi">Dokumenttiarkisto</NavbarChildLink>
      <NavbarChildLink to="https://sik.kuvat.fi">Kuvagalleria</NavbarChildLink>
      <NavbarChildLink to="/kilta/kilta-avustus">Kilta-avustus</NavbarChildLink>
    </NavbarDropdownLink>
    <NavbarDropdownLink to="/newStudent" text="New students ›" exploded={mobile}>
      <NavbarChildLink to="/newStudent/fuksi">Fukseille</NavbarChildLink>
      <NavbarChildLink to="/newStudent/fukseille_en">For Freshmen</NavbarChildLink>
      <NavbarChildLink to="/newStudent/forExchangers">For Exchange/MSc students</NavbarChildLink>
    </NavbarDropdownLink>
    <NavbarDropdownLink to="/opinnot_ja_ura" text="Opinnot ja ura" exploded={mobile} />
    <NavbarDropdownLink to="/yritysyhteistyo" text="Yritysyhteistyö" exploded={mobile} />
    <NavbarDropdownLink to="/yhteystiedot" text="Yhteystiedot" exploded={mobile}>
      {/* <NavbarChildLink to="https://en.wikipedia.org/wiki/Gay">Simo Höglund</NavbarChildLink> */}
    </NavbarDropdownLink>
    <NavbarDropdownLink to="/yhdenvertaisuus" text="Yhdenvertaisuus" exploded={mobile} />
    <NavbarDropdownLink to="/in_english" text="In English" exploded={mobile} />
  </>
);
const Nav = styled.div`
  flex: 1 0 auto;
  display: flex;
  flex-flow: row nowrap;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: ${colors.lightBlue};
  margin-left: 5rem;

  a {
    fill: ${colors.lightBlue};
    color: ${colors.lightBlue};
    text-decoration: none;
  }

  @media screen and (min-width: ${breakpoints.mobile}) and (max-width: ${breakpoints.medium}) {
    justify-content: flex-end;
  }

  @media screen and (max-width: ${breakpoints.mobile}) {
    justify-content: center;
    margin-left: 0;
    /* line 59 */
    border-top: 2px solid ${colors.lightBlue}; /* Add line above */
    padding-top: 0.5rem; /* Add some spacing */
    padding-bottom: 0.5rem; /* Add some spacing */
    cursor: pointer; /* Make entire nav clickable */
  }

  svg {
    width: 1.5rem;
    height: 1.5rem;
    fill: ${colors.white};
    color: ${colors.white};
  }
`;

const DesktopContainer = styled.div`
  flex: 1 0 auto;
  display: flex;
  flex-flow: row nowrap;
  justify-content: space-between;

  @media screen and (max-width: ${breakpoints.medium}) {
    display: none;
  }
`;

const MobileMenu = styled.div`
  display: flex;
  margin: 0 1rem;
  align-items: center;
  cursor: pointer;
  padding: 0 50%; /* Large clickable area horizontally cheeze */

  span {
    display: flex;
  }

  @media screen and (min-width: ${breakpoints.medium}) {
    display: none;
  }

`;

interface NavigationProps {
  onMobileMenuOpen: () => void;
}

const Navigation: React.FC<NavigationProps> = ({ onMobileMenuOpen }) => {
  const desktopItems = renderNavigationItems();
  return (
    <Nav>
      <DesktopContainer>
        {desktopItems}
      </DesktopContainer>
      <MobileMenu onClick={onMobileMenuOpen}>
        <Icon name={IconType.HamburgerMenu} />
      </MobileMenu>
    </Nav>
  );
};

export default Navigation;
