PageSourceSearch

https://f8.edu.vn/assets/index-D4sgmAlB.js

js f8.edu.vn collected 2026-10-09 23:29:58 UTC 47,074 bytes, 5 lines download raw bytes

1
2!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f838fd96-761b-5157-a3e5-71717bfac44d")}catch(e){}}();
3import{t as n}from"./vendor-D9ynouy7.js";import{F as J,af as Ne,bp as Se,bq as Re,T as Ie,X as Ae,a4 as Kn,br as Wn,bs as Te}from"./vendor-icons-C-SZ6ooi.js";import{u as qe,b as Ee,L as Fe}from"./vendor-router-D-10j296.js";import{n as Q,bJ as Fn,cd as De,B as T,V as Cn,bn as Ue,bf as Me,j as Oe,l as Pe,ce as $e,bi as vn,bk as Be,ay as Le}from"./index-QZtKmto7.js";import{s as ae,a as ze,f as Vn}from"./comboPurchaseLink-Dmcj03f7.js";import"./vendor-reel-_v2BQs0k.js";import"./vendor-buffer-DwhYXYZp.js";import"./vendor-toastify-CN110bky.js";import"./vendor-sentry-DkCP74Zt.js";import"./vendor-zustand-CjVDOK-D.js";import"./vendor-sanitizer-CavJxfVx.js";import"./vendor-helmet-CxiJfWxn.js";import"./vendor-tippy-CcYIf-sw.js";import"./vendor-slick-X0JhTi1s.js";import"./vendor-qs-DNWtaKIO.js";import"./vendor-dayjs-De_O56IQ.js";import"./vendor-markdown-ozW-stUs.js";import"./vendor-entities-0t_PSvgD.js";import"./vendor-nprogress-CeY5WMsD.js";import"./vendor-firebase-Dv335-f4.js";const Dn="checkout_order_attempt";function Un(){return typeof window<"u"&&typeof window.sessionStorage<"u"}function He(){if(typeof window.crypto.randomUUID=="function")return window.crypto.randomUUID();const e=new Uint8Array(16);window.crypto.getRandomValues(e),e[6]=(e[6]??0)&15|64,e[8]=(e[8]??0)&63|128;const t=Array.from(e,i=>i.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function Ge(){if(!Un())return null;try{const e=window.sessionStorage.getItem(Dn),t=e?JSON.parse(e):null;return!t||typeof t.marker!="string"||typeof t.idempotencyKey!="string"||t.marker.length===0||t.marker.length>512||!/^checkout-[0-9a-f-]{36}$/i.test(t.idempotencyKey)?(kn(),null):t}catch{return kn(),null}}function Ke(e){const t=e.trim();if(!t||t.length>512)throw new Error("Không thể khởi tạo lượt xác nhận thanh toán.");const i=Ge();if((i==null?void 0:i.marker)===t)return i.idempotencyKey;const o={marker:t,idempotencyKey:`checkout-${He()}`};return Un()&&window.sessionStorage.setItem(Dn,JSON.stringify(o)),o.idempotencyKey}function kn(){Un()&&window.sessionStorage.removeItem(Dn)}const Mn=window.httpRequest.post,We=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,Ve=/^[a-z][a-z0-9_]{0,63}$/,Qe=new Set(["review_cart","refresh_quote","restart_checkout","retry_same_request","owner_order","order_detail","manage_pending_orders","fix_request"]);function v(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function U(e){return typeof e=="string"&&e.trim()!==""?e.trim():null}function M(e,t){const i=U(e);if(!i)throw new Error(`Dữ liệu ${t} từ máy chá»§ không hợp lệ.`);return i}function le(e){const t=U(e);return t&&We.test(t)?t:null}function L(e,t,i=!1){if(i&&e===null)return null;if(typeof e!="number"||!Number.isSafeInteger(e)||e<0)throw new Error(`Dữ liệu ${t} từ máy chá»§ không hợp lệ.`);return e}function cn(e,t){if(typeof e!="number"||!Number.isSafeInteger(e)||e<=0)throw new Error(`Dữ liệu ${t} từ máy chá»§ không hợp lệ.`);return e}function ue(e){if(!Array.isArray(e))throw new Error("Dữ liệu chuẩn bị thanh toán từ máy chá»§ không hợp lệ.");const t=e.map(i=>cn(i,"chuẩn bị thanh toán"));if(t.length===0||new Set(t).size!==t.length)throw new Error("Dữ liệu chuẩn bị thanh toán từ máy chá»§ không hợp lệ.");return[...t].sort((i,o)=>i-o)}function Ye(e){const t=v(e);return{cartItemId:cn(t.cart_item_id,"dòng thanh toán"),purchasableKey:M(t.purchasable_key,"dòng thanh toán"),purchasableType:M(t.purchasable_type,"dòng thanh toán"),purchasableId:cn(t.purchasable_id,"dòng thanh toán"),quantity:cn(t.quantity,"dòng thanh toán"),configuration:{...v(t.configuration)},title:M(t.title_snapshot,"dòng thanh toán"),imageUrl:U(t.image_url_snapshot),sku:U(t.sku_snapshot),listUnitPrice:L(t.list_unit_price,"giá thanh toán"),unitPrice:L(t.unit_price,"giá thanh toán"),lineSubtotal:L(t.line_subtotal,"giá thanh toán"),discountAmount:L(t.discount_amount,"giảm giá"),finalAmount:L(t.final_amount,"thành tiền"),fulfillmentKind:M(t.fulfillment_kind,"hình thức thá»±c hiện")}}function Qn(e){const t=v(e);if(typeof t.required!="boolean")throw new Error("Dữ liệu yêu cầu giao nhận từ máy chá»
3§ không hợp lệ.");const i=v(t.source);return{key:M(t.key,"yêu cầu giao nhận"),label:M(t.label,"yêu cầu giao nhận"),required:t.required,type:M(t.type??"text","loại yêu cầu giao nhận"),source:Object.keys(i).length>0?i:void 0}}function Yn(e){const t=v(e);return{id:cn(t.id,"phương thức giao nhận"),code:M(t.code,"phương thức giao nhận"),label:M(t.label,"phương thức giao nhận"),kind:M(t.kind,"phương thức giao nhận"),fee:L(t.fee,"phí giao nhận"),estimatedText:U(t.estimated_text),pickupAddress:U(t.pickup_address),pickupHours:U(t.pickup_hours),pickupInstructions:U(t.pickup_instructions),publicContact:U(t.public_contact),distanceRules:Xe(t.distance_rules)}}function Xe(e){const t=v(e),i=typeof t.free_radius_m=="number"?t.free_radius_m:null,o=typeof t.free_min_quantity=="number"?t.free_min_quantity:null;return i===null||i<0||o===null||o<1?null:{freeRadiusM:i,freeMinQuantity:o,requiresCoordinates:t.requires_coordinates===!0}}function Ze(e){const t=v(e);if(typeof t.requires_shipping!="boolean")throw new Error("Dữ liệu yêu cầu thanh toán từ máy chá»§ không hợp lệ.");if(!t.requires_shipping)return{requiresShipping:!1,shipping:null};const i=v(t.shipping);if(!Array.isArray(i.options)||i.options.length===0)throw new Error("Dữ liệu yêu cầu giao nhận từ máy chá»§ không hợp lệ.");const o=Object.fromEntries(Object.entries(v(i.fields_by_kind)).map(([s,h])=>[s,Array.isArray(h)?h.map(Qn):[]]));return{requiresShipping:!0,shipping:{selectedMethod:i.selected_method===null?null:Yn(i.selected_method),options:i.options.map(Yn),fields:Array.isArray(i.fields)?i.fields.map(Qn):[],fieldsByKind:o}}}function Je(e,t,i){const o=v(e);if(o.currency!=="VND")throw new Error("Dữ liệu tổng tiền từ máy chá»§ không hợp lệ.");const s=L(o.items_subtotal,"tổng tiền"),h=L(o.discount_total,"tổng giảm giá"),c=L(o.shipping_fee,"phí giao nhận",i&&t),l=L(o.grand_total,"tổng thanh toán",i&&t),d=i?L(o.amount_before_shipping,"tạm tính"):l-c,m=i?o.pricing_complete===!0:!0;if(h>s||d!==s-h||t&&i&&(c!==null||l!==null||m)||!t&&(c!==0||l!==d||!m)||!i&&l!==d+c)throw new Error("Dữ liệu chuẩn bị thanh toán từ máy chá»§ không hợp lệ.");return{itemsSubtotal:s,discountTotal:h,shippingFee:c,grandTotal:l,amountBeforeShipping:d,currency:"VND",pricingComplete:m}}function de(e,t){const i=v(e),o=v(i.data??i);if(o.contract_version!==2)throw new Error("Dữ liệu chuẩn bị thanh toán từ máy chá»§ không hợp lệ.");if(t&&(o.advisory!==!0||v(o.capabilities).can_issue_quote!==!0))throw new Error("Dữ liệu chuẩn bị thanh toán từ máy chá»§ không hợp lệ.");const s=ue(o.selected_cart_item_ids);if(!Array.isArray(o.lines))throw new Error("Dữ liệu chuẩn bị thanh toán từ máy chá»§ không hợp lệ.");const h=o.lines.map(Ye).sort((l,d)=>l.cartItemId-d.cartItemId);if(h.length!==s.length||h.some((l,d)=>l.cartItemId!==s[d]))throw new Error("Dữ liệu chuẩn bị thanh toán từ máy chá»§ không hợp lệ.");const c=Ze(o.requirements);return{selectedCartItemIds:s,pricingRevision:M(o.pricing_revision,"chuẩn bị thanh toán"),lines:h,summary:Je(o.summary,c.requiresShipping,t),requirements:c,discount:o.discount===null||o.discount===void 0?null:{...v(o.discount)}}}function he(e,t){const i=ue(e),o=(t==null?void 0:t.trim().toUpperCase())||null;return o?{cart_item_ids:i,discount_code:o}:{cart_item_ids:i}}async function Nn(e,t){const i=await Mn(Q.rest.checkout.prepare(),he(e,t),Fn({}));return de(i,!0)}async function Sn(e){const t={...he(e.cartItemIds,e.discountCode),checkout_data:e.shipping?{shipping:e.shipping}:{}},i=await Mn(Q.rest.checkout.quote(),t,Fn({})),o=v(i),s=v(o.data??o),h=de({data:{...s,selected_cart_item_ids:e.cartItemIds}},!1),c=M(s.quote_token,"báo giá"),l=M(s.expires_at,"hạn báo giá");if(c.length<22||!Number.isFinite(Date.parse(l)))throw new Error("Dữ liệu báo giá từ máy chá»§ không hợp lệ.");return{...h,quoteToken:c,expiresAt:l}}async function nt(e){const t=await Mn(Q.rest.orders.create(),{quote_token:e.quoteToken,checkout_data:e.checkoutData,...De()},Fn({headers:{"Idempotency-Key":e.idempotencyKey}})),i=v(t),o=v(i.data),s=v(i.commerce),h=v(s.payment_recovery),c=le(o.uuid),l=h.action;if(!c||s.contract_version!==2||typeof s.replayed!="boolean"||typeof s.requires_payment!="boolean"||l!=="owner_order"&&l!=="order_detail"||h.order_uuid!==c)throw new Error("Dữ liệu xác nhận đơn hàng từ máy chá»
3§ không hợp lệ.");return{orderUuid:c,orderId:cn(o.id,"đơn hàng"),totalPrice:L(o.total_price,"đơn hàng"),replayed:s.replayed,requiresPayment:s.requires_payment,recoveryAction:l}}function rn(e){var C;const t=v((C=e==null?void 0:e.response)==null?void 0:C.data),i=v(t.errors),o=v(i.recovery),s=i.retry_after,h=U(i.reason_code),c=h&&Ve.test(h)?h:"checkout_unknown",l=U(o.action),d=l&&Qe.has(l)?l:"review_cart",m=i.retryable===!0&&c==="idempotency_in_progress"&&d==="retry_same_request";return{message:U(i.message??t.message)??"Không thể tiếp tục thanh toán. Vui lòng thá»­ lại.",reasonCode:c,...c==="payment_destination_conflict"?{paymentDestinationGroups:et(v(i.context).groups)}:{},retryable:m,retryAfterSeconds:m&&typeof s=="number"&&Number.isSafeInteger(s)&&s>0?s:null,recoveryAction:d,orderUuid:le(o.order_uuid)}}function et(e){if(!Array.isArray(e))return[];const t=[],i=new Set;for(const o of e){const s=v(o),h=U(s.label),c=s.cart_item_ids;if(!h||!Array.isArray(c)||c.length===0||c.some(l=>typeof l!="number"||!Number.isSafeInteger(l)||l<=0||i.has(l)))return[];for(const l of c)i.add(l);if(new Set(c).size!==c.length)return[];t.push({label:h,cartItemIds:c})}return t.length>=2?t:[]}const tt="Checkout-module__container___LbAim",it="Checkout-module__header___-WxZ0",ot="Checkout-module__backLink___th1Ub",rt="Checkout-module__headingRow___mtslO",st="Checkout-module__eyebrow___UhbD6",ct="Checkout-module__layout___w0hp6",at="Checkout-module__layoutSummaryFirst___E3rSO",lt="Checkout-module__summaryColumn___rSCKC",ut="Checkout-module__mainColumn___hDdnf",dt="Checkout-module__section___O8TFz",ht="Checkout-module__summaryCard___N9UNm",mt="Checkout-module__digitalNotice___ZXh7K",pt="Checkout-module__errorBanner___6Tffc",gt="Checkout-module__successCard___vLDG8",_t="Checkout-module__emptyCard___qFgrH",ft="Checkout-module__sectionHeadingRow___-P4-D",yt="Checkout-module__sectionTitle___umcY1",kt="Checkout-module__countBadge___smyj9",Ct="Checkout-module__lineList___2Q4Rb",bt="Checkout-module__lineItem___zX6CG",xt="Checkout-module__lineImage___VUaem",wt="Checkout-module__lineBody___1f-mx",jt="Checkout-module__lineMeta___83And",vt="Checkout-module__configuration___GB7Ch",Nt="Checkout-module__quantity___m87oR",St="Checkout-module__linePrice___mHopN",Rt="Checkout-module__shippingOptions___Kz4mZ",It="Checkout-module__shippingOption___SSU8F",At="Checkout-module__shippingOptionBody___oVed5",Tt="Checkout-module__shippingOptionTop___qfhxE",qt="Checkout-module__shippingForm___MajYb",Et="Checkout-module__formGrid___G2p6M",Ft="Checkout-module__formField___PCrZI",Dt="Checkout-module__fieldError___dDhUx",Ut="Checkout-module__fieldHint___t50J9",Mt="Checkout-module__fieldRetry___s-MaP",Ot="Checkout-module__adminUnitMode___2iJAc",Pt="Checkout-module__mapPicker___V2V1t",$t="Checkout-module__mapHint___AH9RH",Bt="Checkout-module__mapControls___cs7-h",Lt="Checkout-module__mapActions___RT4yw",zt="Checkout-module__mapCanvasWrapper___4tPdP",Ht="Checkout-module__mapCanvas___n32dE",Gt="Checkout-module__mapUnavailable___ZeXwm",Kt="Checkout-module__mapStatus___4aMXF",Wt="Checkout-module__mapConfirmed___rcZ19",Vt="Checkout-module__mapPending___-HhNd",Qt="Checkout-module__mapError___s8YXI",Yt="Checkout-module__shippingHint___AwURk",Xt="Checkout-module__discountForm___rbtuO",Zt="Checkout-module__comboCodeWarning___CZsi4",Jt="Checkout-module__comboCodeWarningBody___Uzb-D",ni="Checkout-module__comboCodeWarningTitle___Y592M",ei="Checkout-module__comboCodeWarningActions___hw5sW",ti="Checkout-module__appliedDiscount___Pjdzc",ii="Checkout-module__summaryRows___5cPkU",oi="Checkout-module__discountRow___TaBry",ri="Checkout-module__strikeRow___iT650",si="Checkout-module__totalRow___8WdvQ",ci="Checkout-module__totalHint___OnVqq",ai="Checkout-module__securityNote___QplLj",li="Checkout-module__quoteTimer___w6Crw",ui="Checkout-module__blockedNote___4CgTx",di="Checkout-module__expiredBox___1fkRr",hi="Checkout-module__successIcon___16equ",mi="Checkout-module__orderReference___Bwsdn",pi="Checkout-module__loadingShell___KQeLa",gi="Checkout-module__paymentGroups___-1uDi",_i="Checkout-module__accountLine___q2fge",r={container:tt,header:it,backLink:ot,headingRow:rt,eyebrow:st,layout:ct,layoutSummaryFirst:at,summaryColumn:lt,mainColumn:ut,section:dt,summaryCard:ht,digitalNotice:mt,errorBanner:pt,successCard:gt,emptyCard:_t,sectionHeadingRow:ft,sectionTitle:yt,countBadge:kt,lineList:Ct,lineItem:bt,lineImage:
3xt,lineBody:wt,lineMeta:jt,configuration:vt,quantity:Nt,linePrice:St,shippingOptions:Rt,shippingOption:It,shippingOptionBody:At,shippingOptionTop:Tt,shippingForm:qt,formGrid:Et,formField:Ft,fieldError:Dt,fieldHint:Ut,fieldRetry:Mt,adminUnitMode:Ot,mapPicker:Pt,mapHint:$t,mapControls:Bt,mapActions:Lt,mapCanvasWrapper:zt,mapCanvas:Ht,mapUnavailable:Gt,mapStatus:Kt,mapConfirmed:Wt,mapPending:Vt,mapError:Qt,shippingHint:Yt,discountForm:Xt,comboCodeWarning:Zt,comboCodeWarningBody:Jt,comboCodeWarningTitle:ni,comboCodeWarningActions:ei,appliedDiscount:ti,summaryRows:ii,discountRow:oi,strikeRow:ri,totalRow:si,totalHint:ci,securityNote:ai,quoteTimer:li,blockedNote:ui,expiredBox:di,successIcon:hi,orderReference:mi,loadingShell:pi,paymentGroups:gi,accountLine:_i};function fi({groups:e=[],selectedCartItemIds:t,onSelect:i}){const o=e.flatMap(s=>s.cartItemIds);return e.length<2||o.length!==t.length||new Set(o).size!==o.length||o.some(s=>!t.includes(s))?null:n.jsxs("section",{className:r.paymentGroups,"aria-label":"Chọn nhóm thanh toán",children:[n.jsx("p",{children:"Các nhóm này nhận thanh toán vào tài khoản khác nhau. Chọn nhóm muốn mua trước; những sản phẩm còn lại vẫn ở trong giỏ hàng. Giá và phí giao hàng sẽ được tính lại cho nhóm đã chọn."}),n.jsx("div",{children:e.map(s=>n.jsxs(T,{type:"button",variant:"outline",size:"lg",onClick:()=>i(s.cartItemIds),children:["Thanh toán ",s.label]},s.cartItemIds.join(",")))})]})}function Xn(e){return`${Cn(e)}đ`}function yi(e){return e==="course"?"Khóa học":e==="product"?"Sản phẩm":"Mục trong đơn hàng"}function ki({lines:e}){const t=e.reduce((i,o)=>i+o.quantity,0);return n.jsxs("section",{className:r.section,"aria-labelledby":"checkout-items-heading",children:[n.jsxs("div",{className:r.sectionHeadingRow,children:[n.jsx("div",{children:n.jsx("h2",{id:"checkout-items-heading",className:r.sectionTitle,children:"Các mục đã chọn"})}),n.jsxs("span",{className:r.countBadge,children:[t," mục"]})]}),n.jsx("div",{className:r.lineList,children:e.map(i=>n.jsxs("article",{className:r.lineItem,children:[n.jsx("div",{className:r.lineImage,children:i.imageUrl?n.jsx("img",{src:i.imageUrl,alt:"",loading:"lazy"}):n.jsx(J,{icon:i.purchasableType==="course"?Ne:Se})}),n.jsxs("div",{className:r.lineBody,children:[n.jsxs("div",{className:r.lineMeta,children:[n.jsx("span",{children:yi(i.purchasableType)}),i.sku?n.jsxs("span",{children:["SKU: ",i.sku]}):null]}),n.jsx("h3",{children:i.title}),Object.keys(i.configuration).length>0?n.jsx("p",{className:r.configuration,children:Object.entries(i.configuration).map(([o,s])=>`${o}: ${String(s)}`).join(" · ")}):null,i.quantity>1?n.jsxs("p",{className:r.quantity,children:["Số lượng: ",i.quantity]}):null]}),n.jsxs("div",{className:r.linePrice,children:[n.jsx("strong",{children:Xn(i.finalAmount)}),i.discountAmount>0?n.jsxs("span",{children:["Đã giảm ",Xn(i.discountAmount)]}):null]})]},i.cartItemId))})]})}const Ci=window.httpRequest.get;function En(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function ln(e,t){if(typeof e!="string"||e.trim()==="")throw new Error(`Dữ liệu ${t} từ máy chủ không hợp lệ.`);return e.trim()}function bi(e){const t=En(e);return{code:ln(t.code,"đơn vị hành chính"),parentCode:typeof t.parent_code=="string"&&t.parent_code.trim()!==""?t.parent_code.trim():null,provinceCode:ln(t.province_code,"đơn vị hành chính"),name:ln(t.name,"đơn vị hành chính"),fullName:ln(t.full_name,"đơn vị hành chính"),unitType:ln(t.unit_type,"đơn vị hành chính")}}function xi(e){const i=En(e).data;if(Array.isArray(i))return i;const o=En(i);return Array.isArray(o.data)?o.data:[]}async function wi(e){const t=await Ci(Ue.reference.administrativeUnits(e));return xi(t).map(bi)}const ji=window.React.useCallback,vi=window.React.useEffect,Zn=window.React.useState,Jn={units:[],loading:!1,error:""},ne=new Map;function Ni(e,t,i){return`${e}:${t}:${i||"root"}`}function Rn({set:e,level:t,parentCode:i="",enabled:o=!0}){const[s,h]=Zn(0),[c,l]=Zn(Jn),d=o&&(t==="province"||i!==""),m=Ni(e,t,i);vi(()=>
3{if(!d){l(Jn);return}const y=ne.get(m);if(y){l({units:y,loading:!1,error:""});return}let p=!0;return l({units:[],loading:!0,error:""}),wi({set:e,level:t,parentCode:i}).then(E=>{ne.set(m,E),p&&l({units:E,loading:!1,error:""})}).catch(()=>{p&&l({units:[],loading:!1,error:"Không tải được danh mục hành chính."})}),()=>{p=!1}},[d,m,t,i,s,e]);const C=ji(()=>h(y=>y+1),[]);return{...c,loading:c.loading&&d,refetch:C}}const ee="address_unit_set",te="new",pn="old";function Si(e,t){const i=e.map(o=>n.jsx("option",{value:o.fullName,children:o.fullName},o.fullName));return t&&!e.some(o=>o.fullName===t)&&i.unshift(n.jsx("option",{value:t,children:t},t)),i}function In({id:e,label:t,value:i,units:o,loading:s,error:h,disabled:c,disabledHint:l,required:d,onChange:m,onRetry:C}){const y=`${e}-error`,p=`${e}-hint`,E=i===""||o.some(O=>O.fullName===i),k=s?"Đang tải danh mục...":`Chọn ${t.toLowerCase()}`,A=[h?y:"",l?p:""].filter(Boolean).join(" ");return n.jsxs("div",{className:r.formField,children:[n.jsxs("label",{htmlFor:e,children:[t,d?n.jsx("span",{"aria-hidden":"true",children:" *"}):null]}),n.jsxs("select",{id:e,value:i,required:d&&!c,disabled:c,"aria-invalid":!!h,"aria-describedby":A||void 0,onChange:O=>m(O.target.value),children:[n.jsx("option",{value:"",children:k}),Si(o,i)]}),l?n.jsx("span",{id:p,className:r.fieldHint,children:l}):null,!E&&!s&&!h?n.jsx("span",{className:r.fieldHint,children:"Giá trị hiện tại không có trong danh mục đang chọn."}):null,h?n.jsxs("span",{id:y,className:r.fieldError,role:"alert",children:[h," ",n.jsx("button",{type:"button",className:r.fieldRetry,onClick:C,children:"Thử lại"})]}):null]})}function Ri({values:e,errors:t,required:i,onChangeValues:o}){const s=e[ee]===pn?pn:te,h=s===pn,c=Rn({set:s,level:"province"}),l=c.units.find(p=>p.fullName===e.province)??null,d=Rn({set:s,level:"district",parentCode:(l==null?void 0:l.code)??"",enabled:h}),m=d.units.find(p=>p.fullName===e.district)??null,C=h?(m==null?void 0:m.code)??"":(l==null?void 0:l.code)??"",y=Rn({set:s,level:"ward",parentCode:C});return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:`${r.formField} ${r.adminUnitMode}`,"data-wide":"true",children:[n.jsx("input",{id:"checkout-address-unit-set",type:"checkbox",checked:h,onChange:p=>o({[ee]:p.target.checked?pn:te,province:"",district:"",ward:""})}),n.jsx("label",{htmlFor:"checkout-address-unit-set",children:"Dùng đơn vị hành chính cũ (trước 01/07/2025, có quận/huyện)"})]}),n.jsx(In,{id:"checkout-shipping-province",label:"Tỉnh, thành phố",value:e.province??"",units:c.units,loading:c.loading,error:c.error||t.province||"",disabled:!1,disabledHint:"",required:i,onChange:p=>o({province:p,district:"",ward:""}),onRetry:c.refetch}),h?n.jsx(In,{id:"checkout-shipping-district",label:"Quận, huyện",value:e.district??"",units:d.units,loading:d.loading,error:d.error||t.district||"",disabled:!l,disabledHint:l?"":"Chọn tỉnh, thành phố trước.",required:i,onChange:p=>o({district:p,ward:""}),onRetry:d.refetch}):null,n.jsx(In,{id:"checkout-shipping-ward",label:"Phường, xã",value:e.ward??"",units:y.units,loading:y.loading,error:y.error||t.ward||"",disabled:!l||h&&!m,disabledHint:l&&h&&!m?"Chọn quận, huyện trước.":"",required:i,onChange:p=>o({ward:p}),onRetry:y.refetch})]})}const me="";let An=null,Tn=!1,yn=null;function pe(){return me.trim()!==""}function ie(e){yn=e}function Ii(){var e;return pe()?(e=window.google)!=null&&e.maps&&!Tn?Promise.resolve(window.google):(An??(An=new Promise((t,i)=>{var l;(l=document.querySelector("script[data-f8-google-maps]"))==null||l.remove();const o=document.createElement("script");let s=!1;const h=d=>{An=null,Tn=!0,window.clearTimeout(c),o.remove(),s||i(new Error(d)),s=!0},c=window.setTimeout(()=>h("Không tải được bản đồ. Vui lòng thử lại."),15e3);o.dataset.f8GoogleMaps="true",o.async=!0,o.src=`https://maps.googleapis.com/maps/api/js?key=${encodeURIComponent(me)}&libraries=places&loading=async&callback=__f8GoogleMapsReady`,window.gm_authFailure=()=>{h("Google Maps đang tạm thời không khả dụng. Vui lòng thử tải lại bản đồ."),yn==null||yn()},window.__f8GoogleMapsReady=()=>{var d;s||((d=window.google)!=null&&d.maps?(s=!0,Tn=!1,window.clearTimeout(c),t(window.google)):h("Không khởi tạo được bản đồ. Vui lòng thử lại."))},o.addEventListener("error",()=>{h("Không tải được Google Maps. Vui lòng thử lại.")}),document.head.appendChild(o)})),An):Promise.reject(new Error("Chưa cấu hình Google Maps cho trang thanh toán."))}const gn=window.React.useCallback,un=window.React.useEffect,W=window.React.useRef,sn=window.React.useState,Ai={lat:21.027763,lng:105.83416};function Ti({addressQuery:e,latitude:t,longitude:i,onCoordinatesChange:o}){const s=W(null),h=W(null),c=W(null),l=W(null),d=W(null),m=W({latitude:t,longitude:i}),C=W(o),[y,p]=sn(""),[E,k]=sn(""),[A,O]=sn(!1),[F,P]=sn(!1),[nn,en]=sn(0),[V,$]=sn(null),a=W(0),R=W(!1),z=W(e);z.current=e,un(()=>{C.current=o},[o]),un(()=>{m.current={latitude:t,longitude:i}},[t,i]),un(()=>(ie(()=>{R.current=!0,a.current+=1,$(null),C.current(null,null),P(!0),O(!1),p(""),k("Google Maps đang tạm thời không khả dụng. Vui lòng thử tải lại bản đồ để kiểm tra điểm giao trước khi thanh toán.")}),()=>{ie(null)}),[]);const H=gn((w,b)=>{const x={lat:Number(w.toFixed(7)),lng:Number(b.toFixed(7))};a.current+=1,$(null),m.current={latitude:x.lat,longitude:x.lng},C.current(x.lat,x.lng)},[]),q=gn((w,b)=>{const x=c.current,B=l.current;!x||!B||(d.current?d.current.setPosition({lat:w,lng:b}
3):(d.current=new x.maps.Marker({map:B,position:{lat:w,lng:b},draggable:!0,title:"Vị trí giao hàng"}),c.current=x,d.current.addListener("dragend",()=>{var N;const f=(N=d.current)==null?void 0:N.getPosition();f&&!R.current&&(H(f.lat(),f.lng()),p("Đã cập nhật điểm giao theo vị trí bạn chọn."))})),B.setCenter({lat:w,lng:b}))},[H]);un(()=>{let w=!1;if(R.current=!1,P(!1),k(""),!pe()){P(!0),R.current=!0,C.current(null,null),k("Chưa cấu hình bản đồ. Chưa thể xác minh điểm giao; vui lòng thử lại sau.");return}return Ii().then(b=>{if(w||R.current||!s.current||l.current)return;c.current=b;const x=m.current,B=x.latitude!==null&&x.longitude!==null?{lat:x.latitude,lng:x.longitude}:Ai;if(l.current=new b.maps.Map(s.current,{center:B,zoom:16,mapTypeControl:!1,streetViewControl:!1}),h.current){const f=new b.maps.places.Autocomplete(h.current);f.addListener("place_changed",()=>{var G;const N=(G=f.getPlace().geometry)==null?void 0:G.location;N&&!w&&!R.current&&(H(N.lat(),N.lng()),q(N.lat(),N.lng()),p("Đã cập nhật vị trí theo địa điểm tìm kiếm."))})}x.latitude!==null&&x.longitude!==null&&q(x.latitude,x.longitude),O(!0)}).catch(b=>{w||(R.current=!0,a.current+=1,C.current(null,null),O(!1),P(!0),k(b instanceof Error?b.message:"Không tải được bản đồ. Vui lòng thử lại."))}),()=>{w=!0,a.current+=1}},[nn,H,q]);const Y=gn(()=>{const w=c.current;if(!w||!A)return;const b=e.trim();if(!b){k("Vui lòng nhập địa chỉ cụ thể trước khi tìm vị trí.");return}k(""),p("Đang xác định vị trí từ địa chỉ...");const x=++a.current;C.current(null,null),$(null),new w.maps.Geocoder().geocode({address:b},(B,f)=>{if(x!==a.current||b!==z.current.trim()||R.current)return;const N=B==null?void 0:B[0];if(f!=="OK"||!N){p(""),k("Không xác định được địa chỉ. Kiểm tra số nhà, tên đường rồi bấm “Tìm từ địa chỉ đã nhập”, hoặc tìm địa điểm trên bản đồ.");return}const G=N.geometry.location;$({lat:G.lat(),lng:G.lng()}),q(G.lat(),G.lng()),p("Bản đồ gợi ý vị trí theo địa chỉ. Hãy kiểm tra đúng số nhà, tòa nhà rồi xác nhận, hoặc kéo ghim đến điểm nhận hàng.")})},[e,q,A]);un(()=>{if(a.current+=1,$(null),p(""),!A||!e.trim()||m.current.latitude!==null&&m.current.longitude!==null)return;const w=a.current,b=window.setTimeout(()=>{w===a.current&&Y()},450);return()=>window.clearTimeout(b)},[e,A,Y]);const bn=gn(()=>{if(!A||R.current)return;const w=++a.current;if(C.current(null,null),m.current={latitude:null,longitude:null},$(null),!navigator.geolocation){k("Trình duyệt không hỗ trợ lấy vị trí hiện tại.");return}k(""),p("Đang lấy vị trí hiện tại..."),navigator.geolocation.getCurrentPosition(b=>{if(w!==a.current||R.current)return;const x={lat:b.coords.latitude,lng:b.coords.longitude};$(x),q(x.lat,x.lng),p("Đây là vị trí thiết bị. Chỉ xác nhận nếu bạn muốn nhận hàng tại điểm này; nếu không, hãy tìm địa chỉ giao hàng.")},()=>{w!==a.current||R.current||(p(""),k("Không lấy được vị trí hiện tại. Hãy tìm địa điểm trên bản đồ."))},{enableHighAccuracy:!0,timeout:1e4})},[q,A]),tn=!F&&!V&&t!==null&&i!==null;return n.jsxs("div",{className:r.mapPicker,children:[n.jsx("p",{className:r.mapHint,children:"Chọn đúng điểm giao trên bản đồ để tính phí vận chuyển. Điểm giao cần khớp với địa chỉ bạn đã nhập."}),n.jsxs("div",{className:r.mapControls,children:[n.jsx("label",{htmlFor:"checkout-map-place-search",children:"Tìm địa điểm trên Google Maps"}),n.jsx("input",{id:"checkout-map-place-search",ref:h,type:"text",disabled:!A,maxLength:200,placeholder:"Ví dụ: 12 Ngõ 88 Lương Định Của"}),n.jsxs("div",{className:r.mapActions,children:[n.jsx(T,{type:"button",variant:"outline",size:"sm",onClick:Y,disabled:!A,children:"Tìm từ địa chỉ đã nhập"}),n.jsx(T,{type:"button",variant:"outline",size:"sm",onClick:bn,disabled:!A,children:"Dùng vị trí hiện tại"}),F?n.jsx(T,{type:"button",variant:"outline",size:"sm",onClick:()=>{s.current&&s.current.replaceChildren(),l.current=null,d.current=null,c.current=null,O(!1),en(w=>w+1)},children:"Thử tải lại bản đồ"}):null,V&&A?n.jsx(T,{type:"button",variant:"outline",size:"sm",onClick:()=>{H(V.lat,V.lng),p("Đã xác nhận điểm nhận hàng trên bản đồ.")},children:"Nhận hàng tại vị trí này"}):null]})]}),n.jsxs("div",{className:r.mapCanvasWrapper,children:[n.jsx("div",{ref:s,className:r.mapCanvas,"data-auth-failed":F,role:"application","aria-label":"Bản đồ chọn vị trí giao hàng"}),F?n.jsxs("div",{className:r.mapUnavailable,role:"status",children:[n.jsx("strong",{children:"Bản đồ tạm thời không khả dụng"}),n.jsx("span",{children:"Thông tin đã nhập được giữ lại. Hãy thử tải lại để xác minh điểm giao trước khi thanh toán."})]}):null]}),y?n.jsx("p",{className:r.mapStatus,role:"status",children:y}):null,E?n.jsx("p",{className:r.mapError,role:"alert",children:E}):null,n.jsx("p",{className:tn?r.mapConfirmed:r.mapPending,"aria-live":"polite",children:tn?`Đã xác nhận tọa độ giao hàng: ${t==null?void 0:t.toFixed(5)}, ${i==null?void 0:i.toFixed(5)}.`:F?"Chưa thể xác minh điểm giao khi bản đồ không khả dụng.":"Chưa xác nhận điểm giao. Hãy nhập đủ địa chỉ hoặc tìm địa điểm trên bản đồ."})]})}function oe(e){return e.fee===0?"Miễn phí":`${Cn(e.fee)}đ`}function qi(e){return e.key==="phone"?"tel":"text"}function Ei(e){return{recipient_name:"name",phone:"tel",province:"address-level1",district:"address-level2",ward:"address-level3",address_line:"street-address"}[e.key]}function Fi({requirements:e,selectedMethodCode:t,values:i,errors:o,loading:s,onSelectMethod:h,onChange:c,onChangeValues:l,onSubmit:d}){var P,nn,en,V,$;const m=e.options.find(a=>a.code===t)??null,C=m?e.fieldsByKind[m.kind]??e.fields:[],y=((P=m==null?void 0:m.distanceRules)==null?void 0:P.requiresCoordinates)===!0,p=Number.parseFloat(i.latitude??""),E=Number.parseFloat(i.longitude??""),k=y&&Number.isFinite(p)&&Number.isFinite(E),A=!!((nn=i.address_line)!=null&&nn.trim()&&((en=i.province)!=null&&en.trim())&&((V=i.ward)!=null&&V.trim())),O=["address_line","ward","district","province"].map(a=>
3(i[a]??"").trim()).filter(Boolean).join(", "),F=(($=C.find(a=>a.type==="admin_unit"))==null?void 0:$.key)??null;return n.jsxs("section",{className:r.section,"aria-labelledby":"checkout-shipping-heading",children:[n.jsx("div",{className:r.sectionHeadingRow,children:n.jsxs("div",{children:[n.jsx("p",{className:r.eyebrow,children:"Giao nhận"}),n.jsx("h2",{id:"checkout-shipping-heading",className:r.sectionTitle,children:"Chọn cách nhận hàng"})]})}),n.jsx("div",{className:r.shippingOptions,role:"radiogroup","aria-label":"Phương thức giao nhận",children:e.options.map(a=>n.jsxs("label",{className:r.shippingOption,"data-selected":a.code===t,children:[n.jsx("input",{type:"radio",name:"shipping_method",value:a.code,checked:a.code===t,onChange:()=>h(a.code)}),n.jsxs("span",{className:r.shippingOptionBody,children:[n.jsxs("span",{className:r.shippingOptionTop,children:[n.jsx("strong",{children:a.label}),n.jsx("b",{children:a.distanceRules?`Phí cơ bản ${oe(a)}`:oe(a)})]}),a.estimatedText?n.jsx("span",{children:a.estimatedText}):null,a.pickupAddress?n.jsx("span",{children:a.pickupAddress}):null,a.pickupHours?n.jsxs("span",{children:["Giờ nhận: ",a.pickupHours]}):null,a.pickupInstructions?n.jsx("span",{children:a.pickupInstructions}):null]})]},a.code))}),m?n.jsxs("form",{className:r.shippingForm,onSubmit:a=>{a.preventDefault(),d()},noValidate:!0,children:[n.jsx("div",{className:r.formGrid,children:C.map(a=>{const R=`checkout-shipping-${a.key}`,z=`${R}-error`,H=a.key==="note";if(a.type==="admin_unit"&&a.key!==F)return null;const q={id:R,value:i[a.key]??"",required:a.required,"aria-invalid":!!o[a.key],"aria-describedby":o[a.key]?z:void 0,onChange:Y=>c(a.key,Y.target.value)};return n.jsxs("div",{className:r.formField,"data-wide":a.key==="address_line"||H,children:[a.type!=="admin_unit"?n.jsxs("label",{htmlFor:R,children:[a.label,a.required?n.jsx("span",{"aria-hidden":"true",children:" *"}):null]}):null,a.type==="admin_unit"?n.jsx(Ri,{values:i,errors:o,required:y,onChangeValues:l}):H?n.jsx("textarea",{...q,rows:3,maxLength:500}):n.jsx("input",{...q,type:qi(a),autoComplete:Ei(a),maxLength:a.key==="address_line"?500:a.key==="phone"?32:160}),a.type!=="admin_unit"&&o[a.key]?n.jsx("span",{id:z,className:r.fieldError,role:"alert",children:o[a.key]}):null,a.key==="address_line"&&y?n.jsx("span",{className:r.fieldHint,children:"Nhập chính xác số nhà/tên tòa nhà để shipper giao nhanh và không nhầm địa chỉ."}):null]},a.key)})}),y?n.jsx(Ti,{addressQuery:A?O:"",latitude:k?p:null,longitude:k?E:null,onCoordinatesChange:(a,R)=>{l({latitude:a===null?"":String(a),longitude:R===null?"":String(R)})}}):null,n.jsx(T,{type:"submit",variant:"outline",size:"lg",loading:s,disabled:y&&!k,children:"Cập nhật báo giá"})]}):n.jsx("p",{className:r.shippingHint,children:"Chọn một phương thức để nhập thông tin nhận hàng."})]})}function dn(e){return`${Cn(e)}đ`}function Di(e){const t=Math.floor(e/60),i=e%60;return`${t}:${String(i).padStart(2,"0")}`}function Ui({summary:e,hasQuote:t,quoteExpired:i,quoteRemainingSeconds:o,confirming:s,disabled:h,requiresShipping:c=!0,comboCodePending:l=null,account:d=null,onConfirm:m,onRefresh:C}){const y=l!==null;return n.jsxs("aside",{className:r.summaryCard,"aria-labelledby":"checkout-summary-heading",children:[n.jsx("h2",{id:"checkout-summary-heading",className:r.sectionTitle,children:"Tóm tắt đơn hàng"}),n.jsxs("dl",{className:r.summaryRows,children:[n.jsxs("div",{className:e.discountTotal>0?r.strikeRow:void 0,children:[n.jsx("dt",{children:"Giá gốc"}),n.jsx("dd",{children:dn(e.itemsSubtotal)})]}),e.discountTotal>0?n.jsxs("div",{className:r.discountRow,children:[n.jsx("dt",{children:"Ưu đãi"}),n.jsxs("dd",{children:["-",dn(e.discountTotal)]})]}):null,c?n.jsxs("div",{children:[n.jsx("dt",{children:"Phí giao nhận"}),n.jsx("dd",{children:e.shippingFee===null?"Chưa tính":dn(e.shippingFee)})]}):null]}),n.jsxs("div",{className:r.totalRow,children:[n.jsx("span",{children:"Tổng thanh toán"}),n.jsx("strong",{children:e.grandTotal===null?dn(e.amountBeforeShipping):dn(e.grandTotal)})]}),e.grandTotal===null?n.jsx("p",{className:r.totalHint,children:"Chưa gồm phí giao nhận"}):null,t&&o!==null&&!i?n.jsxs("p",{className:r.quoteTimer,"aria-live":"polite",children:["Mức giá này được giữ trong ",Di(o)," nữa"]}):null,i?n.jsxs("div",{className:r.expiredBox,role:"status",children:[n.jsx("p",{children:"Đã quá thời gian giữ giá. Bấm nút bên dưới để lấy lại mức giá mới nhất, ưu đãi của bạn vẫn còn."}),n.jsx(T,{type:"button",variant:"outline",size:"sm",leftIcon:Re,onClick:C,children:"Lấy lại mức giá"})]}):null,d?n.jsxs("p",{className:r.accountLine,"data-testid":"checkout-account",children:["Đơn cho tài khoản: ",n.jsx("strong",{children:d.name||d.email}),d.name&&d.email?n.jsxs("span",{children:[" · ",d.email]}):null]}):null,n.jsx(T,{type:"button",variant:"primary",size:"xl",width:"full",leftIcon:Ie,disabled:h||!t||i||y,loading:s,onClick:m,children:"Xác nhận đơn hàng"}),y?n.jsxs("p",{className:r.blockedNote,children:["Mã ",n.jsx("strong",{children:l})," chưa áp được. Chọn một cách ở khung cảnh báo để tiếp tục."]}):n.jsx("p",{className:r.securityNote,children:"Bước sau sẽ hiện mã QR và số tài khoản để chuyển khoản."})]})}const Mi=`${Q.routes.zaloConsult}?${new URLSearchParams({entry_point:"page",utm_source:"checkout",utm_medium:"combo_code_unavailable"}).toString()}`;function Oi({pendingCode:e,appliedCode:t,reasonCode:i,currentTotal:o,onBuyWithoutCode:s}){if(!ae(e,t))return null;const h=i==="discount_expired"?n.jsxs(n.Fragment,{children:["Mã ",n.jsx("strong",{children:e})," đã hết hạn"]}):n.jsxs(n.Fragment,{children:["Mã ",n.jsx("strong",{children:e})," không dùng được cho đơn này"]});return n.jsxs("div",{className:r.comboCodeWarning,role:"alert","data-testid":"combo-code-warning",children:[n.jsx(J,{icon:Ae}
3),n.jsxs("div",{className:r.comboCodeWarningBody,children:[n.jsx("p",{className:r.comboCodeWarningTitle,children:h}),n.jsxs("p",{children:["Tổng tiền hiện là giá gốc: ",n.jsxs("strong",{children:[Cn(o),"đ"]}),". Bạn có thể nhắn tư vấn viên để xin mã mới, hoặc mua luôn với giá này."]}),n.jsxs("div",{className:r.comboCodeWarningActions,children:[n.jsx(T,{variant:"primary",size:"lg",width:"full",to:Mi,children:"Nhắn tư vấn xin mã mới"}),n.jsx(T,{variant:"outline",size:"lg",width:"full",onClick:s,children:"Mua với giá hiện tại"})]})]})]})}const re=window.React.useCallback,_n=window.React.useEffect,se=window.React.useMemo,fn=window.React.useRef,I=window.React.useState,ce=30*60*1e3,Pi=["province","district","ward","address_line","note"];function ge(e){if(!Array.isArray(e))return[];const t=e.filter(i=>typeof i=="number"&&Number.isSafeInteger(i)&&i>0);return Array.from(new Set(t)).sort((i,o)=>i-o)}function $i(e){if(!e||typeof e!="object"||Array.isArray(e))return[];const t=e.checkoutSelection;return!t||typeof t!="object"||Array.isArray(t)?[]:ge(t.cart_item_ids)}function qn(e,t="checkout_local_error"){return{message:e,reasonCode:t,retryable:!1,retryAfterSeconds:null,recoveryAction:"review_cart",orderUuid:null}}function co(){const e=qe(),t=Ee(),i=Me(u=>u.fetchCart),o=Oe(Pe),[s,h]=I(()=>{const u=$i(e.state);return u.length>0?u:$e()}),[c,l]=I(null),[d,m]=I(null),[C,y]=I(),[p,E]=I(""),[k,A]=I({}),[O,F]=I({}),[P]=I(()=>ze()),[nn,en]=I(!1),[V,$]=I(null),[a,R]=I(()=>P??""),[z,H]=I(null),q=fn(P),Y=fn(!1),[bn,tn]=I(!0),[w,b]=I(!1),[x,B]=I(!1),[f,N]=I(null),[G,_e]=I(null),[On,Pn]=I(null),xn=fn(null),K=fn(0),hn=()=>{K.current+=1,b(!1),m(null),y(void 0)},an=re((u,g)=>{m(u),l(u),y(g),N(null),vn(u.selectedCartItemIds,u.expiresAt)},[]),$n=re(async u=>{const g=++K.current,_=(u??"").trim().toUpperCase()||null;b(!0),m(null),y(void 0),q.current=_,N(null);try{const S=await Nn(s,_);if(g!==K.current)return;if(l(S),H(_),m(null),y(void 0),!S.requirements.requiresShipping){const D=await Sn({cartItemIds:s,discountCode:_});if(g!==K.current)return;an(D)}}catch(S){g===K.current&&N(rn(S))}finally{g===K.current&&b(!1)}},[an,s]);_n(()=>{let u=!1;return(async()=>{if(s.length===0){N(qn("Chưa có sản phẩm nào được chọn để thanh toán.","checkout_selection_empty")),tn(!1);return}try{const S=(await i()).items.filter(j=>s.includes(j.id));if(S.length!==s.length||S.some(j=>!Be(j)))throw qn("Giỏ hàng đã thay đổi hoặc có sản phẩm không còn đủ điều kiện thanh toán.","checkout_selection_invalid");let D=q.current,Z;try{Z=await Nn(s,D)}catch(j){if(D===null||Y.current||rn(j).reasonCode==="payment_destination_conflict")throw j;u||$(rn(j).reasonCode??null),D=null,Z=await Nn(s,null)}if(u)return;if(l(Z),H(D),q.current=D,vn(s,new Date(Date.now()+ce).toISOString()),!Z.requirements.requiresShipping){const j=await Sn({cartItemIds:s,discountCode:D});if(u)return;an(j)}}catch(_){if(u)return;const S=_&&typeof _=="object"&&"reasonCode"in _?_:rn(_);N(S)}finally{u||tn(!1)}})(),()=>{u=!0}},[an,s,i,$n,P]),_n(()=>{var u;f&&((u=xn.current)==null||u.focus())},[f]),_n(()=>{var g;if(!c)return;const u=((g=c.requirements.shipping)==null?void 0:g.options)??[];E(_=>{var S;return _&&u.some(D=>D.code===_)?_:u.length===1?((S=u[0])==null?void 0:S.code)??"":""})},[c]),_n(()=>{if(!d){Pn(null);return}const u=()=>{const _=Math.max(0,Math.ceil((Date.parse(d.expiresAt)-Date.now())/1e3));Pn(_)};u();const g=window.setInterval(u,1e3);return()=>window.clearInterval(g)},[d]);const X=se(()=>{var u;return((u=c==null?void 0:c.requirements.shipping)==null?void 0:u.options.find(g=>g.code===p))??null},[c,p]),fe=se(()=>{const u=c==null?void 0:c.requirements.shipping;return!u||!X?[]:u.fieldsByKind[X.kind]??u.fields},[c,X]),Bn=On===0,Ln=()=>{var D,Z;if(!X)return N(qn("Vui lòng chọn phương thức giao nhận.","shipping_method_required")),null;const u={};fe.forEach(j=>{j.required&&!(k[j.key]??"").trim()&&(u[j.key]=`Vui lòng nhập ${j.label.toLowerCase()}.`)});const g=(k.phone??"").trim();if(g&&!/^[0-9+().\s-]{8,20}$/.test(g)&&(u.phone="Số điện thoại chưa đúng định dạng."),(D=X.distanceRules)!=null&&D.requiresCoordinates){const j=k.address_unit_set==="old";[{key:"province",label:"tỉnh, thành phố"},...j?[{key:"district",label:"quận, huyện"}]:[],{key:"ward",label:"phường, xã"}
3].forEach(({key:Gn,label:ve})=>{(k[Gn]??"").trim()||(u[Gn]=`Vui lòng chọn ${ve}.`)});const we=Number.parseFloat(k.latitude??""),je=Number.parseFloat(k.longitude??"");(!Number.isFinite(we)||!Number.isFinite(je))&&(u.latitude="Vui lòng xác nhận vị trí giao hàng trên bản đồ.")}F(u);const _=Object.keys(u)[0];if(_)return window.requestAnimationFrame(()=>{var j;return(j=document.getElementById(`checkout-shipping-${_}`))==null?void 0:j.focus()}),null;const S={method_code:X.code,recipient_name:(k.recipient_name??"").trim(),phone:g};if(Pi.forEach(j=>{const on=(k[j]??"").trim();on&&(S[j]=on)}),(Z=X.distanceRules)!=null&&Z.requiresCoordinates){const j=Number.parseFloat(k.latitude??""),on=Number.parseFloat(k.longitude??"");if(!Number.isFinite(j)||!Number.isFinite(on))return null;S.latitude=j,S.longitude=on}return S},wn=async(u,g=z)=>{const _=++K.current;b(!0),N(null);try{const S=await Sn({cartItemIds:s,discountCode:g,shipping:u});if(_!==K.current)return;an(S,u)}catch(S){if(_!==K.current)return;m(null),y(void 0),N(rn(S))}finally{_===K.current&&b(!1)}},ye=()=>{const u=Ln();u&&wn(u)},ke=async()=>{await $n(a)},Ce=o?{name:String(o.full_name??"").trim(),email:typeof o.email=="string"?o.email:""}:null,jn=nn?null:P,be=()=>{Vn(),R(""),en(!0)},zn=async()=>{if(!d||Bn||x||(f==null?void 0:f.reasonCode)==="payment_destination_conflict")return;B(!0),N(null);const u=[d.pricingRevision,d.expiresAt,d.selectedCartItemIds.join(","),(C==null?void 0:C.method_code)??"digital"].join("|");try{const g=await nt({quoteToken:d.quoteToken,idempotencyKey:Ke(u),checkoutData:C?{shipping:C}:{}});Le({event:"begin_checkout",event_id:`order_${g.orderId}`,landing_id:"checkout"}),kn(),Vn(),g.requiresPayment?t(`${Q.routes.payment}?order_id=${encodeURIComponent(g.orderUuid)}`,{replace:!0}):_e(g)}catch(g){N(rn(g))}finally{B(!1)}},Hn=()=>{if(c!=null&&c.requirements.requiresShipping){const u=Ln();u&&wn(u);return}wn()},xe=u=>{hn(),kn(),Y.current=!0,l(null),tn(!0),N(null),F({});const g=ge(u);vn(g,new Date(Date.now()+ce).toISOString()),t(e.pathname+e.search,{replace:!0,state:{checkoutSelection:{cart_item_ids:g}}}),h(g)},mn=(f==null?void 0:f.reasonCode)==="payment_destination_conflict"?n.jsx(fi,{groups:f.paymentDestinationGroups,selectedCartItemIds:s,onSelect:xe}):null;return G?n.jsx("main",{className:r.container,children:n.jsxs("section",{className:r.successCard,"aria-labelledby":"checkout-success-heading",children:[n.jsx("span",{className:r.successIcon,children:n.jsx(J,{icon:Kn})}),n.jsx("p",{className:r.eyebrow,children:"Thanh toán không phát sinh"}),n.jsx("h1",{id:"checkout-success-heading",children:"Đơn hàng đã hoàn tất"}),n.jsx("p",{children:"Đơn hàng không cần chuyển khoản và đã được hệ thống xử lý an toàn."}),n.jsxs("span",{className:r.orderReference,children:["Mã tham chiếu: ",G.orderUuid]}),n.jsx(T,{to:Q.routes.home,variant:"primary",size:"lg",children:"Về trang chủ"})]})}):bn?n.jsx("main",{className:r.container,"aria-busy":"true",children:n.jsxs("div",{className:r.loadingShell,children:[n.jsx("span",{}),n.jsx("span",{}),n.jsx("span",{})]})}):c?n.jsxs("main",{className:r.container,children:[n.jsxs("header",{className:r.header,children:[n.jsxs(Fe,{to:Q.routes.cart,className:r.backLink,children:[n.jsx(J,{icon:Te}),"Quay lại giỏ hàng"]}),n.jsx("div",{className:r.headingRow,children:n.jsx("div",{children:n.jsx("h1",{children:"Kiểm tra và xác nhận đơn hàng"})})})]}),f?n.jsxs("div",{className:r.errorBanner,ref:xn,tabIndex:-1,role:"alert",children:[n.jsx(J,{icon:Wn}),n.jsxs("div",{children:[n.jsx("strong",{children:f.message}),mn,f.reasonCode==="idempotency_in_progress"?n.jsx(T,{type:"button",variant:"link",size:"sm",onClick:zn,children:"Thử lại xác nhận"}):f.recoveryAction==="owner_order"&&f.orderUuid?n.jsx(T,{to:`${Q.routes.payment}?order_id=${encodeURIComponent(f.orderUuid)}`,variant:"link",size:"sm",children:"Tiếp tục thanh toán đơn hiện có"}):f.recoveryAction==="refresh_quote"?n.jsx(T,{type:"button",variant:"link",size:"sm",onClick:Hn,children:"Lấy lại mức giá"}):null]})]}):null,n.jsxs("div",{className:`${r.layout} ${c.requirements.requiresShipping?"":r.layoutSummaryFirst}`,children:[n.jsxs("div",{className:r.mainColumn,children:[n.jsx(ki,{lines:c.lines}
3),n.jsxs("section",{className:r.section,"aria-labelledby":"checkout-discount-heading",children:[n.jsx("div",{className:r.sectionHeadingRow,children:n.jsxs("div",{children:[n.jsx("p",{className:r.eyebrow,children:"Ưu đãi"}),n.jsx("h2",{id:"checkout-discount-heading",className:r.sectionTitle,children:"Mã giảm giá"})]})}),n.jsxs("div",{className:r.discountForm,children:[n.jsx("label",{htmlFor:"checkout-discount",children:"Nhập mã nếu bạn có"}),n.jsxs("div",{children:[n.jsx("input",{id:"checkout-discount",value:a,maxLength:64,autoComplete:"off",placeholder:"Ví dụ: F8WELCOME",onChange:u=>R(u.target.value)}),n.jsx(T,{type:"button",variant:"outline",loading:w,onClick:()=>void ke(),children:"Áp dụng"})]}),z?n.jsxs("p",{className:r.appliedDiscount,children:["Đang áp dụng mã ",z]}):null]})]}),c.requirements.shipping?n.jsx(Fi,{requirements:c.requirements.shipping,selectedMethodCode:p,values:k,errors:O,loading:w,onSelectMethod:u=>{E(u),hn(),N(null),F({})},onChange:(u,g)=>{A(_=>({..._,...["address_line","province","district","ward","address_unit_set"].includes(u)?{latitude:"",longitude:""}:{},[u]:g})),F(_=>({..._,[u]:""})),hn()},onChangeValues:u=>{A(g=>({...g,...Object.keys(u).some(_=>["address_line","province","district","ward","address_unit_set"].includes(_))?{latitude:"",longitude:""}:{},...u})),F(g=>{const _={...g};return Object.keys(u).forEach(S=>delete _[S]),_}),hn()},onSubmit:ye}):n.jsxs("section",{className:r.digitalNotice,children:[n.jsx(J,{icon:Kn}),n.jsxs("div",{children:[n.jsx("strong",{children:"Không cần thông tin giao nhận"}),n.jsx("p",{children:"Các sản phẩm trong đơn được cung cấp trực tuyến sau khi hoàn tất."})]})]})]}),n.jsxs("div",{className:r.summaryColumn,children:[n.jsx(Oi,{pendingCode:jn,appliedCode:z,reasonCode:V,currentTotal:(d??c).summary.grandTotal??(d??c).summary.amountBeforeShipping,onBuyWithoutCode:be}),n.jsx(Ui,{summary:(d??c).summary,hasQuote:d!==null,quoteExpired:Bn,quoteRemainingSeconds:On,confirming:x,disabled:w||(f==null?void 0:f.reasonCode)==="payment_destination_conflict",requiresShipping:c.requirements.requiresShipping,comboCodePending:ae(jn,z)?jn:null,account:Ce,onConfirm:()=>void zn(),onRefresh:Hn})]})]})]}):n.jsx("main",{className:r.container,children:n.jsxs("section",{className:r.emptyCard,ref:xn,tabIndex:-1,role:"alert",children:[n.jsx(J,{icon:Wn}),n.jsx("h1",{children:mn?"Chọn nhóm muốn thanh toán":"Chưa thể chuẩn bị thanh toán"}),n.jsx("p",{children:(f==null?void 0:f.message)??"Giỏ hàng không có lựa chọn hợp lệ."}),mn,n.jsx(T,{to:Q.routes.cart,variant:mn?"link":"primary",size:"lg",children:"Kiểm tra giỏ hàng"})]})})}export{co as default};
4
5//# debugId=f838fd96-761b-5157-a3e5-71717bfac44d

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.