import React from 'react';
import ReactSelect, { SingleValue } from "react-select";

export interface OptionType {
    value: string | number;
    label: string;
}

interface SelectProps {
    options: OptionType[];
    placeholder: string;
    value: string | number | null;
    onChange: (selectedOption: SingleValue<OptionType>) => void;
    name: string;
}

export function Select({options, placeholder, value, onChange, name}: SelectProps) {
    return (
        <>
            <label htmlFor={name}>{placeholder}</label>
            <ReactSelect options={options} placeholder={placeholder}
                         value={options.find((option) => option.value === value)}
                    onChange={onChange} name={name}/>
        </>
    );
}
