import{a as h}from"./chunk-ZZGBPGC6.js";import{a as j,b as u}from"./chunk-OU45VCVM.js";import{a as E}from"./chunk-ULT7T2WM.js";import{b as d}from"./chunk-JC2BH436.js";var v=d(j()),y=d(E());var m='django-stepper-collection{display:block}django-stepper-collection .stepper-horizontal{display:flex;justify-content:space-between;list-style:none;padding:0}django-stepper-collection .stepper-step{display:flex;flex-grow:1;justify-content:center}django-stepper-collection .stepper-step .stepper-head{display:flex;flex-grow:1;align-items:center}django-stepper-collection .stepper-step .stepper-head::before{margin-right:.5rem}django-stepper-collection .stepper-step .stepper-head::after{margin-left:.5rem}django-stepper-collection .stepper-step .stepper-head::before,django-stepper-collection .stepper-step .stepper-head::after{content:"";flex:1;height:1px;width:100%;background-color:gray}django-stepper-collection .stepper-step:not([aria-current=step]).visited .stepper-head-icon{cursor:pointer;background-color:color-mix(in srgb, light-dark(hsl(213, 96%, 64%), hsl(213, 96%, 36%)), var(--django-formset-background-color) 50%)}django-stepper-collection .stepper-step[aria-current=step].visited .stepper-head-icon{background-color:light-dark(hsl(213, 96%, 64%), hsl(213, 96%, 36%));color:var(--django-formset-background-color)}django-stepper-collection .stepper-step .stepper-head-icon{display:flex;align-items:center;justify-content:center;width:2rem;height:2rem;border-radius:50%;border:1px solid gray;background-color:color-mix(in srgb, var(--django-formset-background-color), currentcolor 5%);color:var(--django-formset-fg-color)}django-stepper-collection .stepper-step .stepper-head-icon.has-label{margin-right:.5rem}django-stepper-collection>django-form-collection:not([aria-current=step]){display:none}';var l=class{constructor(e,t,r){this.visited=!1;this.activateVisited=e=>{this.visited&&this.activateStep()};this.collectionChanged=e=>{let t=null;for(let r of this.collection.steps)r.visited&&(t?(r.visited=!1,r.listItem.classList.remove("visited")):Object.values(r.formCollection.querySelectorAll("form")).some(s=>!s.checkValidity())&&(t=r))};var s,o;this.collection=e,this.listItem=t,this.formCollection=r,this.path=((s=t.getAttribute("prefix"))==null?void 0:s.split("."))??[],this.induceActivate=this.evalInducer(t,(...i)=>this.activateStep(...i)),(o=this.listItem.querySelector(".stepper-head"))==null||o.addEventListener("click",this.activateVisited),r.addEventListener("change",this.collectionChanged)}evalInducer(e,t){let r=e.getAttribute("df-induce-activate");if(!(0,y.default)(r))return()=>{};try{let s=new Function(`return ${u(r,{startRule:"InduceExpression"})}`);return(...o)=>{s.call(this)&&t(...o)}}catch(s){throw new Error(`Error while parsing <django-form-collection df-induce-activate="${r}">: ${s}.`)}}isButtonActive(e,t){let r=e[0]!==""?e:(()=>{let i=[...this.path],p=e.filter(b=>b!==""),S=e.length-p.length;return i.splice(i.length-S+1),i.push(...p),i})(),s=this.collection.formset,o=s.buttons.find(i=>(0,v.default)(i.path,r));return t==="active"&&o===s.currentActiveButton}activateStep(...e){this.collection.steps.forEach(t=>{t.formCollection.ariaCurrent=t.listItem.ariaCurrent=t===this?"step":null}),this.setAsVisited()}setAsVisited(){this.visited=!0,this.listItem.classList.add("visited")}},c=class{constructor(e){this.baseSelector="django-stepper-collection";this.steps=[];this.registerInducer=e=>{if(!(e instanceof CustomEvent))return;this.formset=e.detail.formset,this.formset.registerInducer(this,this.updateOperability);let t=null;for(let r of this.steps)t&&Object.values(t.formCollection.querySelectorAll("form")).every(s=>s.checkValidity())&&r.setAsVisited(),t=r};this.element=e;let t=e.querySelectorAll("li.stepper-step");e.querySelectorAll("django-form-collection").forEach((s,o)=>{this.steps.push(new l(this,t.item(o),s))});let r=this.element.closest("django-formset");r&&r.addEventListener("django-formset-connected",this.registerInducer,{once:!0}),this.styleSheet=h.stylesAreInstalled(this.baseSelector)??this.appendStyles()}connectedCallback(){var e;(e=this.steps[0])==null||e.activateStep()}updateOperability(...e){for(let t of this.steps)t.induceActivate(...e)}appendStyles(){let e=document.createElement("style");if(e.innerText=m,document.head.appendChild(e),!e.sheet)throw new Error("Could not create <style> element");return e.sheet}},n=Symbol("StepperCollection"),g,f=class extends(g=HTMLElement,n,g){constructor(){super(),this[n]=new c(this)}connectedCallback(){this[n].connectedCallback()}};export{f as StepperCollectionElement};
