import{create as t}from"@bufbuild/protobuf";import{SearchQuerySchema as o,TagSchema as l}from"@orderlyshop/core-client";var w=["keywords","tags","hidden-query","order-by","store-id","featured"];function h(e={}){return t(o,{Query:e.query??e.keywords,HiddenQuery:e.hiddenQuery,Tags:(e.tags??[]).map(r=>t(l,{Value:r})),OrderBy:e.orderBy??[],StoreId:e.storeId,Featured:e.featured??!1})}function x(e={}){return m(e)?t(o,e):h(e)}function C(e){let r=S(e),n=i(e,r,"keywords"),u=i(e,r,"hidden-query"),a=i(e,r,"store-id"),s=b(e,r,"featured"),f=y(e,r,"tags"),c=y(e,r,"order-by");if(!(!n&&!u&&!a&&s===void 0&&f.length===0&&c.length===0))return t(o,{Query:n||void 0,HiddenQuery:u||void 0,Tags:f.map(Q=>t(l,{Value:Q})),OrderBy:c,StoreId:a||void 0,Featured:s??!1})}function S(e){let r=[...e.children].find(n=>n.localName==="query");return r instanceof HTMLElement&&(r.hidden=!0),r}function m(e){return"Query"in e||"HiddenQuery"in e||"Tags"in e||"OrderBy"in e||"StoreId"in e||"Featured"in e}function i(e,r,n){return A(e.getAttribute(n),r?.getAttribute(n),g(r,n))}function y(e,r,n){return B([...d(e.getAttribute(n)),...d(r?.getAttribute(n)),...d(g(r,n))])}function b(e,r,n){return e.hasAttribute(n)&&!e.getAttribute(n)||r?.hasAttribute(n)&&!r.getAttribute(n)?!0:E(i(e,r,n))}function g(e,r){return[...e?.children??[]].find(u=>u.localName===r)?.textContent?.trim()}function A(...e){return e.map(r=>r?.trim()).find(Boolean)??""}function d(e){return(e??"").split(/[\n,]/g).map(r=>r.trim()).filter(Boolean)}function B(e){return[...new Set(e)]}function E(e){if(e){if(["true","1","yes",""].includes(e.toLowerCase()))return!0;if(["false","0","no"].includes(e.toLowerCase()))return!1}}export{h as createSearchQuery,w as declarativeQueryAttributes,C as declarativeSearchQuery,x as normalizeSearchQuery};
//# sourceMappingURL=query.js.map