'use strict';

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

var _redux = require('redux');

var _reactRedux = require('../../../common/react-redux');

var _qtiImports = require('../../../common/actions/qtiImports');

var _qtiImports2 = require('../../api/qtiImports');

var _constants = require('../../../constants');

var _ImportModal = require('../../../common/components/ImportModal');

var _ImportModal2 = _interopRequireDefault(_ImportModal);

var _formatMessage = require('../../../common/format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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

var callsToCheck = [_constants.CREATE_QTI_IMPORT, _constants.FILE_UPLOAD_CALL, _constants.FILE_UPLOAD_URL_CALL];

// Consuming Components must pass in qtiImportRecord, parentType, and parentId
var mapStateToProps = exports.mapStateToProps = function mapStateToProps(state, props) {
  var qtiImportRecord = props.qtiImport;
  var pv = (0, _ImportModal.progressValue)(qtiImportRecord.progressNumber(), state.get('calls'), callsToCheck);

  return {
    failureMessage: qtiImportRecord.message || '',
    importMessage: 'Archivos QTI 1.2 y 2.x (.zip) \xFAnicamente',
    progressValue: pv,
    acceptFileType: '.zip',
    importModalId: 'qtiImport'
  };
};

var mapDispatchToProps = exports.mapDispatchToProps = function mapDispatchToProps(dispatch, props) {
  var boundQtiFileUpload = (0, _redux.bindActionCreators)(_qtiImports2.qtiFileUpload, dispatch);
  return {
    onContinue: (0, _redux.bindActionCreators)(_qtiImports.clearQtiImports, dispatch),
    fileUpload: function fileUpload(file, cancelAction) {
      boundQtiFileUpload(file, props.parentId, props.parentType, cancelAction);
    }
  };
};

exports.default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_ImportModal2.default);