"use strict";

exports.__esModule = true;
exports.default = void 0;

require("core-js/modules/es6.object.assign");

require("core-js/modules/web.dom.iterable");

require("core-js/modules/es6.array.iterator");

require("core-js/modules/es6.object.keys");

require("core-js/modules/es7.array.includes");

require("core-js/modules/es6.string.includes");

require("core-js/modules/es6.regexp.match");

require("core-js/modules/es6.regexp.split");

require("core-js/modules/es6.regexp.constructor");

require("core-js/modules/es6.regexp.replace");

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _lodash = require("lodash");

var _ = require("./..");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }

/**
 * @category containers
 * @component list-item
 * @variations collab-ui-react
 */
var SpaceListItem =
/*#__PURE__*/
function (_React$PureComponent) {
  _inheritsLoose(SpaceListItem, _React$PureComponent);

  function SpaceListItem() {
    var _this;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _React$PureComponent.call.apply(_React$PureComponent, [this].concat(args)) || this;
    _this.state = {
      id: _this.props.id || (0, _lodash.uniqueId)('cui-space-list-item-')
    };
    return _this;
  }

  var _proto = SpaceListItem.prototype;

  _proto.render = function render() {
    var _this$props = this.props,
        attachments = _this$props.attachments,
        className = _this$props.className,
        childrenLeft = _this$props.childrenLeft,
        childrenRight = _this$props.childrenRight,
        header = _this$props.header,
        headerSecondary = _this$props.headerSecondary,
        highlightColor = _this$props.highlightColor,
        isAlertOn = _this$props.isAlertOn,
        isBold = _this$props.isBold,
        isDecrypting = _this$props.isDecrypting,
        isMentioned = _this$props.isMentioned,
        isMuted = _this$props.isMuted,
        isOverview = _this$props.isOverview,
        isUnread = _this$props.isUnread,
        resultRight = _this$props.resultRight,
        searchTerm = _this$props.searchTerm,
        subheader = _this$props.subheader,
        title = _this$props.title,
        type = _this$props.type,
        props = _objectWithoutPropertiesLoose(_this$props, ["attachments", "className", "childrenLeft", "childrenRight", "header", "headerSecondary", "highlightColor", "isAlertOn", "isBold", "isDecrypting", "isMentioned", "isMuted", "isOverview", "isUnread", "resultRight", "searchTerm", "subheader", "title", "type"]);

    var id = this.state.id;
    var getTitle = !title && typeof header === 'string' ? header : title;

    var getIcon = function getIcon() {
      if (isMuted) {
        return _react.default.createElement(_.Icon, {
          color: "$white-60",
          name: "alert-muted_12"
        });
      } else if (isUnread) {
        return _react.default.createElement("i", {
          style: {
            fontSize: '12px',
            color: '#07C1E4'
          },
          className: "icon icon-unread-badge_16"
        });
      } else if (isMentioned) {
        return _react.default.createElement(_.Icon, {
          color: "blue",
          name: "mention_12"
        });
      } else if (isAlertOn) {
        return _react.default.createElement(_.Icon, {
          color: "$white-60",
          name: "alert_12"
        });
      }

      return null;
    };

    var leftSection = isOverview ? _react.default.createElement(_.Avatar, {
      isOverview: true,
      icon: _react.default.createElement(_.Icon, {
        name: "handset_24"
      })
    }) : childrenLeft;

    var rightSection = _react.default.createElement(_.ListItemSection, {
      key: "child-2",
      position: "right"
    }, childrenRight ? childrenRight : getIcon());

    var addEscapes = function addEscapes(text) {
      return text && text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") || '';
    };

    var highlightSubheader = function highlightSubheader() {
      var escapedTerm = addEscapes(searchTerm);
      var re = new RegExp("(" + escapedTerm + ")", 'gi');
      return searchTerm && typeof subheader === 'string' ? subheader.split(re).map(function (ele, idx) {
        return ele.match(re) ? _react.default.createElement("span", {
          key: "subheader-" + idx,
          className: "cui-list-item__subheader--highlight",
          style: {
            color: highlightColor
          }
        }, ele) : ele;
      }) : subheader;
    };

    var highlightHeader = function highlightHeader() {
      var escapedTerm = addEscapes(searchTerm);
      var re = new RegExp("(" + escapedTerm + ")", 'gi');
      return searchTerm && typeof header === 'string' ? header.split(re).map(function (ele, idx) {
        return ele.match(re) ? _react.default.createElement("span", {
          key: "header-" + idx,
          className: "cui-list-item__header--highlight",
          style: {
            color: highlightColor
          }
        }, ele) : ele;
      }) : header;
    };

    var getHeader = ['search', 'filter', 'flag', 'filter-search'].includes(type) ? [_react.default.createElement("span", {
      key: "header-0",
      className: "cui-list-item__header-main"
    }, header), headerSecondary && _react.default.createElement("span", {
      className: "cui-list-item__header-secondary",
      key: "header-1"
    }, headerSecondary)] : highlightHeader();
    var children = [_react.default.createElement(_.ListItemSection, {
      key: "child-0",
      position: "left"
    }, leftSection || _react.default.createElement(_.Avatar, {
      title: "NA"
    })), _react.default.createElement(_.ListItemSection, {
      key: "child-1",
      position: "center"
    }, _react.default.createElement("div", {
      className: 'cui-list-item__header' + ("" + ((searchTerm || isOverview) && " cui-list-item__header--overview" || '')) + ("" + (isDecrypting && " cui-decrypting" || ''))
    }, getHeader), ['search', 'filter', 'flag', 'filter-search'].includes(type) ? _react.default.createElement(_.ListItemSection, {
      position: "center",
      className: "cui-list-item__result-container"
    }, ['flag'].includes(type) ? _react.default.createElement(_.ListItemSection, {
      position: "center",
      key: "attachment-line-1",
      className: "cui-list-item__attachment"
    }, _react.default.createElement("div", {
      className: "cui-list-item__attachment--top"
    }, _react.default.createElement(_.ListItemSection, {
      position: "center",
      className: "cui-list-item__attachment--top-left"
    }, highlightSubheader(subheader)), resultRight && _react.default.createElement(_.ListItemSection, {
      position: "right",
      className: "cui-list-item__attachment--top-right"
    }, resultRight)), attachments && attachments.length && _react.default.createElement("div", {
      className: "cui-list-item__attachment--bottom"
    }, attachments[0])) : _react.default.createElement("div", {
      className: "cui-list-item__result"
    }, highlightSubheader(subheader))) : _react.default.createElement("div", {
      className: "cui-list-item__subheader" + ("" + (isDecrypting && " cui-decrypting" || ''))
    }, subheader))].concat(!type ? [rightSection] : []);
    return _react.default.createElement(_.ListItem, _extends({
      className: "" + (isBold && " cui-list-item--unread" || '') + ("" + (type && " cui-list-item--space-" + type || '')) + ("" + (className && " " + className || '')),
      id: id,
      title: getTitle,
      type: "space"
    }, props), children);
  };

  return SpaceListItem;
}(_react.default.PureComponent);

