import {FormControl, InputLabel} from "@mui/material";
import Select from "@mui/material/Select";
import MenuItem from "@mui/material/MenuItem";
import * as React from "react";

export function SelectEdit({label, value, array, handler, attributeName,  width, margin}) {

    return (
        <FormControl sx={{width: width, m: margin}}>
            <InputLabel>{label}</InputLabel>
            <Select
                autoWidth
                label={label}
                value={!value ? "" : value}
                onChange={(e) => handler(attributeName, e.target.value)}
            >
                <MenuItem value="">
                    <em>None</em>
                </MenuItem>
                {array.map((c) => {
                    return (<MenuItem key={c.id} value={c.name}>{c.name}</MenuItem>)
                })}
            </Select>
        </FormControl>
    )
}