import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import Col from 'react-bootstrap/lib/Col';
import ButtonToolbar from 'react-bootstrap/lib/ButtonToolbar';
import { Panel } from '../../Panel';
import { Block } from '../../Block';
import { Row } from '../../Row';
var VIEW_MODE_DETAILS = 'VIEW_MODE_DETAILS';
var VIEW_MODE_FULL = 'VIEW_MODE_FULL';
export var CommonListLayout =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(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.createElement("div", {
          className: "rc-list-actions-toolbar-gap"
        });
      }

      return null;
    }

    var classes = classnames({
      'bottom-border': this.props.viewMode === VIEW_MODE_FULL
    });
    return React.createElement("div", {
      className: classes
    }, React.createElement(ButtonToolbar, {
      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.createElement(Block, {
        noOffset: true
      }, React.createElement(Row, null, React.createElement(Col, {
        xs: filtersColSize
      }, filters), React.createElement(Col, {
        xs: actionsColSize
      }, React.createElement("div", {
        className: "pull-right"
      }, actions))));
    }

    return React.createElement("div", null, React.createElement(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.createElement(Col, {
        xs: 9,
        className: "vcenter text-right"
      }, renderPagination());
    }

    return React.createElement("div", null, React.createElement(Block, {
      noOffset: true
    }, React.createElement(Row, null, React.createElement(Col, {
      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.createElement("div", {
        "data-test-automation-id": "listContainer"
      }, list);
    }

    var paginationBlock = null;

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

    return React.createElement(Row, {
      className: "rc-list-wrapper"
    }, React.createElement(Col, {
      xs: listShortViewCol,
      className: "rc-list-left"
    }, React.createElement(Panel, {
      noPadding: true,
      noLeftBorder: true
    }, React.createElement(Block, {
      "data-test-automation-id": "listContainer"
    }, list), paginationBlock)), React.createElement(Col, {
      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.createElement(Row, null, React.createElement(Col, {
      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.createElement(Panel, {
      testAutomationId: this.props.testAutomationId,
      className: classnames(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.Component);

_defineProperty(CommonListLayout, "propTypes", {
  renderCounterText: PropTypes.func.isRequired,
  renderPagination: PropTypes.func.isRequired,
  className: PropTypes.string,
  testAutomationId: PropTypes.string,
  list: PropTypes.node.isRequired,
  viewMode: PropTypes.oneOf([VIEW_MODE_DETAILS, VIEW_MODE_FULL]),
  details: PropTypes.node,
  head: PropTypes.node,
  subhead: PropTypes.node,
  filters: PropTypes.node,
  filtersColSize: PropTypes.number,
  actions: PropTypes.node,
  actionsColSize: PropTypes.number,
  listActions: PropTypes.node,
  subFooter: PropTypes.node,
  withoutToolbarGap: PropTypes.bool,
  isTransparent: PropTypes.bool,
  hasPagination: PropTypes.bool,
  listShortViewCol: PropTypes.number,
  detailsShortViewCol: PropTypes.number,
  cancelMinHeight: PropTypes.bool,
  withoutGrid: PropTypes.bool
});

_defineProperty(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
});

_defineProperty(CommonListLayout, "VIEW_MODE_DETAILS", VIEW_MODE_DETAILS);

_defineProperty(CommonListLayout, "VIEW_MODE_FULL", VIEW_MODE_FULL);