"use strict";const u=require("@tempots/dom"),f=require("./timer-BJHOsuS6.cjs");function m({initialStatus:n="closed",openedAfter:t,closedAfter:i}){const e=u.prop(n),o=()=>{e.set("start-opening")},l=()=>{e.set("start-closing")},c=e.map(s=>s!=="closed"&&s!=="start-closing"&&s!=="closing"),d=s=>{s?o():l()},a=()=>{d(!c.value)},r=[],p=s=>{r.push(e.on(C=>{C==="closed"&&s()}))};let g=()=>{};e.on(s=>{switch(g(),s){case"start-opening":g=f.g(()=>e.set("opening"));break;case"opening":g=t(()=>e.set("opened"));break;case"start-closing":g=f.g(()=>e.set("closing"));break;case"closing":g=i(()=>e.set("closed"));break;case"closed":g=()=>{};break}}),e.onDispose(()=>{r.forEach(s=>s()),g()});const h=e.map(s=>s==="closed"),v=e.map(s=>s==="start-opening"),O=e.map(s=>s==="opening"),b=e.map(s=>s==="opened"),k=e.map(s=>s==="closing"),L=e.map(s=>s==="start-closing");return{status:e,open:o,close:l,toggle:a,setOpen:d,display:c,isClosed:h,isStartOpening:v,isOpening:O,isOpened:b,isClosing:k,isStartClosing:L,dispose:()=>e.dispose(),listenOnClosed:p}}function S({initialStatus:n="closed",duration:t,openDuration:i=t??500,closeDuration:e=t??500}={}){return m({initialStatus:n,openedAfter:o=>f.I(o,i),closedAfter:o=>f.I(o,e)})}function A(n,t){let i=!1,e=null;function o(){i||(i=!0,n.removeEventListener("transitionend",l),n.removeEventListener("animationend",c),e&&(clearTimeout(e),e=null),t())}function l(r){r.target===n&&o()}function c(r){r.target===n&&o()}const d=()=>{if(typeof n.getAnimations>"u"){e=setTimeout(o,16);return}n.addEventListener("transitionend",l),n.addEventListener("animationend",c),n.getAnimations().length===0&&(e=setTimeout(o,1e3))},a=f.g(d);return()=>{i=!0,a(),e&&(clearTimeout(e),e=null),n.removeEventListener("transitionend",l),n.removeEventListener("animationend",c)}}function y({initialStatus:n="closed",element:t}={}){let i=t;return{setElement:e=>{i=e},...m({initialStatus:n,openedAfter:e=>i==null?(e(),()=>{}):A(i,e),closedAfter:e=>i==null?(e(),()=>{}):A(i,e)})}}function $(n){if(n==null)return[];const t=[];return n.fade&&t.push("fade"),n.slide&&t.push(`slide-${n.slide}`),n.scale!=null&&t.push("scale"),t.length>0?t:["none"]}function P(n){if(n==null)return[];const t=[];return n.scale!=null&&typeof n.scale=="number"&&t.push(["--scale-factor",String(n.scale)]),n.transformOrigin!=null&&t.push(["--transform-origin",n.transformOrigin]),n.duration!=null&&t.push(["--animation-duration",`${n.duration}ms`]),n.easing!=null&&t.push(["--animation-easing",n.easing]),t}function T(n,t){if(n==null)return;const i=t==="start-opening"||t==="opening"||t==="opened";return"enter"in n||"exit"in n?i?n.enter:n.exit:n}function E({animation:n,status:t}){const i=u.computedOf(n,t)((e,o)=>{const l=T(e,o),d=$(l).map(a=>`bc-animated-toggle--${a}`).join(" ");return d?`bc-animated-toggle ${d} bc-animated-toggle--${o}`:`bc-animated-toggle bc-animated-toggle--${o}`});return u.Fragment(u.attr.class(i),u.WithElement(e=>{let o=[];function l(a){for(const r of o)e.style.removeProperty(r);o=a.map(([r])=>r);for(const[r,p]of a)e.style.setProperty(r,p)}const c=u.computedOf(n,t)((a,r)=>{const p=T(a,r);return P(p)});l(u.Value.get(c));const d=u.Value.on(c,l);return u.OnDispose(()=>{d();for(const a of o)e.style.removeProperty(a)})}))}function w({initialStatus:n="closed",animation:t},i){return u.WithElement(e=>{const{setElement:o,dispose:l,...c}=y({initialStatus:n,element:e});return o(e),u.Fragment(E({status:c.status,animation:t}),u.OnDispose(l),i(c))})}exports.AnimatedToggle=w;exports.AnimatedToggleClass=E;exports.useAnimatedElementToggle=y;exports.useAnimatedToggle=m;exports.useTimedToggle=S;
