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 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("post");
  const view = await loadView({
    kind: "postType",
    name: "post",
    slug: activeView,
    defaultView: getDefaultView(postTypeObject, activeView)
  });
  return view.type === "list";
}
function MobilePostsView() {
  const { query = {} } = useLocation();
  const { canvas = "view" } = query;
  return canvas === "edit" ? /* @__PURE__ */ jsx(Editor, {}) : /* @__PURE__ */ jsx(PostList, { postType: "post" });
}
const postsRoute = {
  name: "posts",
  path: "/",
  areas: {
    sidebar: /* @__PURE__ */ jsx(
      SidebarNavigationScreen,
      {
        title: __("Posts"),
        isRoot: true,
        content: /* @__PURE__ */ jsx(DataViewsSidebarContent, { postType: "post" })
      }
    ),
    content: /* @__PURE__ */ jsx(PostList, { postType: "post" }),
    async preview({ query }) {
      const isList = await isListView(query);
      return isList ? /* @__PURE__ */ jsx(Editor, { isPostsList: true }) : void 0;
    },
    mobile: /* @__PURE__ */ jsx(MobilePostsView, {}),
    async edit({ query }) {
      const isList = await isListView(query);
      const hasQuickEdit = !isList && !!query.quickEdit;
      return hasQuickEdit ? /* @__PURE__ */ jsx(PostEdit, { postType: "post", 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 {
  postsRoute
};
//# sourceMappingURL=posts.js.map
