"use strict";(self.webpackChunk_surecart_blocks_next=self.webpackChunk_surecart_blocks_next||[]).push([[3513],{974:function(e,t,i){i.d(t,{c:function(){return n},g:function(){return d},i:function(){return s}});const n=e=>((null==e?void 0:e.data)||[]).map((e=>{var t;return{...(null==e?void 0:e.id)?{id:e.id}:{},price_id:e.price.id,quantity:e.quantity,variant_id:null===(t=e.variant)||void 0===t?void 0:t.id}})),d=(e,t)=>((null==e?void 0:e.data)||[]).find((e=>e.price.id===t)),s=(e,t)=>{var i;return!!((null==(i=null==t?void 0:t.line_items)?void 0:i.data)||[]).map((e=>e.price.id)).find((t=>(null==e?void 0:e.id)===t))}},3513:function(e,t,i){i.r(t),i.d(t,{sc_line_items_provider:function(){return s}});var n=i(6892),d=i(974);const s=class{constructor(e){(0,n.r)(this,e),this.scUpdateLineItems=(0,n.c)(this,"scUpdateLineItems",7),this.order=void 0,this.syncItems=[]}handleLineItemToggle(e){const t=e.detail;this.addSyncItem("toggle",t)}handleLineItemRemove(e){const t=e.detail;this.addSyncItem("remove",t)}handleLineItemAdd(e){const t=e.detail;this.addSyncItem("add",t)}handleLineItemUpdate(e){const t=e.detail;this.addSyncItem("update",t)}async syncItemsHandler(e){(null==e?void 0:e.length)&&setTimeout((()=>{var e;if(!(null===(e=this.syncItems)||void 0===e?void 0:e.length))return;const t=this.processSyncItems();this.scUpdateLineItems.emit(t),this.syncItems=[]}),100)}addSyncItem(e,t){this.syncItems=[...this.syncItems,{type:e,payload:t}]}processSyncItems(){var e;let t=(0,d.c)((null===(e=null==this?void 0:this.order)||void 0===e?void 0:e.line_items)||[]);const i={toggle:this.toggleItem,add:this.addItem,remove:this.removeItem,update:this.updateItem};return(this.syncItems||[]).forEach((e=>{t=i[e.type](e.payload,t)})),t}addItem(e,t){return[...t,e]}toggleItem(e,t){var i;const n=null===(i=t.find((t=>t.price_id===e.price_id)))||void 0===i?void 0:i.price_id;return n?t.filter((e=>n!==e.price_id)):[...t,e]}removeItem(e,t){return e.price_id?t.filter((t=>t.price_id!==e.price_id)):t}updateItem(e,t){const i=t.findIndex((t=>t.price_id===e.price_id));return-1===i?[...t,e]:(t[i]=e,t)}render(){return(0,n.h)("slot",{key:"b68b25a62a4071a092d44fe4eb063c098368f0eb"})}static get watchers(){return{syncItems:["syncItemsHandler"]}}}}}]);