"use strict";

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

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

var _AppBarLeft = _interopRequireDefault(require("./AppBarLeft"));

var _AppBarRight = _interopRequireDefault(require("./AppBarRight"));

var _AppBarContent = _interopRequireDefault(require("./AppBarContent"));

var _primitives = require("../../primitives");

var _utils = require("./utils");

var _reactNative = require("react-native");

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

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

const APPBAR_HEADER_HEIGHT = 56;
const DEFAULT_SPACING_BETWEEN_LEFT_CONTENT_AND_RIGHT = 2;
const DEFAULT_HORIZONTAL_PADDING = 2;

const AppBar = ({
  height = APPBAR_HEADER_HEIGHT,
  statusBarHeight = _utils.APPROX_STATUSBAR_HEIGHT,
  space = DEFAULT_SPACING_BETWEEN_LEFT_CONTENT_AND_RIGHT,
  ...props
}) => {
  let childMap = new Map();

  _react.default.Children.toArray(props.children).reduce((prevVal, child) => {
    if ( /*#__PURE__*/_react.default.isValidElement(child)) {
      childMap.set(child.type, child);
    }

    return prevVal;
  }, childMap);

  let defaultStyle = {
    height,
    marginTop: statusBarHeight
  }; // If status bar height is present, no need for SafeAreaView as View will handle the topOffset using marginTop

  const Wrapper = statusBarHeight ? _react.default.Fragment : _reactNative.SafeAreaView;
  return /*#__PURE__*/_react.default.createElement(Wrapper, null, /*#__PURE__*/_react.default.createElement(_primitives.View, {
    style: defaultStyle
  }, /*#__PURE__*/_react.default.createElement(_primitives.Box, _extends({
    flex: 1,
    px: DEFAULT_HORIZONTAL_PADDING
  }, props), /*#__PURE__*/_react.default.createElement(_primitives.HStack, {
    space: space,
    flex: 1
  }, childMap.get(_AppBarLeft.default), childMap.get(_AppBarContent.default), childMap.get(_AppBarRight.default)))));
};

AppBar.Left = _AppBarLeft.default;
AppBar.Right = _AppBarRight.default;
AppBar.Content = _AppBarContent.default;
var _default = AppBar;
exports.default = _default;
//# sourceMappingURL=AppBar.js.map