"use strict";(globalThis.webpackChunk=globalThis.webpackChunk||[]).push([["app_components_search_custom-scopes-element_ts"],{60722:(e,t,s)=>{s.r(t),s.d(t,{CustomScopesElement:()=>CustomScopesElement});var a=s(39595),o=s(11824);function i(e,t){if(t.has(e))throw TypeError("Cannot initialize the same private elements twice on an object")}function n(e,t,s){if(!t.has(e))throw TypeError("attempted to "+s+" private field on non-instance");return t.get(e)}function l(e,t){var s=n(e,t,"get");return s.get?s.get.call(e):s.value}function r(e,t,s){i(e,t),t.set(e,s)}function c(e,t,s){var a=n(e,t,"set");return!function(e,t,s){if(t.set)t.set.call(e,s);else{if(!t.writable)throw TypeError("attempted to set read only private field");t.value=s}}(e,a,s),s}function u(e,t,s){if(!t.has(e))throw TypeError("attempted to get private field on non-instance");return s}function p(e,t){i(e,t),t.add(e)}function h(e,t,s,a){var o,i=arguments.length,n=i<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,s):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,s,a);else for(var l=e.length-1;l>=0;l--)(o=e[l])&&(n=(i<3?o(n):i>3?o(t,s,n):o(t,s))||n);return i>3&&n&&Object.defineProperty(t,s,n),n}var d=new WeakMap,m=new WeakMap,g=new WeakMap,f=new WeakMap,v=new WeakMap,b=new WeakSet,S=new WeakSet,y=new WeakSet;let CustomScopesElement=class CustomScopesElement extends HTMLElement{connectedCallback(){c(this,d,parseInt(this.getAttribute("data-max-custom-scopes")||"10",10))}initialize(e,t,s,a){c(this,m,e),c(this,g,t),c(this,f,s),c(this,v,a)}mode(){return this.createCustomScopeForm.hidden?"manage":"create"}customScopesSubmit(e){"manage"===this.mode()?this.create(""):this.saveCustomScope(e)}customScopesCancel(){"manage"!==this.mode()&&this.hasScopes?this.setMode("manage"):this.customScopesModalDialog.close()}setMode(e){this.hasScopes&&"manage"===e?(this.createCustomScopeForm.hidden=!0,this.manageCustomScopesForm.hidden=!1,u(this,b,w).call(this,"Saved searches","Create saved search")):(this.createCustomScopeForm.hidden=!1,this.manageCustomScopesForm.hidden=!0)}async saveCustomScope(e){e.preventDefault();let t=e.target.form;if(!t.checkValidity()){t.reportValidity();return}if((await fetch(t.action,{method:"POST",body:new FormData(t)})).ok){l(this,m)?.clear();let e=await l(this,g).call(this);this.setScopes(e),t.reset(),this.setMode("manage")}}async show(){let e=await l(this,g).call(this);this.setScopes(e),this.customScopesModalDialog instanceof HTMLDialogElement?this.customScopesModalDialog.showModal():this.customScopesModalDialog.show(),this.setMode("manage")}openCustomScopesDialog(e){this.customScopesModalDialog instanceof HTMLDialogElement?this.customScopesModalDialog.showModal():this.customScopesModalDialog.show(),e.stopPropagation()}async editCustomScope(e){e.stopPropagation(),e.preventDefault();let t=e.target.getAttribute("data-id");t||(t=e.target.closest("button")?.getAttribute("data-id")||null);let s=await u(this,y,T).call(this,t);t&&s&&(u(this,b,w).call(this,"Update saved search","Update saved search"),this.customScopesIdField.value=s.id,this.customScopesNameField.value=s.name,this.customScopesQueryField.value=s.query,u(this,S,C).call(this,!1),this.setMode("create"))}create(e){u(this,b,w).call(this,"Create saved search","Create saved search"),this.customScopesIdField.value="",this.customScopesNameField.value="",this.customScopesQueryField.value=e,this.customScopesModalDialog instanceof HTMLDialogElement?this.customScopesModalDialog.showModal():this.customScopesModalDialog.show(),u(this,S,C).call(this,!0),this.setMode("create")}async deleteCustomScope(e){let t=l(this,f),s=e.target.getAttribute("data-id");if(s||(s=e.target.closest("button")?.getAttribute("data-id")||null),!t||!s)return;let a=new FormData;if(a.append("id",s),a.append("_method","delete"),(await fetch(t,{method:"POST",headers:{"Scoped-CSRF-Token":l(this,v)},body:a})).ok){let e=await l(this,g).call(this);this.setScopes(e)}l(this,m)?.clear(),this.setMode("manage")}setScopes(e){this.hasScopes=e.length>0;let t=e.map(e=>(0,o.qy)`
${e.name}
${e.query}
`);(0,o.XX)((0,o.qy)`${t}`,this.list)}constructor(...e){super(...e),p(this,b),p(this,S),p(this,y),r(this,d,{writable:!0,value:void 0}),r(this,m,{writable:!0,value:void 0}),r(this,g,{writable:!0,value:void 0}),r(this,f,{writable:!0,value:void 0}),r(this,v,{writable:!0,value:void 0}),c(this,g,()=>Promise.resolve([])),this.hasScopes=!1}};function w(e,t){this.customScopesSubmitButton.textContent=t,this.customScopesModalDialog.getElementsByTagName("h1")[0].textContent=e}function C(e){let t=e&&(l(this,m)?.len()||0)>=l(this,d);t?this.customScopesModalDialogFlash.innerHTML=`
Limit of 10 saved searches reached. Please delete an existing saved search before creating a new one.
`:this.customScopesModalDialogFlash.textContent="",this.customScopesSubmitButton.disabled=t}async function T(e){let t=l(this,m)?.get();return void 0===t&&(t=await l(this,g).call(this)),t.find(t=>t.id.toString()===e)}h([a.aC],CustomScopesElement.prototype,"list",void 0),h([a.aC],CustomScopesElement.prototype,"createCustomScopeForm",void 0),h([a.aC],CustomScopesElement.prototype,"manageCustomScopesForm",void 0),h([a.aC],CustomScopesElement.prototype,"customScopesModalDialog",void 0),h([a.aC],CustomScopesElement.prototype,"customScopesModalDialogFlash",void 0),h([a.aC],CustomScopesElement.prototype,"customScopesIdField",void 0),h([a.aC],CustomScopesElement.prototype,"customScopesNameField",void 0),h([a.aC],CustomScopesElement.prototype,"customScopesQueryField",void 0),h([a.aC],CustomScopesElement.prototype,"customScopesSubmitButton",void 0),CustomScopesElement=h([a.p_],CustomScopesElement)},11824:(e,t,s)=>{s.d(t,{XX:()=>a.XX,_3:()=>a._3,qy:()=>a.qy});var a=s(31143)},31143:(e,t,s)=>{s.d(t,{qy:()=>T,XX:()=>v,_3:()=>E});let a=new Map;function o(e){if(a.has(e))return a.get(e);let t=e.length,s=0,o=0,i=0,n=[];for(let a=0;as&&(n.push(Object.freeze({type:"string",start:s,end:o,value:e.slice(s,o)})),s=o),n.push(Object.freeze({type:"part",start:o,end:a+2,value:e.slice(s+2,a).trim()})),a+=1,s=a+1)}return s"string"==typeof e?e:e.value).join("");this.element.setAttributeNS(this.attr.namespaceURI,this.attr.name,e)}}};let l=new WeakMap;let NodeTemplatePart=class NodeTemplatePart{constructor(e,t){this.expression=t,l.set(this,[e]),e.textContent=""}get value(){return l.get(this).map(e=>e.textContent).join("")}set value(e){this.replace(e)}get previousSibling(){return l.get(this)[0].previousSibling}get nextSibling(){return l.get(this)[l.get(this).length-1].nextSibling}replace(...e){let t=e.map(e=>"string"==typeof e?new Text(e):e);for(let e of(t.length||t.push(new Text("")),l.get(this)[0].before(...t),l.get(this)))e.remove();l.set(this,t)}};function r(e){return{processCallback(t,s,a){var o;if("object"==typeof a&&a){for(let t of s)if(t.expression in a){let s=null!==(o=a[t.expression])&&void 0!==o?o:"";e(t,s)}}}}}function c(e,t){e.value=String(t)}function u(e,t){return"boolean"==typeof t&&e instanceof AttributeTemplatePart&&"boolean"==typeof e.element[e.attributeName]&&(e.booleanValue=t,!0)}let p=r(c);r((e,t)=>{u(e,t)||c(e,t)});let h=new WeakMap,d=new WeakMap;let TemplateInstance=class TemplateInstance extends DocumentFragment{constructor(e,t,s=p){var a,i;super(),Object.getPrototypeOf(this)!==TemplateInstance.prototype&&Object.setPrototypeOf(this,TemplateInstance.prototype),this.appendChild(e.content.cloneNode(!0)),d.set(this,Array.from(function*(e){let t;let s=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT,null,!1);for(;t=s.nextNode();)if(t instanceof Element&&t.hasAttributes())for(let e=0;ee+t+(s{let s=e(...t);return b.add(s),s}}let y=new WeakMap;let EventHandler=class EventHandler{constructor(e,t){this.element=e,this.type=t,this.element.addEventListener(this.type,this),y.get(this.element).set(this.type,this)}set(e){"function"==typeof e?this.handleEvent=e.bind(this.element):"object"==typeof e&&"function"==typeof e.handleEvent?this.handleEvent=e.handleEvent.bind(e):(this.element.removeEventListener(this.type,this),y.get(this.element).delete(this.type))}static for(e){y.has(e.element)||y.set(e.element,new Map);let t=e.attributeName.slice(2),s=y.get(e.element);return s.has(t)?s.get(t):new EventHandler(e.element,t)}};function w(e,t){b.has(t)&&(t(e),1)||u(e,t)||e instanceof AttributeTemplatePart&&e.attributeName.startsWith("on")&&(EventHandler.for(e).set(t),e.element.removeAttributeNS(e.attributeNamespace,e.attributeName),1)||t instanceof TemplateResult&&e instanceof NodeTemplatePart&&(t.renderInto(e),1)||t instanceof DocumentFragment&&e instanceof NodeTemplatePart&&(t.childNodes.length&&e.replace(...t.childNodes),1)||function(e,t){if(!("object"==typeof t&&Symbol.iterator in t))return!1;if(!(e instanceof NodeTemplatePart))return e.value=Array.from(t).join(" "),!0;{let s=[];for(let e of t)if(e instanceof TemplateResult){let t=document.createDocumentFragment();e.renderInto(t),s.push(...t.childNodes)}else e instanceof DocumentFragment?s.push(...e.childNodes):s.push(String(e));return s.length&&e.replace(...s),!0}}(e,t)||c(e,t)}let C=r(w);function T(e,...t){return new TemplateResult(e,t,C)}let M=new WeakMap;S((...e)=>t=>{M.has(t)||M.set(t,{i:e.length});let s=M.get(t);for(let a=0;a{at=>{var s,a;if(!(t instanceof NodeTemplatePart))return;let o=document.createElement("template"),i=null!==(a=null===(s=TemplateResult.cspTrustedTypesPolicy)||void 0===s?void 0:s.createHTML(e))&&void 0!==a?a:e;o.innerHTML=i;let n=document.importNode(o.content,!0);t.replace(...n.childNodes)})}}]); //# sourceMappingURL=app_components_search_custom-scopes-element_ts-ed0cd5093a20.js.map