"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _chunkZPKPFWPFjs = require('./chunk-ZPKPFWPF.js');


var _chunkOB7RTL5Kjs = require('./chunk-OB7RTL5K.js');


var _chunkPBYYSY3Zjs = require('./chunk-PBYYSY3Z.js');






var _chunkQ75LDFBTjs = require('./chunk-Q75LDFBT.js');


var _chunkEYXYZEIPjs = require('./chunk-EYXYZEIP.js');

// tmp-babel/profiles/web/ProfileComponent/index.js
var _react = require('react');
var _avatars = require('@baseapp-frontend/design-system/components/web/avatars');
var _drawers = require('@baseapp-frontend/design-system/components/web/drawers');
var _icons = require('@baseapp-frontend/design-system/components/web/icons');
var _images = require('@baseapp-frontend/design-system/components/web/images');
var _web = require('@baseapp-frontend/design-system/hooks/web');
var _utils = require('@baseapp-frontend/utils');
var _material = require('@mui/material');
var _navigation = require('next/navigation');
var _numbro = require('numbro'); var _numbro2 = _interopRequireDefault(_numbro);
var _reactrelay = require('react-relay');
var _jsxruntime = require('react/jsx-runtime');
function _slicedToArray(r, e) {
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _nonIterableRest() {
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray(r, a) {
  if (r) {
    if ("string" == typeof r) return _arrayLikeToArray(r, a);
    var t = {}.toString.call(r).slice(8, -1);
    return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  }
}
function _arrayLikeToArray(r, a) {
  (null == a || a > r.length) && (a = r.length);
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  return n;
}
function _iterableToArrayLimit(r, l) {
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  if (null != t) {
    var e, n, i, u, a = [], f = true, o = false;
    try {
      if (i = (t = t.call(r)).next, 0 === l) {
        if (Object(t) !== t) return;
        f = false;
      } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
    } catch (r2) {
      o = true, n = r2;
    } finally {
      try {
        if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
      } finally {
        if (o) throw n;
      }
    }
    return a;
  }
}
function _arrayWithHoles(r) {
  if (Array.isArray(r)) return r;
}
var ProfileComponent = function ProfileComponent2(_ref) {
  var _profile$bannerImage$, _profile$bannerImage, _profile$image, _profile$urlPath2;
  var profileRef = _ref.profile, currentProfileId = _ref.currentProfileId;
  var profile = _reactrelay.useFragment.call(void 0, _chunkEYXYZEIPjs.ProfileComponentFragment, profileRef);
  var smDown = _web.useResponsive.call(void 0, "down", "sm");
  var router = _navigation.useRouter.call(void 0, );
  var _useState = _react.useState.call(void 0, null), _useState2 = _slicedToArray(_useState, 2), anchorEl = _useState2[0], setAnchorEl = _useState2[1];
  var open = Boolean(anchorEl);
  var handleClick = function handleClick2(event) {
    setAnchorEl(event.currentTarget);
  };
  var handleClose = function handleClose2() {
    setAnchorEl(null);
  };
  var _useNotification = _utils.useNotification.call(void 0, ), sendToast = _useNotification.sendToast;
  var handleShareClick = function handleShareClick2() {
    var _profile$urlPath$path, _profile$urlPath;
    var path = (_profile$urlPath$path = profile === null || profile === void 0 || (_profile$urlPath = profile.urlPath) === null || _profile$urlPath === void 0 ? void 0 : _profile$urlPath.path) !== null && _profile$urlPath$path !== void 0 ? _profile$urlPath$path : "/profile/".concat(profile === null || profile === void 0 ? void 0 : profile.id);
    var url = [process.env.NEXT_PUBLIC_APP_BASE_URL, path].join("");
    navigator.clipboard.writeText(url);
    sendToast("Profile URL copied to clipboard!", {
      type: "success"
    });
    handleClose();
  };
  var formatFollowCount = function formatFollowCount2(count) {
    if (!count || count === 0) {
      return 0;
    }
    if (count <= 1e3) {
      return count;
    }
    if (count < 105e4) {
      return _numbro2.default.call(void 0, count).format({
        average: true
      });
    }
    return _numbro2.default.call(void 0, count).format({
      average: true,
      mantissa: 1
    });
  };
  var renderProfileUpdatesButtons = function renderProfileUpdatesButtons2() {
    if (currentProfileId === (profile === null || profile === void 0 ? void 0 : profile.id)) {
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Button, {
        variant: "soft",
        size: "medium",
        color: "inherit",
        startIcon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _icons.OutlinedEditIcon, {}),
        sx: {
          maxWidth: smDown ? "100%" : "fit-content"
        },
        onClick: function onClick() {
          return router.push("/user/settings");
        },
        children: "Edit Profile"
      });
    }
    return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
      className: "flex flex-row gap-2",
      children: [!(profile !== null && profile !== void 0 && profile.isBlockedByMe) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkZPKPFWPFjs.FollowToggleButton_default, {
        targetId: profile === null || profile === void 0 ? void 0 : profile.id,
        isFollowedByMe: profile === null || profile === void 0 ? void 0 : profile.isFollowedByMe,
        currentProfileId,
        profileRef: profile
      }), (profile === null || profile === void 0 ? void 0 : profile.isBlockedByMe) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkPBYYSY3Zjs.BlockButtonWithDialog_default, {
        target: profile,
        handleCloseMenu: handleClose,
        currentProfileId
      })]
    });
  };
  var menuOptions = /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, {
    children: [/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _material.MenuItem, {
      onClick: handleShareClick,
      disableRipple: true,
      children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _icons.ShareIcon, {}), "Share profile"]
    }), smDown && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Divider, {}), profile && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, {
      children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkPBYYSY3Zjs.BlockButtonWithDialog_default, {
        target: profile,
        handleCloseMenu: handleClose,
        currentProfileId,
        isMenu: true
      }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkOB7RTL5Kjs.ReportButtonWithDialog_default, {
        handleClose,
        targetId: profile === null || profile === void 0 ? void 0 : profile.id
      })]
    })]
  });
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", {
    className: "flex h-full w-full justify-center",
    children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkQ75LDFBTjs.ProfileContainer, {
      children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _images.ImageWithFallback, {
        src: (_profile$bannerImage$ = profile === null || profile === void 0 || (_profile$bannerImage = profile.bannerImage) === null || _profile$bannerImage === void 0 ? void 0 : _profile$bannerImage.url) !== null && _profile$bannerImage$ !== void 0 ? _profile$bannerImage$ : "",
        fallbackSrc: "/png/profile-banner-fallback.png",
        alt: "Home Banner",
        width: 868,
        height: 290,
        className: "overflow-hidden rounded-lg",
        style: {
          height: "290px",
          objectFit: "cover"
        }
      }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkQ75LDFBTjs.ProfileContentContainer, {
        children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _avatars.AvatarWithPlaceholder, {
          className: "self-start justify-self-center",
          width: 96,
          height: 96,
          src: profile === null || profile === void 0 || (_profile$image = profile.image) === null || _profile$image === void 0 ? void 0 : _profile$image.url
        }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkQ75LDFBTjs.ProfileDescriptionContainer, {
          children: [/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkQ75LDFBTjs.ProfileNameContainer, {
            children: [/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
              className: "justify-self-start sm:col-span-full sm:justify-self-center",
              children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
                component: "h6",
                variant: "h6",
                children: profile === null || profile === void 0 ? void 0 : profile.name
              }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
                variant: "body2",
                color: "text.secondary",
                children: profile !== null && profile !== void 0 && (_profile$urlPath2 = profile.urlPath) !== null && _profile$urlPath2 !== void 0 && _profile$urlPath2.path ? "@".concat(profile.urlPath.path) : ""
              })]
            }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
              className: "flex w-full justify-self-stretch",
              children: [/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
                className: "flex-grow border-r border-dashed border-divider text-center sm:w-full",
                children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
                  component: "h6",
                  variant: "h6",
                  children: formatFollowCount(profile === null || profile === void 0 ? void 0 : profile.followersCount)
                }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
                  variant: "body2",
                  color: "text.secondary",
                  children: "Followers"
                })]
              }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
                className: "flex-grow text-center sm:w-full",
                children: [/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
                  component: "h6",
                  variant: "h6",
                  children: formatFollowCount(profile === null || profile === void 0 ? void 0 : profile.followingCount)
                }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Typography, {
                  variant: "body2",
                  color: "text.secondary",
                  children: "Following"
                })]
              })]
            })]
          }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", {
            className: "prose-caption text-text-secondary",
            children: profile === null || profile === void 0 ? void 0 : profile.biography
          })]
        }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", {
          className: "grid grid-cols-[auto_min-content] gap-3 min-sm:col-start-2 min-sm:grid-cols-[fit-content_min-content] min-sm:justify-end",
          children: [renderProfileUpdatesButtons(), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _material.Button, {
            color: "inherit",
            variant: "soft",
            sx: {
              maxWidth: "fit-content",
              minWidth: "max-content"
            },
            onClick: handleClick,
            children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _icons.ThreeDotsIcon, {})
          }), !smDown && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQ75LDFBTjs.StyledMenu, {
            anchorEl,
            open,
            onClose: handleClose,
            children: menuOptions
          }), smDown && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _drawers.SwipeableDrawer, {
            anchor: "bottom",
            open,
            onClose: handleClose,
            children: menuOptions
          })]
        })]
      })]
    })
  });
};
var ProfileComponent_default = ProfileComponent;



exports.ProfileComponent_default = ProfileComponent_default;
//# sourceMappingURL=chunk-TTCHZ2OD.js.map