import {
  StyledMenuItem
} from "./chunk-UFDYJICI.mjs";
import {
  ProfileItemFragment
} from "./chunk-YTT7MYZX.mjs";

// tmp-babel/profiles/web/profile-popover/ProfilesList/ProfileMenuItem/index.js
import { useCurrentProfile } from "@baseapp-frontend/authentication";
import { AvatarWithPlaceholder } from "@baseapp-frontend/design-system/components/web/avatars";
import { CheckMarkIcon } from "@baseapp-frontend/design-system/components/web/icons";
import { Box, Typography } from "@mui/material";
import { useFragment } from "react-relay";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
function _typeof(o) {
  "@babel/helpers - typeof";
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
    return typeof o2;
  } : function(o2) {
    return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
  }, _typeof(o);
}
function ownKeys(e, r) {
  var t = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var o = Object.getOwnPropertySymbols(e);
    r && (o = o.filter(function(r2) {
      return Object.getOwnPropertyDescriptor(e, r2).enumerable;
    })), t.push.apply(t, o);
  }
  return t;
}
function _objectSpread(e) {
  for (var r = 1; r < arguments.length; r++) {
    var t = null != arguments[r] ? arguments[r] : {};
    r % 2 ? ownKeys(Object(t), true).forEach(function(r2) {
      _defineProperty(e, r2, t[r2]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) {
      Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
    });
  }
  return e;
}
function _defineProperty(e, r, t) {
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
}
function _toPropertyKey(t) {
  var i = _toPrimitive(t, "string");
  return "symbol" == _typeof(i) ? i : i + "";
}
function _toPrimitive(t, r) {
  if ("object" != _typeof(t) || !t) return t;
  var e = t[Symbol.toPrimitive];
  if (void 0 !== e) {
    var i = e.call(t, r || "default");
    if ("object" != _typeof(i)) return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return ("string" === r ? String : Number)(t);
}
var ProfileMenuItem = function ProfileMenuItem2(_ref) {
  var _profile$urlPath, _profile$name, _profile$image$url, _profile$image, _profile$name2;
  var profileRef = _ref.profileRef, onProfileChange = _ref.onProfileChange, _ref$avatarProps = _ref.avatarProps, avatarProps = _ref$avatarProps === void 0 ? {} : _ref$avatarProps, _ref$width = _ref.width, width = _ref$width === void 0 ? 36 : _ref$width, _ref$height = _ref.height, height = _ref$height === void 0 ? 36 : _ref$height;
  var _useCurrentProfile = useCurrentProfile(), currentProfile = _useCurrentProfile.currentProfile;
  var profile = useFragment(ProfileItemFragment, profileRef);
  if (!profile) {
    return null;
  }
  var profileUrlPath = (_profile$urlPath = profile.urlPath) === null || _profile$urlPath === void 0 ? void 0 : _profile$urlPath.path;
  var isActiveProfile = profile.id === (currentProfile === null || currentProfile === void 0 ? void 0 : currentProfile.id);
  return /* @__PURE__ */ _jsxs(StyledMenuItem, {
    tabIndex: 0,
    active: isActiveProfile,
    onClick: function onClick() {
      return onProfileChange(profile);
    },
    "aria-label": "Switch to ".concat((_profile$name = profile.name) !== null && _profile$name !== void 0 ? _profile$name : "this profile"),
    children: [/* @__PURE__ */ _jsx(AvatarWithPlaceholder, _objectSpread({
      width,
      height,
      src: (_profile$image$url = (_profile$image = profile.image) === null || _profile$image === void 0 ? void 0 : _profile$image.url) !== null && _profile$image$url !== void 0 ? _profile$image$url : "",
      alt: "Profile avatar",
      color: "secondary"
    }, avatarProps)), /* @__PURE__ */ _jsxs(Box, {
      display: "flex",
      flexDirection: "column",
      flexGrow: 1,
      overflow: "hidden",
      children: [/* @__PURE__ */ _jsx(Typography, {
        component: "p",
        variant: "subtitle2",
        noWrap: true,
        children: (_profile$name2 = profile.name) !== null && _profile$name2 !== void 0 ? _profile$name2 : ""
      }), profileUrlPath && /* @__PURE__ */ _jsx(Typography, {
        variant: "subtitle2",
        sx: {
          color: "text.secondary"
        },
        noWrap: true,
        children: profileUrlPath
      })]
    }), isActiveProfile && /* @__PURE__ */ _jsx(CheckMarkIcon, {
      sx: {
        fontSize: 24
      }
    })]
  });
};
var ProfileMenuItem_default = ProfileMenuItem;

export {
  ProfileMenuItem_default
};
//# sourceMappingURL=chunk-54XLWLYF.mjs.map