var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
import { jsx, jsxs } from "react/jsx-runtime";
import React, { useEffect, useState } from "react";
import styled, { withTheme } from "styled-components";
import { node, string, func, bool } from "prop-types";
import {
  Animated,
  TouchableWithoutFeedback,
  Easing,
  Modal
} from "react-native";
import Text from "../../Text";
const ClosableArea = styled(Animated.View)`
  ${({
  theme: {
    yoga: { colors }
  }
}) => `
    position: relative;
    width: 100%;
    height: 100%;

    background-color: ${colors.text.primary};
  `}
`;
const ContentWrapper = styled(Animated.View)`
  position: absolute;
  justify-content: flex-end;

  width: 100%;
`;
const Content = styled.View`
  ${({
  theme: {
    yoga: {
      components: { dropdown }
    }
  }
}) => `
    justify-content: center;
    width: 100%;

    background-color: ${dropdown.backdrop.content.backgroundColor};
    border-top-left-radius: ${dropdown.backdrop.content.border.radius.topLeft}px;
    border-top-right-radius: ${dropdown.backdrop.content.border.radius.topRight}px;
  `}
`;
const Title = styled(Text.Bold)`
  ${({
  theme: {
    yoga: {
      components: { dropdown }
    }
  }
}) => `
    width: 100%;
    padding:
      ${dropdown.backdrop.content.title.padding.top}px
      ${dropdown.backdrop.content.title.padding.right}px
      ${dropdown.backdrop.content.title.padding.bottom}px
      ${dropdown.backdrop.content.title.padding.left}px;

    font-size: ${dropdown.backdrop.content.title.font.size}px;

    text-align: center;
  `}
`;
const Backdrop = (_a) => {
  var _b = _a, {
    visible = false,
    title = null,
    children,
    onClose = () => {
    },
    theme: {
      yoga: {
        transition,
        components: { dropdown }
      }
    }
  } = _b, props = __objRest(_b, [
    "visible",
    "title",
    "children",
    "onClose",
    "theme"
  ]);
  const [isOpen, toggleIsOpen] = useState(visible);
  const [backgroundAnimation] = useState(new Animated.Value(0));
  const [contentAnimation] = useState(
    new Animated.Value(-dropdown.backdrop.content.height)
  );
  const animate = (animation, toValue) => Animated.timing(animation, {
    toValue,
    duration: transition.duration[0],
    easing: Easing.out(Easing.ease),
    useNativeDriver: false
  }).start(() => !visible && toggleIsOpen(false));
  useEffect(() => {
    if (visible)
      toggleIsOpen(true);
    animate(backgroundAnimation, visible ? 0.5 : 0);
    animate(contentAnimation, visible ? 0 : -dropdown.backdrop.content.height);
  }, [visible]);
  return isOpen && /* @__PURE__ */ jsxs(Modal, __spreadProps(__spreadValues({}, props), { transparent: true, animationType: "none", children: [
    /* @__PURE__ */ jsx(TouchableWithoutFeedback, { onPress: onClose, children: /* @__PURE__ */ jsx(ClosableArea, { style: { opacity: backgroundAnimation } }) }),
    /* @__PURE__ */ jsx(ContentWrapper, { style: { bottom: contentAnimation }, children: /* @__PURE__ */ jsxs(Content, { children: [
      title && /* @__PURE__ */ jsx(Title, { children: title }),
      children
    ] }) })
  ] }));
};
Backdrop.propTypes = {
  visible: bool,
  title: string,
  children: node.isRequired,
  onClose: func
};
var Backdrop_default = withTheme(Backdrop);
export {
  Backdrop_default as default
};
