"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var SnackbarAnimationWrapper_exports = {};
__export(SnackbarAnimationWrapper_exports, {
  default: () => SnackbarAnimationWrapper_default
});
module.exports = __toCommonJS(SnackbarAnimationWrapper_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = __toESM(require("react"));
var import_react_native = require("react-native");
var import_prop_types = require("prop-types");
var import_styled_components = __toESM(require("styled-components"));
const durationDictionary = {
  fast: 4e3,
  default: 8e3,
  slow: 1e4,
  indefinite: -1
};
const Wrapper = (0, import_styled_components.default)(import_react_native.Animated.View)(
  () => `
    position: absolute;
    width: 100%;
    bottom: 0px;
  `
);
const SnackbarAnimationWrapper = (0, import_react.forwardRef)(
  ({ onSnackbarClose = void 0, children, duration }, ref) => {
    const { height: windowHeight } = (0, import_react_native.useWindowDimensions)();
    const [childrenHeight, setChildrenHeight] = (0, import_react.useState)();
    const translateY = (0, import_react.useRef)(new import_react_native.Animated.Value(windowHeight)).current;
    const timeoutRef = (0, import_react.useRef)();
    const childrenRef = (0, import_react.useRef)();
    const openAnimation = () => {
      import_react_native.Animated.spring(translateY, {
        toValue: 0,
        bounciness: 0,
        useNativeDriver: true
      }).start();
    };
    const closeAnimation = (callback) => {
      if (childrenHeight) {
        import_react_native.Animated.spring(translateY, {
          toValue: childrenHeight,
          bounciness: 0,
          useNativeDriver: true
        }).start(({ finished }) => {
          if (finished && callback) {
            callback();
          }
        });
        if (onSnackbarClose) {
          onSnackbarClose();
        }
      }
    };
    const setupSnackbarTimeout = () => {
      const timeoutDuration = durationDictionary[duration];
      const shouldCloseOnTimer = childrenHeight && timeoutDuration > 0;
      if (shouldCloseOnTimer) {
        timeoutRef.current = setTimeout(() => {
          clearTimeout(timeoutRef.current);
          closeAnimation();
        }, timeoutDuration);
      }
    };
    const openSnackbar = () => {
      openAnimation();
      setupSnackbarTimeout();
    };
    const closeSnackbar = (callback) => {
      clearTimeout(timeoutRef.current);
      closeAnimation(callback);
    };
    (0, import_react.useImperativeHandle)(ref, () => ({
      open: () => {
        openSnackbar();
      },
      close: (callback) => {
        closeSnackbar(callback);
      },
      translateY: (dy) => {
        translateY.setValue(dy);
      }
    }));
    (0, import_react.useEffect)(() => () => clearTimeout(timeoutRef.current), []);
    return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Wrapper, { style: { zIndex: 10, transform: [{ translateY }] }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_react_native.View,
      {
        testID: "wrapper",
        ref: childrenRef,
        onLayout: ({
          nativeEvent: {
            layout: { height }
          }
        }) => {
          setChildrenHeight(height);
          translateY.setValue(height);
        },
        children
      }
    ) });
  }
);
SnackbarAnimationWrapper.propTypes = {
  onSnackbarClose: import_prop_types.func,
  children: import_prop_types.node.isRequired,
  duration: (0, import_prop_types.oneOf)(["fast", "default", "slow", "indefinite"]).isRequired
};
var SnackbarAnimationWrapper_default = SnackbarAnimationWrapper;
