import './index.less';
import {Input} from 'tdesign-react';

export default function (props) {
    const {align, className, type, suffixIcon, name, value, prefixIcon, placeholder} = props;
    const realAlign = align ?? 'left';
    const realType = type ?? 'text';
    const realName = name ?? '';
    const realSuffixIcon = suffixIcon ?? '';
    const realPrefixIcon = prefixIcon ?? '';
    const realPlaceholder = placeholder ?? '';

    // 通知父组件
    const inputChange = (value: number) => {
        if (props.onChange) {
            props.onChange(value, realName);
        }
    }
    return (
        <Input
            className={['c-reset-input', className].join('')}
            placeholder={realPlaceholder}
            value={value}
            type={realType}
            align={realAlign}
            suffixIcon={realSuffixIcon}
            prefixIcon={realPrefixIcon}
            clearable
            onChange={(value) => {
                inputChange(value);
            }}
            onClear={() => {
                console.log('onClear');
            }}
        />
    );
}
