'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _path = require('path');

var _path2 = _interopRequireDefault(_path);

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var Item = function (_Component) {
  _inherits(Item, _Component);

  function Item(props) {
    _classCallCheck(this, Item);

    var _this = _possibleConstructorReturn(this, (Item.__proto__ || Object.getPrototypeOf(Item)).call(this, props));

    _this.onHover = function () {
      _this.setState({ 'hover': true });
      _this.props.setFooterText(_this.props.name);
    };

    _this.onOut = function () {
      _this.setState({ 'hover': false });
      _this.props.setFooterText('');
    };

    _this.toggleSelected = function () {

      if (!_this.props.selected) {
        _this.props.selectTexture(_this.props.texture);
      } else {
        _this.props.deselectTexture(_this.props.texture);
      }
    };

    _this.onClickPreview = function (e) {
      e.preventDefault();
      _this.props.onTexturePreview(_this.props.texture);
    };

    _this.onClickClipboard = function (e) {
      e.preventDefault();
      _this.props.copyToClipboard(_this.props.texture);
    };

    _this.dragStart = function (e) {
      e.preventDefault();
      var absPath = _path2.default.join(_this.props.texture.basepath, _this.props.path);
      require('electron').ipcRenderer.send('ondragstart', absPath);
    };

    _this.state = {
      'hover': false
    };

    return _this;
  }

  _createClass(Item, [{
    key: 'render',
    value: function render() {
      var _this2 = this;

      var hoverMenu = null;
      if (this.state.hover) {
        hoverMenu = _react2.default.createElement(
          'div',
          { className: 'center-block', style: hoverMenuStyle },
          _react2.default.createElement('div', { className: 'fa fa-eye', style: hoverItemStyle, onClick: this.onClickPreview }),
          _react2.default.createElement('div', { className: 'fa fa-camera-retro', style: hoverItemStyle, onClick: function onClick() {
              return _this2.props.openDesktopViewer(_this2.props.texture);
            } })
        );
      }

      var imgStyle = itemStyle;
      if (this.props.selected) {
        imgStyle = selectedStyle;
      } else if (this.state.hover) {
        imgStyle = hoverStyle;
      }

      return _react2.default.createElement(
        'div',
        {
          draggable: 'true',
          className: 'col-xs-3 col-sm-3 col-md-3 col-lg-3 center-block',
          onMouseEnter: this.onHover,
          onMouseLeave: this.onOut,
          onDragStart: this.dragStart },
        _react2.default.createElement('img', {
          className: 'img-responsive img-rounded',
          src: _path2.default.join(this.props.texture.basepath, this.props.path),
          alt: '',
          style: imgStyle,
          onClick: this.toggleSelected }),
        hoverMenu
      );
    }
  }]);

  return Item;
}(_react.Component);

exports.default = Item;


var itemStyle = {
  width: '64px',
  height: '64px'
};

var hoverStyle = {
  width: '64px',
  height: '64px',
  border: '2px',
  boxShadow: '0px 0px 20px 0px rgba(0, 0, 0, 0.6)'
};

var selectedStyle = {
  width: '64px',
  height: '64px',
  border: '2px',
  boxShadow: '0px 0px 30px 0px rgba(26, 189, 0, 1)'
};

var hoverMenuStyle = {
  position: 'absolute',
  bottom: '0',
  width: '64px',
  height: '20px',
  display: 'flex',
  flexDirection: 'row',
  alignItems: 'center',
  justifyContent: 'center',
  backgroundColor: 'rgba(0, 0, 0, 0.5)',
  borderRadius: '0 0 8px 8px'
};

var hoverItemStyle = {
  flex: '1',
  textAlign: 'center',
  color: 'rgba(255, 255, 255, 0.7)',
  cursor: 'pointer'
};