<script>
  let { currentView = 'dashboard', onNavigate = () => {} } = $props();
  let collapsed = $state(false);

  const navItems = [
    { id: 'dashboard', label: 'Dashboard', icon: '🏠' },
    { id: 'tasks', label: 'Tasks', icon: '📋' },
  ];
</script>

<aside class="sidebar {collapsed ? 'collapsed' : ''}">
  <div class="sidebar-header">
    {#if !collapsed}
      <span class="sidebar-title">Menu</span>
    {/if}
    <button
      class="collapse-btn"
      onclick={() => collapsed = !collapsed}
      title={collapsed ? 'Expand' : 'Collapse'}
    >
      {collapsed ? '▶' : '◀'}
    </button>
  </div>

  <nav class="sidebar-nav">
    {#each navItems as item}
      <button
        class="nav-item {currentView === item.id ? 'active' : ''}"
        onclick={() => onNavigate(item.id)}
        title={item.label}
      >
        <span class="nav-icon">{item.icon}</span>
        {#if !collapsed}
          <span class="nav-label">{item.label}</span>
        {/if}
      </button>
    {/each}
  </nav>
</aside>

<style>
  .sidebar {
    width: 200px;
    min-height: 100vh;
    background: var(--color-bg-card);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    transition: width 0.25s ease;
    flex-shrink: 0;
  }

  .sidebar.collapsed {
    width: 56px;
  }

  .sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 12px;
    border-bottom: 1px solid var(--color-border);
    min-height: 56px;
  }

  .sidebar-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
  }

  .collapse-btn {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 4px;
    font-size: 10px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
  }

  .collapse-btn:hover {
    color: var(--color-text-primary);
    background: var(--color-bg-card-hover);
  }

  .sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
  }

  .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s;
    white-space: nowrap;
    text-align: left;
  }

  .nav-item:hover {
    background: var(--color-bg-card-hover);
    color: var(--color-text-primary);
  }

  .nav-item.active {
    background: color-mix(in srgb, var(--color-accent) 15%, transparent);
    color: var(--color-accent);
  }

  .nav-icon {
    font-size: 16px;
    flex-shrink: 0;
  }

  .nav-label {
    overflow: hidden;
  }
</style>
