import React from 'react';
import { TextInput } from 'react-native-paper';
import { TextInputMask } from 'react-native-masked-text';
let maskInput = null;
/**
 * A text input supporting mask through {@see ICrossEditorProps.maskProps}.
 *
 * When using mask the raw value will be exported in the `onChangeText` event, not the masked value.
 *
 * Default {@see ICrossEditorProps.mode mode} is 'outlined'.
 *
 * Props are {@see ICrossEditorProps}
 *
 *
 * @example
 * ```
 <CrossEditor
  label='Mobile'
  maskProps={{ type: 'cel-phone' }} />
 ```
 */
export class CrossEditor extends React.Component {
    constructor(props) {
        super(props);
    }
    render() {
        const paperProps = Object.assign({}, this.props, { mode: this.props.mode || 'outlined' });
        // console.log('** CrossEditor paper props = ', paperProps);
        if (this.props.maskProps && this.props.maskProps.type) {
            const maskedProps = Object.assign({}, this.props, this.props.maskProps);
            // console.log('** CrossEditor masked props = ', maskedProps);
            // console.log('*** CrossEditor: render TextInputMask');
            return (React.createElement(TextInputMask, Object.assign({}, maskedProps, { ref: (comp) => (maskInput = comp), 
                // @ts-ignore - bad map
                customTextInput: TextInput, customTextInputProps: paperProps, onChangeText: () => {
                    //console.log('**** CrossEditor: onChangeText');
                    if (!maskInput || !maskInput.getRawValue) {
                        //console.log('TextInputMask missing getRawValue', maskInput);
                        return;
                    }
                    // @ts-ignore - bad map
                    const rawValue = maskInput.getRawValue();
                    //console.log('CrossEditor rawValue = ', rawValue || 'nothing');
                    if (maskedProps && maskedProps.onChangeText) {
                        maskedProps.onChangeText(rawValue);
                        return;
                    }
                    if (paperProps.onChangeText) {
                        paperProps.onChangeText(rawValue);
                        return;
                    }
                    // console.log('***** CrossEditor: no listener *****');
                } })));
        }
        // console.log('** CrossEditor: render paper TextInput **');
        return React.createElement(TextInput, Object.assign({}, paperProps, { mode: paperProps.mode }));
    }
}
export default CrossEditor;
//# sourceMappingURL=CrossEditor.js.map