"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.BannerErrorState = void 0;
var _reactNative = require("react-native");
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
var _context = require("../../context");
var _core = require("../../core");
var _IOColors = require("../../core/IOColors");
var _hooks = require("../../hooks");
var _icons = require("../icons");
var _layout = require("../layout");
var _typography = require("../typography");
var _buttons = require("../buttons");
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 styles = _reactNative.StyleSheet.create({
  container: {
    flexDirection: "row",
    alignItems: "center",
    alignContent: "center",
    borderRadius: _core.IOBannerRadius,
    borderCurve: "continuous",
    padding: _core.IOBannerBigSpacing
  }
});

/* Component Types */

/**
 ** TODO: Move it to the `io-app-design-system` package
 */
const BannerErrorState = ({
  viewRef,
  icon = "warningFilled",
  label,
  actionText,
  onPress,
  accessibilityHint,
  accessibilityLabel,
  testID
}) => {
  const {
    onPressIn,
    onPressOut,
    scaleAnimatedStyle
  } = (0, _hooks.useScaleAnimation)("medium");
  const theme = (0, _context.useIOTheme)();
  const {
    themeType
  } = (0, _context.useIOThemeContext)();

  /* Styles */
  const foregroundColor = theme["textBody-tertiary"];
  const backgroundColor = "grey-50";
  const dynamicContainerStyles = {
    backgroundColor: themeType === "dark" ? (0, _IOColors.hexToRgba)(_IOColors.IOColors[backgroundColor], 0.1) : _IOColors.IOColors[backgroundColor]
  };
  const renderMainBlock = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
    style: {
      flex: 1,
      alignItems: "center",
      gap: 8
    },
    accessible: true
    // A11y related props
    ,
    accessibilityLabel: accessibilityLabel,
    accessibilityHint: accessibilityHint,
    accessibilityRole: actionText !== undefined ? "button" : undefined,
    children: [icon && /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
      name: icon,
      size: 24,
      color: foregroundColor
    }), label && /*#__PURE__*/(0, _jsxRuntime.jsx)(_typography.Body, {
      color: foregroundColor,
      style: {
        textAlign: "center"
      },
      children: label
    }), actionText &&
    /*#__PURE__*/
    /* Disable pointer events to avoid
        pressed state on the button */
    (0, _jsxRuntime.jsxs)(_reactNative.View, {
      pointerEvents: "none",
      accessibilityElementsHidden: true,
      importantForAccessibility: "no-hide-descendants",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_layout.VSpacer, {
        size: 4
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_buttons.IOButton, {
        variant: "link",
        color: "primary",
        onPress: onPress,
        label: actionText
      })]
    })]
  });
  const PressableContent = () => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
    ref: viewRef,
    testID: testID,
    onPress: onPress,
    onPressIn: onPressIn,
    onPressOut: onPressOut,
    accessible: false,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
      style: [styles.container, dynamicContainerStyles, scaleAnimatedStyle],
      children: renderMainBlock()
    })
  });
  const StaticComponent = () => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    ref: viewRef,
    testID: testID,
    style: [styles.container, dynamicContainerStyles]
    // A11y related props
    ,
    accessible: false,
    accessibilityHint: accessibilityHint,
    accessibilityLabel: accessibilityLabel,
    accessibilityRole: "text",
    children: renderMainBlock()
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeReanimated.default.View, {
    entering: _reactNativeReanimated.FadeIn.duration(150),
    exiting: _reactNativeReanimated.FadeOut.duration(150),
    children: actionText ? /*#__PURE__*/(0, _jsxRuntime.jsx)(PressableContent, {}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(StaticComponent, {})
  });
};
exports.BannerErrorState = BannerErrorState;
//# sourceMappingURL=BannerErrorState.js.map