"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Toast = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _native = _interopRequireWildcard(require("styled-components/native"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const ToastContainer = (0, _native.default)(_reactNative.Animated.View)`
  ${({
  type
}) => {
  let backgroundColor = '#333';
  switch (type) {
    case 'success':
      backgroundColor = '#4caf50';
      break;
    case 'error':
      backgroundColor = '#f44336';
      break;
    case 'info':
      backgroundColor = '#2196F3';
      break;
  }
  return (0, _native.css)`
      background-color: ${backgroundColor};
    `;
}}
  padding: 12px;
  border-radius: 6px;
  margin-bottom: 8px;
  width: 240px;
  shadow-color: #000;
  shadow-offset: 0px 2px;
  shadow-opacity: 0.2;
  shadow-radius: 4px;
  elevation: 3;
`;
const Title = _native.default.Text`
  font-weight: bold;
  color: white;
  font-size: 15px;
`;
const Message = _native.default.Text`
  color: white;
  font-size: 13px;
  margin-top: 4px;
`;
const ProgressBar = (0, _native.default)(_reactNative.Animated.View)`
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background-color: rgba(255, 255, 255, 0.6);
`;
const Toast = ({
  title,
  message,
  type,
  duration = 3000
}) => {
  const fadeAnim = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
  const translateY = (0, _react.useRef)(new _reactNative.Animated.Value(10)).current;
  const progressAnim = (0, _react.useRef)(new _reactNative.Animated.Value(1)).current;
  (0, _react.useEffect)(() => {
    // Анимация появления и исчезновения
    _reactNative.Animated.sequence([_reactNative.Animated.parallel([_reactNative.Animated.timing(fadeAnim, {
      toValue: 1,
      duration: 300,
      useNativeDriver: true
    }), _reactNative.Animated.timing(translateY, {
      toValue: 0,
      duration: 300,
      useNativeDriver: true
    }), _reactNative.Animated.timing(progressAnim, {
      toValue: 0,
      duration,
      useNativeDriver: false
    })]), _reactNative.Animated.delay(duration - 300), _reactNative.Animated.parallel([_reactNative.Animated.timing(fadeAnim, {
      toValue: 0,
      duration: 300,
      useNativeDriver: true
    }), _reactNative.Animated.timing(translateY, {
      toValue: 10,
      duration: 300,
      useNativeDriver: true
    })])]).start();
  }, [fadeAnim, translateY, progressAnim, duration]);
  const progressWidth = progressAnim.interpolate({
    inputRange: [0, 1],
    outputRange: ['0%', '100%']
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(ToastContainer, {
    type: type,
    style: {
      opacity: fadeAnim,
      transform: [{
        translateY
      }]
    },
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Title, {
      children: title
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Message, {
      children: message
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(ProgressBar, {
      style: {
        width: progressWidth
      }
    })]
  });
};
exports.Toast = Toast;
//# sourceMappingURL=Toast.js.map