1import{t as c}from"./app-Dortbj3I.js";import{b1 as p}from"./errorReporter-Bcsmabke.js";try{let n=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},e=new n.Error().stack;e&&(n._sentryDebugIds=n._sentryDebugIds||{},n._sentryDebugIds[e]="a32c783b-5658-450f-939e-ae4c3339a17c",n._sentryDebugIdIdentifier="sentry-dbid-a32c783b-5658-450f-939e-ae4c3339a17c")}catch{}const f=()=>{var n,e,t;return((e=(n=window.Pelcro)==null?void 0:n.user)==null?void 0:e.csrfToken)||((t=document.querySelector('meta[name="csrf-token"]'))==null?void 0:t.getAttribute("content"))||""};async function h(n,{method:e="GET",body:t=null}={}){const r={Accept:"application/json","X-Requested-With":"XMLHttpRequest","X-CSRF-TOKEN":f()};t!==null&&(r["Content-Type"]="application/json");const i=await fetch(n,{method:e,credentials:"same-origin",headers:r,body:t!==null?JSON.stringify(t):void 0});let o=null;try{o=await i.json()}catch{}return{response:i,data:o}}class w{constructor(e){this.root=e,this.tbody=e.querySelector("[data-applications-tbody]"),this.emptyState=e.querySelector("[data-applications-empty]"),this.tableWrap=e.querySelector("[data-applications-table]"),this.storeUrl=e.dataset.storeUrl,this.actionUrlTemplate=e.dataset.actionUrlTemplate,this.reactivateUrlTemplate=e.dataset.reactivateUrlTemplate,this.pending={revoke:null,delete:null},this.bindCreate(),this.bindRowActions(),this.bindConfirmButtons(),this.initClipboard(),this.wireModalReset()}wireModalReset(){var t,r;if(!this.createModal||!((t=window.HSOverlay)!=null&&t.getInstance))return;const e=window.HSOverlay.getInstance(this.createModal,!0);(r=e==null?void 0:e.element)!=null&&r.on&&e.element.on("open",()=>{this.switchView("form"),this.clearCreateError()})}switchView(e){this.createModal&&(this.createModal.querySelectorAll("[data-application-view]").forEach(t=>{t.classList.toggle("hidden",t.getAttribute("data-application-view")!==e)}),this.createModal.querySelectorAll("[data-application-title]").forEach(t=>{t.classList.toggle("hidden",t.getAttribute("data-application-title")!==e)}))}initClipboard(){typeof window.ClipboardJS>"u"||document.querySelectorAll("#application-create-modal .js-clipboard").forEach(e=>{new window.ClipboardJS(e,{text:r=>{const i=document.querySelector(r.getAttribute("data-clipboard-target"));return i?"value"in i?i.value:(i.textContent||"").trim():""}}).on("success",r=>{const i=r.trigger.querySelector(".js-clipboard-default"),o=r.trigger.querySelector(".js-clipboard-success");i&&o&&(i.classList.add("hidden"),o.classList.remove("hidden"),setTimeout(()=>{i.classList.remove("hidden"),o.classList.add("hidden")},2e3)),r.clearSelection&&r.clearSelection()})})}bindCreate(){this.createForm=document.getElementById("application-create-form"),this.createSubmit=document.querySelector("[data-application-create-submit]"),this.createError=document.querySelector("[data-application-create-error]"),this.createModal=document.getElementById("application-create-modal"),this.nameInput=document.getElementById("application-name"),this.redirectInput=document.getElementById("application-redirect-url"),this.createForm&&(this.createForm.addEventListener("submit",e=>{e.preventDefault(),this.onCreate()}),this.bindSiteSelect())}bindSiteSelect(){this.siteSelect=this.createForm.querySelector("[data-application-site-select]"),!(!this.siteSelect||!this.createModal)&&this.createModal.addEventListener("open.hs.overlay",()=>{var e,t,r,i;(t=(e=window.HSSelect)==null?void 0:e.getInstance)!=null&&t.call(e,this.siteSelect)||(i=(r=window.HSSelect)==null?void 0:r.autoInit)==null||i.call(r)})}selectedSiteId(){var t;const e=(t=this.siteSelect)==null?void 0:t.value;return e?Number(e):null}async onCreate(){var i,o,s,u,l,m;const e=(((i=this.nameInput)==null?void 0:i.value)||"").trim(),t=(((o=this.redirectInput)==null?void 0:o.value)||"").trim();if(this.clearCreateError(),!e||!t){this.showCreateError("Please provide a name and a redirect URL.");return}const r=this.selectedSiteId();if(r===null){this.showCreateError("Select the site this application may access.");return}this.setBusy(this.createSubmit,!0);try{const{response:d,data:a}=await h(this.storeUrl,{method:"POST",body:{name:e,redirect_url:t,site_id:r}});
1if(d.status===422){this.showCreateError(this.firstValidationError(a)||"Please check the form and try again.");return}if(!d.ok||!(a!=null&&a.application_secret)||!(a!=null&&a.row_html)){this.showCreateError(a&&a.message||"There was an error creating your application. Please try again.");return}this.insertRow(a.row_html),this.createForm.reset(),(m=(l=(u=(s=window.HSSelect)==null?void 0:s.getInstance)==null?void 0:u.call(s,this.siteSelect))==null?void 0:l.setValue)==null||m.call(l,""),this.revealApplication(a.application_id,a.application_secret)}catch(d){p(d,{op:"onCreate",component:"ApplicationsController"}),this.showCreateError("There was an error creating your application. Please try again.")}finally{this.setBusy(this.createSubmit,!1)}}revealApplication(e,t){const r=document.getElementById("application-reveal-id"),i=document.getElementById("application-reveal-secret");r&&(r.textContent=e!=null?String(e):""),i&&(i.textContent=t||""),this.switchView("reveal")}bindRowActions(){document.addEventListener("click",e=>{const t=e.target.closest("[data-application-revoke]");if(t){this.openConfirm("revoke",t);return}const r=e.target.closest("[data-application-delete]");if(r){this.openConfirm("delete",r);return}const i=e.target.closest("[data-application-reactivate]");i&&(this.closeParentDropdown(i),this.onReactivate(i.dataset.clientId))})}openConfirm(e,t){this.closeParentDropdown(t),this.pending[e]=t.dataset.clientId;const r=document.querySelector(`[data-application-${e}-name]`);r&&(r.textContent=t.dataset.clientName||"this application");const i=document.getElementById(`application-${e}-modal`);i&&window.HSOverlay&&window.HSOverlay.open(i)}bindConfirmButtons(){const e=document.querySelector("[data-application-revoke-confirm]"),t=document.querySelector("[data-application-delete-confirm]");e&&e.addEventListener("click",()=>this.onRevokeOrDelete("revoke",e)),t&&t.addEventListener("click",()=>this.onRevokeOrDelete("delete",t))}async onRevokeOrDelete(e,t){const r=this.pending[e];if(!r)return;const i=this.actionUrlTemplate.replace("CLIENT_ID",encodeURIComponent(r));this.setBusy(t,!0);try{const{response:o,data:s}=await h(i,{method:"DELETE",body:{action:e}});if(!o.ok){c.error(s&&s.message||`The application could not be ${e==="revoke"?"revoked":"deleted"}. Please try again.`);return}e==="delete"?(this.removeRow(r),c.success("Application deleted.")):(this.replaceRow(r,s==null?void 0:s.row_html),c.success("Application revoked.")),this.closeModal(document.getElementById(`application-${e}-modal`)),this.pending[e]=null}catch(o){p(o,{op:"onRevokeOrDelete",component:"ApplicationsController",extra:{action:e}}),c.error("Something went wrong. Please try again.")}finally{this.setBusy(t,!1)}}async onReactivate(e){if(!e)return;const t=this.reactivateUrlTemplate.replace("CLIENT_ID",encodeURIComponent(e));try{const{response:r,data:i}=await h(t,{method:"GET"});if(!r.ok||!(i!=null&&i.row_html)){c.error(i&&i.message||"The application could not be reactivated. Please try again.");return}this.replaceRow(e,i.row_html),c.success("Application reactivated.")}catch(r){p(r,{op:"onReactivate",component:"ApplicationsController"}),c.error("Something went wrong. Please try again.")}}rowFromHtml(e){const t=document.createElement("template");return t.innerHTML=(e||"").trim(),t.content.firstElementChild}insertRow(e){const t=this.rowFromHtml(e);!t||!this.tbody||(this.tbody.insertBefore(t,this.tbody.firstElementChild),this.refreshEmptyState(),this.reinitPreline())}replaceRow(e,t){const r=document.getElementById(`application-row-${e}`),i=this.rowFromHtml(t);r&&i&&(r.replaceWith(i),this.reinitPreline())}removeRow(e){var t;(t=document.getElementById(`application-row-${e}`))==null||t.remove(),this.refreshEmptyState()}refreshEmptyState(){var t,r,i;const e=!!((t=this.tbody)!=null&&t.querySelector("[data-application-row]"));(r=this.tableWrap)==null||r.classList.toggle("hidden",!e),(i=this.emptyState)==null||i.classList.toggle("hidden",e)}reinitPreline(){var e;(e=window.HSStaticMethods)!=null&&e.autoInit&&window.HSStaticMethods.autoInit()}closeParentDropdown(e){var i;const t=e.closest(".hs-dropdown");
1if(!t)return;if((i=window.HSDropdown)!=null&&i.getInstance){const o=window.HSDropdown.getInstance(t);if(o!=null&&o.close){o.close();return}}t.classList.remove("open");const r=t.querySelector(".hs-dropdown-menu");r&&(r.classList.remove("opacity-100","block"),r.classList.add("opacity-0","hidden"))}closeModal(e){e&&window.HSOverlay&&window.HSOverlay.close(e)}firstValidationError(e){if(e!=null&&e.errors){const t=Object.values(e.errors)[0];return Array.isArray(t)?t[0]:t}return(e==null?void 0:e.message)||null}showCreateError(e){this.createError&&(this.createError.textContent=e,this.createError.classList.remove("hidden"))}clearCreateError(){this.createError&&(this.createError.textContent="",this.createError.classList.add("hidden"))}setBusy(e,t){e&&(e.disabled=!!t,e.classList.toggle("opacity-50",!!t),e.classList.toggle("pointer-events-none",!!t))}}function S(){const n=document.querySelector("[data-applications-root]");n&&new w(n)}function E(){}function v(){}export{v as finalize,E as indexAction,S as init};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.