import React from 'react';
import { Dropdown } from '@theorchard/suite-components';
import { NR_CONTRACT_TERM_TYPES } from 'src/apollo/type-constants/contract';
import { getSelectedOptions } from 'src/utils/searchable-dropdown-option';

export interface NrTermTypePropTypes {
    className?: string;
    isClearable?: boolean;
    isDisabled?: boolean;
    id: string;
    isMultiSelect?: boolean;
    onChange: any;
    name: string;
    placeholder?: string;
    value: string | [];
}

export const NrTermTypeSelect: React.FC<NrTermTypePropTypes> = ({
    className = '',
    isClearable = true,
    isDisabled = false,
    id,
    isMultiSelect = false,
    name,
    onChange,
    placeholder = '',
    value,
}) => (
    <>
        <Dropdown
            controlled
            className={`SelectNrTermType ${className}`}
            closeMenuOnSelect={!isMultiSelect}
            id={id}
            isClearable={isClearable}
            isDisabled={isDisabled}
            isMulti={isMultiSelect}
            name={name}
            onChange={onChange}
            options={NR_CONTRACT_TERM_TYPES}
            value={getSelectedOptions(NR_CONTRACT_TERM_TYPES, value)}
            placeholder={placeholder}
            isLoading={false}
        />
    </>
);