SpaceListItem.propTypes = {
  /** @prop SpaceListItem Attachment Array | null */
  attachments: _propTypes.default.arrayOf(_propTypes.default.node),

  /** @prop Children nodes to render for left section | null */
  childrenLeft: _propTypes.default.node,

  /** @prop Children nodes to render for right section | null */
  childrenRight: _propTypes.default.node,

  /** @prop Optional HTML class string | '' */
  className: _propTypes.default.string,

  /** @prop ListItem header node */
  header: _propTypes.default.node.isRequired,

  /** @prop Secondary header for center section | '' */
  headerSecondary: _propTypes.default.string,

  /** @prop Highlight Color for Regex | '' */
  highlightColor: _propTypes.default.string,

  /** @prop HTML ID for SpaceListItem | '' */
  id: _propTypes.default.string,

  /** @prop Determines if SpaceListItem's Alert is on | false */
  isAlertOn: _propTypes.default.bool,

  /** @prop Determines if SpaceListItem is Bolded | false */
  isBold: _propTypes.default.bool,

  /** @prop Determines if SpaceListItem decrypting | false */
  isDecrypting: _propTypes.default.bool,

  /** @prop Determines if SpaceListItem has been mentioned | false */
  isMentioned: _propTypes.default.bool,

  /** @prop Determines if SpaceListItem has been muted | false */
  isMuted: _propTypes.default.bool,

  /** @prop Determines if SpaceListItem is an Overview item | false */
  isOverview: _propTypes.default.bool,

  /** @prop Determines if SpaceListItem is unread | false */
  isUnread: _propTypes.default.bool,

  /** @prop Children node for result right section | null */
  resultRight: _propTypes.default.node,

  /** @prop Word used for search | '' */
  searchTerm: _propTypes.default.string,

  /** @prop SpaceListItem subheader node | ''s */
  subheader: _propTypes.default.node,

  /** @prop SpaceListItem title | '' */
  title: _propTypes.default.string,

  /** @prop SpaceListItem type | '' */
  type: _propTypes.default.oneOf(['', 'filter', 'filter-search', 'filter-summary', 'flag', 'search'])
};
SpaceListItem.defaultProps = {
  attachments: null,
  childrenLeft: null,
  childrenRight: null,
  className: '',
  headerSecondary: '',
  highlightColor: '',
  id: '',
  isAlertOn: false,
  isBold: false,
  isDecrypting: false,
  isMentioned: false,
  isMuted: false,
  isOverview: false,
  isUnread: false,
  resultRight: null,
  searchTerm: '',
  subheader: '',
  title: '',
  type: ''
};
SpaceListItem.displayName = 'SpaceListItem';
var _default = SpaceListItem;
/**
* @name Space List
*
* @category containers
* @component list-item
* @section space
*
* @js
*
import {
  Icon,
  List,
  ListItemHeader,
  SpaceListItem,
} from '@collab-ui/react';
import { NavLink } from 'react-router-dom';

export default class SpaceListExamples extends React.PureComponent {

  render() {
    const anchorNode = <NavLink to='/containers/list-item' />;
    return(
      <div className="medium-4 columns">
        <List style={{backgroundColor: 'black'}}>
          <SpaceListItem isOverview header='Overview Item' />
          <SpaceListItem header='Header Only'/>
          <SpaceListItem header='Bold Unread' isBold isUnread/>
          <SpaceListItem header='Bold Mentioned' isBold isMentioned/>
          <SpaceListItem header='isAlertOn' isAlertOn/>
          <SpaceListItem header='isMuted' isMuted/>
          <SpaceListItem header='Disabled' subheader='subheader' disabled/>
          <SpaceListItem header='Subheader as Node' subheader={<span style={{color: '#98D5CA'}}>Marketing</span>}/>
          <ListItemHeader header='List Header-Type(space)' children={<a>More</a>} type='space'/>
          <SpaceListItem header='Header with SearchTerm' searchTerm='search'/>
          <SpaceListItem header='Both Headers w/ SearchTerm' subheader='Searchable subheader' searchTerm='search'/>
          <SpaceListItem header='Subheader(node)-searchTerm' subheader={<span style={{color: '#D7ABE1'}}>Searching</span>} searchTerm='search'/>
          <SpaceListItem header='Type(search)' headerSecondary='16:00' subheader='HighlightColor changes search color' searchTerm='search' type='search' highlightColor='white'/>
          <SpaceListItem header='Type(filter)' headerSecondary='12/03/2018' subheader='headerSecondary=string' searchTerm='Barbara' type='filter' />
          <SpaceListItem header='Type(filter-search)' headerSecondary='12/03/2018' subheader='For search after a (filter)' type='filter-search' searchTerm='(filter)'/>
          <SpaceListItem header='Type(filter-summary) (8)' type='filter-summary' childrenLeft={<Icon name='alert_12' />}/>
          <SpaceListItem header='Type(flag)-attachments' attachments={[<span><Icon name='document_12' />  <span>Ideas.pdf</span></span>]} subheader='resultRight=node, attachments=[node]' headerSecondary='12/03/2018' type='flag' resultRight={<Icon name='flag-active_12'/>}/>
          <SpaceListItem header='Type(flag)' subheader='header&subheader=node' headerSecondary='08/03/2018' type='flag' resultRight={<Icon name='flag-active_12'/>}/>
        </List>
      </div>
    );
  }
}
**/

