'use strict';

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

var _class, _temp;

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _shallowEqual = require('fbjs/lib/shallowEqual');

var _shallowEqual2 = _interopRequireDefault(_shallowEqual);

var _reselect = require('reselect');

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

var _lodash = require('lodash');

var _reactFontawesome = require('react-fontawesome');

var _reactFontawesome2 = _interopRequireDefault(_reactFontawesome);

var _slotitems = require('./slotitems');

var _statuslabel = require('views/components/ship-parts/statuslabel');

var _statuslabel2 = _interopRequireDefault(_statuslabel);

var _aaciIndicator = require('./aaci-indicator');

var _aaciIndicator2 = _interopRequireDefault(_aaciIndicator);

var _oaswIndicator = require('./oasw-indicator');

var _oaswIndicator2 = _interopRequireDefault(_oaswIndicator);

var _gameUtils = require('views/utils/game-utils');

var _tools = require('views/utils/tools');

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

require('./assets/ship-item.css');

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

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

function getMaterialStyle(percent) {
  if (percent <= 50) return 'red';else if (percent <= 75) return 'orange';else if (percent < 100) return 'yellow';else return 'green';
}

function _ref([ship, $ship] = [], repairDock, { $shipTypes }, escaped) {
  return {
    ship: ship || {},
    $ship: $ship || {},
    $shipTypes,
    labelStatus: (0, _gameUtils.getShipLabelStatus)(ship, $ship, repairDock, escaped)
  };
}

