"use strict";var __defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(e,t)=>{for(var o in t)__defProp(e,o,{get:t[o],enumerable:!0})},__copyProps=(e,t,o,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of __getOwnPropNames(t))__hasOwnProp.call(e,n)||n===o||__defProp(e,n,{get:()=>t[n],enumerable:!(r=__getOwnPropDesc(t,n))||r.enumerable});return e},__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),use_taxonomy_search_exports={};__export(use_taxonomy_search_exports,{default:()=>use_taxonomy_search_default}),module.exports=__toCommonJS(use_taxonomy_search_exports);var import_element=require("@wordpress/element"),import_data=require("@wordpress/data"),import_components=require("@woocommerce/components");async function getTaxonomiesMissingParents(e,t){const o=[],r={};if(e.forEach(e=>{r[e.id]=e}),e.forEach(e=>{e.parent>0&&!r[e.parent]&&o.push(e.parent)}),o.length>0){const r=await(0,import_data.resolveSelect)("core").getEntityRecords("taxonomy",t,{include:o});if(r)return getTaxonomiesMissingParents([...r,...e],t)}return e}const PAGINATION_SIZE=30,useTaxonomySearch=(e,t={fetchParents:!0})=>{const[o,r]=(0,import_element.useState)(!1);return{searchEntity:async function(o){r(!0);let n=[];try{const r=await(0,import_data.resolveSelect)("core").getEntityRecords("taxonomy",e,{per_page:30,search:(0,import_components.escapeHTML)(o)});r&&(n=r,t?.fetchParents&&(n=await getTaxonomiesMissingParents(n,e)))}finally{r(!1)}return n},isResolving:o}};var use_taxonomy_search_default=useTaxonomySearch;