import React, { Component } from 'react';
import cls from 'classnames';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { CommonThemeProps } from '../types';
import { NumberPicker as NextNumberPicker } from '@alifd/next';
import { NumberPickerProps as NextNumberPickerProps } from '@alifd/next/types/number-picker';
interface NumberPickerProps
  extends NextNumberPickerProps,
  CommonThemeProps {
  state?: 'error' | 'loading' | 'success' | 'warning';
}
class NumberPicker extends Component<NumberPickerProps> {
  onFocus = e => {
    const { onFocus } = this.props;
    const dom = e.target;
    dom.parentNode.parentElement.classList.add('next-input-group-focus');
    console.log(dom.parentNode.parentElement);
    onFocus && onFocus(e);
  };
  onBlur = e => {
    const { onBlur } = this.props;
    const dom = e.target;
    dom.parentNode.parentElement.classList.remove('next-input-group-focus');
    console.log(dom.parentNode.parentElement);
    onBlur && onBlur(e);
  };
  render() {
    const { type } = this.props;
    const { theme = 'white', prefix = 'next-', className, ...otherProps } = this.props;
    // const state = this.props.state ? this.props.state : '';
    const { state } = this.props;
    // inline 模式
    if (type === 'inline' && state === 'error') {
      return (
        <NextNumberPicker
          {...otherProps}
          onFocus={this.onFocus}
          onBlur={this.onBlur}
          prefix={prefix}
          className={cls(className, {
            [`${prefix}number-picker-error`]: true,
            [`${prefix}white`]: theme === 'white',
            [`${prefix}grey`]: theme === 'grey',
          })}
        />
      );

    }
    return (
      <NextNumberPicker
        {...otherProps}
        onFocus={this.onFocus}
        onBlur={this.onBlur}
        prefix={prefix}
        className={cls(className, {
          [`${prefix}white`]: theme === 'white',
          [`${prefix}grey`]: theme === 'grey',
        })}
      />
    );
  }
}
hoistNonReactStatics(NumberPicker, NextNumberPicker);
export default NumberPicker;
