"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var sidebar_global_styles_wrapper_exports = {};
__export(sidebar_global_styles_wrapper_exports, {
  default: () => GlobalStylesUIWrapper,
  useSection: () => useSection
});
module.exports = __toCommonJS(sidebar_global_styles_wrapper_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_admin_ui = require("@wordpress/admin-ui");
var import_i18n = require("@wordpress/i18n");
var import_data = require("@wordpress/data");
var import_core_data = require("@wordpress/core-data");
var import_element = require("@wordpress/element");
var import_router = require("@wordpress/router");
var import_compose = require("@wordpress/compose");
var import_components = require("@wordpress/components");
var import_url = require("@wordpress/url");
var import_icons = require("@wordpress/icons");
var import_ui = __toESM(require("../global-styles/ui"));
var import_lock_unlock = require("../../lock-unlock");
const { useLocation, useHistory } = (0, import_lock_unlock.unlock)(import_router.privateApis);
const GlobalStylesPageActions = ({
  isStyleBookOpened,
  setIsStyleBookOpened,
  path
}) => {
  const history = useHistory();
  const canEditCSS = (0, import_data.useSelect)((select) => {
    const { getEntityRecord, __experimentalGetCurrentGlobalStylesId } = select(import_core_data.store);
    const globalStylesId = __experimentalGetCurrentGlobalStylesId();
    const globalStyles = globalStylesId ? getEntityRecord("root", "globalStyles", globalStylesId) : void 0;
    return !!globalStyles?._links?.["wp:action-edit-css"];
  }, []);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_components.Button,
      {
        isPressed: isStyleBookOpened,
        icon: import_icons.seen,
        label: (0, import_i18n.__)("Style Book"),
        onClick: () => {
          setIsStyleBookOpened(!isStyleBookOpened);
          const updatedPath = !isStyleBookOpened ? (0, import_url.addQueryArgs)(path, { preview: "stylebook" }) : (0, import_url.removeQueryArgs)(path, "preview");
          history.navigate(updatedPath);
        },
        size: "compact"
      }
    ),
    canEditCSS && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_components.DropdownMenu,
      {
        icon: import_icons.moreVertical,
        label: (0, import_i18n.__)("More"),
        toggleProps: { size: "compact" },
        children: ({ onClose }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.MenuGroup, { children: canEditCSS && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          import_components.MenuItem,
          {
            onClick: () => {
              onClose();
              history.navigate(
                (0, import_url.addQueryArgs)(path, {
                  section: "/css"
                })
              );
            },
            children: (0, import_i18n.__)("Additional CSS")
          }
        ) })
      }
    )
  ] });
};
const useSection = () => {
  const { path, query } = useLocation();
  const history = useHistory();
  return (0, import_element.useMemo)(() => {
    return [
      query.section ?? "/",
      (updatedSection) => {
        history.navigate(
          (0, import_url.addQueryArgs)(path, {
            section: updatedSection
          })
        );
      }
    ];
  }, [path, query.section, history]);
};
function GlobalStylesUIWrapper() {
  const { path } = useLocation();
  const [isStyleBookOpened, setIsStyleBookOpened] = (0, import_element.useState)(
    path.includes("preview=stylebook")
  );
  const isMobileViewport = (0, import_compose.useViewportMatch)("medium", "<");
  const [section, onChangeSection] = useSection();
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_admin_ui.Page,
    {
      actions: !isMobileViewport ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        GlobalStylesPageActions,
        {
          isStyleBookOpened,
          setIsStyleBookOpened,
          path
        }
      ) : null,
      className: "edit-site-styles",
      title: (0, import_i18n.__)("Styles"),
      children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_ui.default, { path: section, onPathChange: onChangeSection })
    }
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useSection
});
//# sourceMappingURL=index.js.map
