'use strict';

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

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _dec, _class, _class2, _temp2;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _Heading = require('@instructure/ui-elements/lib/components/Heading');

var _Heading2 = _interopRequireDefault(_Heading);

var _AccessibleContent = require('@instructure/ui-a11y/lib/components/AccessibleContent');

var _AccessibleContent2 = _interopRequireDefault(_AccessibleContent);

var _IconPlusLine = require('instructure-icons/lib/Line/IconPlusLine');

var _IconPlusLine2 = _interopRequireDefault(_IconPlusLine);

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

var _Button2 = _interopRequireDefault(_Button);

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

var _lib2 = _interopRequireDefault(_lib);

var _Page = require('../../../../common/components/layout/Page');

var _Page2 = _interopRequireDefault(_Page);

var _PaginatedCollection = require('../../../../common/components/shared/PaginatedCollection');

var _PaginatedCollection2 = _interopRequireDefault(_PaginatedCollection);

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

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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

var _BanksList = require('../../BanksList');

var _BanksList2 = _interopRequireDefault(_BanksList);

var _CreateBankModal = require('../../CreateBankModal');

var _CreateBankModal2 = _interopRequireDefault(_CreateBankModal);

var _NavWrapper = require('../NavWrapper');

var _NavWrapper2 = _interopRequireDefault(_NavWrapper);

var _theme = require('./theme');

var _theme2 = _interopRequireDefault(_theme);

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

var styles = {
  template: function template(theme) {
    return '/*  imported from styles.css  */\n\n.Banks__styles__content {\n  padding: ' + theme.contentPaddingTopBottom + ' ' + theme.contentPaddingLeftRight + ';\n  background-color: ' + theme.contentBackgroundColor + ';\n}\n\n.Banks__styles__header {\n  display: flex;\n  flex-direction: row;\n  padding-bottom: ' + theme.headerPadding + ';\n  border-bottom: ' + theme.headerBorderWidth + ' solid ' + theme.headerBorderColor + ';\n  justify-content: space-between;\n}\n';
  },
  'content': 'Banks__styles__content',
  'header': 'Banks__styles__header'
};
var Banks = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp2 = _class2 = function (_Component) {
  (0, _inherits3.default)(Banks, _Component);

  function Banks() {
    var _ref;

    var _temp, _this, _ret;

    (0, _classCallCheck3.default)(this, Banks);

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

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = Banks.__proto__ || Object.getPrototypeOf(Banks)).call.apply(_ref, [this].concat(args))), _this), _this.onCreateBank = function () {
      _this.props.createBank();
      _this.props.openModal(_constants.CREATE_BANK_MODAL, { modalTrigger: _this.createBankButton });
    }, _this.getPage = function (page) {
      return _this.props.getBanks({ page: page });
    }, _this.focusCreateBankButton = function () {
      _this.createBankButton && _this.createBankButton.focus();
    }, _this.handleCreateBankButtonRef = function (node) {
      _this.createBankButton = node;
    }, _this.renderRecords = function (recordIds) {
      return _react2.default.createElement(_BanksList2.default, {
        focusCreateBankButton: _this.focusCreateBankButton,
        createBankButton: _this.createBankButton,
        getUserInfo: _this.props.getUserInfo,
        getShareableUsers: _this.props.getShareableUsers,
        navigateToBank: _this.props.navigateToBank,
        recordIds: recordIds
      });
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(Banks, [{
    key: 'renderHeader',
    value: function renderHeader() {
      return _react2.default.createElement(
        'div',
        { className: styles.header },
        _react2.default.createElement(
          _Heading2.default,
          { as: this.props.isCompact ? 'h2' : 'h1', level: 'h1' },
          'Banki'
        ),
        _react2.default.createElement(
          _Button2.default,
          {
            ref: this.handleCreateBankButtonRef,
            type: 'button',
            variant: 'primary',
            onClick: this.onCreateBank,
            'data-automation': 'sdk-create-new-bank-button',
            icon: _IconPlusLine2.default
          },
          _react2.default.createElement(
            _AccessibleContent2.default,
            { alt: 'Utw\xF3rz bank' },
            'Bank'
          )
        )
      );
    }
  }, {
    key: 'renderNav',
    value: function renderNav() {
      return _react2.default.createElement(_NavWrapper2.default, {
        closeTray: this.props.closeTray,
        navigateToBuild: this.props.navigateToBuild
      });
    }
  }, {
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        _Page2.default,
        null,
        this.renderNav(),
        _react2.default.createElement(
          'div',
          { className: styles.content },
          this.renderHeader(),
          _react2.default.createElement(_PaginatedCollection2.default, {
            empty: 'Nie masz jeszcze banku',
            getPage: this.getPage,
            renderRecords: this.renderRecords,
            stateKey: _constants.BANKS_BANK_PAGINATION
          }),
          _react2.default.createElement(_CreateBankModal2.default, null)
        )
      );
    }
  }]);
  Banks.displayName = 'Banks'
  ;
  return Banks;
}(_react.Component), _class2.propTypes = {
  closeTray: _propTypes2.default.func.isRequired,
  createBank: _propTypes2.default.func.isRequired,
  getBanks: _propTypes2.default.func.isRequired,
  getUserInfo: _propTypes2.default.func,
  getShareableUsers: _propTypes2.default.func,
  isCompact: _propTypes2.default.bool,
  navigateToBank: _propTypes2.default.func.isRequired, // can be from consumer
  navigateToBuild: _propTypes2.default.func, // from consumer
  openModal: _propTypes2.default.func.isRequired
}, _class2.defaultProps = {
  getUserInfo: null,
  getShareableUsers: null,
  isCompact: false,
  navigateToBuild: null
}, _temp2)) || _class);
exports.default = Banks;