"use strict";(()=>{var A=document.querySelector('[flipico-cart="cart-button"]'),N=document.querySelector('[flipico-cart="added-to-cart-modal"]');var z=async o=>{try{let e=await fetch("https://koszyk.inspiredbyid.com/api/retrieve-payment-intent",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({paymentIntent:o})});if(!e.ok)throw new Error(`HTTP error! status: ${e.status}`);return(await e.json()).paymentIntentResult}catch{return null}},C=async o=>{try{let e=await fetch("https://koszyk.inspiredbyid.com/api/fetch-order-from-baselinker",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({orderId:o})});if(!e.ok)throw new Error(`HTTP error! status: ${e.status}`);return await e.json()}catch(e){throw console.error("Error fetching order:",e),e}};function D(o){document.querySelectorAll('[flipico-cart="summary-list"]').forEach(i=>{if(i){let n=r=>r.toLocaleString("pl-PL",{minimumFractionDigits:2,maximumFractionDigits:2});i.innerHTML="",o.forEach(r=>{let c=document.createElement("div");c.className="w-commerce-commercecheckoutorderitem order-item",c.innerHTML=`
${r.name}
Ilo\u015B\u0107:
${r.quantity}
${n(r.price_brutto)} z\u0142
`,i.appendChild(c)})}})}function L(){console.log("%c \u2764\uFE0F Flipico Components ",` background: linear-gradient(135deg, #7b2cff, #c799ff); color: #fff; font-weight: bold; font-size: 20px; padding: 8px 16px; border-radius: 8px; box-shadow: 0 0 12px rgba(123, 44, 255, 0.6); display: inline-block; `),console.log("%c\u2728 This system was lovingly crafted by Flipico Agency.",` background: #ffffff; color: #333; font-size: 15px; padding: 6px 10px; border: 1px solid #eee; border-radius: 6px; `),console.log("%c\u{1F680} Powered by %ccustom attributes %c(flipico-cart)%c, %cStripe%c payments, %cInPost%c parcel integration, and %cBaseLinker synchronization.","color: #555;","color: #555;","color: #7b2cff; font-weight: bold;","color: #555;","color: #635BFF; font-weight: bold;","color: #555;","color: #ffcc00; font-weight: bold;","color: #555;","color: #00b2a9; font-weight: bold;"),console.log("%c\u{1F4A1} Tip: Embrace innovation. Build with Flipico.",` color: #7b2cff; font-size: 13px; font-style: italic; `)}var _=async()=>{try{let o=new URLSearchParams(window.location.search),e=o.get("redirect_status")??"",i=o.get("payment_intent")??"";if(e==="succeeded"&&i){let n=await z(i);if(!n){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}let r=n.metadata?.order_id;if(!r){alert("Nie znale\u017Ali\u015Bmy Twojego zam\xF3wienia. Skontaktuj si\u0119 z nami w celu wyja\u015Bnienia sytuacji."),console.error("Order ID not found in payment intent metadata.");return}try{let c=await C(r),a=H();if(a){let{email:l,name:s,address:d,city:u,zip:m,country:p,nip:f,phone:y,additionalInfo:v,shipmentMethod:E,parcelMachine:I,companyName:h,companyAddress:k,companyZIP:g,companyCity:w}=a,t=c?.orders?.[0];if(!t){console.error("Order not found.");return}let{products:x}=t;l&&(l.textContent=t?.email||""),s&&(s.textContent=t?.delivery_fullname||""),d&&(d.textContent=t?.delivery_address||""),u&&(u.textContent=t?.delivery_city||""),m&&(m.textContent=t?.delivery_postcode||""),p&&(p.textContent=t?.delivery_country||""),y&&(y.textContent=t?.phone||""),v&&(v.textContent=t?.user_comments||""),E&&(E.textContent=t?.delivery_method||""),I&&(I.textContent=t?.delivery_point_id||""),f&&(t?.invoice_nip?f.textContent=t.invoice_nip:f.parentElement?.remove()),h&&(t?.invoice_company?h.textContent=t.invoice_company:h.parentElement?.remove()),k&&(t?.invoice_address?k.textContent=t.invoice_address:k.parentElement?.remove()),g&&(t?.invoice_postcode?g.textContent=t.invoice_postcode:g.parentElement?.remove()),w&&(t?.invoice_city?w.textContent=t.invoice_city:w.parentElement?.remove()),D(x);let b=x.reduce(($,S)=>$+S.price_brutto*S.quantity,0),q=b*.23,T=t?.payment_done,M=Math.max(T,0),j=Math.round((T-b-t?.delivery_price)*100)/100;P(b,q,t?.delivery_method,t?.delivery_price,M,j)}}catch(c){alert("Wyst\u0105pi\u0142 b\u0142\u0105d podczas pobierania zam\xF3wienia. Skontaktuj si\u0119 z nami."),console.error("Error fetching Baselinker order:",c)}}else if(e==="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 n=await z(i);if(!n){alert("Wyst\u0105pi\u0142 b\u0142\u0105d podczas pobierania informacji o p\u0142atno\u015Bci.");return}if(n.status==="succeeded"){o.set("redirect_status","succeeded");let r=`${window.location.pathname}?${o.toString()}`;window.location.replace(r)}else if(n.status==="requires_payment_method"){alert("Nie doko\u0144czy\u0142e\u015B p\u0142atno\u015Bci. Kliknij OK, aby spr\xF3bowa\u0107 jeszcze raz.");let r=`${window.location.origin}/koszyk`;window.location.replace(r)}},1e4);else if(e==="cancelled"){alert("Anulowa\u0142e\u015B p\u0142atno\u015B\u0107. Spr\xF3buj jeszcze raz. Kliknij OK, aby nast\u0105pi\u0142o przekierowanie.");let n=`${window.location.origin}/koszyk`;window.location.replace(n)}}catch(o){alert("Wyst\u0105pi\u0142 b\u0142\u0105d. Skontaktuj si\u0119 z nami w celu wyja\u015Bnienia sytuacji."),console.error("Error retrieving order details:",o)}},H=()=>{let o=document.querySelector('[flipico-cart="checkout-email"]'),e=document.querySelector('[flipico-cart="checkout-name"]'),i=document.querySelector('[flipico-cart="checkout-address"]'),n=document.querySelector('[flipico-cart="checkout-city"]'),r=document.querySelector('[flipico-cart="checkout-zip"]'),c=document.querySelector('[flipico-cart="checkout-country"]'),a=document.querySelector('[flipico-cart="checkout-nip"]'),l=document.querySelector('[flipico-cart="checkout-phone"]'),s=document.querySelector('[flipico-cart="checkout-additional-info"]'),d=document.querySelector('[flipico-cart="checkout-shipment"]'),u=document.querySelector('[flipico-cart="checkout-parcel-input"]'),m=document.querySelector('[flipico-cart="checkout-company-name"]'),p=document.querySelector('[flipico-cart="checkout-company-address"]'),f=document.querySelector('[flipico-cart="checkout-company-zip"]'),y=document.querySelector('[flipico-cart="checkout-company-city"]');return{email:o,name:e,address:i,city:n,zip:r,country:c,nip:a,phone:l,additionalInfo:s,shipmentMethod:d,parcelMachine:u,companyName:m,companyAddress:p,companyZIP:f,companyCity:y}},P=(o,e,i,n,r,c)=>{let a=f=>f.toLocaleString("pl-PL",{minimumFractionDigits:2,maximumFractionDigits:2}),l=document.querySelector('[flipico-cart="checkout-products-cost"]');l&&(l.textContent=`${a(o)} z\u0142`);let s=document.querySelector('[flipico-cart="checkout-tax"]');s&&(s.textContent=`${a(e)} z\u0142`);let d=document.querySelector('[flipico-cart="checkout-shipping-choice"]');d&&(d.textContent=`${i}`);let u=document.querySelector('[flipico-cart="checkout-shipping-cost"]');u&&(u.textContent=`${a(n)} z\u0142`);let m=document.querySelector('[flipico-cart="checkout-coupon-amount"]');m&&(m.textContent=`${a(c)} z\u0142`);let p=document.querySelector('[flipico-cart="checkout-total"]');p&&(p.textContent=`${a(r)} z\u0142`)};document.addEventListener("DOMContentLoaded",async()=>{L(),await _()});})();