"use strict";Liferay.Loader.define("@liferay!analytics-settings-web$testing-library/dom@8.20.0/dist/queries/label-text",["module","exports","require","../config","../helpers","../label-helpers","./all-utils"],(function(e,t,l){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.queryByLabelText=t.queryAllByLabelText=t.getByLabelText=t.getAllByLabelText=t.findByLabelText=t.findAllByLabelText=void 0;var r=l("../config"),a=l("../helpers"),o=l("../label-helpers"),n=l("./all-utils");const queryAllLabelsByText=(e,t,{exact:l=!0,trim:r,collapseWhitespace:a,normalizer:i}={})=>{const s=l?n.matches:n.fuzzyMatches,u=(0,n.makeNormalizer)({collapseWhitespace:a,trim:r,normalizer:i});return function queryAllLabels(e){return Array.from(e.querySelectorAll("label,input")).map((e=>({node:e,textToMatch:(0,o.getLabelContent)(e)}))).filter((({textToMatch:e})=>null!==e))}(e).filter((({node:e,textToMatch:l})=>s(l,e,t,u))).map((({node:e})=>e))},queryAllByLabelText=(e,t,{selector:l="*",exact:r=!0,collapseWhitespace:i,trim:s,normalizer:u}={})=>{(0,a.checkContainerType)(e);const c=r?n.matches:n.fuzzyMatches,h=(0,n.makeNormalizer)({collapseWhitespace:i,trim:s,normalizer:u}),y=Array.from(e.querySelectorAll("*")).filter((e=>(0,o.getRealLabels)(e).length||e.hasAttribute("aria-labelledby"))).reduce(((r,a)=>{const n=(0,o.getLabels)(e,a,{selector:l});n.filter((e=>Boolean(e.formControl))).forEach((e=>{c(e.content,e.formControl,t,h)&&e.formControl&&r.push(e.formControl)}));const i=n.filter((e=>Boolean(e.content))).map((e=>e.content));return c(i.join(" "),a,t,h)&&r.push(a),i.length>1&&i.forEach(((e,l)=>{c(e,a,t,h)&&r.push(a);const o=[...i];o.splice(l,1),o.length>1&&c(o.join(" "),a,t,h)&&r.push(a)})),r}),[]).concat((0,n.queryAllByAttribute)("aria-label",e,t,{exact:r,normalizer:h}));return Array.from(new Set(y)).filter((e=>e.matches(l)))},getAllByLabelText=(e,t,...l)=>{const a=queryAllByLabelText(e,t,...l);if(!a.length){const a=queryAllLabelsByText(e,t,...l);if(a.length){const l=a.map((t=>function getTagNameOfElementAssociatedWithLabelViaFor(e,t){const l=t.getAttribute("for");if(!l)return null;const r=e.querySelector(`[id="${l}"]`);return r?r.tagName.toLowerCase():null}(e,t))).filter((e=>!!e));throw l.length?(0,r.getConfig)().getElementError(l.map((e=>`Found a label with the text of: ${t}, however the element associated with this label (<${e} />) is non-labellable [https://html.spec.whatwg.org/multipage/forms.html#category-label]. If you really need to label a <${e} />, you can use aria-label or aria-labelledby instead.`)).join("\n\n"),e):(0,r.getConfig)().getElementError(`Found a label with the text of: ${t}, however no form control was found associated to that label. Make sure you're using the "for" attribute or "aria-labelledby" attribute correctly.`,e)}throw(0,r.getConfig)().getElementError("Unable to find a label with the text of: "+t,e)}return a};const getMultipleError=(e,t)=>"Found multiple elements with the text of: "+t,e=(0,n.wrapSingleQueryWithSuggestion)((0,n.makeSingleQuery)(queryAllByLabelText,getMultipleError),queryAllByLabelText.name,"query");t.queryByLabelText=e;const i=(0,n.makeSingleQuery)(getAllByLabelText,getMultipleError),s=(0,n.makeFindQuery)((0,n.wrapAllByQueryWithSuggestion)(getAllByLabelText,getAllByLabelText.name,"findAll"));t.findAllByLabelText=s;const u=(0,n.makeFindQuery)((0,n.wrapSingleQueryWithSuggestion)(i,getAllByLabelText.name,"find"));t.findByLabelText=u;const c=(0,n.wrapAllByQueryWithSuggestion)(getAllByLabelText,getAllByLabelText.name,"getAll");t.getAllByLabelText=c;const h=(0,n.wrapSingleQueryWithSuggestion)(i,getAllByLabelText.name,"get");t.getByLabelText=h;const y=(0,n.wrapAllByQueryWithSuggestion)(queryAllByLabelText,queryAllByLabelText.name,"queryAll");t.queryAllByLabelText=y}}));
//# sourceMappingURL=label-text.js.map