"use strict";

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

exports.__esModule = true;
exports.CommonListLayout = void 0;

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

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

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

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

var _classnames = _interopRequireDefault(require("classnames"));

var _Col = _interopRequireDefault(require("react-bootstrap/lib/Col"));

var _ButtonToolbar = _interopRequireDefault(require("react-bootstrap/lib/ButtonToolbar"));

var _Panel = require("../../Panel");

var _Block = require("../../Block");

var _Row = require("../../Row");

var VIEW_MODE_DETAILS = 'VIEW_MODE_DETAILS';
var VIEW_MODE_FULL = 'VIEW_MODE_FULL';

var CommonListLayout =
/*#__PURE__*/
function (_React$Component) {
  (0, _inheritsLoose2.default)(CommonListLayout, _React$Component);

  function CommonListLayout() {
    return _React$Component.apply(this, arguments) || this;
  }

  var _proto = CommonListLayout.prototype;

  _proto.renderListActionsToolbar = function renderListActionsToolbar() {
    if (!this.props.listActions) {
      if (this.props.viewMode === VIEW_MODE_FULL) {
        return null;
      } else if (!this.props.withoutToolbarGap) {
        return _react.default.createElement("div", {
          className: "rc-list-actions-toolbar-gap"
        });
      }

      return null;
    }

    var classes = (0, _classnames.default)({
      'bottom-border': this.props.viewMode === VIEW_MODE_FULL
    });
    return _react.default.createElement("div", {
      className: classes
    }, _react.default.createElement(_ButtonToolbar.default, {
      className: "no-offset cta-toolbar"
    }, this.props.listActions));
  };

  _proto.renderHeader = function renderHeader() {
    var middleSection = null;
    var _this$props = this.props,
        filtersColSize = _this$props.filtersColSize,
        actionsColSize = _this$props.actionsColSize,
        filters = _this$props.filters,
        actions = _this$props.actions,
        head = _this$props.head,
        subhead = _this$props.subhead;

    if (!filters && !actions && !head && !subhead) {
      return null;
    }

    if (filters || actions) {
      middleSection = _react.default.createElement(_Block.Block, {
        noOffset: true
      }, _react.default.createElement(_Row.Row, null, _react.default.createElement(_Col.default, {
        xs: filtersColSize
      }, filters), _react.default.createElement(_Col.default, {
        xs: actionsColSize
      }, _react.default.createElement("div", {
        className: "pull-right"
      }, actions))));
    }

    return _react.default.createElement("div", null, _react.default.createElement(_Block.Block, {
      cancelTopOffset: true,
      cancelHorizontalOffset: true
    }, head), middleSection, subhead);
  };

  _proto.renderFooter = function renderFooter() {
    var _this$props2 = this.props,
        viewMode = _this$props2.viewMode,
        subFooter = _this$props2.subFooter,
        renderCounterText = _this$props2.renderCounterText,
        renderPagination = _this$props2.renderPagination,
        withoutGrid = _this$props2.withoutGrid;

    if (withoutGrid || viewMode !== VIEW_MODE_FULL) {
      return null;
    }

    var paginationBlock = null;

    if (this.props.hasPagination) {
      paginationBlock = _react.default.createElement(_Col.default, {
        xs: 9,
        className: "vcenter text-right"
      }, renderPagination());
    }

    return _react.default.createElement("div", null, _react.default.createElement(_Block.Block, {
      noOffset: true
    }, _react.default.createElement(_Row.Row, null, _react.default.createElement(_Col.default, {
      xs: 3,
      className: "vcenter"
    }, renderCounterText()), paginationBlock)), subFooter);
  };

  _proto.renderDetails = function renderDetails() {
    return this.props.details;
  };

  _proto.renderBody = function renderBody() {
    var _this$props3 = this.props,
        viewMode = _this$props3.viewMode,
        list = _this$props3.list,
        hasPagination = _this$props3.hasPagination,
        listShortViewCol = _this$props3.listShortViewCol,
        detailsShortViewCol = _this$props3.detailsShortViewCol,
        renderPagination = _this$props3.renderPagination;

    if (viewMode === VIEW_MODE_FULL) {
      return _react.default.createElement("div", {
        "data-test-automation-id": "listContainer"
      }, list);
    }

    var paginationBlock = null;

    if (hasPagination) {
      paginationBlock = _react.default.createElement(_Block.Block, {
        addLeftOffset: true,
        addRightOffset: true
      }, _react.default.createElement(_Row.Row, null, _react.default.createElement(_Col.default, {
        xs: 12
      }, _react.default.createElement("div", {
        className: "pull-right"
      }, renderPagination(false)))));
    }

    return _react.default.createElement(_Row.Row, {
      className: "rc-list-wrapper"
    }, _react.default.createElement(_Col.default, {
      xs: listShortViewCol,
      className: "rc-list-left"
    }, _react.default.createElement(_Panel.Panel, {
      noPadding: true,
      noLeftBorder: true
    }, _react.default.createElement(_Block.Block, {
      "data-test-automation-id": "listContainer"
    }, list), paginationBlock)), _react.default.createElement(_Col.default, {
      xs: detailsShortViewCol,
      "data-test-automation-id": "detailsContainer",
      className: "rc-list-details-container"
    }, this.renderDetails()));
  };

  _proto.renderPanelBody = function renderPanelBody() {
    if (this.props.withoutGrid) {
      return null;
    }

    return _react.default.createElement(_Row.Row, null, _react.default.createElement(_Col.default, {
      xs: 12
    }, this.renderListActionsToolbar(), this.renderBody()));
  };

  _proto.render = function render() {
    var _this$props4 = this.props,
        isTransparent = _this$props4.isTransparent,
        cancelMinHeight = _this$props4.cancelMinHeight;
    return _react.default.createElement(_Panel.Panel, {
      testAutomationId: this.props.testAutomationId,
      className: (0, _classnames.default)(this.props.className, 'rc-list-layout'),
      header: this.renderHeader(),
      footer: this.renderFooter(),
      isTransparent: isTransparent,
      noBorder: isTransparent,
      cancelMinHeight: cancelMinHeight,
      noPadding: true
    }, this.renderPanelBody());
  };

  return CommonListLayout;
}(_react.default.Component);

