1import{r as o,R as e,_ as se}from"./index-BLexuuUs.js";import{d as u}from"./dayjs.min-D8ifrjgx.js";import"./de-CI8nwH5B.js";import{u as ie}from"./index.esm-CjR1eyLh.js";import{u as oe}from"./index-D6IIU_1M.js";import{i as q}from"./index-BQxMik4V.js";import{c as y}from"./cx-2dOUpm6k.js";import{f as ce}from"./fetcher-zps9LNKv.js";import{n as me}from"./negotiateAsset-C2tQ0gvB.js";import{u as de}from"./useTrapFocus-D7UDQY50.js";function ue({clubs:n,selected:a,onSelect:g}){const[l,d]=o.useState(!1),f=o.useRef(null);return o.useEffect(()=>{n.length===1&&!a&&g(n[0])},[n,a,g]),o.useEffect(()=>{const c=p=>{f.current&&!f.current.contains(p.target)&&d(!1)},s=p=>p.key==="Escape"&&d(!1);return document.addEventListener("click",c),document.addEventListener("keydown",s),()=>{document.removeEventListener("click",c),document.removeEventListener("keydown",s)}},[]),n.length<=1?null:e.createElement("div",{className:"calendar-club-select",ref:f},e.createElement("div",{className:"xui-select btn_wide"},e.createElement("button",{type:"button",className:"xui-select__trigger","aria-haspopup":"listbox","aria-expanded":l,onClick:()=>d(c=>!c)},e.createElement("span",{className:y("is-ellipsis",a?"xui-select__selected":"xui-select__placeholder")},a?a.title||a.name:"Club auswählen"),e.createElement("span",{className:"xui-select__caret"})),e.createElement("ul",{className:y("xui-select-options",l&&"is-active"),role:"listbox"},n.map(c=>{const s=c.id===(a==null?void 0:a.id);return e.createElement("li",{key:c.id,role:"option","aria-selected":s},e.createElement("button",{type:"button",className:y("xui-select-option is-ellipsis",s&&"is-selected"),onClick:()=>{g(c),d(!1)}},c.title||c.name))}))))}u.locale("de");const ge=["Mo","Di","Mi","Do","Fr","Sa","So"],fe=n=>{const a=n.startOf("month").subtract((n.startOf("month").day()+6)%7,"day"),g=Math.ceil(((n.startOf("month").day()+6)%7+n.endOf("month").date())/7);return Array.from({length:g},(l,d)=>Array.from({length:7},(f,c)=>a.add(d*7+c,"day")))};function pe({value:n,min:a,onSelect:g}){const l=o.useMemo(()=>u().startOf("day"),[]),[d,f]=o.useState(n.startOf("month")),c=(a??l).startOf("day"),s=o.useMemo(()=>fe(d),[d]),p=n.isSame(l,"day")&&d.isSame(l,"month"),A=()=>{f(l.startOf("month")),g(l)};return o.createElement("dp-day-calendar",{class:"clear"},e.createElement("div",{className:"dp-day-calendar-container"},e.createElement("div",{className:"dp-calendar-nav-container","data-flex":"center-items"},e.createElement("button",{type:"button",className:"dp-calendar-nav-left","aria-label":"Vorheriger Monat",onClick:()=>f(m=>m.subtract(1,"month"))},"â¹"),e.createElement("div",{className:"flex-space"}),e.createElement("div",{className:"dp-nav-header"},d.format("MMMM YYYY")),e.createElement("div",{className:"flex-space"}),e.createElement("button",{type:"button",className:"dp-current-location-btn","aria-label":"Heute",title:"Zu heute springen",onClick:A,disabled:p,style:{width:24,height:24,borderRadius:"50%",background:p?"var(--color-text-lighter, #ccc)":"var(--color-link, currentColor)",border:`1px solid ${p?"var(--color-text-lighter, #ccc)":"var(--color-link, currentColor)"}`,boxShadow:"inset 0 0 0 3px var(--color-background, #fff)",cursor:p?"not-allowed":"pointer",opacity:p?.5:1,padding:0,margin:"0 8px"}}),e.createElement("button",{type:"button",className:"dp-calendar-nav-right","aria-label":"Nächster Monat",onClick:()=>f(m=>m.add(1,"month"))},"âº")),e.createElement("div",{className:"dp-calendar-wrapper"},e.createElement("div",{className:"dp-weekdays"},ge.map(m=>e.createElement("span",{key:m,className:"dp-calendar-weekday"},m))),s.map((m,_)=>e.createElement("div",{key:_,className:"dp-calendar-week"},m.map(r=>{const x=r.month()===d.month();return e.createElement("button",{key:r.toString(),type:"button",className:y("dp-calendar-day",!x&&(r.isBefore(d,"month")?"dp-prev-month":"dp-next-month"),r.isSame(n,"day")&&"dp-selected",r.isSame(l,"day")&&"dp-current-day"),disabled:r.isBefore(c,"day"),onClick:()=>g(r),"aria-pressed":r.isSame(n,"day"),"aria-label":r.format("dddd, DD. MMMM YYYY")},r.date())}))))))}u.locale("de");const K=`${typeof location<"u"?location.host:""}-selectedClub`,Ee=/^([-!#-'*+/-9=?A-Z^-~]+(\.[-!#-'*+/-9=?A-Z^-~]+)*|"([]!#-[^-~ \t]|(\\[\t -~]))+")@[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?(\.[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?)+$/,M=(n,a)=>u(n).isSame(u(a),"day"),V=n=>`${n.slice(0,1)}.`,O=(n,a)=>`${n}`==`${a}`,be=async n=>{const g=(await fetch(n).then(l=>l.json())).flatMap(l=>l.appointmentTypes??[]);return Array.from(new Map(g.map(l=>[l.id,l])).values()).sort((l,d)=>
1(l.sortBy??1e9)-(d.sortBy??1e9))},he=(n,a,g)=>fetch("/api/counseling",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({startDate:a,amountOfDaysToLookup:2,timeFrom:"08:00",timeTill:"23:00",studioId:n,appointmentTypeId:g,dayPreference:{monday:!0,tuesday:!0,wednesday:!0,thursday:!0,friday:!0,saturday:!0,sunday:!0}})}).then(l=>{if(!l.ok)throw new Error("failed_to_load");return l.json()});function Ye({club:n,hoAppointmentMails:a}){const g=window.isHO??!1,l=o.useMemo(()=>u().startOf("day"),[]),d=o.useMemo(()=>l.add(1,"day"),[l]),f=t=>M(t,l)?"Heute":M(t,d)?"Morgen":`Am ${u(t).format("DD.MM.YYYY")}`,{data:c}=q("/api/clubs",ce),[s,p]=o.useState(null);o.useEffect(()=>{if(!(!(c!=null&&c.length)||s)){if(n){const t=c.find(i=>O(i.id,n));t&&p(t);return}try{const t=JSON.parse(localStorage.getItem(K)??"null");t&&c.find(i=>i.remoteID===t.remoteID)&&p(t)}catch{}}},[c,n,s]);const A=t=>{p(t);try{localStorage.setItem(K,JSON.stringify(t))}catch{}},[m,_]=o.useState(()=>!a||typeof window>"u"?null:new URLSearchParams(window.location.search).get("appointmentType")||null),{data:r,isValidating:x}=q(a&&(s!=null&&s.remoteID)?`/api/counselingCategories/${s.remoteID}`:null,be);o.useEffect(()=>{!a||!r||_(t=>t!=null&&(r.length===0||r.some(i=>O(i.id,t)))?t:r.length===1?r[0].id:null)},[r,a]),o.useEffect(()=>{if(!a||typeof window>"u")return;const t=new URL(window.location.href);m?t.searchParams.set("appointmentType",String(m)):t.searchParams.delete("appointmentType"),window.history.replaceState("","",t.toString())},[m,a]);const[N,J]=o.useState(()=>l.add(1,"hour")),{data:D,isValidating:G}=oe(s!=null&&s.remoteID&&(!a||m)?`counseling:${s.remoteID}:${N.format("YYYY-MM-DD")}:${m??""}`:null,()=>he(s.remoteID,N.format("YYYY-MM-DD"),m),{revalidateOnFocus:!1,revalidateOnReconnect:!1,revalidateIfStale:!1}),h=o.useMemo(()=>Array.isArray(D)?{today:D.filter(t=>M(t.begin,N)&&u(t.begin).isAfter(u())),other:D.filter(t=>!M(t.begin,N)).slice(0,10)}:null,[D,N]),$=o.useMemo(()=>{if(!h)return[];const t=[...h.today,...h.other].map(i=>i.employee).filter(Boolean);return Array.from(new Map(t.map(i=>[i.id,i])).values()).sort((i,b)=>i.name.localeCompare(b.name))}
1,[h]),[C,X]=o.useState(null),[E,P]=o.useState(null),[v,R]=o.useState(null),[z,F]=o.useState(null),B=()=>{P(null),R(null),F(null)},Q=de(!!E,B),{register:w,handleSubmit:ee,formState:{errors:T,isValid:te,isSubmitting:I},reset:L}=ie({mode:"onChange",defaultValues:{gender:"",firstname:"",lastname:"",email:"",phone:""}});o.useEffect(()=>{E&&L()},[E,L]);const H=o.useRef(!1),ae=async({gender:t,firstname:i,lastname:b,phone:k,email:S})=>{var j;if(H.current)return;H.current=!0,F(null);const W={personalData:{gender:t,name:i,surname:b},contact:{phone:k,email:S},timeBlock:E,callbackUrl:`${location.origin||`https://${location.host}`}/beratungstermin/aktivierung`};try{const Y=await fetch("/api/counseling/book",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(W)});if(!Y.ok)throw new Error(((j=await Y.json().catch(()=>({})))==null?void 0:j.message)||"Fehler beim Buchen");R(W)}catch(Y){F(Y.message)}finally{H.current=!1}},Z=t=>{var i;return C&&((i=t.employee)==null?void 0:i.id)!==C?null:e.createElement("li",{"data-col":"6",key:`${t.begin}-${t.employeeId}`},e.createElement("button",{type:"button",className:"counseling-list__item",onClick:()=>P(t)},e.createElement("small",{className:"is-ink-lighter"},f(t.begin),", "),e.createElement("br",null),e.createElement("strong",null,u(t.begin).format("HH:mm")," bis ",u(t.end).format("HH:mm")," Uhr"),t.employee&&e.createElement(e.Fragment,null,e.createElement("br",null),e.createElement("small",{className:"is-ink-lighter"},"bei ",t.employee.name," ",V(t.employee.surname)))))},ne=a&&!m&&!!r&&r.length>1,le=a&&!!r&&r.length===0&&!x,re=!a||!!m,U=r==null?void 0:r.find(t=>O(t.id,m));return e.createElement("div",{className:"counseling-booking"},(G||x)&&e.createElement("div",{className:"loader is-global"}),e.createElement("div",{className:"counseling-booking-header"},e.createElement("h1",null,"Beratungstermin ",n&&s&&e.createElement("span",null,"im ",s.title||s.name)," ","buchen"),!n&&c&&e.createElement(ue,{clubs:c,selected:s,onSelect:A})),e.createElement("div",{className:y("counseling-booking-body",!(s!=null&&s.name)&&"is-hidden"),"data-grid":!0},ne&&e.createElement("div",{"data-col":"12",className:"counseling-booking-body__col"},e.createElement("div",{className:"counseling-booking-title"},e.createElement("h2",null,"Wähle eine Beratungsart")),e.createElement("ul",{className:"counseling-list","data-grid":"small-gutter",role:"listbox","aria-label":"Beratungsarten"},r.map(t=>{const i=O(m,t.id);return e.createElement("li",{"data-col":"6",key:t.id,role:"option","aria-selected":i},e.createElement("button",{type:"button",className:y("counseling-list__item",i&&"is-selected"),onClick:()=>_(t.id)},e.createElement("strong",null,t.name)))})),e.createElement("div",{className:"spacer"})),le&&e.createElement("div",{"data-col":"12",className:"counseling-booking-body__col"},e.createElement("div",{className:"well"},"Es sind aktuell keine Beratungsarten verfügbar.")),re&&e.createElement(e.Fragment,null,e.createElement("div",{"data-col":"6@md",className:"counseling-booking-body__col"},a&&r&&r.length>1&&U&&e.createElement("div",{className:"counseling-booking-title","data-flex":"center-items"},e.createElement("h2",{className:"flex-space"},U.name),e.createElement("button",{type:"button",className:"btn btn_small btn_clear",onClick:()=>_(null)},"Beratungsart ändern")),e.createElement("div",{className:"counseling-booking-title"},e.createElement("h2",null,"Wähle einen Tag")),e.createElement(pe,{value:N,min:l,onSelect:t=>J(t.startOf("day").add(1,"hour"))}),e.createElement("div",{className:"spacer"})),h&&e.createElement("div",{"data-col":"6@md",className:"counseling-booking-body__col"},$.length>1&&e.createElement(e.Fragment,null,e.createElement("div",{className:"counseling-booking-title"},e.createElement("h2",null,"Verfügbare Trainer")),e.createElement("ul",{className:"counseling-list","data-grid":"small-gutter",role:"listbox","aria-label":"Verfügbare Trainer"},$.map(t=>{var k;const i=C===t.id,b=()=>X(i?null:t.id);return e.createElement("li",{"data-col":"6",tabIndex:0,role:"option","aria-selected":i,key:t.id,onClick:b,onKeyDown:S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),b())}},e.createElement("div",{className:y("counseling-list__item",i&&"is-selected"),"data-flex":"center-items"}
1,!!((k=t.images)!=null&&k.length)&&e.createElement("div",{className:"avatar"},e.createElement("img",{loading:"lazy",alt:t.name,src:me(t.images[0],300)})),e.createElement("div",{className:"x-space-2"}),e.createElement("strong",null,t.name," ",V(t.surname))))})),e.createElement("div",{className:"spacer"})),e.createElement("div",{className:"counseling-booking-title"},e.createElement("h2",null,"Verfügbare Termine")),e.createElement("ul",{className:"counseling-list","data-grid":"small-gutter","data-flex":"center"},!h.today.length&&e.createElement("li",{"data-col":"12"},e.createElement("div",{className:"well"},f(N)," gibt es leider keine Termine mehr.")),h.today.map(Z)),e.createElement("div",{className:"spacer"}),e.createElement("div",{className:"counseling-booking-title"},e.createElement("h3",null,"Weitere Termine")),e.createElement("ul",{className:"counseling-list","data-grid":"small-gutter","data-flex":"center"},!h.other.length&&e.createElement("li",{"data-col":"12"},e.createElement("div",{className:"well"},"Es gibt leider keine weiteren Termine.")),h.other.map(Z)),e.createElement("div",{className:"spacer"})))),e.createElement("div",{ref:Q,className:y("modal-wrapper modal-wrapper_backdrop",E&&"is-active")},e.createElement("div",{className:"modal","data-col":"3@md"},e.createElement("button",{type:"button",onClick:B,className:"modal__dismiss","aria-label":"SchlieÃen"},e.createElement("svg",{className:"ixo","aria-hidden":"true"},e.createElement("use",{xlinkHref:"#close"}))),e.createElement("div",{className:"modal__body",style:{marginTop:"0.5rem"}},E&&!v&&e.createElement("div",null,e.createElement("header",{className:"align-center"},e.createElement("h4",null,"Beratungstermin bestätigen"),e.createElement("p",null,f(E.begin)," ",u(E.begin).format("DD.MM.YYYY")," um"," ",u(E.begin).format("HH:mm")," Uhr",E.employee&&e.createElement(e.Fragment,null,e.createElement("br",null),e.createElement("small",null,"bei ",E.employee.name," ",V(E.employee.surname))))),z&&e.createElement("div",{className:"alert alert_error"},z),e.createElement("form",{onSubmit:ee(ae),noValidate:!0},e.createElement("div",{className:"field-group",role:"group"},e.createElement("label",{className:"field-group__label",htmlFor:"gender"},"Anrede"),e.createElement("select",{autoComplete:"sex",className:"input",id:"gender",defaultValue:"",...w("gender",{required:!0})},e.createElement("option",{value:"",disabled:!0,hidden:!0},"Anrede wählen"),e.createElement("option",{value:"m"},"Herr"),e.createElement("option",{value:"f"},"Frau"),g&&e.createElement("option",{value:"d"},"Divers"))),e.createElement("div",{className:"field-group",role:"group"},e.createElement("div",{"data-grid":!0},e.createElement("div",{"data-col":"6"},e.createElement("label",{htmlFor:"firstname",className:"field-group__label"},"Vorname"),e.createElement("input",{className:"input",id:"firstname",placeholder:"Vorname...",type:"text",...w("firstname",{required:!0})})),e.createElement("div",{"data-col":"6"},e.createElement("label",{htmlFor:"lastname",className:"field-group__label"},"Nachname"),e.createElement("input",{className:"input",id:"lastname",placeholder:"Nachname...",type:"text",...w("lastname",{required:!0})})))),e.createElement("div",{className:"field-group",role:"group"},e.createElement("label",{htmlFor:"phone",className:"field-group__label"},"Telefonnummer"),e.createElement("input",{className:"input",id:"phone",placeholder:"Telefonnummer...",type:"tel",...w("phone",{required:"Pflichtfeld.",validate:async t=>{if(!t)return"Pflichtfeld.";const{parsePhoneNumberFromString:i}=await se(async()=>{const{parsePhoneNumberFromString:k}=await import("./index-C6Ci6vE7.js");return{parsePhoneNumberFromString:k}},[]),b=i(t,{extract:!1,defaultCountry:"DE"});return(b==null?void 0:b.isValid())||"Ungültige Telefonnummer."}})}),T.phone&&e.createElement("small",{className:"is-ink-error"},T.phone.message)),e.createElement("div",{className:"field-group",role:"group"},e.createElement("label",{htmlFor:"counseling-email",className:"field-group__label"},"E-Mail Adresse"),e.createElement("input",{className:"input",id:"c
1ounseling-email",placeholder:"E-Mail Adresse...",type:"email",...w("email",{required:"Pflichtfeld.",pattern:{value:Ee,message:"Ungültige E-Mail Adresse."}})}),T.email&&e.createElement("small",{className:"is-ink-error"},T.email.message)),e.createElement("ul",{"data-grid":"small-gutter"},e.createElement("li",{"data-col":"6"},e.createElement("button",{type:"button",onClick:B,className:"btn btn_block btn_clear"},"Abbrechen")),e.createElement("li",{"data-col":"6"},e.createElement("button",{type:"submit",disabled:!te||I,className:"btn btn_block"},"Bestätigen",I&&e.createElement("div",{className:"loader is-local"})))))),v&&e.createElement("div",null,"Hallo ",v.personalData.name,", ",e.createElement("br",null),"wir haben Deine Terminanfrage für das folgende Datum erhalten:",e.createElement("div",{className:"is-h3 is-margin-middle-3"},f(v.timeBlock.begin)," ",u(v.timeBlock.begin).format("DD.MM.YYYY")," um"," ",u(v.timeBlock.begin).format("HH:mm")," Uhr"),e.createElement("p",{className:"is-h5 is-ink-highlight"},"Es ist wichtig den Termin zeitnah zu bestätigen.",e.createElement("br",null),e.createElement("br",null),"Bitte klicke auf den Link in der E-Mail, die Du in Kürze erhältst. Andernfalls kann der Termin zwischenzeitlich belegt sein."))))))}export{Ye as default};
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.