"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf3 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _reactImmutableProptypes = _interopRequireDefault(require("react-immutable-proptypes"));

var _Button = _interopRequireDefault(require("@instructure/ui-buttons/lib/components/Button"));

var _Grid = _interopRequireWildcard(require("@instructure/ui-layout/lib/components/Grid"));

var _lib = _interopRequireDefault(require("@instructure/ui-themeable/lib"));

var _IconUpload = _interopRequireDefault(require("@instructure/ui-icons/lib/Line/IconUpload"));

var _IconComplete = _interopRequireDefault(require("@instructure/ui-icons/lib/Line/IconComplete"));

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-i18n/lib/format-message"));

var _FileSelector = _interopRequireDefault(require("../../../../common/components/shared/file_selector/FileSelector"));

var _theme = _interopRequireDefault(require("./theme"));

var _dec, _class, _class2, _temp;

var styles = {
  componentId: 'fqArL',
  template: function template(theme) {
    return "\n\n.quiz-core__ImportFileSelector--uploadIconContainer {\n  color: ".concat(theme.uploadIconContainerColor || 'inherit', ";\n  font-size: ").concat(theme.uploadIconContainerColorFontSize || 'inherit', ";\n  text-align: right;\n}\n\n[dir=\"ltr\"] .quiz-core__ImportFileSelector--uploadIconContainer {\n  text-align: right;\n}\n\n[dir=\"rtl\"] .quiz-core__ImportFileSelector--uploadIconContainer {\n  text-align: right;\n}\n\n.quiz-core__ImportFileSelector--checkIconContainer {\n  color: ").concat(theme.checkIconContainerColor || 'inherit', ";\n  font-size: ").concat(theme.checkIconContainerFontSize || 'inherit', ";\n  text-align: right;\n}\n\n[dir=\"ltr\"] .quiz-core__ImportFileSelector--checkIconContainer {\n  text-align: right;\n}\n\n[dir=\"rtl\"] .quiz-core__ImportFileSelector--checkIconContainer {\n  text-align: right;\n}\n\n.quiz-core__ImportFileSelector--smallText {\n  padding: 0 ").concat(theme.smallTextPadding || 'inherit', ";\n  font-size: ").concat(theme.smallTextFontSize || 'inherit', ";\n  color: ").concat(theme.smallTextColor || 'inherit', ";\n}\n\n.quiz-core__ImportFileSelector--selector {\n  margin-top: ").concat(theme.selectorMargin || 'inherit', ";\n}\n\n.quiz-core__ImportFileSelector--fileListSuccess {\n  color: ").concat(theme.fileListSuccessColor || 'inherit', ";\n}\n");
  },
  'uploadIconContainer': 'quiz-core__ImportFileSelector--uploadIconContainer',
  'checkIconContainer': 'quiz-core__ImportFileSelector--checkIconContainer',
  'smallText': 'quiz-core__ImportFileSelector--smallText',
  'selector': 'quiz-core__ImportFileSelector--selector',
  'fileListSuccess': 'quiz-core__ImportFileSelector--fileListSuccess'
};
var ImportFileSelector = (_dec = (0, _lib.default)(_theme.default, styles), _dec(_class = (_temp = _class2 =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(ImportFileSelector, _Component);

  function ImportFileSelector() {
    var _getPrototypeOf2;

    var _this;

    (0, _classCallCheck2.default)(this, ImportFileSelector);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(ImportFileSelector)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.renderFileList = function () {
      var fileName = _this.props.files.get(0).name;

      return _react.default.createElement("div", null, [function (_ref) {
        var children = _ref.children;
        return _react.default.createElement("span", {
          className: styles.fileListSuccess,
          key: "0"
        }, children);
      }({
        children: [fileName]
      }), " ", function (_ref2) {
        var children = _ref2.children;
        return _react.default.createElement("span", {
          key: "1"
        }, children);
      }({
        children: ["\u062C\u0627\u0647\u0632."]
      })]);
    };

    return _this;
  }

  (0, _createClass2.default)(ImportFileSelector, [{
    key: "renderUploadIcon",
    value: function renderUploadIcon() {
      return _react.default.createElement("div", {
        className: styles.uploadIconContainer
      }, _react.default.createElement(_IconUpload.default, null));
    }
  }, {
    key: "renderCheckmarkIcon",
    value: function renderCheckmarkIcon() {
      return _react.default.createElement("div", {
        className: styles.checkIconContainer
      }, _react.default.createElement(_IconComplete.default, null));
    }
  }, {
    key: "renderFilePickerText",
    value: function renderFilePickerText() {
      var _params, _s;

      return _react.default.createElement("div", null, (_params = [function (_ref3) {
        var children = _ref3.children;
        return _react.default.createElement("span", {
          className: styles.smallText,
          key: "0"
        }, children);
      }, function (_ref4) {
        var children = _ref4.children;
        return _react.default.createElement(_Button.default, {
          key: "1"
        }, children);
      }], ["\u0627\u0644\u0633\u062D\u0628 \u0648\u0627\u0644\u0625\u0641\u0644\u0627\u062A \u0647\u0646\u0627 ", (_s = _params["0"], typeof _s === "function" ? _s({
        children: ["\u0623\u0648"]
      }) : _s), " ", (_s = _params["1"], typeof _s === "function" ? _s({
        children: ["\u0627\u0644\u0627\u0633\u062A\u0639\u0631\u0627\u0636"]
      }) : _s)]));
    }
  }, {
    key: "renderWrapper",
    value: function renderWrapper(renderIcon, renderText) {
      return _react.default.createElement(_Grid.default, null, _react.default.createElement(_Grid.GridRow, {
        vAlign: "middle"
      }, _react.default.createElement(_Grid.GridCol, {
        width: 3
      }, renderIcon()), _react.default.createElement(_Grid.GridCol, null, renderText())));
    }
  }, {
    key: "renderContent",
    value: function renderContent() {
      if (this.props.files && this.props.files.size) {
        return this.renderWrapper(this.renderCheckmarkIcon, this.renderFileList);
      } else {
        return this.renderWrapper(this.renderUploadIcon, this.renderFilePickerText);
      }
    }
  }, {
    key: "render",
    value: function render() {
      return _react.default.createElement("div", {
        className: styles.selector
      }, _react.default.createElement(_FileSelector.default, {
        content: this.renderContent(),
        fileHandler: this.props.receiveFile,
        acceptAttribute: this.props.acceptAttribute
      }));
    }
  }]);
  ImportFileSelector.displayName = "ImportFileSelector";
  return ImportFileSelector;
}(_react.Component), _class2.propTypes = {
  files: _reactImmutableProptypes.default.list.isRequired,
  receiveFile: _propTypes.default.func.isRequired,
  acceptAttribute: _propTypes.default.string.isRequired
}, _temp)) || _class);
exports.default = ImportFileSelector;