import React from "react";
import {
  FormControl,
  InputLabel,
  Select,
  MenuItem,
  SelectChangeEvent,
} from "@mui/material";
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
import { SIDEBAR_LINKS } from "@/constants/SidebarLink.constants";
import { ISidebarLink } from "@/interfaces/SidebarLink.interfaces";
import { Em } from "./DropDown.styled";
import PageLinks from "../../../../components/PageLinks/PageLinks";

interface Props {
  onChange?: (event: SelectChangeEvent<string>) => void;
}

export default function SidebarDropdown({ onChange }: Props) {
  const [value, setValue] = React.useState("");

  const handleChange = (event: SelectChangeEvent<string>) => {
    setValue(event.target.value);
    onChange?.(event);
  };

  return (
    <FormControl fullWidth variant="outlined" sx={{ maxWidth: 200 }}>
      <InputLabel id="sidebar-dropdown-label">Navigate To</InputLabel>
      <Select
        labelId="sidebar-dropdown-label"
        value={value}
        onChange={handleChange}
        label="Navigate To"
        MenuProps={{
          PaperProps: {
            style: {
              maxHeight: 200,
            },
          },
        }}
      >
        <MenuItem value="" disabled>
          <Em>
            Select a page
            <ChevronRightIcon fontSize="small" sx={{ ml: 1 }} />
          </Em>
        </MenuItem>
        {SIDEBAR_LINKS.map((link: ISidebarLink) => (
          <PageLinks
            key={link.path}
            title={link.title}
            path={link.path}
            icon={link.icon}
          />
        ))}
      </Select>
    </FormControl>
  );
}
