"use strict";

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

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/es6.object.assign");

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

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

var _ChatContent = _interopRequireDefault(require("./ChatContent"));

var _FileContent = _interopRequireDefault(require("./FileContent"));

var _IconContent = _interopRequireDefault(require("./IconContent"));

var _lodash = require("lodash");

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; }

var ContentItem =
/*#__PURE__*/
function (_React$PureComponent) {
  _inheritsLoose(ContentItem, _React$PureComponent);

  function ContentItem() {
    return _React$PureComponent.apply(this, arguments) || this;
  }

  var _proto = ContentItem.prototype;

  _proto.render = function render() {
    var _this$props = this.props,
        actionNode = _this$props.actionNode,
        aspect = _this$props.aspect,
        className = _this$props.className,
        content = _this$props.content,
        failedText = _this$props.failedText,
        fileSize = _this$props.fileSize,
        height = _this$props.height,
        icon = _this$props.icon,
        isProtected = _this$props.isProtected,
        loading = _this$props.loading,
        loadingText = _this$props.loadingText,
        style = _this$props.style,
        subtitle = _this$props.subtitle,
        title = _this$props.title,
        type = _this$props.type,
        width = _this$props.width,
        props = _objectWithoutPropertiesLoose(_this$props, ["actionNode", "aspect", "className", "content", "failedText", "fileSize", "height", "icon", "isProtected", "loading", "loadingText", "style", "subtitle", "title", "type", "width"]);

    var otherProps = (0, _lodash.omit)(Object.assign({}, props), ['gifIcon']);

    var findAspect = function findAspect(width, height) {
      if (width && height) {
        var aspectRatioObj = {
          1: 'oneOne',
          .75: 'threeFour',
          .66: 'twoThree',
          .4: 'tall',
          4.35: 'wide',
          1.33: 'fourThree',
          1.5: 'threeTwo',
          1.78: 'sixteenNine'
        };
        var providedAspectRatio = width / height;
        var closestAspectRatio = Object.keys(aspectRatioObj).reduce(function (prev, curr) {
          return Math.abs(curr - providedAspectRatio) < Math.abs(prev - providedAspectRatio) ? curr : prev;
        });
        return aspectRatioObj[closestAspectRatio];
      }

      return type === 'chat' ? 'sixteenNine' : 'threeTwo';
    };

    var chosenItem = function chosenItem() {
      if (failedText && type === 'chat') {
        return _react.default.createElement("div", {
          className: 'cui-content cui-content--failed' + ("" + (className && " " + className || ''))
        }, _react.default.createElement("div", {
          className: "cui-content--failed-container"
        }, _react.default.createElement("i", {
          className: "icon icon-warning_28 cui-content--failed-warning"
        }), _react.default.createElement("p", {
          className: "cui-content--failed-message"
        }, failedText)));
      } else if (type === 'chat') {
        return _react.default.createElement(_ChatContent.default, _extends({
          actionNode: actionNode,
          aspect: aspect ? aspect : findAspect(width, height),
          className: className,
          content: content,
          fileSize: fileSize,
          height: height,
          isProtected: isProtected,
          loading: loading,
          style: style,
          title: title,
          type: type,
          width: width
        }, props));
      } else if (type === 'file' && !icon) {
        return _react.default.createElement(_FileContent.default, _extends({
          actionNode: actionNode,
          aspect: aspect ? aspect : findAspect(width, height),
          className: className,
          content: content,
          height: height,
          icon: icon,
          isProtected: isProtected,
          loading: loading,
          loadingText: loadingText,
          subtitle: subtitle,
          title: title,
          type: type,
          width: width
        }, props));
      } else if (icon) {
        return _react.default.createElement(_IconContent.default, _extends({
          actionNode: actionNode,
          className: className,
          icon: icon,
          isProtected: isProtected,
          loading: loading,
          subtitle: subtitle,
          title: title
        }, otherProps));
      }
    };

    return _react.default.createElement("div", null, chosenItem());
  };

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

ContentItem.displayName = 'ContentItem';
ContentItem.defaultProps = {
  actionNode: null,
  aspect: null,
  className: '',
  content: null,
  failedText: '',
  fileSize: '',
  icon: '',
  isProtected: false,
  loading: false,
  loadingText: 'Loading',
  style: null,
  subtitle: '',
  title: '',
  type: 'chat'
};
ContentItem.propTypes = {
  /** @prop Node to render buttons inside Content Item | null */
  actionNode: _propTypes.default.node,

  /** @prop Set the Content Item's aspect size | null */
  aspect: _propTypes.default.oneOf(['fourThree', 'nineSixteen', 'oneOne', 'sixteenNine', 'tall', 'threeFour', 'threeTwo', 'twoThree', 'wide']),

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

  /** @prop Set the image/gif of the Content Item | '' */
  content: _propTypes.default.string,

  /** @prop Set the failed text to show when content fails to load | '' */
  failedText: _propTypes.default.string,

  /** @prop Show the size of the file | '' */
  fileSize: _propTypes.default.string,

  /** @prop Show icon at top right corner of Content Item */
  gifIcon: _propTypes.default.string,

  /** @prop Height of the image in px */
  height: _propTypes.default.number,

  /** @prop Set the type of icon to show | '' */
  icon: _propTypes.default.string,

  /** @prop Show visibility of action node buttons | false */
  isProtected: _propTypes.default.bool,

  /** @prop Show loading spinner | false */
  loading: _propTypes.default.bool,

  /** @prop Change loading text */
  loadingText: _propTypes.default.string,

  /** @prop Additional css styling applied to the button | null  */
  style: _propTypes.default.object,

  /** @prop Set the subtitle of the Content Item | '' */
  subtitle: _propTypes.default.string,

  /** @prop Set the title of the Content Item | '' */
  title: _propTypes.default.string,

  /** @prop Set the type of Content Item to display */
  type: _propTypes.default.oneOf(['chat', 'file']),

  /** @prop Width of the image in px */
  width: _propTypes.default.number
};
var _default = ContentItem;
/**
* @name Content Item with and without isProtected prop
*
* @category containers
* @component content-item
* @section default
*
* @js
*
import {
  Button,
  ContentItem,
  Icon,
} from '@collab-ui/react';

 export default class ChatContentItem extends React.PureComponent {

  render() {

    const actionNode =
    (
      <div>
        <Button
          ariaLabel='For the Win'
          style={{backgroundColor:'black'}}
          circle
          size={32}
        >
          <Icon name='open-in-folder_14' color='white' />
        </Button>

        <Button
          ariaLabel='For the Win'
          style={{backgroundColor:'black'}}
          circle
          size={32}
        >
          <Icon name='icon-arrow-tail-down_14' color='white' />
        </Button>
      </div>
    )

    const handleClick = () => {
      alert('Image onClick')
    }

    return(
    <div className='columns large'>
      <div className= 'docs-example docs-example--spacing'>
        <ContentItem
          actionNode={actionNode}
          aspect='sixteenNine'
          content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg'
          fileSize='24 KB'
          onClick={handleClick}
          type='chat'
          title='Screen Shot 208-11-07 at 10.30.02 AM.png' />
      </div>

      <div className= 'docs-example docs-example--spacing'>
        <ContentItem
          aspect='sixteenNine'
          content= 'https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg'
          fileSize='24 KB'
          isProtected={true}
          onClick={handleClick}
          title='Nice seating.png'
          type='chat' />
      </div>

      <div className= 'docs-example docs-example--spacing'>
        <ContentItem
          aspect='sixteenNine'
          content= 'http://upload.wikimedia.org/wikipedia/commons/d/dd/Muybridge_race_horse_animated.gif'
          fileSize='50 KB'
          gifIcon='icon icon-gif_24'
          isProtected={true}
          title='Race Horse.gif'
          type='chat' />
      </div>
    </div>
    );
  }
}
**/

/**
* @name Content Item in File View with and without isProtected Prop
*
* @category containers
* @component content-item
* @section file
*
* @js
*
import {
  Button,
  ContentItem,
  Icon,
} from '@collab-ui/react';

 export default class FileContentItem extends React.PureComponent {

  render() {

    const actionNode =
    (
      <div>
        <Button
          ariaLabel='For the Win'
          style={{backgroundColor:'black'}}
          circle
          size={32}
        >
          <Icon name='chat_12' color='white' />
        </Button>

        <Button
          ariaLabel='For the Win'
          style={{backgroundColor:'black'}}
          circle
          size={32}
        >
          <Icon name='open-in-folder_12' color='white' />
        </Button>

        <Button
          ariaLabel='For the Win'
          style={{backgroundColor:'black'}}
          circle
          size={32}
        >
          <Icon name='icon-arrow-tail-down_12' color='white' />
        </Button>
      </div>
    )

     const handleClick = () => {
      alert('Image onClick');
    }

    return(
    <div className='columns large'>
      <div className= 'docs-example docs-example--spacing'>
        <ContentItem
          actionNode={actionNode}
          aspect='threeTwo'
          content='https://vmcdn.ca/f/files/sudbury/uploadedImages/news/localNews/2015/06/090615_IKEA_sized.jpg;w=630'
          onClick={handleClick}
          subtitle='Barbara German, 4 days'
          title='Logo.pdf'
          type='file' />
        </div>

      <div className= 'docs-example docs-example--spacing'>
        <ContentItem
          aspect='threeTwo'
          content='https://vmcdn.ca/f/files/sudbury/uploadedImages/news/localNews/2015/06/090615_IKEA_sized.jpg;w=630'
          isProtected={true}
          subtitle='Barbara German, 4 days'
          title='Screen Shot 2018-10-11 at 5.22.32 PM.png'
          type='file' />
      </div>

      <div className= 'docs-example docs-example--spacing'>
        <ContentItem
          actionNode={actionNode}
          aspect='threeTwo'
          content='http://upload.wikimedia.org/wikipedia/commons/d/dd/Muybridge_race_horse_animated.gif'
          gifIcon='icon icon-gif_20'
          onClick={handleClick}
          subtitle='Barbara German, 4 days'
          title='Race Horse.gif'
          type='file' />
      </div>
    </div>
    );
  }
}

**/

/**
* @name Content Item with different size
*
* @category containers
* @component content-item
* @section size
*
* @js
*
import {
  Button,
  ContentItem,
  Icon,
} from '@collab-ui/react';

 export default class ContentItemSizes extends React.PureComponent {

  render() {
    const actionNode =
    (
      <div>
        <Button
          ariaLabel='For the Win'
          style={{backgroundColor:'black'}}
          circle
          size={32}
        >
          <Icon name='chat_12' color='white' />
        </Button>

        <Button
          ariaLabel='For the Win'
          style={{backgroundColor:'black'}}
          circle
          size={32}
        >
          <Icon name='open-in-folder_12' color='white' />
        </Button>

        <Button
          ariaLabel='For the Win'
          style={{backgroundColor:'black'}}
          circle
          size={32}
        >
          <Icon name='icon-arrow-tail-down_12' color='white' />
        </Button>
      </div>
    )

     const handleClick = () => {
      alert('Image onClick');
    }

    return(
      <div>
        <ContentItem
          aspect='twoThree'
          content='http://www.emertatmassage.com/wp-content/uploads/2014/06/img-16.jpg'
          subtitle='Barbara German, 4 days'
          type='file'
          actionNode={actionNode}
          onClick={handleClick}
          title='2:3' />

        <ContentItem
          aspect='threeFour'
          content='http://www.emertatmassage.com/wp-content/uploads/2014/06/img-16.jpg'
          subtitle='Barbara German, 4 days'
          onClick={handleClick}
          type='file'
          title='3:4' />

        <ContentItem
          aspect='sixteenNine'
          content='http://panoramicvisions.com/images/banner-img11.jpg'
          subtitle='Barbara German, 4 days'
          type='file'
          title='16:9' />

        <ContentItem
          aspect='nineSixteen'
          content='http://www.emertatmassage.com/wp-content/uploads/2014/06/img-16.jpg'
          subtitle='Barbara German, 4 days'
          type='file'
          title='9:16' />

        <ContentItem
          aspect='oneOne'
          content='http://www.emertatmassage.com/wp-content/uploads/2014/06/img-16.jpg'
          subtitle='Barbara German, 4 days'
          type='file'
          title='1:1' />

        <ContentItem
          aspect='fourThree'
          content='http://www.emertatmassage.com/wp-content/uploads/2014/06/img-16.jpg'
          subtitle='Barbara German, 4 days'
          type='file'
          title='4:3' />

        <ContentItem
          aspect='threeTwo'
          content='http://www.emertatmassage.com/wp-content/uploads/2014/06/img-16.jpg'
          subtitle='Barbara German, 4 days'
          type='file'
          title='3:2' />

        <ContentItem
          aspect='oneOne'
          content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg'
          subtitle='Barbara German, 4 days'
          type='chat'
          onClick={handleClick}
          title='1:1, 3:2 Container' />

        <ContentItem
          aspect='threeFour'
          content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg'
          subtitle='Barbara German, 4 days'
          type='chat'
          title='3:4, 3:2 container' />

        <ContentItem
          aspect='twoThree'
          content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg'
          subtitle='Barbara German, 4 days'
          type='chat'
          title='2:3, 3:2 container' />

        <ContentItem
          aspect='tall'
          content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg'
          subtitle='Barbara German, 4 days'
          type='chat'
          title='Tall, 3:2 container' />

        <ContentItem
          aspect='wide'
          content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg'
          subtitle='Barbara German, 4 days'
          type='chat'
          title='Wide, 16:9 container' />

        <ContentItem
          aspect='fourThree'
          content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg'
          subtitle='Barbara German, 4 days'
          type='chat'
          title='4:3' />

        <ContentItem
          aspect='threeTwo'
          content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg'
          subtitle='Barbara German, 4 days'
          type='chat'
          title='3:2' />

        <ContentItem
          aspect='sixteenNine'
          content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg'
          subtitle='Barbara German, 4 days'
          type='chat'
          title='16:9' />
      </div>
    );
  }
}
**/

/**
* @name Content Item Loading
*
* @category containers
* @component content-item
* @section spinner
*
* @js
*
import { ContentItem } from '@collab-ui/react';

 export default class ContentItemLoading extends React.PureComponent {

  render() {
    return(
    <div className='columns large'>

      <div className= 'docs-example docs-example--spacing'>
        <ContentItem
          aspect='threeTwo'
          content= 'https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg'
          loading={true}
          loadingText='Loading'
          subtitle='Barbara German, 4 days'
          type='file'
          title='Logo.pdf' />
        </div>

      <div className= 'docs-example docs-example--spacing'>
        <ContentItem
          aspect='sixteenNine'
          content= 'https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg'
          loading={true}
          subtitle='Barbara German, 4 days'
          type='chat'
          title='Logo.pdf' />
      </div>

      <div className= 'docs-example docs-example--spacing'>
        <ContentItem
          aspect='sixteenNine'
          loading={true}
          subtitle='Barbara German, 4 days'
          type='chat'
          title='Logo.pdf' />
      </div>
    </div>
    );
  }
}
**/

/**
* @name Finding aspect with image Width and Height Prop
*
* @category containers
* @component content-item
* @section aspect
*
* @js
*
import { ContentItem } from '@collab-ui/react';

 export default class ContentItemWidthHeight extends React.PureComponent {

  render() {
    return(
    <div className='columns large'>
      <ContentItem
        content='https://newevolutiondesigns.com/images/freebies/yellow-wallpaper-12.jpg'
        fileSize='24 KB'
        height={400}
        title='Nice seating.png'
        type='chat'
        width={300} />
    </div>
    );
  }
}
**/

/**
* @name Failed to Load Content
*
* @category containers
* @component content-item
* @section failed
*
* @js
*
import { ContentItem } from '@collab-ui/react';

 export default class ContentItemFailed extends React.PureComponent {

  render() {
    return(
    <div className='columns large'>
      <ContentItem
        failedText='Failed to load  preview. Tap to download the file.'
        fileSize='24 KB'
        onDownload={this.alertSomething}
        title='Nice seating.png'
        type='chat'
        showInFolder={this.showInFolder} />
    </div>
    );
  }
}
**/

/**
* @name Icon File View
*
* @category containers
* @component content-item
* @section icon
*
* @js
*
import {
  Button,
  ContentItem,
  Icon,
} from '@collab-ui/react';

 export default class ContentItemIcon extends React.PureComponent {

  render() {

    const handleClick = () => {
      alert('file onClick');
    }

    const folderClick = e => {
      alert('folder clicked');
      e.stopPropagation();
    }

    const downloadClick = e => {
      alert('download clicked');
      e.stopPropagation();
    }

    const actionNode =
    (
      <div>
        <Button
          ariaLabel='For the Win'
          circle
          onClick={folderClick}
          style={{backgroundColor:'black'}}
          size={32}
        >
          <Icon name='open-in-folder_14' color='white' />
        </Button>

        <Button
          ariaLabel='For the Win'
          circle
          onClick={downloadClick}
          style={{backgroundColor:'black'}}
          size={32}
        >
          <Icon name='icon-arrow-tail-down_14' color='white' />
        </Button>
      </div>
    )

    return(
    <div className='columns large'>
      <ContentItem
        actionNode={actionNode}
        fileSize='24 KB'
        icon='icon-pdf_72'
        onClick={handleClick}
        subtitle='Barbara German, 12/05/18'
        title='Ideas.pdf'
        type='file'/>
    </div>
    );
  }
}
**/

exports.default = _default;