"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = useLayoutAreas;
var _router = require("@wordpress/router");
var _data = require("@wordpress/data");
var _coreData = require("@wordpress/core-data");
var _lockUnlock = require("../../lock-unlock");
var _editor = _interopRequireDefault(require("../editor"));
var _sidebarNavigationScreen = _interopRequireDefault(require("../sidebar-navigation-screen"));
var _sidebarNavigationScreenMain = _interopRequireDefault(require("../sidebar-navigation-screen-main"));
var _sidebarDataviews = _interopRequireDefault(require("../sidebar-dataviews"));
var _postList = _interopRequireDefault(require("../post-list"));
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

const {
  useLocation
} = (0, _lockUnlock.unlock)(_router.privateApis);
function useLayoutAreas() {
  const {
    params = {}
  } = useLocation();
  const {
    postType,
    layout,
    canvas
  } = params;
  const labels = (0, _data.useSelect)(select => {
    return select(_coreData.store).getPostType(postType)?.labels;
  }, [postType]);

  // Posts list.
  if (['post'].includes(postType)) {
    const isListLayout = layout === 'list' || !layout;
    return {
      key: 'posts-list',
      areas: {
        sidebar: /*#__PURE__*/(0, _jsxRuntime.jsx)(_sidebarNavigationScreen.default, {
          title: labels?.name,
          isRoot: true,
          content: /*#__PURE__*/(0, _jsxRuntime.jsx)(_sidebarDataviews.default, {})
        }),
        content: /*#__PURE__*/(0, _jsxRuntime.jsx)(_postList.default, {
          postType: postType
        }),
        preview: (isListLayout || canvas === 'edit') && /*#__PURE__*/(0, _jsxRuntime.jsx)(_editor.default, {
          isPostsList: true
        }),
        mobile: canvas === 'edit' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_editor.default, {
          isPostsList: true
        }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_postList.default, {
          postType: postType
        })
      },
      widths: {
        content: isListLayout ? 380 : undefined
      }
    };
  }

  // Fallback shows the home page preview
  return {
    key: 'default',
    areas: {
      sidebar: /*#__PURE__*/(0, _jsxRuntime.jsx)(_sidebarNavigationScreenMain.default, {}),
      preview: /*#__PURE__*/(0, _jsxRuntime.jsx)(_editor.default, {
        isPostsList: true
      }),
      mobile: canvas === 'edit' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_editor.default, {
        isPostsList: true
      })
    }
  };
}
//# sourceMappingURL=router.js.map