import React__default, { useContext, useState } from 'react';
import { a as LocalizationContext } from '../../LocalizationContext-426f3d58.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-4105bc4d.js';
import EditDetails from './EditDetailsModal.js';
import '../../stringSet-a62108b2.js';
import '../../index-90420b99.js';
import '../../withSendbird.js';
import '../../_rollupPluginBabelHelpers-a69fd1ce.js';
import '../../UserProfileContext-a59f0533.js';
import 'prop-types';
import '../../uuid-2e8efc75.js';
import '../../ui/Avatar.js';
import '../../ui/ImageRenderer.js';
import '../../ui/Icon.js';
import '../../utils-20147203.js';
import '../../color-e708f53d.js';
import '../../ui/Modal.js';
import 'react-dom';
import '../../index-3e548496.js';
import '../../ui/Button.js';
import '../../ui/IconButton.js';
import '../../MediaQueryContext-b531adc9.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
