"use strict";

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

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

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

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

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

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

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

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

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

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 _templateObject3() {
  var data = _taggedTemplateLiteral(["\n  position: relative;\n  flex-direction: column;\n  flex-grow: 1;\n  background-color: ", ";\n  box-shadow: ", ";\n"]);

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

  return data;
}

function _templateObject2() {
  var data = _taggedTemplateLiteral(["\n  position: absolute;\n  top: 50%;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  width: 4rem;\n  height: 4rem;\n  background-color: ", ";\n  fill: ", ";\n  cursor: pointer;\n  transform: translate(0, -50%);\n  transition: transform 0.2s cubic-bezier(0, 0, 0.51, 0.99), opacity 0.2s cubic-bezier(0, 0, 0.51, 0.99);\n  transition-delay: 0.1s;\n\n  ", ";\n\n  ", ";\n\n  &:hover {\n    fill:", ";\n    transform: translate(0, -50%);\n    opacity: 1;\n    transition-delay: 0s;\n  };\n\n  ", ";\n"]);

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

  return data;
}

function _templateObject() {
  var data = _taggedTemplateLiteral(["\n  z-index: 1;\n  position: absolute;\n  display: flex;\n  flex-direction: column;\n\n  ", ";\n\n  ", ";\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 Wrap = _styledComponents.default.div(_templateObject(), function (props) {
  return props.isRight && "\n    left: 100%;\n  ";
}, function (props) {
  return !props.isRight && "\n    right: 100%;\n  ";
}, function (props) {
  return props.isOpen && "\n    position: relative;\n    left: auto;\n    right: auto;\n  ";
});

var Toggle = _styledComponents.default.div(_templateObject2(), _styles.ONYX, _styles.SONIC_SILVER, function (props) {
  return !props.isRight && "\n    left: 100%;\n    border-top-right-radius: 2px;\n    border-bottom-right-radius: 2px;\n  ";
}, function (props) {
  return props.isRight && "\n    right: 100%;\n    border-top-left-radius: 2px;\n    border-bottom-left-radius: 2px;\n  ";
}, _styles.PASTEL_GRAY, function (props) {
  return props.isOpen && "\n    fill:".concat(_styles.PASTEL_GRAY, ";\n    opacity: 0.6;\n    transform: ").concat(props.isRight ? 'translate(28px, -50%)' : 'translate(-28px, -50%)', ";\n  ");
});

var Content = (0, _styledComponents.default)(_component.PageVHWrap)(_templateObject3(), _styles.JET, function (props) {
  return props.isOpen ? '3px 0rem 12px -6px #1b1b1b' : 'none';
});

var PageSidePane =
/*#__PURE__*/
function (_Component) {
  _inherits(PageSidePane, _Component);

  function PageSidePane(props) {
    var _this;

    _classCallCheck(this, PageSidePane);

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

    _defineProperty(_assertThisInitialized(_this), "onToggle", function () {
      _this.setState({
        isOpen: !_this.state.isOpen
      });

      _this.props.onToggle();
    });

    _this.state = {
      isOpen: props.isOpenByDefault
    };
    return _this;
  }

  _createClass(PageSidePane, [{
    key: "shouldComponentUpdate",
    value: function shouldComponentUpdate() {
      return true;
    }
  }, {
    key: "render",
    value: function render() {
      var isOpen = this.state.isOpen;
      var _this$props = this.props,
          isRight = _this$props.isRight,
          toggleIcon = _this$props.toggleIcon,
          children = _this$props.children;
      return _react.default.createElement(Wrap, {
        isOpen: isOpen,
        isRight: isRight
      }, _react.default.createElement(Toggle, {
        isOpen: isOpen,
        isRight: isRight,
        onClick: this.onToggle
      }, _react.default.createElement(_component2.default, {
        svg: toggleIcon,
        size: 1.6
      })), _react.default.createElement(Content, null, children));
    }
  }]);

  return PageSidePane;
}(_react.Component);

PageSidePane.propTypes = {
  isOpenByDefault: _propTypes.bool,
  isRight: _propTypes.bool,
  toggleIcon: _propTypes.string.isRequired,
  onToggle: _propTypes.func,
  children: _propTypes.node.isRequired
};
PageSidePane.defaultProps = {
  isOpenByDefault: false,
  isRight: false,
  onToggle: function onToggle() {}
};
var _default = PageSidePane;
exports.default = _default;