import React__default, { useContext, useState } from 'react';
import { a as LocalizationContext } from '../../LocalizationContext-1701e5c8.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-f50d7ab0.js';
import EditDetails from './EditDetailsModal.js';
import '../../stringSet-e9bb0333.js';
import '../../index-ff8f2f61.js';
import '../../withSendbird.js';
import '../../_rollupPluginBabelHelpers-cc035350.js';
import '../../UserProfileContext-74e9a128.js';
import 'prop-types';
import '../../uuid-8b344dd2.js';
import '../../ui/Avatar.js';
import '../../ui/ImageRenderer.js';
import '../../ui/Icon.js';
import '../../utils-cd7ab927.js';
import '../../color-ea3bf5b8.js';
import '../../ui/Modal.js';
import 'react-dom';
import '../../index-44c86e58.js';
import '../../ui/Button.js';
import '../../ui/IconButton.js';
import '../../MediaQueryContext-e5b401d0.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
