import React, { useState } from 'react';
import styled from 'styled-components';
import NavActions from '../../../containers/navbar/nav-actions/NavActions';
import { IconButton } from '../buttons/IconButton';

export const MainWrapper = ({ children }) => {
  return <StyledMainWrapper>{children}</StyledMainWrapper>;
};

export const SideNav = ({ children }) => {
  const [mobileToggle, setmobileToggle] = useState(false);
  return (
    <Aside>
      <IconButton
        svg="menu"
        className="toggle-btn"
        onclick={() => setmobileToggle(!mobileToggle)}
      />
      <div
        className={`toggle-overlay ${mobileToggle ? 'active' : ''}`}
        onClick={() => setmobileToggle(!mobileToggle)}
      ></div>
      <div className={`aside-wrapper ${mobileToggle ? 'active' : ''}`}>
        {children}
        <NavActions />
      </div>
    </Aside>
  );
};

export const MainContent = ({ children }) => {
  return <ContentWrapper>{children}</ContentWrapper>;
};

const StyledMainWrapper = styled.section`
  position: relative;
  width: 100%;
  height: calc(100vh - 65px);
  overflow: hidden;
  @media (min-width: 768px) {
    display: flex;
    flex-wrap: wrap;
  }
`;
const ContentWrapper = styled.section`
  width: 100%;
  overflow: hidden;
  background: #ffffff;
  border-radius: 10px;
  padding: 1.5rem 2rem;
  height: calc(100vh - 65px);
  .search-bg {
    background: #f6f8ff;
    border: 1px solid #e8edff;
    &:focus-within {
      background: #fff;
    }
  }
  @media (min-width: 768px) {
    width: calc(100% - 220px);
    padding: 2.5rem 4rem;
  }
`;
const Aside = styled.aside`
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  @media (min-width: 768px) {
    width: 220px;
    height: 100%;
  }
  .toggle-btn {
    width: 48px;
    position: absolute;
    right: 1rem;
    top: 0.5rem;
    svg {
      width: 30px;
      height: 30px;
      color: var(--co-head);
    }
    @media (min-width: 768px) {
      display: none;
    }
  }
  .toggle-overlay {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: -100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 3;
    transition: left 0.3s ease-in-out;
    &.active {
      left: 0;
    }
    @media (min-width: 768px) {
      display: none;
    }
  }
  .aside-wrapper {
    position: absolute;
    padding: 3rem 0rem;
    width: 250px;
    background: #f6f8ff;
    left: -100%;
    z-index: 4;
    transition: left 0.2s ease-in-out;
    height: 100%;
    &.active {
      left: 0;
    }
    @media (min-width: 768px) {
      position: relative;
      top: 0;
      left: 0;
      width: 220px;
      height: 100%;
    }
  }
`;
