"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.RequestItem = RequestItem;
var _reactNative = require("react-native");
var _Avatar = _interopRequireDefault(require("../../../../../components/Avatar"));
var _Typography = require("../../../../../../core/components/Typography/Typography");
var _BrandBadge = require("../../../../../elements/BrandBadge");
var _components = require("../../../../../components");
var _Skeleton = _interopRequireDefault(require("../../../../../../core/components/Skeleton/Skeleton"));
var _objects = require("../../../../../hooks/objects");
var _usePendingFollowRequest = require("../../../../../hooks/queries/usePendingFollowRequest");
var _native = require("@react-navigation/native");
var _BehaviourProvider = require("../../../../../providers/BehaviourProvider");
var _styles = require("./styles");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function RequestItem({
  userId
}) {
  var _user$avatar;
  const {
    styles
  } = (0, _styles.useStyles)();
  const {
    user
  } = (0, _objects.useUser)({
    userId
  });
  const {
    acceptRequest,
    declineRequest,
    isLoading
  } = (0, _usePendingFollowRequest.usePendingFollowRequest)();
  const {
    AmityUserPendingFollowRequestsPageBehavior
  } = (0, _BehaviourProvider.useBehaviour)();
  const navigation = (0, _native.useNavigation)();
  const handlePressUser = () => {
    if (AmityUserPendingFollowRequestsPageBehavior !== null && AmityUserPendingFollowRequestsPageBehavior !== void 0 && AmityUserPendingFollowRequestsPageBehavior.goToUserProfilePage) {
      AmityUserPendingFollowRequestsPageBehavior.goToUserProfilePage({
        userId
      });
    } else {
      navigation.navigate('UserProfile', {
        userId
      });
    }
  };
  return /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.container
  }, /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    activeOpacity: 0.7,
    style: styles.userContainer,
    onPress: handlePressUser
  }, /*#__PURE__*/React.createElement(_Avatar.default.User, {
    userId: userId,
    imageStyle: styles.avatar,
    userName: user === null || user === void 0 ? void 0 : user.displayName,
    uri: (user === null || user === void 0 ? void 0 : user.avatarCustomUrl) ?? (user === null || user === void 0 || (_user$avatar = user.avatar) === null || _user$avatar === void 0 ? void 0 : _user$avatar.fileUrl)
  }), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.nameContainer
  }, /*#__PURE__*/React.createElement(_Typography.Typography.BodyBold, {
    numberOfLines: 1,
    ellipsizeMode: "tail",
    style: styles.displayName
  }, user === null || user === void 0 ? void 0 : user.displayName), (user === null || user === void 0 ? void 0 : user.isBrand) && /*#__PURE__*/React.createElement(_BrandBadge.BrandBadge, {
    accessible: true,
    accessibilityLabel: "Brand verified",
    width: 16,
    height: 16
  }))), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.buttonsContainer
  }, /*#__PURE__*/React.createElement(_components.Button, {
    type: "primary",
    disabled: isLoading,
    style: styles.button,
    size: _components.BUTTON_SIZE.LARGE,
    onPress: () => acceptRequest(userId, (user === null || user === void 0 ? void 0 : user.displayName) ?? userId)
  }, "Accept"), /*#__PURE__*/React.createElement(_components.Button, {
    type: "secondary",
    disabled: isLoading,
    style: styles.button,
    size: _components.BUTTON_SIZE.LARGE,
    onPress: () => declineRequest(userId)
  }, "Decline")));
}
function RequestItemSkeleton() {
  const {
    styles
  } = (0, _styles.useStyles)();
  return /*#__PURE__*/React.createElement(_Skeleton.default, {
    style: styles.container
  }, /*#__PURE__*/React.createElement(_Skeleton.default, {
    style: styles.skeletonContainer
  }, /*#__PURE__*/React.createElement(_Skeleton.default.Circle, {
    width: 40,
    height: 40
  }), /*#__PURE__*/React.createElement(_Skeleton.default.Line, {
    width: 140,
    height: 10
  })));
}
RequestItem.Skeleton = RequestItemSkeleton;
//# sourceMappingURL=RequestItem.js.map