"use strict";(()=>{var ne=Object.create;var R=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var se=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(n,i)=>(typeof require<"u"?require:n)[i]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var le=(e,n,i,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of oe(n))!re.call(e,o)&&o!==i&&R(e,o,{get:()=>n[o],enumerable:!(t=ae(n,o))||t.enumerable});return e};var ce=(e,n,i)=>(i=e!=null?ne(ie(e)):{},le(n||!e||!e.__esModule?R(i,"default",{value:e,enumerable:!0}):i,e));var de=document.querySelector("#cart-button"),Ae=document.querySelector("#added-to-cart");window.cartUploadedFiles={};async function A(){try{let n=await(await fetch("https://koszyk.vsprint.pl/api/cart",{credentials:"include"})).json();if(!Array.isArray(n))throw new Error("Received data is not an array");return n}catch(e){return console.error("Failed to fetch cart items:",e),[]}}async function K(){de?.classList.remove("hide");let e=document.querySelector(".state-default"),n=document.querySelector(".state-empty"),i=document.querySelector(".state-error");try{let t=await A(),o=t.reduce((a,c)=>a+c.price*c.quantity,0),d=document.getElementById("cart-total");d&&(d.style.display="block",d.textContent=`${o.toFixed(2)} z\u0142 + VAT`);let s=document.getElementById("cart-quantity");if(s){let a=t.reduce((c,p)=>c+p.quantity,0);s.textContent=a.toString()}e&&n&&i&&(t.length>0?(n.style.display="none",i.style.display="none",e.style.display="block"):(e.style.display="none",i.style.display="none",n.style.display="flex")),await me(t)}catch(t){console.error("Failed to update cart UI:",t),e&&n&&i&&(n.style.display="none",e.style.display="none",i.style.display="flex")}}async function ue(e,n=null){try{let i=n==="null"?null:n,t=await fetch(`https://koszyk.vsprint.pl/api/cart/${e}`,{method:"DELETE",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({variant:i})});if(!t.ok)throw new Error(`Failed to remove item: ${t.statusText}`);window.dataLayer.push({ecommerce:null}),window.dataLayer.push({event:"remove_from_cart",ecommerce:{items:[{item_id:e,item_name:e,affiliation:"Konferencja App"}]}}),await K()}catch(i){console.error("Failed to remove item from cart:",i)}}async function _(e,n,i=null,t){try{let o=await fetch(`https://koszyk.vsprint.pl/api/cart/${e}`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({variant:i==="null"?null:i,quantity:n,attendees:t})});if(!o.ok)throw new Error(`Failed to update item quantity: ${o.statusText}`);window.location.href.includes("koszyk")||await K()}catch(o){console.error("Failed to update item quantity:",o)}}function pe(){document.addEventListener("change",async e=>{let n=e.target;if(!n.classList.contains("is-quantity"))return;let i=parseInt(n.value,10),t=n.closest(".cart-item"),o=t?.querySelector(".deletebutton")?.getAttribute("data-item-id"),d=t?.querySelector(".deletebutton")?.getAttribute("data-variant")||null;o&&i>0&&await _(o,i,d)})}async function me(e){let n=document.querySelector(".cart-list");if(!n)return;n.innerHTML="",e.forEach(t=>{let o=document.createElement("div");o.className="cart-item",o.innerHTML=`
${t.ticketType.toUpperCase()}
Wariant:
${t.variant}
Cena:
${t.price} z\u0142 + VAT
Ilo\u015B\u0107:
${t.quantity}
`,n.appendChild(o)}),pe(),document.querySelectorAll(".deletebutton").forEach(t=>{t.addEventListener("click",async o=>{let d=o.currentTarget,s=d.getAttribute("data-item-id"),a=d.getAttribute("data-variant")||null;s?await ue(s,a):console.error("Failed to remove item from cart: missing item ID")})})}function V(e,n){let i=document.createElement("select");i.classList.add("form_input"),i.dataset.input="variant",i.setAttribute("validate","true");let t=document.createElement("option");return t.value="",t.disabled=!0,t.selected=!0,t.textContent=e,i.appendChild(t),n.forEach(({value:o,label:d})=>{let s=document.createElement("option");s.value=o,s.textContent=d,i.appendChild(s)}),ye(i),i}function ye(e){e.style.appearance="none",e.style.setProperty("-webkit-appearance","none"),e.style.setProperty("-moz-appearance","none"),e.style.paddingRight="2.5rem",e.style.boxSizing="border-box";let n=``;e.style.backgroundImage=`url("data:image/svg+xml;charset=UTF-8,${encodeURIComponent(n)}")`,e.style.backgroundRepeat="no-repeat",e.style.backgroundPosition="right 1rem center"}async function fe(e){await fetch(`https://koszyk.vsprint.pl/api/cart/${e.id}`,{method:"PUT",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({variant:e.variant,quantity:e.quantity,attendees:e.attendees,uploadedFile:e.uploadedFile,categories:e.categories})})}function F(e,n){let i=[{value:"Rynek polski",label:"Rynek polski"},{value:"Rynek zagraniczny",label:"Rynek zagraniczny"},{value:"Automatyzacja",label:"Automatyzacja"}],t=[{value:"Szczecin",label:"Szczecin"},{value:"Gda\u0144sk",label:"Gda\u0144sk"},{value:"Bydgoszcz",label:"Bydgoszcz"},{value:"Pozna\u0144",label:"Pozna\u0144"}];document.querySelectorAll(".order-item-list").forEach((d,s)=>{d&&(d.innerHTML="",e.forEach(a=>{let c=document.createElement("div");c.className="order-item is-compact";let p=a.ticketType.toLowerCase();if(c.innerHTML=` ${a.ticketType.toUpperCase()} `,n===1&&s===0){let u=a.ticketType,m=()=>{};if(u==="VIP"||u==="Premium"||u==="Standard"||u==="Objazd\xF3wka Standard"||u==="Objazd\xF3wka Premium"){let l=document.createElement("div");if(l.className="cart-product-parameter",a.variant!==null)l.innerHTML=`
Wariant:
${a.variant}
`;else{l.style.marginBottom="0.5rem";let r=null;u==="VIP"?r=V("Wybierz rodzaj warsztat\xF3w",i):(u==="Objazd\xF3wka Standard"||u==="Objazd\xF3wka Premium")&&(r=V("Wybierz miasto",t)),r&&(r.value=a.variant||"",l.innerHTML='
Wariant:
',l.appendChild(r),r.addEventListener("change",async()=>{a.variant=r.value,await _(a.id,a.quantity,a.variant),r.disabled=!0,r.style.cursor="not-allowed"}))}c.appendChild(l)}let w=document.createElement("div");w.className="cart-options-grid";let h=p.includes("odchylenia od najni\u017Cszej ceny")||p.includes("wsp\xF3\u0142czynnika konwersji")||p.includes("w\u0142asnych produkt\xF3w vs konkurencja"),f=p.includes("pozycji w\u015Br\xF3d konkurencji")||p.includes("top 100")||p.includes("raport dynamiki kategorii")||p.includes("najlepsze dni tygodnia")||p.includes("raport konkurencji");if(h){let l=document.createElement("div");l.className="cart-product-parameter cart-upload-wrapper",l.dataset.itemId=a.id;let r=document.createElement("div");r.className="upload-description text-size-small",r.style.marginBottom="0.5rem",p.includes("odchylenia od najni\u017Cszej ceny")||p.includes("w\u0142asnych produkt\xF3w")||p.includes("konwersji")?r.textContent="Dane do sprzedawcy: lista link\xF3w do produkt\xF3w":p.includes("konkurencji")||p.includes("najlepsze dni tygodnia")?r.textContent="Dane do sprzedawcy: kategoria do por\xF3wnania":r.textContent="Dane do sprzedawcy: pliki \u017Ar\xF3d\u0142owe lub dane raportowe";let y=document.createElement("ul");y.className="uploaded-file-list",y.style.listStyle="none",y.style.padding="0",y.style.margin="0 0 0.5rem 0";let b=document.createElement("div");b.className="uppy-uploader",b.dataset.itemId=a.id,l.appendChild(r),l.appendChild(y),l.appendChild(b),w.appendChild(l)}else if(f){let l=1;p.includes("10 kat")?l=10:p.includes("3 kat")&&(l=3);for(let r=0;r1?`Podaj kategori\u0119 #${r+1}`:"Podaj kategori\u0119",y.required=!0,y.dataset.ticketId=a.id,y.dataset.categoryIndex=`${r}`,w.appendChild(y)}}else a.attendees||(a.attendees=[]),m();c.appendChild(w);let E=document.createElement("div");E.className="cart-product-parameter",E.innerHTML=`
Ilo\u015B\u0107:
`;let v=document.createElement("div");v.className="cart-product-parameter",v.innerHTML=`
Cena:
${(a.price*a.quantity).toFixed(2)} z\u0142 + VAT
`,a.attendees||(a.attendees=[]),!h&&!f&&(m=()=>{w.innerHTML="",w.classList.add("attendees-grid"),w.style.display="grid",w.style.gridTemplateColumns="1fr",w.style.gap="1rem";let l=document.getElementById("attendee-grid-style")||document.createElement("style");l.id="attendee-grid-style",l.textContent=` @media (min-width: 768px) { .attendees-grid { grid-template-columns: 1fr 1fr !important; } } .attendee-box { padding: 1rem; border: 1px solid #ccc; border-radius: 0.5rem; background: #fafafa; display: flex; flex-direction: column; gap: 0.75rem; } .attendee-box input { width: 100%; } `,document.head.appendChild(l);for(let y=0;y{j.addEventListener("input",async()=>{a.attendees[y]={firstName:z.value,lastName:M.value,email:N.value,fullName:`${z.value} ${M.value}`},await fe(a)})}),k.appendChild(T),k.appendChild(C),k.appendChild(L),w.appendChild(k)}},m());let g=E.querySelector('input[data-input="quantity"]');g?.addEventListener("input",async()=>{let l=parseInt(g.value,10);if(l>0){if(a.quantity=l,a.attendees||(a.attendees=[]),a.attendees.length>l)a.attendees=a.attendees.slice(0,l);else for(;a.attendees.length{c.innerHTML+=`
Uczestnik #${m+1}:
${u.fullName}
`}),a.variant!==null&&(c.innerHTML+=`
Wariant:
${a.variant}
`),c.innerHTML+=`
Cena:
${a.price} z\u0142 + VAT
Ilo\u015B\u0107:
${a.quantity}
`);d.appendChild(c)}))}),ve()}function ve(){window.uploadedFiles=window.uploadedFiles||{},document.querySelectorAll(".uppy-uploader").forEach(async e=>{let n=e.dataset.itemId;if(!n)return;let t=await(await fetch("https://uploads-ssl.webflow.com/66a258012b74bbf1ea3b848a/66b9183f42a15fc71d13e701_pl_PL.txt")).text();t=t.replace("export default","");let o=document.createElement("script");o.textContent=t,document.head.appendChild(o),await new Promise(u=>{let m=setInterval(()=>{typeof pl_PL<"u"&&(clearInterval(m),u(!0))},100)});let{Uppy:d,Dashboard:s,ImageEditor:a,Transloadit:c}=await import("https://releases.transloadit.com/uppy/v3.21.0/uppy.min.mjs"),p=new d({debug:!0,restrictions:{maxNumberOfFiles:5},locale:pl_PL}).use(c,{waitForEncoding:!0,alwaysRunAssembly:!0,assemblyOptions:{params:{template_id:"621095316d0c4d7997b1bb665adab561",auth:{key:"OIsmHgSeU6rCebQH27EytZunhvrf2CZb"}}}}).use(s,{inline:!0,target:e,proudlyDisplayPoweredByUppy:!1}).use(a,{target:s});p.on("complete",({transloadit:u})=>{console.log("\u{1F9E9} Full Transloadit payload:",u);let m=[];u.forEach(f=>{f.results&&Object.keys(f.results).forEach(E=>{f.results[E].forEach(v=>{v.ssl_url&&m.push(v.ssl_url)})})}),window.uploadedFiles[n]=m;let h=e.closest(".cart-upload-wrapper")?.querySelector(".uploaded-file-list");h&&(h.innerHTML="",m.forEach((f,E)=>{let v=document.createElement("li");v.className="uploaded-file-item",v.style.display="flex",v.style.alignItems="center",v.style.justifyContent="space-between",v.style.gap="0.5rem",v.style.marginBottom="0.25rem";let g=decodeURIComponent(f.split("/").pop()||`plik-${E+1}`),l=document.createElement("a");l.href=f,l.target="_blank",l.textContent=g.length>40?g.slice(0,40)+"\u2026":g,l.className="text-color-brand",l.style.textDecoration="none";let r=document.createElement("button");r.textContent="\u2715",r.className="remove-upload-btn",r.style.border="none",r.style.background="transparent",r.style.cursor="pointer",r.style.color="#b42318",r.title="Usu\u0144 plik",r.addEventListener("click",()=>{window.uploadedFiles[n]=window.uploadedFiles[n].filter(y=>y!==f),v.remove(),console.log(`\u{1F5D1}\uFE0F Usuni\u0119to plik ${f} z item ${n}`)}),v.appendChild(l),v.appendChild(r),h.appendChild(v)})),e.dataset.uploaded="true",console.log(`\u2705 Upload zako\u0144czony dla ${n}:`,m)}),p.on("error",u=>{console.error(`\u274C B\u0142\u0105d Uppy dla ${n}:`,u)})})}function we(e,n,i){let t=e.querySelector(".text-weight-semibold.text-color-brand");t&&(t.textContent=`${(n*i).toFixed(2)} z\u0142 + VAT`)}function W(e){document.querySelectorAll(".order-item-list").forEach(i=>{i&&(i.innerHTML="",e.forEach(t=>{let o=document.createElement("div");o.className="order-item is-compact",o.innerHTML=` ${t.ticketType.toUpperCase()} `,t.variant!==null&&(o.innerHTML+=`
Wariant:
${t.variant}
`),Array.isArray(t.attendees)&&t.attendees.forEach((d,s)=>{let a=document.createElement("div");a.className="cart-product-parameter",a.innerHTML=`
Uczestnik #${s+1}:
${d.fullName} (${d.email})
`,o.appendChild(a)}),o.innerHTML+=`
Cena:
${t.price} z\u0142 + VAT
Ilo\u015B\u0107:
${t.quantity}
`,i.appendChild(o)}))})}var $=async e=>{try{let n=await fetch("https://koszyk.vsprint.pl/api/retrieve-payment-intent",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({paymentIntent:e})});if(!n.ok)throw new Error(`API error! status: ${n.status}`);return(await n.json()).paymentIntentResult}catch{return null}};async function Z(){try{return(await(await fetch("https://koszyk.vsprint.pl/api/session-id",{method:"GET",headers:{"Content-Type":"application/json"},credentials:"include"})).json()).sessionID}catch(e){return console.error("B\u0142\u0105d podczas pobierania ID sesji:",e),null}}function he(){let e=document.querySelectorAll('select[data-input="variant"][validate="true"]'),n=!0;return e.forEach(i=>{i.value===""&&(alert("Prosz\u0119 wybra\u0107 wariant warsztat\xF3w przed przej\u015Bciem dalej."),n=!1)}),n}var ge=()=>{let e=document.querySelector("#Email")?.value||"",n=document.querySelector("#wf-ecom-shipping-name")?.value||"",i=document.querySelector("#nip")?.value||"",t=document.querySelector("#Telefon")?.value||"",o=document.querySelector("#DodatkoweInformacje")?.value||"",d=document.querySelector("#nazwa-firmy")?.value||"",s=document.querySelector("#Kod-pocztowy")?.value||"",a=document.querySelector("#Miasto")?.value||"",c=document.querySelector("#Adres-Firmy")?.value||"",p=document.querySelector("#address-line1")?.value||"",u=document.querySelector("#address-line2")?.value||"",m=document.querySelector("#city")?.value||"",w=document.querySelector("#state")?.value||"",h=document.querySelector("#postal-code")?.value||"",f=document.querySelector("#country")?.value||"PL";return{email:e,name:n,nip:i,phone:t,additionalInfo:o,companyName:d,companyZip:s,companyCity:a,companyAddress:c,addressLine1:p,addressLine2:u,city:m,state:w,postalCode:h,country:f}},Ee=e=>/^\d{10}$/.test(e),q=(e,n)=>!e||e.value.trim()===""?(alert(`Prosz\u0119 uzupe\u0142ni\u0107 pole: ${n}.`),!1):!0,be=()=>{let e=document.querySelector("#Company"),n=document.querySelector("#nip"),i=document.querySelector("#nazwa-firmy"),t=document.querySelector("#Kod-pocztowy"),o=document.querySelector("#Miasto"),d=document.querySelector("#Adres-Firmy");return e?.checked?(n?.value?Ee(n.value.trim()):!0)?q(n,"NIP")&&q(i,"Nazwa firmy")&&q(t,"Kod pocztowy")&&q(o,"Miasto")&&q(d,"Adres firmy"):(alert("Podany NIP jest niepoprawny."),!1):!0},ke=()=>{if(!be())return!1;let i=document.querySelector('div[data-step="1"]')?.querySelectorAll("input[required], select[required]");if(!Array.from(i||[]).every(c=>c.value.trim()!==""))return alert("Prosz\u0119 uzupe\u0142ni\u0107 wszystkie wymagane pola."),!1;if(document.querySelector("#is-items")?.value!=="true")return alert("Koszyk musi zawiera\u0107 przedmioty."),!1;let d=document.querySelectorAll("input.report-category");for(let c of d)if(c.value.trim()==="")return alert("Prosz\u0119 wype\u0142ni\u0107 wszystkie pola kategorii dla raportu."),c.focus(),!1;let s=document.querySelectorAll(".cart-upload-wrapper");for(let c of s){let p=c.dataset.itemId||"",u=window.uploadedFiles||{},m=p?u[p]:void 0;if(!m||m.length===0)return alert("Prosz\u0119 doda\u0107 przynajmniej jeden plik do ka\u017Cdego raportu wymagaj\u0105cego za\u0142\u0105cznika."),c.scrollIntoView({behavior:"smooth",block:"center"}),!1}let a=document.querySelectorAll(".attendee-box");for(let c of a){let p=c.querySelector("input.attendee-first-name"),u=c.querySelector("input.attendee-last-name"),m=c.querySelector("input.attendee-email");if(!p?.value.trim()||!u?.value.trim()||!m?.value.trim())return alert("Prosz\u0119 uzupe\u0142ni\u0107 imi\u0119, nazwisko i email dla ka\u017Cdego uczestnika."),(p||u||m)?.focus(),!1}return!0},Te=()=>{let e=document.querySelector('div[data-step="1"]'),n=document.querySelector("#is-items");if(n&&(n.value=String(!0)),!e)return;e.querySelectorAll("input[required], select[required]").forEach(o=>{o.addEventListener("input",I)}),e.querySelectorAll("input.attendee-first-name, input.attendee-last-name, input.attendee-email").forEach(o=>{o.addEventListener("input",I)}),n?.addEventListener("input",I),I()},Ie=()=>{document.addEventListener("input",n=>{let i=n.target;i&&i.classList.contains("report-category")&&I()}),window.Uppy&&document.querySelectorAll(".uppy-uploader").forEach(n=>{let i=n.dataset.itemId,t=window.Uppy.getUppyByTarget?.(n)||null;t&&(t.on("complete",()=>{console.log(`\u{1F4CE} Uppy upload zako\u0144czony dla ${i}`),I()}),t.on("file-removed",()=>{console.log(`\u{1F5D1}\uFE0F Plik usuni\u0119ty dla ${i}`),I()}))}),new MutationObserver(()=>{I()}).observe(document.body,{childList:!0,subtree:!0})},U=(e,n,i,t)=>{let o=document.querySelector(".products-cost");o&&(o.textContent=`${e.toFixed(2)} z\u0142 + VAT`);let d=document.querySelector(".coupon-amount");d&&d.parentElement&&(t>0?(d.parentElement.style.display="block",d.textContent=`${t.toFixed(2)} z\u0142`):d.parentElement.style.display="none");let s=document.querySelector(".tax");s&&(s.textContent=`${n.toFixed(2)} z\u0142`);let a=document.querySelector(".total-cost");a&&(a.textContent=`${i.toFixed(2)} z\u0142`)},O=(e,n)=>(e.reduce((t,o)=>t+o.price*o.quantity,0)-n).toFixed(2),Le=document.querySelector('a[data-form="next-btn"]'),J=document.querySelector('div[data-step="1"]'),Q=document.querySelector('div[data-step="2"]'),D=document.querySelector("#Company"),S=document.querySelector(".company-info");S&&(S.style.display="none");var G=S?.querySelectorAll("input"),B=document.querySelector("#nip");B?.removeAttribute("required");D&&S&&G&&D.addEventListener("change",()=>{D.checked?(S.style.display="flex",B?.setAttribute("required","true")):(S.style.display="none",G.forEach(e=>e.value=""),B?.removeAttribute("required"))});var I=()=>{let e=document.querySelector('a[data-form="next-btn"]'),n=document.querySelector('div[data-step="1"]'),i=document.querySelector("#is-items");if(!n||!e||!i)return;let t=n.querySelectorAll("input[required], select[required]"),o=n.querySelectorAll("input.attendee-first-name, input.attendee-last-name, input.attendee-email"),d=n.querySelectorAll("input.report-category"),s=n.querySelectorAll(".cart-upload-wrapper"),a=[],c=[],p=[],u=[];if(t.forEach(g=>{if(g.value.trim()===""){let l=g.closest(".form-group")?.querySelector("label")?.textContent?.trim()||g.name||g.id;l&&l!==""&&a.push(l)}}),o.length>0&&o.forEach((g,l)=>{g.value.trim()===""&&c.push(`Bilet #${l+1}`)}),d.length>0&&d.forEach((g,l)=>{g.value.trim()===""&&p.push(`Kategoria #${l+1}`)}),s.length>0){let g=window.uploadedFiles||{};s.forEach(l=>{let r=l.dataset.itemId;if(!r)return;let y=g[r];(!y||y.length===0)&&u.push(`Za\u0142\u0105cznik (${r})`)})}let m=i.value==="true",w=a.length===0,h=c.length===0,f=p.length===0,E=u.length===0,v=w&&m&&(o.length===0||h)&&(d.length===0||f)&&(s.length===0||E);v?console.log("\u2705 Wszystkie dane s\u0105 poprawne. Przycisk \u201EDalej\u201D dost\u0119pny."):(console.group("\u{1F512} Przycisk \u201EDalej\u201D zablokowany \u2013 brakuje:"),m||console.warn('\u{1F6D2} Koszyk jest pusty (isItemsInput !== "true")'),a.length>0&&console.warn("\u{1F4C4} Pola wymagane:",a),c.length>0&&console.warn("\u{1F465} Brakuj\u0105ce imiona i nazwiska:",c),p.length>0&&console.warn("\u{1F4CA} Kategorie raport\xF3w:",p),u.length>0&&console.warn("\u{1F4CE} Brakuj\u0105ce za\u0142\u0105czniki:",u),console.groupEnd()),e.disabled=!v,e.style.cursor=v?"pointer":"not-allowed",e.style.opacity=v?"1":"0.5",e.style.display="block"},Ce=async()=>{J&&Q?(J.style.display="none",Q.style.display="flex",window.scrollTo({top:0,behavior:"smooth"})):console.error("One of the step wrappers is not found.")},ze=async(e,n,i,t,o,d,s)=>{try{return await(await fetch("https://koszyk.vsprint.pl/api/create-payment-intent",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({products_cost:Math.round(e*100),tax_cost:Math.round(n*100),total_amount:Math.round(i*100),coupon_amount:Math.round(t*100),coupon_code:s.code,coupon_type:s.type,currency:"PLN",customer_email:o.email,customer_name:o.name,nip:o.nip,phone:o.phone,additional_info:o.additionalInfo,company_name:o.companyName,company_zip:o.companyZip,company_city:o.companyCity,company_address:o.companyAddress,sessionID:d})})).json()}catch(a){return console.error("Error creating payment intent:",a),null}};async function Se(e){let n=document.querySelector('div[data-output="nip"]'),i=document.querySelector('div[data-output="company-name"]'),t=document.querySelector('div[data-output="company-zip"]'),o=document.querySelector('div[data-output="company-city"]'),d=document.querySelector('div[data-output="company-address"]');e.nip!==""&&n&&i&&d&&t&&o?(n.textContent=e.nip,i.textContent=e.companyName,d.textContent=e.companyAddress,t.textContent=e.companyZip,o.textContent=e.companyCity):e.nip===""&&n&&n.parentElement?.parentElement&&(n.parentElement.parentElement.style.display="none")}var xe=async()=>{let e=window.Stripe?.("pk_live_51QebhPBRhKsel0GPxR0Z3cpb7mXwBvS7pm2HiDTkCyWCJ59IzEcFarfmXsqgnR0RpMuFtF01Ew1CvHN1oJ8mbAGV00eCKC7aDn",{stripeAccount:"acct_1QebhPBRhKsel0GP"});if(!e){console.error("Stripe nie zosta\u0142o zainicjalizowane.");return}let n=document.querySelector('[data-element="payment_form"]');if(n)n.addEventListener("keydown",s=>{s.key==="Enter"&&s.preventDefault()});else{console.error("Payment form element could not be found. Ensure that the form has the correct data-element attribute.");return}let i=await A();if(i.length===0&&window.location.pathname.includes("/koszyk")){alert("Tw\xF3j koszyk jest pusty. Dodaj przedmioty do koszyka."),window.location.href="/";return}Te(),Ie();let t=async(s,a)=>{try{return await(await fetch("https://koszyk.vsprint.pl/api/validate-coupon",{credentials:"include",method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({couponCode:s,cartItems:a})})).json()}catch(c){return console.error("Error checking coupon:",c),{isValid:!1,discountType:null,amount:0}}},o={code:"",type:"",amount:0};document.getElementById("apply-coupon")?.addEventListener("click",async()=>{let s=document.getElementById("coupon-code"),a=document.getElementById("coupon-feedback");if(!s||!a){console.error("Nie znaleziono elementu formularza kuponu.");return}let c=s.value.trim(),{isValid:p,discountType:u,amount:m,couponCode:w}=await t(c,i);if(!p){a.textContent="Nieprawid\u0142owy kupon.",a.style.display="block",a.style.color="#b42318",a.classList.remove("hide");return}o={code:w,type:u,amount:m/100};let h=u==="fixed"?`Zni\u017Cka: ${(m/100).toFixed(2)} z\u0142`:`Zni\u017Cka: ${m}%`;a.innerHTML=`Kupon zosta\u0142 dodany. ${h}
Cena zostanie zrabatowana w kolejnym kroku.`,a.style.display="block",a.style.color="#027a48",a.classList.remove("hide");let f=O(i,0);o.amount=u==="percentage"?Number(f)*(m/100):m/100}),F(i,1),(()=>{document.querySelectorAll("input.attendee-first-name, input.attendee-last-name, input.attendee-email").forEach(a=>{a.removeEventListener("input",I),a.addEventListener("input",I)})})(),Le?.addEventListener("click",async()=>{if(!ke()||!he())return;let s=ge();await Se(s);let a=await A();document.querySelectorAll(".attendee-box").forEach(r=>{let y=r.dataset.ticketId,b=parseInt(r.dataset.attendeeIndex||"0"),k=r.querySelector("input.attendee-first-name")?.value.trim()||"",T=r.querySelector("input.attendee-last-name")?.value.trim()||"",C=r.querySelector("input.attendee-email")?.value.trim()||"",L=a.find(z=>z.id===y);L&&(L.attendees||(L.attendees=[]),L.attendees[b]={firstName:k,lastName:T,email:C,fullName:`${k} ${T}`})}),document.querySelectorAll("input.report-category").forEach(r=>{let y=r.dataset.ticketId,b=parseInt(r.dataset.categoryIndex||"0"),k=r.value.trim(),T=a.find(C=>C.id===y);T&&(T.categories||(T.categories=[]),T.categories[b]=k)});let c=window.uploadedFiles||{};a.forEach(r=>{c[r.id]&&(r.uploadedFile=c[r.id])});for(let r of a)if(!(Array.isArray(r.attendees)&&r.attendees.length===r.quantity)){if(Array.isArray(r.attendees))for(;r.attendees.length{r.preventDefault(),r.stopPropagation(),await E.submit();let y=await e.confirmPayment({elements:E,clientSecret:h.client_secret,redirect:"always",confirmParams:{return_url:l}}),b=document.querySelector(".w-form-done"),k=document.querySelector(".w-form-fail"),T=document.querySelector(".container-medium");y.error?(k&&(k.textContent=`P\u0142atno\u015B\u0107 nieudana: ${y.error.message}`,k.style.display="block"),b&&(b.style.display="none")):(b&&(b.textContent="P\u0142atno\u015B\u0107 zako\u0144czona sukcesem!",b.style.display="block"),k&&(k.style.display="none"),T&&(T.style.display="none"))},!0)})};document.addEventListener("DOMContentLoaded",xe);var qe=()=>{let e=document.querySelector("#Email"),n=document.querySelector("#wf-ecom-shipping-name"),i=document.querySelector("#nip"),t=document.querySelector("#Telefon"),o=document.querySelector("#DodatkoweInformacje"),d=document.querySelector("#nazwa-firmy"),s=document.querySelector("#kod-pocztowy"),a=document.querySelector("#miasto"),c=document.querySelector("#adres");return{email:e,name:n,nip:i,phone:t,additionalInfo:o,companyName:d,companyZip:s,companyCity:a,companyAddress:c}},Me=async()=>{try{let e=new URLSearchParams(window.location.search),n=e.get("redirect_status")??"",i=e.get("payment_intent")??"";if(n==="succeeded"&&i){let t=await $(i);if(!t){alert("Wyst\u0105pi\u0142 b\u0142\u0105d podczas pobierania informacji o zamiarze zap\u0142aty. Skontaktuj si\u0119 z nami w celu wyja\u015Bnienia sytuacji."),console.error("Error retrieving payment intent.");return}console.log("Order Details:",t);let o=[];try{let a=await(await fetch(`https://koszyk.vsprint.pl/api/order-items-from-db?payment_intent=${i}`)).json();if(!a||a.length===0){console.error("Brak bilet\xF3w powi\u0105zanych z payment_intent"),alert("Nie odnaleziono bilet\xF3w dla tego zam\xF3wienia.");return}o=a}catch(s){console.error("Error parsing items from metadata:",s),alert("Wyst\u0105pi\u0142 b\u0142\u0105d podczas przetwarzania informacji o zam\xF3wieniu.");return}W(o);let d=qe();if(d){let{email:s,name:a,nip:c,phone:p,additionalInfo:u,companyName:m,companyZip:w,companyCity:h,companyAddress:f}=d;s&&(s.textContent=t.receipt_email||""),a&&(a.textContent=t.shipping.name||""),p&&(p.textContent=t.shipping.phone||""),u&&(u.textContent=t.metadata.additional_info||"-"),c&&(t.metadata.nip?c.textContent=t.metadata.nip:c.parentElement?.remove()),m&&(t.metadata.company_name?m.textContent=t.metadata.company_name:m.parentElement?.remove()),w&&(t.metadata.company_zip?w.textContent=t.metadata.company_zip:w.parentElement?.remove()),h&&(t.metadata.company_city?h.textContent=t.metadata.company_city:h.parentElement?.remove()),f&&(t.metadata.company_address?f.textContent=t.metadata.company_address:f.parentElement?.remove()),window.dataLayer.push({ecommerce:null}),window.dataLayer.push({event:"purchase",ecommerce:{transaction_id:t.id,affiliation:"Konferencja App",value:t.metadata.total_amount/100,currency:"PLN",tax:t.metadata.tax_cost/100,discount:t.metadata.coupon_amount/100,items:o.map(E=>({item_id:E.id,item_name:E.id,affiliation:"Konferencja App",price:E.price,quantity:E.quantity}))}}),U(t.metadata.products_cost/100,t.metadata.tax_cost/100,t.metadata.total_amount/100,t.metadata.coupon_amount/100)}}else if(n==="pending")alert("Twoje zam\xF3wienie jest nadal przetwarzane. Kliknij OK, aby strona od\u015Bwie\u017Cy\u0142a si\u0119 w przeci\u0105gu 10 sekund, aby sprawdzi\u0107 ponownie status."),setTimeout(async()=>{let t=await $(i);if(!t){alert("Wyst\u0105pi\u0142 b\u0142\u0105d podczas pobierania informacji o p\u0142atno\u015Bci.");return}if(t.status==="succeeded"){e.set("redirect_status","succeeded");let o=`${window.location.pathname}?${e.toString()}`;window.location.replace(o)}else if(t.status==="requires_payment_method"){alert("Nie doko\u0144czy\u0142e\u015B p\u0142atno\u015Bci. Kliknij OK, aby spr\xF3bowa\u0107 jeszcze raz.");let o=`${window.location.origin}/koszyk`;window.location.replace(o)}},1e4);else if(n==="cancelled"){alert("Anulowa\u0142e\u015B p\u0142atno\u015B\u0107. Spr\xF3buj jeszcze raz. Kliknij OK, aby nast\u0105pi\u0142o przekierowanie.");let t=`${window.location.origin}/koszyk`;window.location.replace(t)}}catch(e){alert("Wyst\u0105pi\u0142 b\u0142\u0105d. Skontaktuj si\u0119 z nami w celu wyja\u015Bnienia sytuacji."),console.error("Error retrieving order details:",e)}};document.addEventListener("DOMContentLoaded",Me);})();