import extend from 'extend';
import React, { PropTypes } from 'react';

import { UnwrappedKdSelectDropDown } from '../KdSelectDropDown';
import wrap from '../ItemContainerWrapper';
import { ADD_CHICKLET } from '../../constants';

const defaultProps = {
  selectedValuesInitial: [],
  selectBehavior: ADD_CHICKLET,
  isDisabled: false,
  mainSelector: {
    visible: false,
    selected: '',
    optionValues: {
      anyOption: {
        visible: true,
        label: 'Any String',
      },
      customOptions: [],
      userSpecifiedOption: {
        visible: true,
        label: 'Enter a String(s)...',
      },
    },
  },
  events: {},
  autoComplete: {
    clearTextboxOnSelection: true,
    renderClearTextboxButton: true,
  },
};

const propTypes = {
  theme: PropTypes.oneOfType([
    PropTypes.object,
    PropTypes.func,
  ]).isRequired,
  selectBehavior: PropTypes.string,
  kdFilterModel: PropTypes.object.isRequired,

  api: PropTypes.shape({
    url: PropTypes.string,
    key: PropTypes.string,
  }),

  events: PropTypes.shape({
    onSelect: PropTypes.func,
    onChange: PropTypes.func,
  }),

  mainSelector: PropTypes.shape({
    visible: PropTypes.bool,
    selected: PropTypes.string,

    optionValues: PropTypes.shape({
      selectOption: PropTypes.shape({
        visible: PropTypes.bool,
        label: PropTypes.string,
      }),
      anyOption: PropTypes.shape({
        visible: PropTypes.bool,
        label: PropTypes.string,
      }),
      customOptions: PropTypes.array,
      userSpecifiedOption: PropTypes.shape({
        visible: PropTypes.bool,
        label: PropTypes.string,
      }),
    }),
  }),

  autoComplete: PropTypes.shape({
    onSuccess: PropTypes.func,
    onRender: PropTypes.func,
    onSelect: PropTypes.func,
    onFail: PropTypes.func,
    onDone: PropTypes.func,
    placeholderText: PropTypes.string,
    clearTextboxOnSelection: PropTypes.bool,
    renderClearTextboxButton: PropTypes.bool,
  }),

  selectedValuesInitial: PropTypes.array,
};

function KdSelectString(props) {
  const selectStringProps = extend(true, {}, defaultProps, props, { multipleCategories: false });
  return (<UnwrappedKdSelectDropDown {...selectStringProps} />);
}

KdSelectString.defaultProps = defaultProps;
KdSelectString.propTypes = propTypes;

export default wrap(KdSelectString);
