"use strict";(self.webpackChunk_surecart_surecart=self.webpackChunk_surecart_surecart||[]).push([[9643],{8847:function(e,t,n){n.d(t,{c:function(){return u},g:function(){return a},i:function(){return o}});var r=n(4467);function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function c(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){(0,r.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var u=function(e){return((null==e?void 0:e.data)||[]).map((function(e){var t;return c(c({},(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})}))},a=function(e,t){return((null==e?void 0:e.data)||[]).find((function(e){return e.price.id===t}))},o=function(e,t){var n;return!!((null==(n=null==t?void 0:t.line_items)?void 0:n.data)||[]).map((function(e){return e.price.id})).find((function(t){return(null==e?void 0:e.id)===t}))}},9643:function(e,t,n){n.r(t),n.d(t,{sc_line_items_provider:function(){return l}});var r=n(9394),i=n(467),c=n(3029),u=n(2901),a=n(9280),o=n.n(a),d=n(1346),s=n(8847),l=function(){return(0,u.A)((function e(t){(0,c.A)(this,e),(0,d.r)(this,t),this.scUpdateLineItems=(0,d.c)(this,"scUpdateLineItems",7),this.order=void 0,this.syncItems=[]}),[{key:"handleLineItemToggle",value:function(e){var t=e.detail;this.addSyncItem("toggle",t)}},{key:"handleLineItemRemove",value:function(e){var t=e.detail;this.addSyncItem("remove",t)}},{key:"handleLineItemAdd",value:function(e){var t=e.detail;this.addSyncItem("add",t)}},{key:"handleLineItemUpdate",value:function(e){var t=e.detail;this.addSyncItem("update",t)}},{key:"syncItemsHandler",value:(e=(0,i.A)(o().mark((function e(t){var n=this;return o().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==t?void 0:t.length){e.next=2;break}return e.abrupt("return");case 2:setTimeout((function(){var e;if(null===(e=n.syncItems)||void 0===e?void 0:e.length){var t=n.processSyncItems();n.scUpdateLineItems.emit(t),n.syncItems=[]}}),100);case 3:case"end":return e.stop()}}),e)}))),function(_x){return e.apply(this,arguments)})},{key:"addSyncItem",value:function(e,t){this.syncItems=[].concat((0,r.A)(this.syncItems),[{type:e,payload:t}])}},{key:"processSyncItems",value:function(){var e,t=(0,s.c)((null===(e=null==this?void 0:this.order)||void 0===e?void 0:e.line_items)||[]),n={toggle:this.toggleItem,add:this.addItem,remove:this.removeItem,update:this.updateItem};return(this.syncItems||[]).forEach((function(e){t=n[e.type](e.payload,t)})),t}},{key:"addItem",value:function(e,t){return[].concat((0,r.A)(t),[e])}},{key:"toggleItem",value:function(e,t){var n,i=null===(n=t.find((function(t){return t.price_id===e.price_id})))||void 0===n?void 0:n.price_id;return i?t.filter((function(e){return i!==e.price_id})):[].concat((0,r.A)(t),[e])}},{key:"removeItem",value:function(e,t){return e.price_id?t.filter((function(t){return t.price_id!==e.price_id})):t}},{key:"updateItem",value:function(e,t){var n=t.findIndex((function(t){return t.price_id===e.price_id}));return-1===n?[].concat((0,r.A)(t),[e]):(t[n]=e,t)}},{key:"render",value:function(){return(0,d.h)("slot",{key:"7c3e31dfdd082a71e45d04f0f967504434b0229c"})}}],[{key:"watchers",get:function(){return{syncItems:["syncItemsHandler"]}}}]);var e}()}}]);