import React from 'react';
import AntdInput from 'antd/es/input';

import { ConfigConsumer } from '../config-provider';
import Icons from '../icons';

import './index.less';

const { SearchIcon } = Icons;

const Input = props => (
  <ConfigConsumer>
    {({ getPrefixCls }) => {
      const { prefixCls: customizePrefixCls, ...restProps } = props;
      const prefixCls = getPrefixCls('input', customizePrefixCls);
      return <AntdInput prefixCls={prefixCls} {...restProps} />;
    }}
  </ConfigConsumer>
);

Input.Group = props => (
  <ConfigConsumer>
    {({ getPrefixCls }) => {
      const { prefixCls: customizePrefixCls, ...restProps } = props;
      const prefixCls = getPrefixCls('input', customizePrefixCls);
      return <AntdInput.Group prefixCls={prefixCls} {...restProps} />;
    }}
  </ConfigConsumer>
);

Input.Search = props => (
  <ConfigConsumer>
    {({ getPrefixCls }) => {
      const { prefixCls: customizePrefixCls, ...restProps } = props;
      const prefixCls = getPrefixCls('input', customizePrefixCls);
      return <AntdInput.Search inputPrefixCls={prefixCls} {...restProps} />;
    }}
  </ConfigConsumer>
);

Input.TextArea = props => (
  <ConfigConsumer>
    {({ getPrefixCls }) => {
      const { prefixCls: customizePrefixCls, ...restProps } = props;
      const prefixCls = getPrefixCls('input', customizePrefixCls);
      return <AntdInput.TextArea prefixCls={prefixCls} {...restProps} />;
    }}
  </ConfigConsumer>
);

// antd Password 组件不能自定义 EyeIcon
Input.Password = props => (
  <ConfigConsumer>
    {({ getPrefixCls }) => {
      const { prefixCls: customizePrefixCls, ...restProps } = props;
      const prefixCls = getPrefixCls('input', customizePrefixCls);
      return <AntdInput.Password inputPrefixCls={prefixCls} {...restProps} />;
    }}
  </ConfigConsumer>
);

export default Input;
