'use strict';

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

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactRedux = require('react-redux');

var _reselect = require('reselect');

var _lodash = require('lodash');

var _reactBootstrap = require('react-bootstrap');

var _selectors = require('views/utils/selectors');

var _oasw = require('views/utils/oasw');

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

const { i18n } = window;
const __ = i18n.main.__.bind(i18n.main);

const OASWSelectorFactory = (0, _lodash.memoize)(shipId => (0, _reselect.createSelector)([(0, _selectors.shipDataSelectorFactory)(shipId), (0, _selectors.shipEquipDataSelectorFactory)(shipId)], ([_ship = {}, $ship = {}] = [], _equips = []) => {
  const ship = _extends({}, $ship, _ship);
  const equips = _equips.filter(([_equip, $equip, onslot] = []) => !!_equip && !!$equip).map(([_equip, $equip, onslot]) => _extends({}, $equip, _equip));

  return (0, _oasw.isOASW)(ship, equips);
}));

const OASWIndicator = (0, _reactRedux.connect)((state, { shipId }) => ({
  isOASW: OASWSelectorFactory(shipId)(state)
}))(({ isOASW, shipId }) => isOASW ? _react2.default.createElement(
  'span',
  { className: 'ship-oasw' },
  _react2.default.createElement(
    _reactBootstrap.Label,
    { bsStyle: 'primary' },
    __('OASW')
  )
) : _react2.default.createElement('noscript', null));

exports.default = OASWIndicator;
module.exports = exports['default'];