(function (global, factory) {
  if (typeof define === "function" && define.amd) {
    define(['exports', 'react', 'classnames', './px-drawer-layout.scss', '../../Drawer', '../../AppHeader', '../../BrandingBar', '../../AppNav', '../../Navbar', '../../BaseComponent', '../../../iron/iron-media-query'], factory);
  } else if (typeof exports !== "undefined") {
    factory(exports, require('react'), require('classnames'), require('./px-drawer-layout.scss'), require('../../Drawer'), require('../../AppHeader'), require('../../BrandingBar'), require('../../AppNav'), require('../../Navbar'), require('../../BaseComponent'), require('../../../iron/iron-media-query'));
  } else {
    var mod = {
      exports: {}
    };
    factory(mod.exports, global.react, global.classnames, global.pxDrawerLayout, global.Drawer, global.AppHeader, global.BrandingBar, global.AppNav, global.Navbar, global.BaseComponent, global.ironMediaQuery);
    global.index = mod.exports;
  }
})(this, function (exports, _react, _classnames, _pxDrawerLayout, _Drawer, _AppHeader, _BrandingBar, _AppNav, _Navbar, _BaseComponent2, _ironMediaQuery) {
  'use strict';

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

  var _react2 = _interopRequireDefault(_react);

  var _classnames2 = _interopRequireDefault(_classnames);

  var _pxDrawerLayout2 = _interopRequireDefault(_pxDrawerLayout);

  var _Drawer2 = _interopRequireDefault(_Drawer);

  var _AppHeader2 = _interopRequireDefault(_AppHeader);

  var _BrandingBar2 = _interopRequireDefault(_BrandingBar);

  var _AppNav2 = _interopRequireDefault(_AppNav);

  var _Navbar2 = _interopRequireDefault(_Navbar);

  var _BaseComponent3 = _interopRequireDefault(_BaseComponent2);

  var _ironMediaQuery2 = _interopRequireDefault(_ironMediaQuery);

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

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

  var _createClass = 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);
      }
    }

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

  function _possibleConstructorReturn(self, call) {
    if (!self) {
      throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
    }

    return call && (typeof call === "object" || typeof call === "function") ? call : self;
  }

  function _inherits(subClass, superClass) {
    if (typeof superClass !== "function" && superClass !== null) {
      throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
    }

    subClass.prototype = Object.create(superClass && superClass.prototype, {
      constructor: {
        value: subClass,
        enumerable: false,
        writable: true,
        configurable: true
      }
    });
    if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  }

  var DrawerLayout = function (_BaseComponent) {
    _inherits(DrawerLayout, _BaseComponent);

    function DrawerLayout(props) {
      _classCallCheck(this, DrawerLayout);

      var _this = _possibleConstructorReturn(this, (DrawerLayout.__proto__ || Object.getPrototypeOf(DrawerLayout)).call(this, props, { displayName: 'DrawerLayout' }));

      _this.isAttached = false;
      _this.state = {
        isNarrow: false
      };
      _this.handleMediaChange = _this.handleMediaChange.bind(_this);
      return _this;
    }

    _createClass(DrawerLayout, [{
      key: 'componentDidMount',
      value: function componentDidMount() {
        this.isAttached = true;
      }
    }, {
      key: 'handleMediaChange',
      value: function handleMediaChange(e) {
        var narrow = !e.queryMatches;
        var contentContainer = this.contentContainer;
        var drawer = this.drawer;
        var drawerWidth = drawer.offsetWidth || '256';
        if (narrow) {
          contentContainer.style.marginLeft = '';
          contentContainer.style.marginRight = '';
        } else {
          if (drawer.props.align == 'right') {
            contentContainer.style.marginLeft = '';
            contentContainer.style.marginRight = drawerWidth + 'px';
          } else {
            contentContainer.style.marginLeft = drawerWidth + 'px';
            contentContainer.style.marginRight = '';
          }
        }
        this.setState({ isNarrow: narrow });
      }
    }, {
      key: '_handleDrawerToggle',
      value: function _handleDrawerToggle() {
        var drawer = this.drawer;
        drawer.toggle();
      }
    }, {
      key: 'render',
      value: function render() {
        var _this2 = this;

        var _props = this.props,
            _props$title = _props.title,
            title = _props$title === undefined ? 'Drawer Layout' : _props$title,
            forceNarrow = _props.forceNarrow,
            _props$responsiveWidt = _props.responsiveWidth,
            responsiveWidth = _props$responsiveWidt === undefined ? '768px' : _props$responsiveWidt,
            navItems = _props.navItems,
            drawerContent = _props.drawerContent,
            navbarContent = _props.navbarContent,
            children = _props.children;
        var _state = this.state,
            isOpen = _state.isOpen,
            isNarrow = _state.isNarrow;


        var baseClassNames = (0, _classnames2.default)('px-drawer-layout', { 'px-drawer-layout--is-narrow': isNarrow }, 'l-drawer-layout');

        var headerContent = _react2.default.createElement(
          'div',
          { className: 'flex' },
          _react2.default.createElement(
            'div',
            { className: 'flex__item' },
            _react2.default.createElement(_BrandingBar2.default, { title: title })
          )
        );

        return _react2.default.createElement(
          'div',
          { className: baseClassNames, ref: function ref(el) {
              _this2.baseElement = el;
            } },
          !isNarrow && headerContent,
          _react2.default.createElement(
            'div',
            { id: 'container', className: 'l-drawer-layout__container', ref: function ref(el) {
                _this2.container = el;
              } },
            _react2.default.createElement(
              'div',
              { id: 'drawerContainer', className: 'l-drawer-layout__drawer', ref: function ref(el) {
                  _this2.drawerContainer = el;
                } },
              _react2.default.createElement(
                _Drawer2.default,
                {

                  ref: function ref(el) {
                    _this2.drawer = el;
                  },
                  open: isOpen,
                  docked: !isNarrow,
                  onOverlayClick: function onOverlayClick(e) {
                    return _this2.setState({ isOpen: false });
                  }
                },
                _react2.default.createElement(_AppNav2.default, {
                  vertical: true,
                  items: navItems }),
                drawerContent
              )
            ),
            _react2.default.createElement(
              'div',
              { id: 'contentContainer', className: 'l-drawer-layout__content', ref: function ref(el) {
                  _this2.contentContainer = el;
                } },
              _react2.default.createElement(
                'nav',
                { id: 'navbarContent' },
                _react2.default.createElement(_Navbar2.default, { title: title,
                  showMenuButton: isNarrow,
                  onMenuButtonClick: function onMenuButtonClick(e) {
                    return _this2._handleDrawerToggle(e);
                  } })
              ),
              _react2.default.createElement(
                'div',
                { id: 'content' },
                children
              )
            )
          ),
          _react2.default.createElement(_ironMediaQuery2.default, {
            onChange: this.handleMediaChange,
            query: '(min-width: ' + this.props.responsiveWidth + ')', full: true }),
          _react2.default.createElement(
            'style',
            { jsx: true },
            _pxDrawerLayout2.default
          )
        );
      }
    }]);

    return DrawerLayout;
  }(_BaseComponent3.default);

  exports.default = DrawerLayout;


  DrawerLayout.defaultProps = {
    forceNarrow: false,
    responsiveWidth: '768px',
    narrow: false
  };
});