var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ThreadFooterComponent = exports.InlineLoadingMoreThreadIndicator = void 0;
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
var _reactNativeSvg = _interopRequireWildcard(require("react-native-svg"));
var _MessagesContext = require("../../../contexts/messagesContext/MessagesContext");
var _ThemeContext = require("../../../contexts/themeContext/ThemeContext");
var _ThreadContext = require("../../../contexts/threadContext/ThreadContext");
var _TranslationContext = require("../../../contexts/translationContext/TranslationContext");
var _hooks = require("../../../hooks");
var _useViewport2 = require("../../../hooks/useViewport");
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["backgroundGradientStart", "backgroundGradientStop", "text", "threadHeight"];
var _this = this,
  _jsxFileName = "/home/runner/work/stream-chat-react-native/stream-chat-react-native/package/src/components/Thread/components/ThreadFooterComponent.tsx";
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var styles = _reactNative.StyleSheet.create({
  absolute: {
    position: 'absolute'
  },
  activityIndicatorContainer: {
    padding: 10,
    width: '100%'
  },
  messagePadding: {
    paddingHorizontal: 8
  },
  newThread: {
    alignItems: 'center',
    height: 24,
    justifyContent: 'center',
    marginTop: 8
  },
  text: {
    fontSize: 12,
    textAlign: 'center'
  },
  threadHeaderContainer: {
    marginVertical: 8
  }
});
var InlineLoadingMoreThreadIndicator = exports.InlineLoadingMoreThreadIndicator = function InlineLoadingMoreThreadIndicator() {
  var _useThreadContext = (0, _ThreadContext.useThreadContext)(),
    threadLoadingMore = _useThreadContext.threadLoadingMore;
  var _useTheme = (0, _ThemeContext.useTheme)(),
    accent_blue = _useTheme.theme.colors.accent_blue;
  if (!threadLoadingMore) {
    return null;
  }
  return (0, _jsxRuntime.jsx)(_reactNative.View, {
    style: styles.activityIndicatorContainer,
    children: (0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, {
      color: accent_blue,
      size: "small"
    })
  });
};
var selector = function selector(nextValue) {
  return {
    replyCount: nextValue.replyCount
  };
};
var ThreadFooterComponentWithContext = function ThreadFooterComponentWithContext(props) {
  var _useStateStore;
  var Message = props.Message,
    parentMessagePreventPress = props.parentMessagePreventPress,
    thread = props.thread,
    threadInstance = props.threadInstance;
  var _useTranslationContex = (0, _TranslationContext.useTranslationContext)(),
    t = _useTranslationContex.t;
  var _useViewport = (0, _useViewport2.useViewport)(),
    vw = _useViewport.vw;
  var _useTheme2 = (0, _ThemeContext.useTheme)(),
    _useTheme2$theme = _useTheme2.theme,
    _useTheme2$theme$colo = _useTheme2$theme.colors,
    bg_gradient_end = _useTheme2$theme$colo.bg_gradient_end,
    bg_gradient_start = _useTheme2$theme$colo.bg_gradient_start,
    grey = _useTheme2$theme$colo.grey,
    _useTheme2$theme$thre = _useTheme2$theme.thread.newThread,
    backgroundGradientStart = _useTheme2$theme$thre.backgroundGradientStart,
    backgroundGradientStop = _useTheme2$theme$thre.backgroundGradientStop,
    text = _useTheme2$theme$thre.text,
    threadHeight = _useTheme2$theme$thre.threadHeight,
    newThread = (0, _objectWithoutProperties2["default"])(_useTheme2$theme$thre, _excluded);
  var _ref = (_useStateStore = (0, _hooks.useStateStore)(threadInstance == null ? void 0 : threadInstance.state, selector)) != null ? _useStateStore : {},
    _ref$replyCount = _ref.replyCount,
    replyCount = _ref$replyCount === void 0 ? thread == null ? void 0 : thread.reply_count : _ref$replyCount;
  if (!thread) {
    return null;
  }
  return (0, _jsxRuntime.jsxs)(_reactNative.View, {
    style: styles.threadHeaderContainer,
    testID: "thread-footer-component",
    children: [(0, _jsxRuntime.jsx)(_reactNative.View, {
      style: styles.messagePadding,
      children: (0, _jsxRuntime.jsx)(Message, {
        groupStyles: ['single'],
        message: thread,
        preventPress: parentMessagePreventPress,
        readBy: 0,
        threadList: true
      })
    }), (0, _jsxRuntime.jsxs)(_reactNative.View, {
      style: [styles.newThread, newThread],
      children: [(0, _jsxRuntime.jsxs)(_reactNativeSvg["default"], {
        height: threadHeight != null ? threadHeight : 24,
        style: styles.absolute,
        width: vw(100),
        children: [(0, _jsxRuntime.jsx)(_reactNativeSvg.Rect, {
          fill: "url(#gradient)",
          height: threadHeight != null ? threadHeight : 24,
          width: vw(100),
          x: 0,
          y: 0
        }), (0, _jsxRuntime.jsx)(_reactNativeSvg.Defs, {
          children: (0, _jsxRuntime.jsxs)(_reactNativeSvg.LinearGradient, {
            gradientUnits: "userSpaceOnUse",
            id: "gradient",
            x1: 0,
            x2: 0,
            y1: 0,
            y2: threadHeight != null ? threadHeight : 24,
            children: [(0, _jsxRuntime.jsx)(_reactNativeSvg.Stop, {
              offset: 1,
              stopColor: backgroundGradientStart || bg_gradient_end,
              stopOpacity: 1
            }), (0, _jsxRuntime.jsx)(_reactNativeSvg.Stop, {
              offset: 0,
              stopColor: backgroundGradientStop || bg_gradient_start,
              stopOpacity: 1
            })]
          })
        })]
      }), (0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: [styles.text, {
          color: grey
        }, text],
        children: replyCount === 1 ? t('1 Reply') : t('{{ replyCount }} Replies', {
          replyCount: replyCount
        })
      })]
    }), (0, _jsxRuntime.jsx)(InlineLoadingMoreThreadIndicator, {})]
  });
};
var areEqual = function areEqual(prevProps, nextProps) {
  var prevParentMessagePreventPress = prevProps.parentMessagePreventPress,
    prevThread = prevProps.thread,
    prevThreadInstance = prevProps.threadInstance;
  var nextParentMessagePreventPress = nextProps.parentMessagePreventPress,
    nextThread = nextProps.thread,
    nextThreadInstance = nextProps.threadInstance;
  if (prevParentMessagePreventPress !== nextParentMessagePreventPress) {
    return false;
  }
  var threadEqual = (prevThread == null ? void 0 : prevThread.id) === (nextThread == null ? void 0 : nextThread.id) && (prevThread == null ? void 0 : prevThread.text) === (nextThread == null ? void 0 : nextThread.text) && (prevThread == null ? void 0 : prevThread.reply_count) === (nextThread == null ? void 0 : nextThread.reply_count);
  if (!threadEqual) {
    return false;
  }
  if (prevThreadInstance !== nextThreadInstance) {
    return false;
  }
  var latestReactionsEqual = prevThread && nextThread && Array.isArray(prevThread.latest_reactions) && Array.isArray(nextThread.latest_reactions) ? prevThread.latest_reactions.length === nextThread.latest_reactions.length && prevThread.latest_reactions.every(function (_ref2, index) {
    var _nextThread$latest_re;
    var type = _ref2.type;
    return type === ((_nextThread$latest_re = nextThread.latest_reactions) == null ? void 0 : _nextThread$latest_re[index].type);
  }) : (prevThread == null ? void 0 : prevThread.latest_reactions) === (nextThread == null ? void 0 : nextThread.latest_reactions);
  if (!latestReactionsEqual) {
    return false;
  }
  return true;
};
var MemoizedThreadFooter = _react["default"].memo(ThreadFooterComponentWithContext, areEqual);
var ThreadFooterComponent = exports.ThreadFooterComponent = function ThreadFooterComponent(props) {
  var _useMessagesContext = (0, _MessagesContext.useMessagesContext)(),
    Message = _useMessagesContext.Message;
  var _useThreadContext2 = (0, _ThreadContext.useThreadContext)(),
    parentMessagePreventPress = _useThreadContext2.parentMessagePreventPress,
    thread = _useThreadContext2.thread,
    threadInstance = _useThreadContext2.threadInstance,
    threadLoadingMore = _useThreadContext2.threadLoadingMore;
  return (0, _jsxRuntime.jsx)(MemoizedThreadFooter, Object.assign({
    Message: Message,
    parentMessagePreventPress: parentMessagePreventPress,
    thread: thread,
    threadInstance: threadInstance,
    threadLoadingMore: threadLoadingMore
  }, props));
};
//# sourceMappingURL=ThreadFooterComponent.js.map