'use strict';

var React = require('react');
var LocalizationContext = require('../../LocalizationContext-8cc9717d.js');
var useSendbirdStateContext = require('../../useSendbirdStateContext.js');
var ChannelSettings_context = require('../context.js');
var ui_ChannelAvatar = require('../../ui/ChannelAvatar.js');
var ui_TextButton = require('../../ui/TextButton.js');
var ui_Label = require('../../index-35633fb6.js');
var ChannelSettings_components_EditDetailsModal = require('./EditDetailsModal.js');
require('../../stringSet-ce782136.js');
require('../../index-d749c4c2.js');
require('../../withSendbird.js');
require('../../_rollupPluginBabelHelpers-acf412a3.js');
require('../../UserProfileContext-d993c96b.js');
require('prop-types');
require('../../uuid-1eceb0c8.js');
require('../../ui/Avatar.js');
require('../../ui/ImageRenderer.js');
require('../../ui/Icon.js');
require('../../utils-d9c99217.js');
require('../../color-5cfb41c7.js');
require('../../ui/Modal.js');
require('react-dom');
require('../../index-8029e07a.js');
require('../../ui/Button.js');
require('../../ui/IconButton.js');
require('../../MediaQueryContext-fad211ad.js');
require('../../ui/Input.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

const ChannelProfile = () => {
  var _state$config, _state$config2, _state$config3;
  const state = useSendbirdStateContext();
  const channelSettingStore = ChannelSettings_context.useChannelSettingsContext();
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  const [showModal, setShowModal] = React.useState(false);
  const userId = state === null || state === void 0 ? void 0 : (_state$config = state.config) === null || _state$config === void 0 ? void 0 : _state$config.userId;
  const theme = (state === null || state === void 0 ? void 0 : (_state$config2 = state.config) === null || _state$config2 === void 0 ? void 0 : _state$config2.theme) || 'light';
  const isOnline = state === null || state === void 0 ? void 0 : (_state$config3 = state.config) === null || _state$config3 === void 0 ? void 0 : _state$config3.isOnline;
  const disabled = !isOnline;
  const {
    channel
  } = channelSettingStore;
  const getChannelName = () => {
    if (channel !== null && channel !== void 0 && channel.name && (channel === null || channel === void 0 ? void 0 : channel.name) !== 'Group Channel') {
      return channel.name;
    }
    if ((channel === null || channel === void 0 ? void 0 : channel.name) === 'Group Channel' || !(channel !== null && channel !== void 0 && channel.name)) {
      return ((channel === null || channel === void 0 ? void 0 : channel.members) || []).map(member => member.nickname || stringSet.NO_NAME).join(', ');
    }
    return stringSet.NO_TITLE;
  };
  return /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-channel-profile"
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-channel-profile--inner"
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-channel-profile__avatar"
  }, /*#__PURE__*/React__default["default"].createElement(ui_ChannelAvatar, {
    channel: channel,
    userId: userId,
    theme: theme,
    width: 80,
    height: 80
  })), /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: "sendbird-channel-profile__title",
    type: ui_Label.LabelTypography.SUBTITLE_2,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, getChannelName()), /*#__PURE__*/React__default["default"].createElement(ui_TextButton, {
    disabled: disabled,
    className: "sendbird-channel-profile__edit",
    onClick: () => {
      if (disabled) {
        return;
      }
      setShowModal(true);
    },
    disableUnderline: true
  }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    type: ui_Label.LabelTypography.BUTTON_1,
    color: disabled ? ui_Label.LabelColors.ONBACKGROUND_2 : ui_Label.LabelColors.PRIMARY
  }, stringSet.CHANNEL_SETTING__PROFILE__EDIT)), showModal && /*#__PURE__*/React__default["default"].createElement(ChannelSettings_components_EditDetailsModal, {
    onCancel: () => setShowModal(false),
    onSubmit: () => setShowModal(false)
  })));
};

module.exports = ChannelProfile;
//# sourceMappingURL=ChannelProfile.js.map
