"use strict";

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

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

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _styles = require("@vincent_za/styles");

var _utils = require("@vincent_za/utils");

var _assets = require("@vincent_za/assets");

var _component = _interopRequireDefault(require("../Scroll/component"));

var _Loader = require("../Loader");

var _Error = require("../Error");

var _component2 = _interopRequireDefault(require("../Svg/component"));

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _templateObject6() {
  var data = _taggedTemplateLiteral(["\n  position: absolute;\n  top: ", ";\n  right: ", ";\n  width: 1.2rem;\n  height: 1.2rem;\n  fill: ", ";\n  opacity: ", ";\n\n  &:hover {\n    opacity: 1;\n  };\n"]);

  _templateObject6 = function _templateObject6() {
    return data;
  };

  return data;
}

function _templateObject5() {
  var data = _taggedTemplateLiteral(["\n  padding: 0 ", ";\n"]);

  _templateObject5 = function _templateObject5() {
    return data;
  };

  return data;
}

function _templateObject4() {
  var data = _taggedTemplateLiteral(["\n  display: flex;\n  flex-direction: column;\n  padding: ", ";\n  height: 100%;\n  line-height: 1.5;\n  word-wrap: break-word;\n  color: ", ";\n  overflow: auto;\n  ", ";\n"]);

  _templateObject4 = function _templateObject4() {
    return data;
  };

  return data;
}

function _templateObject3() {
  var data = _taggedTemplateLiteral(["\n  padding: 16px;\n  height: 44px;\n  line-height: 1;\n  text-transform: uppercase;\n  font-family: Lato-bold, sans-serif;\n  color: #607D8B;\n"]);

  _templateObject3 = function _templateObject3() {
    return data;
  };

  return data;
}

function _templateObject2() {
  var data = _taggedTemplateLiteral(["\n  display: flex;\n  flex-direction: column;\n  position: relative;\n  height: 100%;\n  background-color: ", ";\n  box-shadow: 0 0.6rem 11px -0.4rem #1e1e1e69, 0 0 16px -2px #1e1e1e69;\n"]);

  _templateObject2 = function _templateObject2() {
    return data;
  };

  return data;
}

function _templateObject() {
  var data = _taggedTemplateLiteral(["\n  display: flex;\n  flex-direction: column;\n  flex-shrink: 0;\n  padding: ", ";\n\n  ", ";\n"]);

  _templateObject = function _templateObject() {
    return data;
  };

  return data;
}

function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }

var CN_INNER_WRAP = 'pane-inner-wrap';
exports.CN_INNER_WRAP = CN_INNER_WRAP;
var CN_RELATIVE_WRAP = 'pane-relative-wrap';
exports.CN_RELATIVE_WRAP = CN_RELATIVE_WRAP;

var OuterWrap = _styledComponents.default.div(_templateObject(), _styles.REM_UNIT_LG, function (props) {
  return props.isFullscreen && "\n    position: absolute;\n    z-index: 1;\n    top: 0;\n    right: 0;\n    bottom: 0;\n    left: 0;\n    padding: 0 !important;\n    width: 100% !important;\n    height: 100% !important;\n    background-color: ".concat(_styles.CHARLESTON_GREEN, ";\n  ");
});

var RelativeWrap = _styledComponents.default.div(_templateObject2(), _styles.CHARLESTON_GREEN);

var Header = _styledComponents.default.header(_templateObject3());

var InnerWrap = _styledComponents.default.div(_templateObject4(), _styles.REM_UNIT_LG, _styles.SONIC_SILVER, function (props) {
  return props.isFullscreen && 'box-shadow: none;';
});

var InnerWrapScroll = (0, _component.default)(InnerWrap);
var ErrorInlineStyled = (0, _styledComponents.default)(_Error.ErrorInline)(_templateObject5(), _styles.REM_UNIT_LG);
var Icon = (0, _styledComponents.default)(_component2.default)(_templateObject6(), _styles.REM_UNIT_LG, _styles.REM_UNIT_LG, _styles.GRAY_X11, function (props) {
  return props.isFullscreen ? 1 : 0.3;
});

