import React__default, { useContext, useState } from 'react';
import { a as LocalizationContext } from '../../LocalizationContext-57b46f6c.js';
import useSendbirdStateContext from '../../useSendbirdStateContext.js';
import { useChannelSettingsContext } from '../context.js';
import ChannelAvatar from '../../ui/ChannelAvatar.js';
import TextButton from '../../ui/TextButton.js';
import { L as Label, a as LabelTypography, b as LabelColors } from '../../index-4023d1b2.js';
import EditDetails from './EditDetailsModal.js';
import '../../stringSet-7a8ce1ce.js';
import '../../index-865112db.js';
import '../../withSendbird.js';
import '../../_rollupPluginBabelHelpers-0bc76382.js';
import '../../UserProfileContext-29074346.js';
import 'prop-types';
import '../../uuid-1f1bbd9c.js';
import '../../ui/Avatar.js';
import '../../ui/ImageRenderer.js';
import '../../ui/Icon.js';
import '../../utils-6f2bb331.js';
import '../../color-2ed716e6.js';
import '../../ui/Modal.js';
import 'react-dom';
import '../../index-7bff4ce0.js';
import '../../ui/Button.js';
import '../../ui/IconButton.js';
import '../../MediaQueryContext-fbe7af77.js';
import '../../ui/Input.js';

const ChannelProfile = () => {
  var _state$config, _state$config2, _state$config3;
  const state = useSendbirdStateContext();
  const channelSettingStore = useChannelSettingsContext();
  const {
    stringSet
  } = useContext(LocalizationContext);
  const [showModal, setShowModal] = 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.createElement("div", {
    className: "sendbird-channel-profile"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-profile--inner"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-channel-profile__avatar"
  }, /*#__PURE__*/React__default.createElement(ChannelAvatar, {
    channel: channel,
    userId: userId,
    theme: theme,
    width: 80,
    height: 80
  })), /*#__PURE__*/React__default.createElement(Label, {
    className: "sendbird-channel-profile__title",
    type: LabelTypography.SUBTITLE_2,
    color: LabelColors.ONBACKGROUND_1
  }, getChannelName()), /*#__PURE__*/React__default.createElement(TextButton, {
    disabled: disabled,
    className: "sendbird-channel-profile__edit",
    onClick: () => {
      if (disabled) {
        return;
      }
      setShowModal(true);
    },
    disableUnderline: true
  }, /*#__PURE__*/React__default.createElement(Label, {
    type: LabelTypography.BUTTON_1,
    color: disabled ? LabelColors.ONBACKGROUND_2 : LabelColors.PRIMARY
  }, stringSet.CHANNEL_SETTING__PROFILE__EDIT)), showModal && /*#__PURE__*/React__default.createElement(EditDetails, {
    onCancel: () => setShowModal(false),
    onSubmit: () => setShowModal(false)
  })));
};

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