/**
 * @file ResizableTh component
 * @author liangxiaojun(liangxiaojun@derbysoft.com)
 */

import React, {Component} from 'react';
import PropTypes from 'prop-types';

// Components
import {Resizable} from 'react-resizable';

// Vendors
import classNames from 'classnames';

class ResizableTh extends Component {

    constructor(props, ...restArgs) {
        super(props, ...restArgs);
    }

    handleResize = (e, {size}) => {
        const {onResize} = this.props;
        onResize && onResize(size?.width, e);
    };

    handleResizeStart = (e, {size}) => {
        const {onResizeStart} = this.props;
        onResizeStart && onResizeStart(size?.width, e);
    };

    handleResizeStop = (e, {size}) => {
        const {onResizeStop} = this.props;
        onResizeStop && onResizeStop(size?.width, e);
    };

    render() {

        const {children, resizable, activated, deactivated, width} = this.props;

        return resizable ?
            <Resizable className={classNames('resizable-th', {
                activated,
                deactivated
            })}
                       width={width}
                       height={0}
                       onResize={this.handleResize}
                       onResizeStart={this.handleResizeStart}
                       onResizeStop={this.handleResizeStop}>
                {children}
            </Resizable>
            :
            children;

    }
}

ResizableTh.propTypes = {

    children: PropTypes.any,

    resizable: PropTypes.bool,
    activated: PropTypes.bool,
    deactivated: PropTypes.bool,
    width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
    minWidth: PropTypes.number,
    maxWidth: PropTypes.number,

    onResize: PropTypes.func,
    onResizeStart: PropTypes.func,
    onResizeStop: PropTypes.func

};

ResizableTh.defaultProps = {
    minWidth: 40,
    maxWidth: Infinity
};

export default ResizableTh;

@@ -892,16 +892,36 @@
 d, width
+, minWidth, maxWidth
 %7D = this
@@ -928,16 +928,16 @@
 .props;%0A
-
 %0A       
@@ -1161,16 +1161,130 @@
 ght=%7B0%7D%0A
+                       minConstraints=%7B%5BminWidth, null%5D%7D%0A                       maxConstraints=%7B%5BmaxWidth, null%5D%7D%0A
         
@@ -1539,22 +1539,23 @@
 ldren;%0A%0A
-
     %7D%0A
+%0A
 %7D%0A%0AResiz

update ResizableTh