var Pane =
/*#__PURE__*/
function (_React$Component) {
  _inherits(Pane, _React$Component);

  function Pane(props) {
    var _this;

    _classCallCheck(this, Pane);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(Pane).call(this, props));

    _defineProperty(_assertThisInitialized(_this), "onFullscreenToggle", function () {
      var isFullscreen = _this.state.isFullscreen;

      var _this$innerRef$getBou = _this.innerRef.getBoundingClientRect(),
          width = _this$innerRef$getBou.width,
          height = _this$innerRef$getBou.height;

      _this.props.onFullscreenToggleCb({
        isFullscreen: !isFullscreen,
        contentDimensions: {
          width: width,
          height: height
        }
      });

      _this.setState({
        isFullscreen: !isFullscreen
      });
    });

    _defineProperty(_assertThisInitialized(_this), "addInnerRef", function (el) {
      _this.innerRef = el;
    });

    _this.state = {
      isFullscreen: false
    };
    return _this;
  }

  _createClass(Pane, [{
    key: "shouldComponentUpdate",
    value: function shouldComponentUpdate(nextProps, nextState) {
      if (nextState.isFullscreen !== this.state.isFullscreen) return true;
      if (nextProps.children !== this.props.children) return true;
      if (nextProps.asyncStatus !== this.props.asyncStatus) return true;
      if (nextProps.asyncStatusList !== this.props.asyncStatusList) return true;
      return false;
    }
  }, {
    key: "render",
    value: function render() {
      var isFullscreen = this.state.isFullscreen;
      var _this$props = this.props,
          isTouchDevice = _this$props.isTouchDevice,
          title = _this$props.title,
          children = _this$props.children,
          className = _this$props.className,
          asyncStatus = _this$props.asyncStatus,
          asyncStatusList = _this$props.asyncStatusList;
      return _react.default.createElement(OuterWrap, {
        isFullscreen: isFullscreen,
        className: className
      }, _react.default.createElement(RelativeWrap, {
        className: CN_RELATIVE_WRAP
      }, title && _react.default.createElement(Header, null, title), _react.default.createElement(Icon, {
        isFullscreen: isFullscreen,
        svg: _assets.fullscreenSvg,
        onClick: this.onFullscreenToggle
      }), _react.default.createElement(InnerWrapScroll, {
        isTouchDevice: isTouchDevice,
        isFullscreen: isFullscreen,
        className: CN_INNER_WRAP,
        passedRef: this.addInnerRef
      }, _react.default.createElement(_Loader.LineLoader, {
        isDisplayOnLoaded: true,
        asyncStatus: asyncStatus,
        asyncStatusList: asyncStatusList
      }), _react.default.createElement(_Loader.SpinnerLoader, {
        asyncStatus: asyncStatus,
        asyncStatusList: asyncStatusList
      }), _react.default.createElement(ErrorInlineStyled, {
        asyncStatus: asyncStatus,
        asyncStatusList: asyncStatusList
      }), children)));
    }
  }]);

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

Pane.propTypes = {
  isTouchDevice: _propTypes.bool.isRequired,
  title: _propTypes.string,
  children: _propTypes.node.isRequired,
  className: _propTypes.string,
  onFullscreenToggleCb: _propTypes.func,
  asyncStatus: (0, _propTypes.shape)(_utils.PROP_ASYNC_STATUS),
  asyncStatusList: (0, _propTypes.arrayOf)((0, _propTypes.shape)(_utils.PROP_ASYNC_STATUS))
};
Pane.defaultProps = {
  title: undefined,
  className: undefined,
  onFullscreenToggleCb: function onFullscreenToggleCb() {},
  asyncStatus: _utils.SHAPE_ASYNC_STATUS_INITIAL,
  asyncStatusList: []
};
var _default = Pane;
exports.default = _default;