import React__default, { useContext } from 'react';
import { a as LocalizationContext } from '../LocalizationContext-1701e5c8.js';
import { a as UserProfileContext } from '../UserProfileContext-74e9a128.js';
import { getCreateGroupChannel } from '../sendbirdSelectors.js';
import Avatar from './Avatar.js';
import { L as Label, a as LabelTypography, b as LabelColors } from '../index-f50d7ab0.js';
import Button, { ButtonTypes } from './Button.js';
import useSendbirdStateContext from '../useSendbirdStateContext.js';
import '../stringSet-e9bb0333.js';
import '../index-ff8f2f61.js';
import 'prop-types';
import '../_rollupPluginBabelHelpers-cc035350.js';
import '../topics-0b30f52b.js';
import '../utils-05aa9060.js';
import './ImageRenderer.js';
import './Icon.js';
import '../uuid-8b344dd2.js';
import '../withSendbird.js';

function UserProfile(_ref) {
  var _store$config, _store$config2;
  let {
    user,
    currentUserId,
    disableMessaging = false,
    onSuccess
  } = _ref;
  const store = useSendbirdStateContext();
  const createChannel = getCreateGroupChannel(store);
  const logger = store === null || store === void 0 ? void 0 : (_store$config = store.config) === null || _store$config === void 0 ? void 0 : _store$config.logger;
  const {
    stringSet
  } = useContext(LocalizationContext);
  const currentUserId_ = currentUserId || (store === null || store === void 0 ? void 0 : (_store$config2 = store.config) === null || _store$config2 === void 0 ? void 0 : _store$config2.userId);
  // @ts-ignore
  const {
    onUserProfileMessage
  } = useContext(UserProfileContext);
  return /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird__user-profile"
  }, /*#__PURE__*/React__default.createElement("section", {
    className: "sendbird__user-profile-avatar"
  }, /*#__PURE__*/React__default.createElement(Avatar, {
    height: "80px",
    width: "80px",
    src: user === null || user === void 0 ? void 0 : user.profileUrl
  })), /*#__PURE__*/React__default.createElement("section", {
    className: "sendbird__user-profile-name"
  }, /*#__PURE__*/React__default.createElement(Label, {
    type: LabelTypography.H_2,
    color: LabelColors.ONBACKGROUND_1
  }, (user === null || user === void 0 ? void 0 : user.nickname) || stringSet.NO_NAME)), (user === null || user === void 0 ? void 0 : user.userId) !== currentUserId_ && !disableMessaging && /*#__PURE__*/React__default.createElement("section", {
    className: "sendbird__user-profile-message"
  }, /*#__PURE__*/React__default.createElement(Button, {
    type: ButtonTypes.SECONDARY,
    onClick: () => {
      // Create 1:1 channel
      const params = {
        isDistinct: false,
        invitedUserIds: [user === null || user === void 0 ? void 0 : user.userId],
        operatorUserIds: [currentUserId_]
      };
      onSuccess();
      createChannel(params).then(groupChannel => {
        logger.info('UserProfile, channel create', groupChannel);
        if (typeof onUserProfileMessage === 'function') {
          onUserProfileMessage === null || onUserProfileMessage === void 0 ? void 0 : onUserProfileMessage(groupChannel);
        }
      });
    }
  }, stringSet.USER_PROFILE__MESSAGE)), /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird__user-profile-separator"
  }), /*#__PURE__*/React__default.createElement("section", {
    className: "sendbird__user-profile-userId"
  }, /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird__user-profile-userId--label",
    type: LabelTypography.CAPTION_2,
    color: LabelColors.ONBACKGROUND_2
  }, stringSet.USER_PROFILE__USER_ID), /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird__user-profile-userId--value",
    type: LabelTypography.BODY_1,
    color: LabelColors.ONBACKGROUND_1
  }, user === null || user === void 0 ? void 0 : user.userId)));
}

export { UserProfile as default };
//# sourceMappingURL=UserProfile.js.map
