'use strict';

var React = require('react');
var MessageSearch_components_MessageSearchUI = require('./MessageSearch/components/MessageSearchUI.js');
var LocalizationContext = require('./LocalizationContext-af96cf5f.js');
var ui_Icon = require('./ui/Icon.js');
var ui_IconButton = require('./ui/IconButton.js');
var ui_Label = require('./index-73643285.js');
var ui_Loader = require('./ui/Loader.js');
var MessageSearch_context = require('./MessageSearch/context.js');
require('./ui/MessageSearchItem.js');
require('./index-f65677b1.js');
require('./index-83d1d15e.js');
require('./index-6cb4a530.js');
require('./index-4ee95667.js');
require('./ui/Avatar.js');
require('./ui/ImageRenderer.js');
require('./uuid-0b4ed44c.js');
require('./index-ff8ea47f.js');
require('./ui/MessageSearchFileItem.js');
require('./index-f2146bae.js');
require('./_rollupPluginBabelHelpers-c5955c81.js');
require('./utils/message/getOutgoingMessageState.js');
require('./stringSet-68748705.js');
require('prop-types');
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);

const COMPONENT_CLASS_NAME = 'sendbird-message-search-pannel';
function MessageSearchPannel(props) {
  const {
    channelUrl,
    onResultClick,
    onCloseClick,
    messageSearchQuery,
    renderPlaceHolderError,
    renderPlaceHolderLoading,
    renderPlaceHolderNoString,
    renderPlaceHolderEmptyList,
    renderSearchItem
  } = props;
  const [searchString, setSearchString] = React.useState('');
  const [inputString, setInputString] = React.useState('');
  const [loading, setLoading] = React.useState(false);
  const {
    stringSet
  } = React.useContext(LocalizationContext.LocalizationContext);
  let timeout = null;
  React.useEffect(() => {
    if (timeout) {
      clearTimeout(timeout);
    }
    timeout = setTimeout(() => {
      setSearchString(inputString);
      setLoading(true);
      timeout = null;
    }, 500);
  }, [inputString]);
  const handleOnChangeInputString = e => {
    setInputString(e.target.value);
  };
  const handleOnResultLoaded = () => {
    setLoading(false);
  };
  const handleOnClickResetStringButton = e => {
    e.stopPropagation();
    setInputString('');
    setSearchString('');
  };
  return /*#__PURE__*/React__default["default"].createElement("div", {
    className: COMPONENT_CLASS_NAME
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: `${COMPONENT_CLASS_NAME}__header`
  }, /*#__PURE__*/React__default["default"].createElement(ui_Label.Label, {
    className: `${COMPONENT_CLASS_NAME}__header__title`,
    type: ui_Label.LabelTypography.H_2,
    color: ui_Label.LabelColors.ONBACKGROUND_1
  }, stringSet.SEARCH_IN_CHANNEL), /*#__PURE__*/React__default["default"].createElement(ui_IconButton, {
    className: `${COMPONENT_CLASS_NAME}__header__close-button`,
    width: "32px",
    height: "32px",
    onClick: onCloseClick
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    type: ui_Icon.IconTypes.CLOSE,
    fillColor: ui_Icon.IconColors.ON_BACKGROUND_1,
    width: "22px",
    height: "22px"
  }))), /*#__PURE__*/React__default["default"].createElement("div", {
    className: `${COMPONENT_CLASS_NAME}__input`
  }, /*#__PURE__*/React__default["default"].createElement("div", {
    className: `${COMPONENT_CLASS_NAME}__input__container`
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    className: `${COMPONENT_CLASS_NAME}__input__container__search-icon`,
    type: ui_Icon.IconTypes.SEARCH,
    fillColor: ui_Icon.IconColors.ON_BACKGROUND_3,
    width: "24px",
    height: "24px"
  }), /*#__PURE__*/React__default["default"].createElement("input", {
    className: `${COMPONENT_CLASS_NAME}__input__container__input-area`,
    placeholder: stringSet.SEARCH,
    value: inputString,
    onChange: handleOnChangeInputString
  }), inputString && loading && /*#__PURE__*/React__default["default"].createElement(ui_Loader, {
    className: `${COMPONENT_CLASS_NAME}__input__container__spinner`,
    width: "20px",
    height: "20px"
  }, /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    type: ui_Icon.IconTypes.SPINNER,
    fillColor: ui_Icon.IconColors.PRIMARY,
    width: "20px",
    height: "20px"
  })), !loading && inputString && /*#__PURE__*/React__default["default"].createElement(ui_Icon["default"], {
    className: `${COMPONENT_CLASS_NAME}__input__container__reset-input-button`,
    type: ui_Icon.IconTypes.REMOVE,
    fillColor: ui_Icon.IconColors.ON_BACKGROUND_3,
    width: "20px",
    height: "20px",
    onClick: handleOnClickResetStringButton
  }))), /*#__PURE__*/React__default["default"].createElement("div", {
    className: `${COMPONENT_CLASS_NAME}__message-search`
  }, /*#__PURE__*/React__default["default"].createElement(MessageSearch_context.MessageSearchProvider, {
    channelUrl: channelUrl,
    searchString: searchString,
    onResultClick: onResultClick,
    onResultLoaded: handleOnResultLoaded,
    messageSearchQuery: messageSearchQuery
  }, /*#__PURE__*/React__default["default"].createElement(MessageSearch_components_MessageSearchUI.MessageSearchUI, {
    renderPlaceHolderError: renderPlaceHolderError,
    renderPlaceHolderLoading: renderPlaceHolderLoading,
    renderPlaceHolderNoString: renderPlaceHolderNoString,
    renderPlaceHolderEmptyList: renderPlaceHolderEmptyList,
    renderSearchItem: renderSearchItem
  }))));
}

module.exports = MessageSearchPannel;
//# sourceMappingURL=MessageSearch.js.map
