"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 inspector_controls_exports = {};
__export(inspector_controls_exports, {
  default: () => TermsQueryInspectorControls
});
module.exports = __toCommonJS(inspector_controls_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_i18n = require("@wordpress/i18n");
var import_components = require("@wordpress/components");
var import_block_editor = require("@wordpress/block-editor");
var import_hooks = require("../../../utils/hooks");
var import_utils = require("../../utils");
var import_taxonomy_control = __toESM(require("./taxonomy-control"));
var import_order_control = __toESM(require("./order-control"));
var import_empty_terms_control = __toESM(require("./empty-terms-control"));
var import_nested_terms_control = __toESM(require("./nested-terms-control"));
var import_inherit_control = __toESM(require("./inherit-control"));
var import_max_terms_control = __toESM(require("./max-terms-control"));
var import_advanced_controls = __toESM(require("./advanced-controls"));
var import_include_control = __toESM(require("./include-control"));
function TermsQueryInspectorControls({
  attributes,
  setQuery,
  setAttributes,
  clientId,
  templateSlug
}) {
  const { termQuery, tagName: TagName } = attributes;
  const {
    taxonomy,
    orderBy,
    order,
    hideEmpty,
    inherit,
    showNested,
    perPage,
    include
  } = termQuery;
  const dropdownMenuProps = (0, import_hooks.useToolsPanelDropdownMenuProps)();
  const taxonomies = (0, import_utils.usePublicTaxonomies)();
  const isTaxonomyHierarchical = taxonomies.find(
    (_taxonomy) => _taxonomy.slug === taxonomy
  )?.hierarchical;
  const inheritQuery = !!inherit;
  const displayInheritControl = ["taxonomy", "category", "tag", "archive"].includes(templateSlug) || templateSlug?.startsWith("taxonomy-") || templateSlug?.startsWith("category-") || templateSlug?.startsWith("tag-");
  const displayShowNestedControl = isTaxonomyHierarchical && !inheritQuery;
  const hasIncludeFilter = !!include?.length;
  const queryTypeControlLabel = (0, import_i18n.__)("Query type");
  const taxonomyControlLabel = (0, import_i18n.__)("Taxonomy");
  const orderByControlLabel = (0, import_i18n.__)("Order by");
  const emptyTermsControlLabel = (0, import_i18n.__)("Show empty terms");
  const nestedTermsControlLabel = (0, import_i18n.__)("Show nested terms");
  const maxTermsControlLabel = (0, import_i18n.__)("Max terms");
  const includeControlLabel = (0, import_i18n.__)("Selected terms");
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_editor.InspectorControls, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
      import_components.__experimentalToolsPanel,
      {
        label: (0, import_i18n.__)("Settings"),
        resetAll: () => {
          setAttributes({
            termQuery: {
              taxonomy: "category",
              order: "asc",
              orderBy: "name",
              include: [],
              hideEmpty: true,
              showNested: false,
              inherit: false,
              perPage: 10
            }
          });
        },
        dropdownMenuProps,
        children: [
          displayInheritControl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
            import_components.__experimentalToolsPanelItem,
            {
              hasValue: () => inherit !== false,
              label: queryTypeControlLabel,
              onDeselect: () => setQuery({ inherit: false }),
              isShownByDefault: true,
              children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                import_inherit_control.default,
                {
                  label: queryTypeControlLabel,
                  value: inherit,
                  onChange: setQuery
                }
              )
            }
          ),
          !inheritQuery && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
            import_components.__experimentalToolsPanelItem,
            {
              hasValue: () => taxonomy !== "category",
              label: taxonomyControlLabel,
              onDeselect: () => {
                setQuery({ taxonomy: "category" });
              },
              isShownByDefault: true,
              children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                import_taxonomy_control.default,
                {
                  label: taxonomyControlLabel,
                  value: taxonomy,
                  onChange: (value) => (
                    // We also need to reset the include filter when changing taxonomy.
                    setQuery({ taxonomy: value, include: [] })
                  )
                }
              )
            }
          ),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
            import_components.__experimentalToolsPanelItem,
            {
              hasValue: () => orderBy !== "name" || order !== "asc",
              label: orderByControlLabel,
              onDeselect: () => setQuery({ orderBy: "name", order: "asc" }),
              isShownByDefault: true,
              children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                import_order_control.default,
                {
                  label: orderByControlLabel,
                  ...{ orderBy, order },
                  onChange: (newOrderBy, newOrder) => {
                    setQuery({
                      orderBy: newOrderBy,
                      order: newOrder
                    });
                  },
                  disabled: hasIncludeFilter,
                  help: hasIncludeFilter ? (0, import_i18n.__)(
                    "When specific terms are selected, the order is based on their selection order."
                  ) : void 0
                }
              )
            }
          ),
          !inheritQuery && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
            import_components.__experimentalToolsPanelItem,
            {
              hasValue: () => !!include?.length,
              label: includeControlLabel,
              onDeselect: () => setQuery({
                include: [],
                orderBy: "name",
                order: "asc"
              }),
              isShownByDefault: true,
              children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                import_include_control.default,
                {
                  label: includeControlLabel,
                  taxonomy,
                  value: include,
                  onChange: (value) => setQuery({ include: value })
                }
              )
            }
          ),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
            import_components.__experimentalToolsPanelItem,
            {
              hasValue: () => hideEmpty !== true,
              label: emptyTermsControlLabel,
              onDeselect: () => setQuery({ hideEmpty: true }),
              isShownByDefault: true,
              children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                import_empty_terms_control.default,
                {
                  label: emptyTermsControlLabel,
                  value: hideEmpty,
                  onChange: (value) => setQuery({ hideEmpty: value })
                }
              )
            }
          ),
          displayShowNestedControl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
            import_components.__experimentalToolsPanelItem,
            {
              hasValue: () => showNested !== false,
              label: nestedTermsControlLabel,
              onDeselect: () => setQuery({ showNested: false }),
              isShownByDefault: true,
              children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                import_nested_terms_control.default,
                {
                  label: nestedTermsControlLabel,
                  value: showNested,
                  onChange: (value) => setQuery({ showNested: value }),
                  disabled: hasIncludeFilter,
                  help: hasIncludeFilter ? (0, import_i18n.__)(
                    "When specific terms are selected, only those are displayed."
                  ) : void 0
                }
              )
            }
          ),
          /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
            import_components.__experimentalToolsPanelItem,
            {
              hasValue: () => perPage !== 10,
              label: maxTermsControlLabel,
              onDeselect: () => setQuery({ perPage: 10 }),
              isShownByDefault: true,
              children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
                import_max_terms_control.default,
                {
                  label: maxTermsControlLabel,
                  value: perPage,
                  onChange: (value) => setQuery({ perPage: value })
                }
              )
            }
          )
        ]
      }
    ) }),
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_advanced_controls.default,
      {
        TagName,
        setAttributes,
        clientId
      }
    )
  ] });
}
//# sourceMappingURL=index.js.map
