'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _SortableItem = require('./SortableItem');

var _SortableItem2 = _interopRequireDefault(_SortableItem);

var _Badge = require('../Badge');

var _Badge2 = _interopRequireDefault(_Badge);

var _Toggle = require('../Toggle');

var _Toggle2 = _interopRequireDefault(_Toggle);

var _bind = require('classnames/bind');

var _bind2 = _interopRequireDefault(_bind);

var _style = require('./style.scss');

var _style2 = _interopRequireDefault(_style);

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 SortableItemPreview = function (_React$Component) {
  _inherits(SortableItemPreview, _React$Component);

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

    var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(SortableItemPreview).call(this, props));

    _this.render = function () {
      var cx = _bind2.default.bind(_style2.default);
      var previewClasses = cx(_style2.default['sortable-item'], _style2.default.preview, !_this.props.item.active ? 'inactive' : '');
      var badgeOpacity = _this.props.count > 1 ? 1 - 0.6 / (_this.props.count - 1) * _this.props.item.index : 1;

      return _react2.default.createElement(
        'div',
        { className: previewClasses },
        _react2.default.createElement(
          'div',
          { style: { opacity: badgeOpacity } },
          _react2.default.createElement(_Badge2.default, { text: _this.props.item.index + 1, theme: 'sky', optClass: _style2.default['sortable-item-badge'] })
        ),
        _react2.default.createElement(
          'span',
          null,
          _this.props.item.text
        ),
        _react2.default.createElement(
          'div',
          { className: _style2.default.actions },
          _react2.default.createElement(_Toggle2.default, { value: _this.props.item.active, optClass: _style2.default.toggle }),
          _react2.default.createElement(
            'div',
            { className: _style2.default.handle },
            _react2.default.createElement('span', null),
            _react2.default.createElement('span', null),
            _react2.default.createElement('span', null),
            _react2.default.createElement('span', null)
          )
        )
      );
    };

    return _this;
  }

  return SortableItemPreview;
}(_react2.default.Component);

SortableItemPreview.propTypes = {
  item: _react2.default.PropTypes.object.isRequired,
  count: _react2.default.PropTypes.number.isRequired
};
exports.default = SortableItemPreview;