/**
 * @license
 * SPDX-License-Identifier: Apache-2.0
 */

import React from 'react';
import { type LucideIcon } from 'lucide-react';

/** One entry in the user store sidebar. Add to `UserStorePage`'s `NAV_ITEMS`. */
export interface UserNavItem {
  id: string;
  label: string;
  icon: LucideIcon;
}

interface UserStoreSidebarProps {
  items: UserNavItem[];
  activeId: string;
  onSelect: (id: string) => void;
  /** Collapsed → icon-only rail; expanded → labels visible. */
  isOpen: boolean;
}

/**
 * The user store page's left rail. Visually identical to the admin `Sidebar`
 * (fixed, sits under the fixed Header, collapses to an icon rail) but driven by
 * a generic items list so new user sections can be added without touching this.
 */
export default function UserStoreSidebar({ items, activeId, onSelect, isOpen }: UserStoreSidebarProps) {
  return (
    <aside
      className={`fixed left-0 top-0 h-screen bg-[#662582] border-r border-[#662582] text-white flex-col py-xl pt-16 z-40 hidden md:flex transition-all duration-300 ${
        isOpen ? 'w-64' : 'w-20'
      }`}
    >
      {/* Main Navigation Sidebar Links */}
      <nav className="flex-1 space-y-1 overflow-y-auto px-xs">
        {items.map((item) => {
          const IconComponent = item.icon;
          const isActive = activeId === item.id;
          return (
            <button
              key={item.id}
              onClick={() => onSelect(item.id)}
              title={item.label}
              className={`w-full flex items-center py-3 rounded-lg text-left transition-all duration-200 cursor-pointer ${
                isOpen ? 'gap-md px-md' : 'justify-center px-0'
              } ${
                isActive
                  ? 'bg-black/20 text-white font-semibold' + (isOpen ? ' border-l-4 border-white' : '')
                  : 'text-purple-200 hover:bg-white/10 hover:text-white'
              }`}
            >
              <IconComponent size={18} className={isActive ? 'text-white' : 'text-purple-300'} />
              {isOpen && <span className="font-sans text-sm font-medium">{item.label}</span>}
            </button>
          );
        })}
      </nav>
    </aside>
  );
}
