"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/inserter/block-patterns-tab/patterns-filter.js
var patterns_filter_exports = {};
__export(patterns_filter_exports, {
  PatternsFilter: () => PatternsFilter
});
module.exports = __toCommonJS(patterns_filter_exports);
var import_components = require("@wordpress/components");
var import_i18n = require("@wordpress/i18n");
var import_icons = require("@wordpress/icons");
var import_element = require("@wordpress/element");
var import_utils = require("./utils");
var import_jsx_runtime = require("react/jsx-runtime");
var getShouldDisableSyncFilter = (sourceFilter) => sourceFilter !== "all" && sourceFilter !== "user";
var getShouldHideSourcesFilter = (category) => {
  return category.name === import_utils.myPatternsCategory.name;
};
var PATTERN_SOURCE_MENU_OPTIONS = [
  {
    value: "all",
    label: (0, import_i18n._x)("All", "patterns")
  },
  {
    value: import_utils.INSERTER_PATTERN_TYPES.directory,
    label: (0, import_i18n.__)("Pattern Directory")
  },
  {
    value: import_utils.INSERTER_PATTERN_TYPES.theme,
    label: (0, import_i18n.__)("Theme & Plugins")
  },
  {
    value: import_utils.INSERTER_PATTERN_TYPES.user,
    label: (0, import_i18n.__)("User")
  }
];
function PatternsFilter({
  setPatternSyncFilter,
  setPatternSourceFilter,
  patternSyncFilter,
  patternSourceFilter,
  scrollContainerRef,
  category
}) {
  const currentPatternSourceFilter = category.name === import_utils.myPatternsCategory.name ? import_utils.INSERTER_PATTERN_TYPES.user : patternSourceFilter;
  const shouldDisableSyncFilter = getShouldDisableSyncFilter(
    currentPatternSourceFilter
  );
  const shouldHideSourcesFilter = getShouldHideSourcesFilter(category);
  const patternSyncMenuOptions = (0, import_element.useMemo)(
    () => [
      {
        value: "all",
        label: (0, import_i18n._x)("All", "patterns")
      },
      {
        value: import_utils.INSERTER_SYNC_TYPES.full,
        label: (0, import_i18n._x)("Synced", "patterns"),
        disabled: shouldDisableSyncFilter
      },
      {
        value: import_utils.INSERTER_SYNC_TYPES.unsynced,
        label: (0, import_i18n._x)("Not synced", "patterns"),
        disabled: shouldDisableSyncFilter
      }
    ],
    [shouldDisableSyncFilter]
  );
  function handleSetSourceFilterChange(newSourceFilter) {
    setPatternSourceFilter(newSourceFilter);
    if (getShouldDisableSyncFilter(newSourceFilter)) {
      setPatternSyncFilter("all");
    }
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    import_components.DropdownMenu,
    {
      popoverProps: {
        placement: "right-end"
      },
      label: (0, import_i18n.__)("Filter patterns"),
      toggleProps: { size: "compact" },
      icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        import_icons.Icon,
        {
          icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
            import_components.SVG,
            {
              width: "24",
              height: "24",
              viewBox: "0 0 24 24",
              fill: "none",
              xmlns: "http://www.w3.org/2000/svg",
              children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                import_components.Path,
                {
                  d: "M10 17.5H14V16H10V17.5ZM6 6V7.5H18V6H6ZM8 12.5H16V11H8V12.5Z",
                  fill: "currentColor"
                }
              )
            }
          )
        }
      ),
      children: () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
        !shouldHideSourcesFilter && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.MenuGroup, { label: (0, import_i18n.__)("Source"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          import_components.MenuItemsChoice,
          {
            choices: PATTERN_SOURCE_MENU_OPTIONS,
            onSelect: (value) => {
              handleSetSourceFilterChange(value);
              scrollContainerRef.current?.scrollTo(
                0,
                0
              );
            },
            value: currentPatternSourceFilter
          }
        ) }),
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.MenuGroup, { label: (0, import_i18n.__)("Type"), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          import_components.MenuItemsChoice,
          {
            choices: patternSyncMenuOptions,
            onSelect: (value) => {
              setPatternSyncFilter(value);
              scrollContainerRef.current?.scrollTo(
                0,
                0
              );
            },
            value: patternSyncFilter
          }
        ) }),
        /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "block-editor-inserter__patterns-filter-help", children: (0, import_element.createInterpolateElement)(
          (0, import_i18n.__)(
            "Patterns are available from the <Link>WordPress.org Pattern Directory</Link>, bundled in the active theme, or created by users on this site. Only patterns created on this site can be synced."
          ),
          {
            Link: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
              import_components.ExternalLink,
              {
                href: (0, import_i18n.__)(
                  "https://wordpress.org/patterns/"
                )
              }
            )
          }
        ) })
      ] })
    }
  ) });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  PatternsFilter
});
//# sourceMappingURL=patterns-filter.js.map
