import { jsx } from "react/jsx-runtime";
import { privateApis as routerPrivateApis } from "@wordpress/router";
import { __ } from "@wordpress/i18n";
import { loadView } from "@wordpress/views";
import { resolveSelect } from "@wordpress/data";
import { store as coreStore } from "@wordpress/core-data";
import Editor from "../editor";
import SidebarNavigationScreen from "../sidebar-navigation-screen";
import SidebarNavigationScreenUnsupported from "../sidebar-navigation-screen-unsupported";
import DataViewsSidebarContent from "../sidebar-dataviews";
import PostList from "../post-list";
import { unlock } from "../../lock-unlock";
import { PostEdit } from "../post-edit";
import { getDefaultView } from "../post-list/view-utils";
const { useLocation } = unlock(routerPrivateApis);
async function isListView(query) {
  const { activeView = "all" } = query;
  const postTypeObject = await resolveSelect(coreStore).getPostType("page");
  const view = await loadView({
    kind: "postType",
    name: "page",
    slug: activeView,
    defaultView: getDefaultView(postTypeObject, activeView)
  });
  return view.type === "list";
}
function MobilePagesView() {
  const { query = {} } = useLocation();
  const { canvas = "view" } = query;
  return canvas === "edit" ? /* @__PURE__ */ jsx(Editor, {}) : /* @__PURE__ */ jsx(PostList, { postType: "page" });
}
const pagesRoute = {
  name: "pages",
  path: "/page",
  areas: {
    sidebar({ siteData }) {
      const isBlockTheme = siteData.currentTheme?.is_block_theme;
      return isBlockTheme ? /* @__PURE__ */ jsx(
        SidebarNavigationScreen,
        {
          title: __("Pages"),
          backPath: "/",
          content: /* @__PURE__ */ jsx(DataViewsSidebarContent, { postType: "page" })
        }
      ) : /* @__PURE__ */ jsx(SidebarNavigationScreenUnsupported, {});
    },
    content({ siteData }) {
      const isBlockTheme = siteData.currentTheme?.is_block_theme;
      return isBlockTheme ? /* @__PURE__ */ jsx(PostList, { postType: "page" }) : void 0;
    },
    async preview({ query, siteData }) {
      const isBlockTheme = siteData.currentTheme?.is_block_theme;
      if (!isBlockTheme) {
        return void 0;
      }
      const isList = await isListView(query);
      return isList ? /* @__PURE__ */ jsx(Editor, {}) : void 0;
    },
    mobile({ siteData }) {
      const isBlockTheme = siteData.currentTheme?.is_block_theme;
      return isBlockTheme ? /* @__PURE__ */ jsx(MobilePagesView, {}) : /* @__PURE__ */ jsx(SidebarNavigationScreenUnsupported, {});
    },
    async edit({ query }) {
      const isList = await isListView(query);
      const hasQuickEdit = !isList && !!query.quickEdit;
      return hasQuickEdit ? /* @__PURE__ */ jsx(PostEdit, { postType: "page", postId: query.postId }) : void 0;
    }
  },
  widths: {
    async content({ query }) {
      const isList = await isListView(query);
      return isList ? 380 : void 0;
    },
    async edit({ query }) {
      const isList = await isListView(query);
      const hasQuickEdit = !isList && !!query.quickEdit;
      return hasQuickEdit ? 380 : void 0;
    }
  }
};
export {
  pagesRoute
};
//# sourceMappingURL=pages.js.map
