import {
  Drawer,
  List,
  ListItem,
  ListItemText,
  ListItemIcon,
  IconButton,
  Box,
  useMediaQuery,
  InputBase,
  Tooltip,
  Divider
} from '@mui/material';
import { useTheme } from '@mui/material/styles';
import { useEffect, useMemo, useState } from 'react';
import { useAuth } from '../context/AuthContext';
import ExitToAppIcon from '@mui/icons-material/ExitToApp';
// ---- Menu options (unchanged) ----
const menuOptions = {
  public: [
    { text: 'Dashboard', icon:  },
    { text: 'Logout', icon:  },
  ],
  restricted: [],
  private: [
    { text: 'Dashboard', icon:
 },
    { text: 'Logout', icon:  },
  ],
  restricted: [],
  private: [
    { text: 'Dashboard', icon:  },
    { text: 'Catalog', icon:
 },
    { text: 'Catalog', icon:  },
    { text: 'Define your style', icon:
 },
    { text: 'Define your style', icon:  },
    { text: 'Ambient Design', icon:
 },
    { text: 'Ambient Design', icon:  },
    { text: 'Flat Layouts and assets', icon:
 },
    { text: 'Flat Layouts and assets', icon:  },
    { text: 'Export and sharing', icon:
 },
    { text: 'Export and sharing', icon:  },
    { text: 'Shopping cart', icon:
 },
    { text: 'Shopping cart', icon:  },
    { text: 'Settings', icon:
 },
    { text: 'Settings', icon:  },
    { text: 'Help', icon:
 },
    { text: 'Help', icon:  },
    { text: 'Logout', icon:  },
  ],
};
// Mini‑variant sizes
const OPEN_WIDTH = 300;
const MINI_WIDTH = 72;
export default function MenuDrawer({ zone = 'public', open, onClose, onSelect }) {
  const theme = useTheme();
  const isMobile = useMediaQuery('(max-width:900px)');
  const items = useMemo(() => menuOptions[zone] ?? [], [zone]);
  const { logout } = useAuth();
  // Collapsed state is only meaningful on desktop (permanent drawer)
  const [collapsed, setCollapsed] = useState(false);
  // Interpret parent "open" prop:
  // - Mobile (temporary): open controls visibility
  // - Desktop (permanent): open=true => expanded, open=false => collapsed
  useEffect(() => {
    if (!isMobile) {
      setCollapsed(!open);
    }
  }, [open, isMobile]);
  const paperWidth = isMobile ? OPEN_WIDTH : (collapsed ? MINI_WIDTH : OPEN_WIDTH);
  return (
    
      {/* Header */}
      
        {/* Expanded - default */}
        {!collapsed && (
 },
    { text: 'Logout', icon:  },
  ],
};
// Mini‑variant sizes
const OPEN_WIDTH = 300;
const MINI_WIDTH = 72;
export default function MenuDrawer({ zone = 'public', open, onClose, onSelect }) {
  const theme = useTheme();
  const isMobile = useMediaQuery('(max-width:900px)');
  const items = useMemo(() => menuOptions[zone] ?? [], [zone]);
  const { logout } = useAuth();
  // Collapsed state is only meaningful on desktop (permanent drawer)
  const [collapsed, setCollapsed] = useState(false);
  // Interpret parent "open" prop:
  // - Mobile (temporary): open controls visibility
  // - Desktop (permanent): open=true => expanded, open=false => collapsed
  useEffect(() => {
    if (!isMobile) {
      setCollapsed(!open);
    }
  }, [open, isMobile]);
  const paperWidth = isMobile ? OPEN_WIDTH : (collapsed ? MINI_WIDTH : OPEN_WIDTH);
  return (
    
      {/* Header */}
      
        {/* Expanded - default */}
        {!collapsed && (
          
             )}
      
      {/* Collapsed */}
      {collapsed && (
            
          
        )}
      
      {/* Collapsed */}
      {collapsed && (
        
           )}
      {/* Items */}
        
      )}
      {/* Items */}
      
        {items.map(({ text, icon }, index) => {
          // Default items
          return (
            
               {
                  if (isMobile) onClose?.();
                  if (text === 'Logout') {
                    logout();
                  } else {
                    onSelect?.(text);
                  }
                }}
                sx={{
                  px: collapsed ? 0 : 2,
                  minHeight: collapsed ? 48 : 44,
                  cursor: 'pointer',
                  justifyContent: collapsed ? 'center' : 'flex-start',
                  width: '100%',
                }}
              >
                
                  {icon}
                
                {!collapsed && (
                  
                )}
              
            
          );
        })}
      
setCollapsed((c) => !c)} sx={{
          backgroundColor: 'transparent',
          color: 'transparent',
          '&:hover': {
            backgroundColor: '#fff4ec',
            borderColor: 'transparent'
          },
          borderRadius: 0,
          marginLeft: 2,
          width: 40,
          height: 40,
        }}> );
}
        
      
    
  );
}