'use strict';

var React = require('react');
var LocalizationContext = require('../../LocalizationContext-44d2f61b.js');
var ui_Avatar = require('../../ui/Avatar.js');
var ui_Button = require('../../ui/Button.js');
var ui_Modal = require('../../ui/Modal.js');
var ui_Icon = require('../../ui/Icon.js');
var ui_Input = require('../../ui/Input.js');
var ui_Label = require('../../index-2bfd366f.js');
var ui_TextButton = require('../../ui/TextButton.js');
var CreateOpenChannel_context = require('../context.js');
require('../../stringSet-7aebf034.js');
require('../../index-88e8fdfa.js');
require('../../ui/ImageRenderer.js');
require('../../uuid-dee74248.js');
require('prop-types');
require('react-dom');
require('../../index-0a446cca.js');
require('../../ui/IconButton.js');
require('../../_rollupPluginBabelHelpers-21ae158b.js');
require('../../MediaQueryContext-5d311a86.js');
require('../../color-0c04efbd.js');
require('../../useSendbirdStateContext.js');
require('../../withSendbird.js');

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

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

function CreateOpenChannelUI(_ref) {
  let {
    closeModal,
    renderHeader,
    renderProfileInput
  } = _ref;
  const [newFile, setNewFile] = React.useState(null);
  const [currentImage, setCurrentImg] = React.useState(null);
  const inputFormRef = React.useRef(null);
  const inputFileRef = React.useRef(null);
  const inputTextRef = React.useRef(null);
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  const {
    logger,
    createNewOpenChannel
  } = CreateOpenChannel_context.useCreateOpenChannelContext();
  return /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-create-open-channel-ui"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Modal["default"], {
    isFullScreenOnMobile: true,
    titleText: stringSet.CREATE_OPEN_CHANNEL_LIST__TITLE,
    submitText: stringSet.CREATE_OPEN_CHANNEL_LIST__SUBMIT,
    type: ui_Button.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["default"].createElement(React__default["default"].Fragment, null, (renderProfileInput === null || renderProfileInput === void 0 ? void 0 : renderProfileInput()) || /*#__PURE__*/React__default["default"].createElement("form", {
    className: "sendbird-create-open-channel-ui__profile-input",
    ref: inputFormRef,
    onSubmit: e => {
      e.preventDefault();
    }
  }, /*#__PURE__*/React__default["default"].createElement(ui_Input.InputLabel, null, stringSet.CREATE_OPEN_CHANNEL_LIST__SUBTITLE__IMG_SECTION), /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-create-open-channel-ui__profile-input__img-section"
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-create-open-channel-ui__profile-input__img-section__avatar"
  }, currentImage ? /*#__PURE__*/React__default["default"].createElement(ui_Avatar["default"], {
    width: "80px",
    height: "80px",
    src: currentImage
  }) : /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-create-open-channel-ui__profile-input__img-section__avatar--default"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    type: ui_Icon.IconTypes.CHANNELS,
    fillColor: ui_Icon.IconColors.CONTENT,
    width: "46px",
    height: "46px"
  }))), /*#__PURE__*/React__default["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["default"].createElement(ui_TextButton, {
    className: "sendbird-create-open-channel-ui__profile-input__img-section__button",
    onClick: () => inputFileRef.current.click(),
    disableUnderline: true
  }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    type: ui_Label.LabelTypography.BUTTON_1,
    color: ui_Label.LabelColors.PRIMARY
  }, stringSet.CREATE_OPEN_CHANNEL_LIST__SUBTITLE__IMG_UPLOAD))), /*#__PURE__*/React__default["default"].createElement("div", {
    style: {
      marginTop: '20px'
    }
  }, /*#__PURE__*/React__default["default"].createElement(ui_Input.InputLabel, null, stringSet.CREATE_OPEN_CHANNEL_LIST__SUBTITLE__TEXT_SECTION)), /*#__PURE__*/React__default["default"].createElement("div", {
    className: "sendbird-create-open-channel-ui__profile-input__name-section"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Input["default"], {
    name: "sendbird-create-open-channel-ui__profile-input__name-section__input",
    ref: inputTextRef,
    placeHolder: stringSet.CREATE_OPEN_CHANNEL_LIST__SUBTITLE__TEXT_PLACE_HOLDER
  }))))));
}

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