// react
import React from "react";
// third-party
import classNames from "classnames";
import { useRouter } from "next/router";
// application
import AppLink from "./AppLink";

interface Props {
  isOpen: boolean;
}

function Sidebar({ isOpen }: Props) {
  const router = useRouter();

  const menuItems = [
    {
      title: "Dashboard",
      icon: "fas fa-tachometer-alt",
      href: "/",
      exact: true,
    },
    {
      title: "Hero",
      icon: "fas fa-image",
      href: "/hero",
    },
    {
      title: "Productos",
      icon: "fas fa-box",
      href: "/productos",
    },
    {
      title: "Marcas",
      icon: "fas fa-car",
      href: "/brands",
    },
    {
      title: "Modelos",
      icon: "fas fa-truck",
      href: "/models",
    },
    {
      title: "Ofertas",
      icon: "fas fa-tag",
      href: "/ofertas",
    },
    {
      title: "Reportes",
      icon: "fas fa-chart-bar",
      href: "/reportes",
    },
    {
      title: "Configuración",
      icon: "fas fa-cog",
      href: "/configuracion",
    },
    {
      title: "Sincronizar Excel",
      icon: "fas fa-file-excel",
      href: "/sincronizar-excel",
    },
    {
      title: "Usuarios",
      icon: "fas fa-user-plus",
      href: "/admin/registro",
    },
    {
      title: "Sucursales",
      icon: "fas fa-store",
      href: "/sucursal",
    },
    {
      title: "Footer",
      icon: "fas fa-list-alt",
      href: "/footer",
    },
    {
      title: "Nosotros (historia)",
      icon: "fas fa-history",
      href: "/about-us",
    },
    {
      title: "Métodos de envío",
      icon: "fas fa-truck",
      href: "/payment",
    },
    {
      title: "Métodos de pago",
      icon: "fas fa-credit-card",
      href: "/bank-payments",
    },
    {
      title: "Servicios",
      icon: "fas fa-cogs",
      href: "/services",
    },
  ];

  const isActive = (href: string, exact?: boolean) => {
    if (exact) {
      return router.pathname === href;
    }
    return router.pathname.startsWith(href);
  };

  return (
    <aside
      className={classNames("sidebar", {
        "sidebar--open": isOpen,
        "sidebar--closed": !isOpen,
      })}
    >
      <div className="sidebar__header">
        <div className="sidebar__logo">
          <h2>MONTICARS</h2>
          <span className="sidebar__subtitle">Admin Panel</span>
        </div>
      </div>
      <nav className="sidebar__nav">
        <ul className="sidebar__menu">
          {menuItems.map((item) => (
            <li key={item.href} className="sidebar__menu-item">
              <AppLink
                href={item.href}
                className={classNames("sidebar__menu-link", {
                  "sidebar__menu-link--active": isActive(item.href, item.exact),
                })}
              >
                <i className={item.icon} />
                <span>{item.title}</span>
              </AppLink>
            </li>
          ))}
        </ul>
      </nav>
    </aside>
  );
}

export default Sidebar;
