import{s as i}from"./p-1282ed4a.js";import"./p-445fd8b4.js";import{a as o}from"./p-401e165e.js";import{g as d}from"./p-d3366af3.js";import{a as t}from"./p-259c3935.js";const e="surecart/v1/checkouts/",a=["checkout_fees","shipping_fees","line_items","line_item.price","line_item.fees","line_item.variant","line_item.swap","variant.image","price.product","price.current_swap","swap.swap_price","product.product_medias","product.featured_product_media","product.product_collections","product_media.media","customer","customer.shipping_address","payment_intent","discount","discount.promotion","recommended_bumps","bump.price","current_upsell","product.variants","discount.coupon","shipping_address","billing_address","tax_identifier","manual_payment_method","shipping_choices","shipping_choice.shipping_method","invoice"],n=(d={})=>{var t,o,e,a,n,l,u;return{live_mode:"test"!==i.mode,group_key:i.groupId,abandoned_checkout_enabled:i.abandonedCheckoutEnabled,billing_matches_shipping:null===(t=i.checkout)||void 0===t?void 0:t.billing_matches_shipping,metadata:{...(null==d?void 0:d.metadata)||{},...(null===(o=null===window||void 0===window?void 0:window.scData)||void 0===o?void 0:o.page_id)&&{page_id:null===(e=null===window||void 0===window?void 0:window.scData)||void 0===e?void 0:e.page_id},...(null===(a=null==i?void 0:i.product)||void 0===a?void 0:a.id)&&{buy_page_product_id:null===(n=null==i?void 0:i.product)||void 0===n?void 0:n.id},page_url:window.location.href},...(null===(l=null==i?void 0:i.checkout)||void 0===l?void 0:l.email)&&{email:null===(u=null==i?void 0:i.checkout)||void 0===u?void 0:u.email},...d}},l=(d={})=>{var t,o,e,a;return{...!!(null==i?void 0:i.formId)&&{form_id:null==i?void 0:i.formId},...!!(null===(t=null==i?void 0:i.product)||void 0===t?void 0:t.id)&&{product_id:null===(o=null==i?void 0:i.product)||void 0===o?void 0:o.id},...!!(null===(a=null===(e=null==i?void 0:i.checkout)||void 0===e?void 0:e.invoice)||void 0===a?void 0:a.id)&&{type:"open_invoice"},...d}},u=()=>{var t,o;return d(window.location.href,"checkout_id")||((null===(t=null==i?void 0:i.checkout)||void 0===t?void 0:t.id)?null===(o=null==i?void 0:i.checkout)||void 0===o?void 0:o.id:null)},r=(i,d="")=>{let t=i?`${e}${i}`:e;return t=`${t}${d}`,o(t,{expand:a})},s=async({id:i,query:d={}})=>await t({path:o(r(i),l(d))}),v=async({id:i=null,data:d={},query:e={}})=>(i=i||u(),await t({method:i?"PATCH":"POST",path:o(r(i),l(e)),data:n(d)})),c=async({data:i={},query:d={}})=>await t({method:"POST",path:o(r(null),l(d)),data:n(i)}),p=async({id:i,data:d={},query:e={}})=>await t({method:"PATCH",path:o(r(i),l(e)),data:n(d)}),m=async({id:i,data:d={},query:e={},processor:a})=>await t({method:"POST",path:o(r(i,"/finalize"),l({...(null==a?void 0:a.manual)?{manual_payment:!0,manual_payment_method_id:null==a?void 0:a.id}:{processor_type:null==a?void 0:a.id},...e})),data:n(d)}),_=async({checkout:i,data:d,live_mode:e=!1})=>{var n;const l=((null===(n=null==i?void 0:i.line_items)||void 0===n?void 0:n.data)||[]).find((i=>{var t;return(null===(t=null==i?void 0:i.variant)||void 0===t?void 0:t.id)?i.variant.id===d.variant&&i.price.id===d.price&&i.note===d.note:i.price.id===d.price&&i.note===d.note}));if(!(null==i?void 0:i.id))return await t({method:"POST",path:o(r(null)),data:{line_items:[d],live_mode:e}});if(l)return await w({id:null==l?void 0:l.id,data:{...d,quantity:(null==l?void 0:l.quantity)+(null==d?void 0:d.quantity)}});const u=await t({path:o(`surecart/v1/line_items/${(null==l?void 0:l.id)?null==l?void 0:l.id:""}`,{consolidate:!0,expand:[...(a||[]).map((i=>i.includes(".")?i:`checkout.${i}`)),"checkout"]}),method:"POST",data:{...d,checkout:i.id}});return null==u?void 0:u.checkout},h=async({checkoutId:i,itemId:d})=>{const{deleted:o}=await t({path:`surecart/v1/line_items/${d}`,method:"DELETE"});if(!o)throw{code:"error",message:wp.i18n.__("Failed to delete","surecart")};return await s({id:i})},w=async({id:i,data:d})=>{const e=await t({path:o(`surecart/v1/line_items/${i}`,{expand:[...(a||[]).map((i=>i.includes(".")?i:`checkout.${i}`)),"checkout"]}),method:"PATCH",data:d});return null==e?void 0:e.checkout},y=async({id:i,action:d="swap"})=>{const e=await t({path:o(`surecart/v1/line_items/${i}/${d}`,{expand:[...(a||[]).map((i=>i.includes(".")?i:`checkout.${i}`)),"checkout"]}),method:"PATCH"});return null==e?void 0:e.checkout};export{_ as a,e as b,v as c,p as d,a as e,m as f,s as g,c as h,h as r,y as t,w as u};