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

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

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

export default PaymentScheduleSelect;