/**
* @name Contrast Space List
*
* @category containers
* @component list-item
* @section space-contrast
*
* @js
*
import {
  Icon,
  List,
  ListItemHeader,
  SpaceListItem,
} from '@collab-ui/react';
import { NavLink } from 'react-router-dom';

export default class SpaceListExamples extends React.PureComponent {

  render() {
    const anchorNode = <NavLink to='/containers/list-item' />;
    return(
      <div className="medium-4 columns">
        <div className="cui--contrast">
          <List style={{backgroundColor: 'black'}}>
            <SpaceListItem isOverview header='Overview Item' />
            <SpaceListItem header='Header Only'/>
            <SpaceListItem header='Bold Unread' isBold isUnread/>
            <SpaceListItem header='Bold Mentioned' isBold isMentioned/>
            <SpaceListItem header='isAlertOn' isAlertOn/>
            <SpaceListItem header='isMuted' isMuted/>
            <SpaceListItem header='Disabled' subheader='subheader' disabled/>
            <SpaceListItem header='Subheader as Node' subheader={<span style={{color: '#98D5CA'}}>Marketing</span>}/>
            <ListItemHeader header='List Header-Type(space)' children={<a>More</a>} type='space'/>
            <SpaceListItem header='Header with SearchTerm' searchTerm='search'/>
            <SpaceListItem header='Both Headers w/ SearchTerm' subheader='Searchable subheader' searchTerm='search'/>
            <SpaceListItem header='Subheader(node)-searchTerm' subheader={<span style={{color: '#D7ABE1'}}>Searching</span>} searchTerm='search'/>
            <SpaceListItem header='Type(search)' headerSecondary='16:00' subheader='HighlightColor changes search color' searchTerm='search' type='search' highlightColor='white'/>
            <SpaceListItem header='Type(filter)' headerSecondary='12/03/2018' subheader='headerSecondary=string' searchTerm='Barbara' type='filter' />
            <SpaceListItem header='Type(filter-search)' headerSecondary='12/03/2018' subheader='For search after a (filter)' type='filter-search' searchTerm='(filter)'/>
            <SpaceListItem header='Type(filter-summary) (8)' type='filter-summary' childrenLeft={<Icon name='alert_12' />}/>
            <SpaceListItem header='Type(flag)-attachments' attachments={[<span><Icon name='document_12' />  <span>Ideas.pdf</span></span>]} subheader='resultRight=node, attachments=[node]' headerSecondary='12/03/2018' type='flag' resultRight={<Icon name='flag-active_12'/>}/>
            <SpaceListItem header='Type(flag)' subheader='header&subheader=node' headerSecondary='08/03/2018' type='flag' resultRight={<Icon name='flag-active_12'/>}/>
          </List>
        </div>
      </div>
    );
  }
}
**/

exports.default = _default;