import React__default, { useState, useRef, useContext } from 'react';
import { a as LocalizationContext } from '../../LocalizationContext-b2390bf8.js';
import Avatar from '../../ui/Avatar.js';
import { ButtonTypes } from '../../ui/Button.js';
import Modal from '../../ui/Modal.js';
import Icon, { IconTypes, IconColors } from '../../ui/Icon.js';
import Input, { InputLabel } from '../../ui/Input.js';
import { L as Label, a as LabelTypography, b as LabelColors } from '../../index-4372fcec.js';
import TextButton from '../../ui/TextButton.js';
import { useCreateOpenChannelContext } from '../context.js';
import '../../stringSet-eefbc798.js';
import '../../index-67135027.js';
import '../../ui/ImageRenderer.js';
import '../../uuid-a79b5ba8.js';
import 'prop-types';
import 'react-dom';
import '../../index-896545a0.js';
import '../../ui/IconButton.js';
import '../../_rollupPluginBabelHelpers-4f8ebde4.js';
import '../../MediaQueryContext-b4904a2e.js';
import '../../color-9519a526.js';
import '../../useSendbirdStateContext.js';
import '../../withSendbird.js';

function CreateOpenChannelUI(_ref) {
  let {
    closeModal,
    renderHeader,
    renderProfileInput
  } = _ref;
  const [newFile, setNewFile] = useState(null);
  const [currentImage, setCurrentImg] = useState(null);
  const inputFormRef = useRef(null);
  const inputFileRef = useRef(null);
  const inputTextRef = useRef(null);
  const {
    stringSet
  } = useContext(LocalizationContext);
  const {
    logger,
    createNewOpenChannel
  } = useCreateOpenChannelContext();
  return /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-create-open-channel-ui"
  }, /*#__PURE__*/React__default.createElement(Modal, {
    isFullScreenOnMobile: true,
    titleText: stringSet.CREATE_OPEN_CHANNEL_LIST__TITLE,
    submitText: stringSet.CREATE_OPEN_CHANNEL_LIST__SUBMIT,
    type: ButtonTypes.PRIMARY,
    onCancel: closeModal,
    renderHeader: renderHeader,
    onSubmit: () => {
      var _inputTextRef$current;
      const channelName = inputTextRef === null || inputTextRef === void 0 ? void 0 : (_inputTextRef$current = inputTextRef.current) === null || _inputTextRef$current === void 0 ? void 0 : _inputTextRef$current.value;
      if (!channelName) {
        logger.warning('CreateOpenChannelUI: You should fill the channel name');
        return;
      }
      createNewOpenChannel({
        name: channelName,
        coverUrlOrImage: newFile
      });
      closeModal();
    }
  }, /*#__PURE__*/React__default.createElement(React__default.Fragment, null, (renderProfileInput === null || renderProfileInput === void 0 ? void 0 : renderProfileInput()) || /*#__PURE__*/React__default.createElement("form", {
    className: "sendbird-create-open-channel-ui__profile-input",
    ref: inputFormRef,
    onSubmit: e => {
      e.preventDefault();
    }
  }, /*#__PURE__*/React__default.createElement(InputLabel, null, stringSet.CREATE_OPEN_CHANNEL_LIST__SUBTITLE__IMG_SECTION), /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-create-open-channel-ui__profile-input__img-section"
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-create-open-channel-ui__profile-input__img-section__avatar"
  }, currentImage ? /*#__PURE__*/React__default.createElement(Avatar, {
    width: "80px",
    height: "80px",
    src: currentImage
  }) : /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-create-open-channel-ui__profile-input__img-section__avatar--default"
  }, /*#__PURE__*/React__default.createElement(Icon, {
    type: IconTypes.CHANNELS,
    fillColor: IconColors.CONTENT,
    width: "46px",
    height: "46px"
  }))), /*#__PURE__*/React__default.createElement("input", {
    className: "sendbird-create-open-channel-ui__profile-input__img-section__input",
    ref: inputFileRef,
    type: "file",
    accept: "image/gif, image/jpeg, image/png",
    style: {
      display: 'none'
    },
    onChange: e => {
      setCurrentImg(URL.createObjectURL(e.target.files[0]));
      setNewFile(e.target.files[0]);
      inputFileRef.current.value = '';
    }
  }), /*#__PURE__*/React__default.createElement(TextButton, {
    className: "sendbird-create-open-channel-ui__profile-input__img-section__button",
    onClick: () => inputFileRef.current.click(),
    disableUnderline: true
  }, /*#__PURE__*/React__default.createElement(Label, {
    type: LabelTypography.BUTTON_1,
    color: LabelColors.PRIMARY
  }, stringSet.CREATE_OPEN_CHANNEL_LIST__SUBTITLE__IMG_UPLOAD))), /*#__PURE__*/React__default.createElement("div", {
    style: {
      marginTop: '20px'
    }
  }, /*#__PURE__*/React__default.createElement(InputLabel, null, stringSet.CREATE_OPEN_CHANNEL_LIST__SUBTITLE__TEXT_SECTION)), /*#__PURE__*/React__default.createElement("div", {
    className: "sendbird-create-open-channel-ui__profile-input__name-section"
  }, /*#__PURE__*/React__default.createElement(Input, {
    name: "sendbird-create-open-channel-ui__profile-input__name-section__input",
    ref: inputTextRef,
    placeHolder: stringSet.CREATE_OPEN_CHANNEL_LIST__SUBTITLE__TEXT_PLACE_HOLDER
  }))))));
}

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