"use strict";(self.webpackChunk_surecart_surecart=self.webpackChunk_surecart_surecart||[]).push([[9643],{8037:function(e,t,n){n.d(t,{c:function(){return c},g:function(){return o},h:function(){return d},i:function(){return a}});var i=n(4467);function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function u(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){(0,i.A)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var c=function(e){return((null==e?void 0:e.data)||[]).map((function(e){var t;return u(u({},(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})}))},o=function(e,t){return((null==e?void 0:e.data)||[]).find((function(e){return e.price.id===t}))},a=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}))},d=function(e){var t,n,i;return!!(null===(n=null===(t=null==e?void 0:e.line_items)||void 0===t?void 0:t.data)||void 0===n?void 0:n.length)&&(null===(i=null==e?void 0:e.line_items.data)||void 0===i?void 0:i.some((function(e){var t;return null===(t=null==e?void 0:e.price)||void 0===t?void 0:t.recurring_interval_count})))}},9643:function(e,t,n){n.r(t),n.d(t,{sc_line_items_provider:function(){return s}});var i=n(9394),r=n(467),u=n(3029),c=n(2901),o=n(9280),a=n.n(o),d=n(1346),l=n(8037),s=function(){return(0,c.A)((function e(t){(0,u.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,r.A)(a().mark((function e(t){var n=this;return a().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,i.A)(this.syncItems),[{type:e,payload:t}])}},{key:"processSyncItems",value:function(){var e,t=(0,l.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,i.A)(t),[e])}},{key:"toggleItem",value:function(e,t){var n,r=null===(n=t.find((function(t){return t.price_id===e.price_id})))||void 0===n?void 0:n.price_id;return r?t.filter((function(e){return r!==e.price_id})):[].concat((0,i.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,i.A)(t),[e]):(t[n]=e,t)}},{key:"render",value:function(){return(0,d.h)("slot",{key:"c52582c8cb4ba6030b71e372bc85f0031376f8eb"})}}],[{key:"watchers",get:function(){return{syncItems:["syncItemsHandler"]}}}]);var e}()}}]);