"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const React = __importStar(require("react"));
const react_native_1 = require("react-native");
const react_native_typing_animation_1 = require("react-native-typing-animation");
const useUpdateLayoutEffect_1 = require("./hooks/useUpdateLayoutEffect");
const Color_1 = __importDefault(require("./Color"));
const TypingIndicator = ({ isTyping }) => {
    const { yCoords, heightScale, marginScale } = React.useMemo(() => ({
        yCoords: new react_native_1.Animated.Value(200),
        heightScale: new react_native_1.Animated.Value(0),
        marginScale: new react_native_1.Animated.Value(0),
    }), []);
    // on isTyping fire side effect
    useUpdateLayoutEffect_1.useUpdateLayoutEffect(() => {
        if (isTyping) {
            slideIn();
        }
        else {
            slideOut();
        }
    }, [isTyping]);
    // side effect
    const slideIn = () => {
        react_native_1.Animated.parallel([
            react_native_1.Animated.spring(yCoords, {
                toValue: 0,
                useNativeDriver: false,
            }),
            react_native_1.Animated.timing(heightScale, {
                toValue: 35,
                duration: 250,
                useNativeDriver: false,
            }),
            react_native_1.Animated.timing(marginScale, {
                toValue: 8,
                duration: 250,
                useNativeDriver: false,
            }),
        ]).start();
    };
    // side effect
    const slideOut = () => {
        react_native_1.Animated.parallel([
            react_native_1.Animated.spring(yCoords, {
                toValue: 200,
                useNativeDriver: false,
            }),
            react_native_1.Animated.timing(heightScale, {
                toValue: 0,
                duration: 250,
                useNativeDriver: false,
            }),
            react_native_1.Animated.timing(marginScale, {
                toValue: 0,
                duration: 250,
                useNativeDriver: false,
            }),
        ]).start();
    };
    return (React.createElement(react_native_1.Animated.View, { style: [
            styles.container,
            {
                transform: [
                    {
                        translateY: yCoords,
                    },
                ],
                height: heightScale,
                marginBottom: marginScale,
            },
        ] }, isTyping ? (React.createElement(react_native_typing_animation_1.TypingAnimation, { style: { marginLeft: 6, marginTop: 7.2 }, dotRadius: 4, dotMargin: 5.5, dotColor: "rgba(0, 0, 0, 0.38)" })) : null));
};
const styles = react_native_1.StyleSheet.create({
    container: {
        marginLeft: 8,
        width: 45,
        borderRadius: 15,
        backgroundColor: Color_1.default.leftBubbleBackground,
    },
});
exports.default = TypingIndicator;
//# sourceMappingURL=TypingIndicator.js.map