exports.CommonListLayout = CommonListLayout;
(0, _defineProperty2.default)(CommonListLayout, "propTypes", {
  renderCounterText: _propTypes.default.func.isRequired,
  renderPagination: _propTypes.default.func.isRequired,
  className: _propTypes.default.string,
  testAutomationId: _propTypes.default.string,
  list: _propTypes.default.node.isRequired,
  viewMode: _propTypes.default.oneOf([VIEW_MODE_DETAILS, VIEW_MODE_FULL]),
  details: _propTypes.default.node,
  head: _propTypes.default.node,
  subhead: _propTypes.default.node,
  filters: _propTypes.default.node,
  filtersColSize: _propTypes.default.number,
  actions: _propTypes.default.node,
  actionsColSize: _propTypes.default.number,
  listActions: _propTypes.default.node,
  subFooter: _propTypes.default.node,
  withoutToolbarGap: _propTypes.default.bool,
  isTransparent: _propTypes.default.bool,
  hasPagination: _propTypes.default.bool,
  listShortViewCol: _propTypes.default.number,
  detailsShortViewCol: _propTypes.default.number,
  cancelMinHeight: _propTypes.default.bool,
  withoutGrid: _propTypes.default.bool
});
(0, _defineProperty2.default)(CommonListLayout, "defaultProps", {
  className: null,
  testAutomationId: 'panel',
  viewMode: VIEW_MODE_FULL,
  details: null,
  head: null,
  subhead: null,
  filters: null,
  filtersColSize: 7,
  actions: null,
  actionsColSize: 5,
  listActions: null,
  subFooter: null,
  withoutToolbarGap: false,
  isTransparent: false,
  hasPagination: true,
  listShortViewCol: 4,
  detailsShortViewCol: 8,
  cancelMinHeight: false,
  withoutGrid: false
});
(0, _defineProperty2.default)(CommonListLayout, "VIEW_MODE_DETAILS", VIEW_MODE_DETAILS);
(0, _defineProperty2.default)(CommonListLayout, "VIEW_MODE_FULL", VIEW_MODE_FULL);