const shipRowDataSelectorFactory = (0, _lodash.memoize)(shipId => (0, _reselect.createSelector)([(0, _selectors.shipDataSelectorFactory)(shipId), (0, _selectors.shipRepairDockSelectorFactory)(shipId), _selectors.constSelector, (0, _selectors.escapeStatusSelectorFactory)(shipId)], _ref));
const ShipRow = exports.ShipRow = (0, _reactRedux.connect)((state, { shipId }) => shipRowDataSelectorFactory(shipId)(state))((_temp = _class = class ShipRow extends _react.Component {

  shouldComponentUpdate(nextProps) {
    // Remember to expand the list in case you add new properties to display
    const shipPickProps = ['api_lv', 'api_exp', 'api_id', 'api_nowhp', 'api_maxhp', 'api_cond', 'api_fuel', 'api_bull', 'api_soku'];
    return !(0, _shallowEqual2.default)((0, _lodash.omit)(this.props, ['ship']), (0, _lodash.omit)(nextProps, ['ship'])) || !(0, _lodash.isEqual)((0, _lodash.pick)(this.props.ship, shipPickProps), (0, _lodash.pick)(nextProps.ship, shipPickProps));
  }

  render() {
    const { ship, $ship, $shipTypes, labelStatus } = this.props;
    const labelStatusStyle = (0, _gameUtils.getStatusStyle)(labelStatus);
    const hpPercentage = ship.api_nowhp / ship.api_maxhp * 100;
    const fuelPercentage = ship.api_fuel / $ship.api_fuel_max * 100;
    const ammoPercentage = ship.api_bull / $ship.api_bull_max * 100;
    const fuelTip = _react2.default.createElement(
      'span',
      null,
      ship.api_fuel,
      ' / ',
      $ship.api_fuel_max,
      fuelPercentage < 100 && ` (-${Math.floor(($ship.api_fuel_max - ship.api_fuel) * (ship.api_lv > 99 ? 0.85 : 1))})`
    );
    const ammoTip = _react2.default.createElement(
      'span',
      null,
      ship.api_bull,
      ' / ',
      $ship.api_bull_max,
      ammoPercentage < 100 && ` (-${Math.floor(($ship.api_bull_max - ship.api_bull) * (ship.api_lv > 99 ? 0.85 : 1))})`
    );
    return _react2.default.createElement(
      'div',
      { className: 'ship-item' },
      _react2.default.createElement(
        'div',
        { className: 'ship-tile' },
        _react2.default.createElement(
          'div',
          { className: 'ship-basic-item' },
          _react2.default.createElement(
            'div',
            { className: 'ship-info', style: labelStatusStyle },
            _react2.default.createElement(
              'div',
              { className: 'ship-basic' },
              _react2.default.createElement(
                'span',
                { className: 'ship-lv' },
                'Lv. ',
                ship.api_lv || '??'
              ),
              _react2.default.createElement(
                'span',
                { className: 'ship-type' },
                i18n.resources.__(($shipTypes[$ship.api_stype] || { api_name: '??' }).api_name)
              ),
              _react2.default.createElement(
                'span',
                { className: 'ship-speed' },
                __((0, _gameUtils.getSpeedLabel)(ship.api_soku))
              ),
              _react2.default.createElement(_aaciIndicator2.default, { shipId: ship.api_id }),
              _react2.default.createElement(_oaswIndicator2.default, { shipId: ship.api_id })
            ),
            _react2.default.createElement(
              'span',
              { className: 'ship-name' },
              i18n.resources.__($ship.api_name || '??')
            ),
            _react2.default.createElement(
              'span',
              { className: 'ship-exp' },
              'Next. ',
              (ship.api_exp || [])[1]
            )
          ),
          _react2.default.createElement(
            _reactBootstrap.OverlayTrigger,
            {
              placement: 'right',
              overlay: ship.api_ndock_time > 0 ? _react2.default.createElement(
                _reactBootstrap.Tooltip,
                { id: `panebody-repair-time-${ship.api_id}` },
                __('Repair Time'),
                ': ',
                (0, _tools.resolveTime)(ship.api_ndock_time / 1000)
              ) : _react2.default.createElement('noscript', null)
            },
            _react2.default.createElement(
              'div',
              { className: 'ship-stat' },
              _react2.default.createElement(
                'div',
                { className: 'div-row' },
                _react2.default.createElement(
                  'span',
                  { className: 'ship-hp', style: labelStatusStyle },
                  ship.api_nowhp,
                  ' / ',
                  ship.api_maxhp
                ),
                _react2.default.createElement(
                  'div',
                  { className: 'status-label' },
                  _react2.default.createElement(_statuslabel2.default, { label: labelStatus })
                ),
                _react2.default.createElement(
                  'div',
                  { className: 'status-cond', style: labelStatusStyle },
                  _react2.default.createElement(
                    'span',
                    { className: "ship-cond " + (0, _gameUtils.getCondStyle)(ship.api_cond) },
                    _react2.default.createElement(_reactFontawesome2.default, { name: 'star' }),
                    ship.api_cond
                  )
                )
              ),
              _react2.default.createElement(
                'span',
                { className: 'hp-progress top-space', style: labelStatusStyle },
                _react2.default.createElement(_reactBootstrap.ProgressBar, { bsStyle: (0, _gameUtils.getHpStyle)(hpPercentage),
                  now: hpPercentage })
              )
            )
          )
        )
      ),
      _react2.default.createElement(
        'span',
        { className: 'ship-fb', style: labelStatusStyle },
        _react2.default.createElement(
          'span',
          { style: { flex: 1 } },
          _react2.default.createElement(
            _reactBootstrap.OverlayTrigger,
            { placement: 'right', overlay: _react2.default.createElement(
                _reactBootstrap.Tooltip,
                { id: `panebody-fuel-${ship.api_id}` },
                fuelTip
              ) },
            _react2.default.createElement(_reactBootstrap.ProgressBar, { bsStyle: getMaterialStyle(fuelPercentage),
              now: fuelPercentage })
          )
        ),
        _react2.default.createElement(
          'span',
          { style: { flex: 1 } },
          _react2.default.createElement(
            _reactBootstrap.OverlayTrigger,
            { placement: 'right', overlay: _react2.default.createElement(
                _reactBootstrap.Tooltip,
                { id: `panebody-bull-${ship.api_id}` },
                ammoTip
              ) },
            _react2.default.createElement(_reactBootstrap.ProgressBar, { bsStyle: getMaterialStyle(ammoPercentage),
              now: ammoPercentage })
          )
        )
      ),
      _react2.default.createElement(
        'div',
        { className: 'ship-slot', style: labelStatusStyle },
        _react2.default.createElement(_slotitems.Slotitems, { shipId: ship.api_id })
      )
    );
  }
}, _class.propTypes = {
  ship: _propTypes2.default.object,
  $ship: _propTypes2.default.object,
  $shipTypes: _propTypes2.default.object,
  labelStatus: _propTypes2.default.number
}, _temp));