"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = App;
var _data = require("@wordpress/data");
var _router = require("@wordpress/router");
var _element = require("@wordpress/element");
var _coreData = require("@wordpress/core-data");
var _layout = _interopRequireDefault(require("../layout"));
var _lockUnlock = require("../../lock-unlock");
var _store = require("../../store");
var _useCommonCommands = require("../../hooks/commands/use-common-commands");
var _useSetCommandContext = _interopRequireDefault(require("../../hooks/commands/use-set-command-context"));
var _siteEditorRoutes = require("../site-editor-routes");
var _isPreviewingTheme = require("../../utils/is-previewing-theme");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

const {
  RouterProvider
} = (0, _lockUnlock.unlock)(_router.privateApis);
function AppLayout() {
  (0, _useCommonCommands.useCommonCommands)();
  (0, _useSetCommandContext.default)();
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_layout.default, {});
}
function App() {
  (0, _siteEditorRoutes.useRegisterSiteEditorRoutes)();
  const {
    routes,
    currentTheme,
    editorSettings
  } = (0, _data.useSelect)(select => {
    return {
      routes: (0, _lockUnlock.unlock)(select(_store.store)).getRoutes(),
      currentTheme: select(_coreData.store).getCurrentTheme(),
      // This is a temp solution until the has_theme_json value is available for the current theme.
      editorSettings: select(_store.store).getSettings()
    };
  }, []);
  const beforeNavigate = (0, _element.useCallback)(({
    path,
    query
  }) => {
    if (!(0, _isPreviewingTheme.isPreviewingTheme)()) {
      return {
        path,
        query
      };
    }
    return {
      path,
      query: {
        ...query,
        wp_theme_preview: 'wp_theme_preview' in query ? query.wp_theme_preview : (0, _isPreviewingTheme.currentlyPreviewingTheme)()
      }
    };
  }, []);
  const matchResolverArgsValue = (0, _element.useMemo)(() => ({
    siteData: {
      currentTheme,
      editorSettings
    }
  }), [currentTheme, editorSettings]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(RouterProvider, {
    routes: routes,
    pathArg: "p",
    beforeNavigate: beforeNavigate,
    matchResolverArgs: matchResolverArgsValue,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(AppLayout, {})
  });
}
//# sourceMappingURL=index.js.map