"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importStar(require("react"));
const react_native_1 = require("react-native");
const FormError_1 = tslib_1.__importDefault(require("../FormError"));
const styles_1 = require("./styles");
const DatePickerInput = ({ id, accessibility, label = '', error = '', dark = false, editable = true, value = '', testID, mode = 'date', androidMode = 'spinner', locale = 'pt-BR', format = 'DD/MM/YYYY', cancelBtnText = 'Cancelar', confirmBtnText = 'Confirmar', onDateChange = () => { }, maxDate, }) => {
    const [labelAnimatedStyle] = (0, react_1.useState)({
        top: new react_native_1.Animated.Value(styles_1.LABEL_LOWER_STYLE.top),
        fontSize: new react_native_1.Animated.Value(styles_1.LABEL_LOWER_STYLE.fontSize),
    });
    const [date, setDate] = (0, react_1.useState)('');
    const [isPlaceholder, setIsPlaceHolder] = (0, react_1.useState)(true);
    const execAnimation = (0, react_1.useCallback)(() => {
        const animations = Object.keys(styles_1.LABEL_UPPER_STYLE).map((animationProp) => react_native_1.Animated.timing(labelAnimatedStyle[animationProp], {
            toValue: styles_1.LABEL_UPPER_STYLE[animationProp],
            duration: 200,
            useNativeDriver: false,
        }));
        setIsPlaceHolder(false);
        react_native_1.Animated.parallel(animations).start();
    }, [react_native_1.Animated, labelAnimatedStyle]);
    const updateDate = (0, react_1.useCallback)((updatedDate) => {
        setDate(updatedDate);
        execAnimation();
        if (onDateChange) {
            onDateChange(updatedDate);
        }
    }, [onDateChange]);
    (0, react_1.useEffect)(() => {
        if (value) {
            execAnimation();
        }
    }, [value]);
    const customStyles = error
        ? { ...styles_1.DatePickerStyles, dateInput: { borderColor: '#cc0000' } }
        : dark
            ? styles_1.DatePickerStylesDark
            : styles_1.DatePickerStyles;
    return (<FormError_1.default id={id || accessibility} accessibility={accessibility} error={error}>
      <styles_1.Label error={error || ''} style={labelAnimatedStyle} isPlaceholder={isPlaceholder} dark={dark}>
        {label}
      </styles_1.Label>
      <styles_1.DatePicker mode={mode} androidMode={androidMode} locale={locale} placeholder=" " format={format} editable={!editable} date={date} customStyles={customStyles} maxDate={maxDate} testID={testID || accessibility} confirmBtnText={confirmBtnText} cancelBtnText={cancelBtnText} onDateChange={updateDate} showIcon={false} dark={dark}/>
      <styles_1.BottomLine dark={dark}/>
    </FormError_1.default>);
};
exports.default = DatePickerInput;
//# sourceMappingURL=index.js.map