import React from 'react';
import { Select } from 'antd';
import { ApolloSelectProps } from '../editInterface';
import { antiAssign } from '../../../../utils/utils';
import styles from './styles.less';

export const ApolloSelect = (props: ApolloSelectProps) => {
    const { options = [], onChange, isMultiple, isMobile } = props;
    const selfProps = antiAssign(props, ['columnConfig', 'onChange', 'isMultiple', 'options']);
    const changeValue = (value, option) => {
        if (typeof onChange === 'function') {
            onChange(value, option);
        }
    };

    if (isMultiple) {
        selfProps.mode = 'multiple';
    }

    return (
        <Select className={styles.select} {...selfProps} onChange={changeValue}>
            {options.map((item) => {
                return (
                    <Select.Option key={item.id} value={item.id}>
                        {item.name}
                    </Select.Option>
                );
            })}
        </Select>
    );
};
