@trycourier/courier-ui-inbox 1.2.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/components/courier-inbox-feed-button.d.ts +28 -0
  2. package/dist/components/courier-inbox-header.d.ts +28 -11
  3. package/dist/components/courier-inbox-list-item.d.ts +4 -4
  4. package/dist/components/courier-inbox-list.d.ts +9 -4
  5. package/dist/components/courier-inbox-option-menu-item.d.ts +3 -0
  6. package/dist/components/courier-inbox-option-menu.d.ts +19 -12
  7. package/dist/components/courier-inbox-popup-menu.d.ts +57 -10
  8. package/dist/components/courier-inbox-tabs.d.ts +33 -0
  9. package/dist/components/courier-inbox.d.ts +121 -9
  10. package/dist/components/courier-unread-count-badge.d.ts +10 -5
  11. package/dist/datastore/__tests__/inbox-datastore.test.d.ts +1 -0
  12. package/dist/datastore/datatore-events.d.ts +61 -8
  13. package/dist/datastore/inbox-dataset.d.ts +110 -0
  14. package/dist/datastore/inbox-datastore.d.ts +217 -0
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.js +1 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +3225 -1501
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/types/courier-inbox-theme.d.ts +64 -20
  21. package/dist/types/factories.d.ts +21 -8
  22. package/dist/types/inbox-data-set.d.ts +111 -2
  23. package/dist/types/inbox-defaults.d.ts +39 -0
  24. package/dist/types/snapshots.d.ts +6 -0
  25. package/dist/utils/utils.d.ts +7 -0
  26. package/package.json +3 -3
  27. package/dist/components/courier-inbox-header-title.d.ts +0 -23
  28. package/dist/datastore/datastore.d.ts +0 -114
  29. package/dist/types/feed-type.d.ts +0 -1
  30. /package/dist/datastore/__tests__/{datastore.test.d.ts → inbox-dataset.test.d.ts} +0 -0
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@trycourier/courier-js"),require("@trycourier/courier-ui-core")):"function"==typeof define&&define.amd?define(["exports","@trycourier/courier-js","@trycourier/courier-ui-core"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CourierUIInbox={},e.CourierJS,e.CourierUICore)}(this,(function(e,t,i){"use strict";var n=Object.defineProperty,o=(e,t,i)=>((e,t,i)=>t in e?n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,"symbol"!=typeof t?t+"":t,i);function s(e){const t={...e};return e.actions&&(t.actions=e.actions.map((e=>function(e){const t={...e};e.data&&(t.data=JSON.parse(JSON.stringify(e.data)));return t}(e)))),e.data&&(t.data=JSON.parse(JSON.stringify(e.data))),e.tags&&(t.tags=[...e.tags]),e.trackingIds&&(t.trackingIds={...e.trackingIds}),t}function l(e){if(e)return{...e,messages:e.messages.map((e=>s(e)))}}class r extends i.CourierBaseElement{constructor(e){super(),o(this,"_theme"),o(this,"_options",[]),this._theme=e}static get id(){return"courier-inbox-list-item-menu"}onComponentMounted(){const e=document.createElement("ul");e.className="menu",this.appendChild(e)}static getStyles(e){var t,i,n;const o=null==(n=null==(i=null==(t=e.inbox)?void 0:t.list)?void 0:i.item)?void 0:n.menu;return`\n ${r.id} {\n display: none;\n position: absolute;\n background: ${(null==o?void 0:o.backgroundColor)??"red"};\n border: ${(null==o?void 0:o.border)??"1px solid red"};\n border-radius: ${(null==o?void 0:o.borderRadius)??"0px"};\n box-shadow: ${(null==o?void 0:o.shadow)??"0 2px 8px red"};\n user-select: none;\n opacity: 0;\n pointer-events: none;\n transition: opacity 0.15s;\n overflow: hidden;\n }\n\n ${r.id}.visible {\n display: block;\n opacity: 1;\n pointer-events: auto;\n }\n\n ${r.id} ul.menu {\n list-style: none;\n margin: 0;\n padding: 0;\n display: flex;\n flex-direction: row;\n }\n\n ${r.id} li.menu-item {\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n border-bottom: none;\n background: transparent;\n }\n `}setOptions(e){this._options=e,this.renderMenu()}renderMenu(){var e,t,n;const o=this.querySelector("ul.menu");if(!o)return;o.innerHTML="";const s=null==(n=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:n.menu,l=e=>{e.stopPropagation(),e.preventDefault()};this._options.forEach((e=>{var t,n,r;const a=new i.CourierIconButton(e.icon.svg,e.icon.color,null==s?void 0:s.backgroundColor,null==(t=null==s?void 0:s.item)?void 0:t.hoverBackgroundColor,null==(n=null==s?void 0:s.item)?void 0:n.activeBackgroundColor,null==(r=null==s?void 0:s.item)?void 0:r.borderRadius),d=t=>{l(t),e.onClick()};a.addEventListener("click",d),a.addEventListener("touchstart",l),a.addEventListener("touchend",d),a.addEventListener("touchmove",l),a.addEventListener("mousedown",l),a.addEventListener("mouseup",l),o.appendChild(a)}))}show(){this.style.display="block",this.classList.add("visible")}hide(){this.style.display="none",this.classList.remove("visible")}}i.registerElement(r);const a=class e{constructor(){o(this,"_inboxDataSet"),o(this,"_archiveDataSet"),o(this,"_dataStoreListeners",[]),o(this,"_unreadCount"),o(this,"_removeMessageEventListener"),o(this,"isPaginatingInbox",!1),o(this,"isPaginatingArchive",!1)}static get shared(){return e.instance||(e.instance=new e),e.instance}get unreadCount(){return this._unreadCount??0}get inboxDataSet(){return this._inboxDataSet??{feedType:"inbox",messages:[],canPaginate:!1,paginationCursor:null}}get archiveDataSet(){return this._archiveDataSet??{feedType:"archive",messages:[],canPaginate:!1,paginationCursor:null}}addDataStoreListener(e){this._dataStoreListeners.push(e)}removeDataStoreListener(e){this._dataStoreListeners=this._dataStoreListeners.filter((t=>t!==e))}async fetchCachableDataSet(e){var t,i,n,o,s,l,r,a;if(e.canUseCache){if("inbox"===e.feedType&&this._inboxDataSet)return this._inboxDataSet;if("archive"===e.feedType&&this._archiveDataSet)return this._archiveDataSet}const d=await e.fetch;return{feedType:e.feedType,messages:(null==(i=null==(t=d.data)?void 0:t.messages)?void 0:i.nodes)??[],canPaginate:(null==(s=null==(o=null==(n=d.data)?void 0:n.messages)?void 0:o.pageInfo)?void 0:s.hasNextPage)??!1,paginationCursor:(null==(a=null==(r=null==(l=d.data)?void 0:l.messages)?void 0:r.pageInfo)?void 0:a.startCursor)??null}}async fetchUnreadCount(e){var i;if(e.canUseCache&&void 0!==this._unreadCount)return this._unreadCount;return await(null==(i=t.Courier.shared.client)?void 0:i.inbox.getUnreadMessageCount())??0}async load(e){var i,n;try{const i=t.Courier.shared.client;if(!(null==i?void 0:i.options.userId))throw new Error("User is not signed in");const n=e??{canUseCache:!0},[o,s,l]=await Promise.all([this.fetchCachableDataSet({fetch:i.inbox.getMessages(),feedType:"inbox",canUseCache:n.canUseCache}),this.fetchCachableDataSet({fetch:i.inbox.getArchivedMessages(),feedType:"archive",canUseCache:n.canUseCache}),this.fetchUnreadCount(n)]);this._inboxDataSet=o,this._archiveDataSet=s,this._unreadCount=l,this._dataStoreListeners.forEach((e=>{var t,i,n,o,s,l;this._inboxDataSet&&(null==(i=(t=e.events).onDataSetChange)||i.call(t,this._inboxDataSet,"inbox")),this._archiveDataSet&&(null==(o=(n=e.events).onDataSetChange)||o.call(n,this._archiveDataSet,"archive")),null==(l=(s=e.events).onUnreadCountChange)||l.call(s,this._unreadCount??0)}))}catch(o){null==(n=null==(i=t.Courier.shared.client)?void 0:i.options.logger)||n.error("Error loading inbox:",o),this._dataStoreListeners.forEach((e=>{var t,i;null==(i=(t=e.events).onError)||i.call(t,o)}))}}async listenForUpdates(){var e,i;try{await this.connectSocket()}catch(n){null==(i=null==(e=t.Courier.shared.client)?void 0:e.options.logger)||i.error("Error listening for updates:",n),this._dataStoreListeners.forEach((e=>{var t,i;null==(i=(t=e.events).onError)||i.call(t,n)}))}}async connectSocket(){var e,i,n,o,s,l,r,a,d,u,h;const c=null==(e=t.Courier.shared.client)?void 0:e.inbox.socket;try{if(!c)return void(null==(n=null==(i=t.Courier.shared.client)?void 0:i.options.logger)||n.info("CourierInbox socket not available"));if(this._removeMessageEventListener&&this._removeMessageEventListener(),this._removeMessageEventListener=c.addMessageEventListener((e=>{if(e.event===t.InboxMessageEvent.NewMessage){const t=e.data;return void this.addMessage(t,0,"inbox")}const i=this.getMessage({messageId:e.messageId});switch(e.event){case t.InboxMessageEvent.MarkAllRead:this.readAllMessages({canCallApi:!1});break;case t.InboxMessageEvent.Read:i&&this.readMessage({message:i,canCallApi:!1});break;case t.InboxMessageEvent.Unread:i&&this.unreadMessage({message:i,canCallApi:!1});break;case t.InboxMessageEvent.Opened:i&&this.openMessage({message:i,canCallApi:!1});break;case t.InboxMessageEvent.Archive:i&&this.archiveMessage({message:i,canCallApi:!1});break;case t.InboxMessageEvent.ArchiveRead:this.archiveReadMessages({canCallApi:!1});break;case t.InboxMessageEvent.ArchiveAll:this.archiveAllMessages({canCallApi:!1});break;case t.InboxMessageEvent.Clicked:i&&this.clickMessage({message:i,canCallApi:!1});break;case t.InboxMessageEvent.Unarchive:i&&this.unarchiveMessage({message:i,canCallApi:!1});case t.InboxMessageEvent.Unopened:}})),c.isConnecting||c.isOpen)return void(null==(l=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||l.info(`Inbox socket already connecting or open for client ID: [${null==(s=t.Courier.shared.client)?void 0:s.options.connectionId}]`));await c.connect(),null==(d=null==(r=t.Courier.shared.client)?void 0:r.options.logger)||d.info(`Inbox socket connected for client ID: [${null==(a=t.Courier.shared.client)?void 0:a.options.connectionId}]`)}catch(v){null==(h=null==(u=t.Courier.shared.client)?void 0:u.options.logger)||h.error("Failed to connect socket:",v)}}getMessage(e){var t,i;if(e.messageId)return(null==(t=this._inboxDataSet)?void 0:t.messages.find((t=>t.messageId===e.messageId)))??(null==(i=this._archiveDataSet)?void 0:i.messages.find((t=>t.messageId===e.messageId)))}async fetchNextPageOfMessages(e){var i,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,C,x,f,y,S,k,I;switch(e.feedType){case"inbox":if(this.isPaginatingInbox)return null;if((null==(i=this._inboxDataSet)?void 0:i.canPaginate)&&this._inboxDataSet.paginationCursor)try{this.isPaginatingInbox=!0;const e=await(null==(n=t.Courier.shared.client)?void 0:n.inbox.getMessages({paginationLimit:t.Courier.shared.paginationLimit,startCursor:this._inboxDataSet.paginationCursor})),i={feedType:"inbox",messages:(null==(s=null==(o=null==e?void 0:e.data)?void 0:o.messages)?void 0:s.nodes)??[],canPaginate:(null==(a=null==(r=null==(l=null==e?void 0:e.data)?void 0:l.messages)?void 0:r.pageInfo)?void 0:a.hasNextPage)??!1,paginationCursor:(null==(h=null==(u=null==(d=null==e?void 0:e.data)?void 0:d.messages)?void 0:u.pageInfo)?void 0:h.startCursor)??null};return this.addPage(i),i}catch(M){return null==(v=null==(c=t.Courier.shared.client)?void 0:c.options.logger)||v.error("Error fetching next page of inbox messages:",M),null}finally{this.isPaginatingInbox=!1}break;case"archive":if(this.isPaginatingArchive)return null;if((null==(p=this._archiveDataSet)?void 0:p.canPaginate)&&this._archiveDataSet.paginationCursor)try{this.isPaginatingArchive=!0;const e=await(null==(g=t.Courier.shared.client)?void 0:g.inbox.getArchivedMessages({paginationLimit:t.Courier.shared.paginationLimit,startCursor:this._archiveDataSet.paginationCursor})),i={feedType:"archive",messages:(null==(b=null==(m=null==e?void 0:e.data)?void 0:m.messages)?void 0:b.nodes)??[],canPaginate:(null==(x=null==(C=null==(_=null==e?void 0:e.data)?void 0:_.messages)?void 0:C.pageInfo)?void 0:x.hasNextPage)??!1,paginationCursor:(null==(S=null==(y=null==(f=null==e?void 0:e.data)?void 0:f.messages)?void 0:y.pageInfo)?void 0:S.startCursor)??null};return this.addPage(i),i}catch(M){return null==(I=null==(k=t.Courier.shared.client)?void 0:k.options.logger)||I.error("Error fetching next page of archived messages:",M),null}finally{this.isPaginatingArchive=!1}}return null}canMutate(){return!!(t.Courier.shared.client&&this._inboxDataSet&&this._archiveDataSet)}async readMessage({message:e,canCallApi:i=!0}){var n,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet),r=this.getMessageSnapshot(e);if(!r.message.read)try{r.message.read=(new Date).toISOString(),this.applyMessageSnapshot(r),this._unreadCount=l.unreadCount-1,this._dataStoreListeners.forEach((e=>{var t,i;null==(i=(t=e.events).onUnreadCountChange)||i.call(t,this._unreadCount)})),i&&await(null==(n=t.Courier.shared.client)?void 0:n.inbox.read({messageId:e.messageId}))}catch(a){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error reading message:",a),this.applyDatastoreSnapshot(l)}}async unreadMessage({message:e,canCallApi:i=!0}){var n,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet),r=this.getMessageSnapshot(e);if(r.message.read)try{r.message.read=void 0,this.applyMessageSnapshot(r),this._unreadCount=l.unreadCount+1,this._dataStoreListeners.forEach((e=>{var t,i;null==(i=(t=e.events).onUnreadCountChange)||i.call(t,this._unreadCount)})),i&&await(null==(n=t.Courier.shared.client)?void 0:n.inbox.unread({messageId:e.messageId}))}catch(a){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error unreading message:",a),this.applyDatastoreSnapshot(l)}}async openMessage({message:e,canCallApi:i=!0}){var n,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet),r=this.getMessageSnapshot(e);if((void 0!==r.inboxIndex||void 0!==r.archiveIndex)&&!r.message.opened)try{r.message.opened=(new Date).toISOString(),this.applyMessageSnapshot(r),i&&await(null==(n=t.Courier.shared.client)?void 0:n.inbox.open({messageId:e.messageId}))}catch(a){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error opening message:",a),this.applyDatastoreSnapshot(l)}}async clickMessage({message:e,canCallApi:i=!0}){var n,o,s,l,r;if(this.canMutate())try{(null==(n=e.trackingIds)?void 0:n.clickTrackingId)&&i&&await(null==(s=t.Courier.shared.client)?void 0:s.inbox.click({messageId:e.messageId,trackingId:null==(o=e.trackingIds)?void 0:o.clickTrackingId}))}catch(a){null==(r=null==(l=t.Courier.shared.client)?void 0:l.options.logger)||r.error("Error clicking message:",a)}}async archiveMessage({message:e,canCallApi:i=!0}){var n,o,s,l;if(!this.canMutate())return;const r=this.getMessageSnapshot(e);if(void 0===r.inboxIndex)return;const a=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{if(e.archived=(new Date).toISOString(),this.removeMessage(e,r.inboxIndex,"inbox"),null==(n=this._archiveDataSet)?void 0:n.messages){const t=this.findInsertIndex(e,this._archiveDataSet);this.addMessage(e,t,"archive")}i&&await(null==(o=t.Courier.shared.client)?void 0:o.inbox.archive({messageId:e.messageId}))}catch(d){null==(l=null==(s=t.Courier.shared.client)?void 0:s.options.logger)||l.error("Error archiving message:",d),this.applyDatastoreSnapshot(a)}}async unarchiveMessage({message:e,canCallApi:i=!0}){var n,o,s,l;if(!this.canMutate())return;const r=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet),a=this.getMessageSnapshot(e);if(void 0!==a.archiveIndex)try{if(a.message.archived=void 0,this.removeMessage(e,a.archiveIndex,"archive"),null==(n=this._inboxDataSet)?void 0:n.messages){const t=this.findInsertIndex(e,this._inboxDataSet);this.addMessage(e,t,"inbox")}i&&await(null==(o=t.Courier.shared.client)?void 0:o.inbox.unarchive({messageId:e.messageId}))}catch(d){null==(l=null==(s=t.Courier.shared.client)?void 0:s.options.logger)||l.error("Error unarchiving message:",d),this.applyDatastoreSnapshot(r)}}async archiveReadMessages({canCallApi:e=!0}={}){var i,n,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{const o=(new Date).toISOString();((null==(i=this._inboxDataSet)?void 0:i.messages.filter((e=>e.read)))??[]).forEach((e=>{var t,i,n;e.archived=o;const s=null==(t=this._inboxDataSet)?void 0:t.messages.findIndex((t=>t.messageId===e.messageId));if(void 0!==s&&-1!==s&&(null==(i=this._inboxDataSet)||i.messages.splice(s,1)),null==(n=this._archiveDataSet)?void 0:n.messages){const t=this.findInsertIndex(e,this._archiveDataSet);this._archiveDataSet.messages.splice(t,0,e)}})),this._dataStoreListeners.forEach((e=>{var t,i,n,o;this._inboxDataSet&&(null==(i=(t=e.events).onDataSetChange)||i.call(t,this._inboxDataSet,"inbox")),this._archiveDataSet&&(null==(o=(n=e.events).onDataSetChange)||o.call(n,this._archiveDataSet,"archive"))})),e&&await(null==(n=t.Courier.shared.client)?void 0:n.inbox.archiveRead())}catch(r){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error archiving read messages:",r),this.applyDatastoreSnapshot(l)}}async archiveAllMessages({canCallApi:e=!0}={}){var i,n,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{const o=(new Date).toISOString();null==(i=this._inboxDataSet)||i.messages.forEach((e=>{var t;if(e.archived=o,null==(t=this._archiveDataSet)?void 0:t.messages){const t=this.findInsertIndex(e,this._archiveDataSet);this._archiveDataSet.messages.splice(t,0,e)}})),this._inboxDataSet={messages:[],canPaginate:!1,paginationCursor:null,feedType:"inbox"},this._unreadCount=0,this._dataStoreListeners.forEach((e=>{var t,i,n,o,s,l;this._inboxDataSet&&(null==(i=(t=e.events).onDataSetChange)||i.call(t,this._inboxDataSet,"inbox")),this._archiveDataSet&&(null==(o=(n=e.events).onDataSetChange)||o.call(n,this._archiveDataSet,"archive")),null==(l=(s=e.events).onUnreadCountChange)||l.call(s,this._unreadCount)})),e&&await(null==(n=t.Courier.shared.client)?void 0:n.inbox.archiveAll())}catch(r){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error archiving all messages:",r),this.applyDatastoreSnapshot(l)}}async readAllMessages({canCallApi:e=!0}={}){var i,n,o,s,l;if(!this.canMutate())return;const r=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{const s=(new Date).toISOString();null==(i=this._inboxDataSet)||i.messages.forEach((e=>{e.read||(e.read=s)})),null==(n=this._archiveDataSet)||n.messages.forEach((e=>{e.read||(e.read=s)})),this._unreadCount=0,this._dataStoreListeners.forEach((e=>{var t,i,n,o,s,l;this._inboxDataSet&&(null==(i=(t=e.events).onDataSetChange)||i.call(t,this._inboxDataSet,"inbox")),this._archiveDataSet&&(null==(o=(n=e.events).onDataSetChange)||o.call(n,this._archiveDataSet,"archive")),null==(l=(s=e.events).onUnreadCountChange)||l.call(s,this._unreadCount)})),e&&await(null==(o=t.Courier.shared.client)?void 0:o.inbox.readAll())}catch(a){null==(l=null==(s=t.Courier.shared.client)?void 0:s.options.logger)||l.error("Error reading all messages:",a),this.applyDatastoreSnapshot(r)}}findInsertIndex(e,t){const i=t.messages;for(let n=0;n<i.length;n++){const t=i[n];if(t.created&&e.created&&t.created<e.created)return n}return i.length}addPage(e){switch(e.feedType){case"inbox":this._inboxDataSet&&(this._inboxDataSet.canPaginate=e.canPaginate,this._inboxDataSet.paginationCursor=e.paginationCursor,this._inboxDataSet.messages=[...this._inboxDataSet.messages,...e.messages]);break;case"archive":this._archiveDataSet&&(this._archiveDataSet.canPaginate=e.canPaginate,this._archiveDataSet.paginationCursor=e.paginationCursor,this._archiveDataSet.messages=[...this._archiveDataSet.messages,...e.messages])}this._dataStoreListeners.forEach((t=>{var i,n;return null==(n=(i=t.events).onPageAdded)?void 0:n.call(i,e,e.feedType)}))}addMessage(e,t,i){var n,o;switch(i){case"inbox":e.read||void 0===this._unreadCount||(this._unreadCount=this._unreadCount+1),null==(n=this._inboxDataSet)||n.messages.splice(t,0,e);break;case"archive":null==(o=this._archiveDataSet)||o.messages.splice(t,0,e)}this._dataStoreListeners.forEach((n=>{var o,s,l,r;null==(s=(o=n.events).onMessageAdd)||s.call(o,e,t,i),null==(r=(l=n.events).onUnreadCountChange)||r.call(l,this._unreadCount??0)}))}removeMessage(e,t,i){var n,o;switch(i){case"inbox":e.read||void 0===this._unreadCount||(this._unreadCount=this._unreadCount-1),null==(n=this._inboxDataSet)||n.messages.splice(t,1);break;case"archive":null==(o=this._archiveDataSet)||o.messages.splice(t,1)}this._dataStoreListeners.forEach((n=>{var o,s,l,r;null==(s=(o=n.events).onMessageRemove)||s.call(o,e,t,i),null==(r=(l=n.events).onUnreadCountChange)||r.call(l,this._unreadCount??0)}))}applyMessageSnapshot(e){void 0!==e.archiveIndex&&this.updateMessage(e.message,e.archiveIndex,"archive"),void 0!==e.inboxIndex&&this.updateMessage(e.message,e.inboxIndex,"inbox")}applyDatastoreSnapshot(e){const{unreadCount:t,inbox:i,archive:n}=e;this._inboxDataSet=i,this._archiveDataSet=n,this._dataStoreListeners.forEach((e=>{var i,n,o,s,l,r;this._inboxDataSet&&(null==(n=(i=e.events).onDataSetChange)||n.call(i,this._inboxDataSet,"inbox")),this._archiveDataSet&&(null==(s=(o=e.events).onDataSetChange)||s.call(o,this._archiveDataSet,"archive")),null==(r=(l=e.events).onUnreadCountChange)||r.call(l,t)}))}updateMessage(e,t,i){switch(i){case"inbox":this._inboxDataSet&&(this._inboxDataSet.messages[t]=e);break;case"archive":this._archiveDataSet&&(this._archiveDataSet.messages[t]=e)}this._dataStoreListeners.forEach((n=>{var o,s,l,r;null==(s=(o=n.events).onMessageUpdate)||s.call(o,e,t,i),null==(r=(l=n.events).onUnreadCountChange)||r.call(l,this._unreadCount??0)}))}getDatastoreSnapshot(e,t,i){return{unreadCount:e,inbox:l(t),archive:l(i)}}getMessageSnapshot(e){const t=this._archiveDataSet?this._archiveDataSet.messages.findIndex((t=>t.messageId===e.messageId)):void 0,i=this._inboxDataSet?this._inboxDataSet.messages.findIndex((t=>t.messageId===e.messageId)):void 0;return{message:s(e),archiveIndex:t,inboxIndex:i}}};o(a,"instance");let d=a;class u extends i.CourierBaseElement{constructor(e,t,i){super(),o(this,"_themeManager"),o(this,"_theme"),o(this,"_message",null),o(this,"_feedType","inbox"),o(this,"_isMobile",!1),o(this,"_canClick",!1),o(this,"_titleElement"),o(this,"_subtitleElement"),o(this,"_timeElement"),o(this,"_menu"),o(this,"_unreadIndicator"),o(this,"_actionsContainer"),o(this,"_longPressTimeout",null),o(this,"_isLongPress",!1),o(this,"_observer"),o(this,"onItemClick",null),o(this,"onItemLongPress",null),o(this,"onItemActionClick",null),o(this,"onItemVisible",null),this._canClick=t,this._themeManager=e,this._theme=e.getTheme(),this._isMobile="ontouchstart"in window,this.render(),this._setupIntersectionObserver()}static get id(){return"courier-inbox-list-item"}render(){const e=document.createElement("div");e.className="content-container",this._titleElement=document.createElement("p"),this._titleElement.className="title",this._subtitleElement=document.createElement("p"),this._subtitleElement.className="subtitle",this._actionsContainer=document.createElement("div"),this._actionsContainer.className="actions-container",e.appendChild(this._titleElement),e.appendChild(this._subtitleElement),e.appendChild(this._actionsContainer),this._timeElement=document.createElement("p"),this._timeElement.className="time",this._unreadIndicator=document.createElement("div"),this._unreadIndicator.className="unread-indicator",this._menu=new r(this._theme),this._menu.setOptions(this._getMenuOptions()),this.append(this._unreadIndicator,e,this._timeElement,this._menu);const t=e=>{e.stopPropagation(),e.preventDefault()};this._menu.addEventListener("mousedown",t),this._menu.addEventListener("pointerdown",t),this._menu.addEventListener("click",t),this.addEventListener("click",(e=>{this._canClick&&(this._menu&&(this._menu.contains(e.target)||e.composedPath().includes(this._menu))||!this._message||!this.onItemClick||e.target instanceof i.CourierIcon||this._isLongPress||this.onItemClick(this._message))})),this._setupHoverBehavior(),this._setupLongPressBehavior(),this._canClick&&this.classList.add("clickable")}_setupIntersectionObserver(){"undefined"!=typeof window&&"undefined"!=typeof IntersectionObserver&&(this._observer&&this._observer.disconnect(),this._observer=new IntersectionObserver((e=>{e.forEach((e=>{1===e.intersectionRatio&&this.onItemVisible&&this._message&&this.onItemVisible(this._message)}))}),{threshold:1}),this._observer.observe(this))}onComponentUnmounted(){var e;null==(e=this._observer)||e.disconnect()}static getStyles(e){var t,i,n,o,s,l,r,a,d,h,c,v,p,g,m,b,_,C,x,f,y,S,k,I,M,w;const E=null==(t=e.inbox)?void 0:t.list;return`\n ${u.id} {\n display: flex;\n flex-direction: row;\n align-items: flex-start;\n justify-content: space-between;\n border-bottom: ${(null==(i=null==E?void 0:E.item)?void 0:i.divider)??"1px solid red"};\n font-family: inherit;\n cursor: default;\n transition: background-color 0.2s ease;\n margin: 0;\n width: 100%;\n box-sizing: border-box;\n padding: 12px 20px;\n position: relative;\n background-color: ${(null==(n=null==E?void 0:E.item)?void 0:n.backgroundColor)??"transparent"};\n user-select: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n touch-action: manipulation;\n }\n\n /* Only apply hover/active background if clickable */\n @media (hover: hover) {\n ${u.id}.clickable:hover {\n cursor: pointer;\n background-color: ${(null==(o=null==E?void 0:E.item)?void 0:o.hoverBackgroundColor)??"red"};\n }\n }\n\n ${u.id}.clickable:active {\n cursor: pointer;\n background-color: ${(null==(s=null==E?void 0:E.item)?void 0:s.activeBackgroundColor)??"red"};\n }\n\n /* Menu hover / active */\n @media (hover: hover) {\n ${u.id}.clickable:hover:has(courier-inbox-list-item-menu:hover, courier-inbox-list-item-menu *:hover, courier-button:hover, courier-button *:hover) {\n background-color: ${(null==(l=null==E?void 0:E.item)?void 0:l.backgroundColor)??"transparent"};\n }\n }\n\n ${u.id}.clickable:active:has(courier-inbox-list-item-menu:active, courier-inbox-list-item-menu *:active, courier-button:active, courier-button *:active) {\n background-color: ${(null==(r=null==E?void 0:E.item)?void 0:r.backgroundColor)??"transparent"};\n }\n\n ${u.id}:last-child {\n border-bottom: none;\n }\n\n ${u.id} .unread-indicator {\n position: absolute;\n top: 28px;\n left: 6px;\n width: 8px;\n height: 8px;\n border-radius: 50%;\n background-color: ${(null==(a=null==E?void 0:E.item)?void 0:a.unreadIndicatorColor)??"red"};\n display: none;\n }\n\n ${u.id}.unread .unread-indicator {\n display: block;\n }\n\n ${u.id} .content-container {\n flex: 1;\n display: flex;\n flex-direction: column;\n margin-right: 12px;\n }\n\n ${u.id} p {\n margin: 0;\n overflow-wrap: break-word;\n word-break: break-word;\n hyphens: auto;\n line-height: 1.4;\n user-select: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n text-align: left;\n }\n\n ${u.id} .title {\n font-family: ${(null==(h=null==(d=null==E?void 0:E.item)?void 0:d.title)?void 0:h.family)??"inherit"};\n font-size: ${(null==(v=null==(c=null==E?void 0:E.item)?void 0:c.title)?void 0:v.size)??"14px"};\n color: ${(null==(g=null==(p=null==E?void 0:E.item)?void 0:p.title)?void 0:g.color)??"red"};\n margin-bottom: 4px;\n }\n\n ${u.id} .subtitle {\n font-family: ${(null==(b=null==(m=null==E?void 0:E.item)?void 0:m.subtitle)?void 0:b.family)??"inherit"};\n font-size: ${(null==(C=null==(_=null==E?void 0:E.item)?void 0:_.subtitle)?void 0:C.size)??"14px"};\n color: ${(null==(f=null==(x=null==E?void 0:E.item)?void 0:x.subtitle)?void 0:f.color)??"red"};\n }\n\n ${u.id} .time {\n font-family: ${(null==(S=null==(y=null==E?void 0:E.item)?void 0:y.time)?void 0:S.family)??"inherit"};\n font-size: ${(null==(I=null==(k=null==E?void 0:E.item)?void 0:k.time)?void 0:I.size)??"14px"};\n color: ${(null==(w=null==(M=null==E?void 0:E.item)?void 0:M.time)?void 0:w.color)??"red"};\n text-align: right;\n white-space: nowrap;\n }\n\n ${u.id} courier-inbox-list-item-menu {\n z-index: 1;\n position: absolute;\n top: 8px;\n right: 8px;\n display: none;\n }\n\n ${u.id} .actions-container {\n display: flex;\n margin-top: 10px;\n flex-wrap: wrap;\n flex-direction: row;\n align-items: center;\n gap: 8px;\n display: none;\n }\n `}_setupHoverBehavior(){this._isMobile||(this.addEventListener("mouseenter",(()=>{this._isLongPress=!1,this._showMenu()})),this.addEventListener("mouseleave",(()=>this._hideMenu())))}_setupLongPressBehavior(){var e,t,i;const n=null==(i=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:i.menu;if(!(null==n?void 0:n.enabled))return;const o=n.longPress;this.addEventListener("touchstart",(()=>{this._longPressTimeout=window.setTimeout((()=>{this._isLongPress=!0,this._showMenu(),this._message&&this.onItemLongPress&&(this.onItemLongPress(this._message),navigator.vibrate&&navigator.vibrate((null==o?void 0:o.vibrationDuration)??50)),setTimeout((()=>{this._hideMenu(),this._isLongPress=!1}),(null==o?void 0:o.displayDuration)??2e3)}),650)}),{passive:!0}),this.addEventListener("touchend",(()=>{this._longPressTimeout&&(window.clearTimeout(this._longPressTimeout),this._longPressTimeout=null)}))}_getMenuOptions(){var e,t,i,n,o,s,l,r,a,u,h,c,v,p,g;const m=null==(n=null==(i=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:i.menu)?void 0:n.item;let b=[];const _="archive"===this._feedType;return _||b.push({id:(null==(o=this._message)?void 0:o.read)?"unread":"read",icon:{svg:(null==(s=this._message)?void 0:s.read)?null==(l=null==m?void 0:m.unread)?void 0:l.svg:null==(r=null==m?void 0:m.read)?void 0:r.svg,color:(null==(a=this._message)?void 0:a.read)?null==(u=null==m?void 0:m.unread)?void 0:u.color:(null==(h=null==m?void 0:m.read)?void 0:h.color)??"red"},onClick:()=>{this._message&&(this._message.read?d.shared.unreadMessage({message:this._message}):d.shared.readMessage({message:this._message}))}}),b.push({id:_?"unarchive":"archive",icon:{svg:_?null==(c=null==m?void 0:m.unarchive)?void 0:c.svg:null==(v=null==m?void 0:m.archive)?void 0:v.svg,color:_?null==(p=null==m?void 0:m.unarchive)?void 0:p.color:(null==(g=null==m?void 0:m.archive)?void 0:g.color)??"red"},onClick:()=>{this._message&&(_?d.shared.unarchiveMessage({message:this._message}):d.shared.archiveMessage({message:this._message}))}}),b}_showMenu(){var e,t,i;const n=null==(i=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:i.menu;n&&n.enabled&&this._menu&&this._timeElement&&(this._menu.setOptions(this._getMenuOptions()),this._menu.style.display="block",this._menu.show(),this._timeElement.style.opacity="0")}_hideMenu(){var e,t,i;const n=null==(i=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:i.menu;n&&n.enabled&&this._menu&&this._timeElement&&(this._menu.hide(),this._menu.style.display="none",this._timeElement.style.opacity="1")}setMessage(e,t){this._message=e,this._feedType=t,this._updateContent()}setOnItemClick(e){this.onItemClick=e}setOnItemActionClick(e){this.onItemActionClick=e}setOnItemLongPress(e){this.onItemLongPress=e}setOnItemVisible(e){this.onItemVisible=e}_updateContent(){var e,t,n;if(!this._message)return this._titleElement&&(this._titleElement.textContent=""),void(this._subtitleElement&&(this._subtitleElement.textContent=""));this.classList.toggle("unread",!this._message.read&&"archive"!==this._feedType),this._titleElement&&(this._titleElement.textContent=this._message.title||"Untitled Message"),this._subtitleElement&&(this._subtitleElement.textContent=this._message.preview||this._message.body||""),this._timeElement&&(this._timeElement.textContent=function(e){if(!e.created)return"Now";const t=new Date,i=new Date(e.created),n=Math.floor((t.getTime()-i.getTime())/1e3);return n<5?"Now":n<60?`${n}s`:n<3600?`${Math.floor(n/60)}m`:n<86400?`${Math.floor(n/3600)}h`:n<604800?`${Math.floor(n/86400)}d`:n<31536e3?`${Math.floor(n/604800)}w`:`${Math.floor(n/31536e3)}y`}(this._message)),this._menu&&this._menu.setOptions(this._getMenuOptions());const o=this._message.actions&&this._message.actions.length>0;this._actionsContainer&&(this._actionsContainer.style.display=o?"flex":"none");const s=null==(n=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:n.actions;this._actionsContainer&&this._message.actions&&(this._actionsContainer.innerHTML="",this._message.actions.forEach((e=>{var t,n,o,l,r;const a=new i.CourierButton({mode:this._themeManager.mode,text:e.content,variant:"secondary",backgroundColor:null==s?void 0:s.backgroundColor,hoverBackgroundColor:null==s?void 0:s.hoverBackgroundColor,activeBackgroundColor:null==s?void 0:s.activeBackgroundColor,border:null==s?void 0:s.border,borderRadius:null==s?void 0:s.borderRadius,shadow:null==s?void 0:s.shadow,fontFamily:null==(t=null==s?void 0:s.font)?void 0:t.family,fontSize:null==(n=null==s?void 0:s.font)?void 0:n.size,fontWeight:null==(o=null==s?void 0:s.font)?void 0:o.weight,textColor:null==(l=null==s?void 0:s.font)?void 0:l.color,onClick:()=>{this._message&&this.onItemActionClick&&this.onItemActionClick(this._message,e)}});null==(r=this._actionsContainer)||r.appendChild(a)})))}}i.registerElement(u);class h extends i.CourierBaseElement{constructor(e){super(),o(this,"_theme"),o(this,"_style"),this._theme=e}static get id(){return"courier-inbox-skeleton-list-item"}onComponentMounted(){this._style=i.injectGlobalStyle(h.id,h.getStyles(this._theme)),this.render()}onComponentUnmounted(){var e;null==(e=this._style)||e.remove()}render(){const e=new c(this._theme),t=new c(this._theme),i=new c(this._theme);this.appendChild(e),this.appendChild(t),this.appendChild(i)}static getStyles(e){return`\n ${h.id} {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n width: 100%;\n box-sizing: border-box;\n }\n\n ${h.id} > *:first-child {\n width: 35%;\n }\n\n ${h.id} > *:nth-child(2) {\n width: 100%;\n }\n\n ${h.id} > *:nth-child(3) {\n width: 82%;\n }\n `}}i.registerElement(h);class c extends i.CourierBaseElement{constructor(e){super(),o(this,"_theme"),o(this,"_style"),this._theme=e}static get id(){return"courier-skeleton-animated-row"}onComponentMounted(){this._style=i.injectGlobalStyle(c.id,c.getStyles(this._theme)),this.render()}onComponentUnmounted(){var e;null==(e=this._style)||e.remove()}render(){const e=document.createElement("div");e.className="skeleton-item",this.appendChild(e)}static getStyles(e){var t,i,n,o,s,l,r,a,d,u,h,v;const p=(null==(n=null==(i=null==(t=e.inbox)?void 0:t.loading)?void 0:i.animation)?void 0:n.barColor)??"#000",g=4===p.length?`#${p[1]}${p[1]}${p[2]}${p[2]}${p[3]}${p[3]}`:p,m=parseInt(g.slice(1,3),16),b=parseInt(g.slice(3,5),16),_=parseInt(g.slice(5,7),16),C=`rgba(${m}, ${b}, ${_}, 0.8)`,x=`rgba(${m}, ${b}, ${_}, 0.4)`;return`\n ${c.id} {\n display: flex;\n height: 100%;\n width: 100%;\n align-items: flex-start;\n justify-content: flex-start;\n }\n\n ${c.id} .skeleton-item {\n height: ${(null==(l=null==(s=null==(o=e.inbox)?void 0:o.loading)?void 0:s.animation)?void 0:l.barHeight)??"14px"};\n width: 100%;\n background: linear-gradient(\n 90deg,\n ${C} 25%,\n ${x} 50%,\n ${C} 75%\n );\n background-size: 200% 100%;\n animation: ${c.id}-shimmer ${(null==(d=null==(a=null==(r=e.inbox)?void 0:r.loading)?void 0:a.animation)?void 0:d.duration)??"2s"} ease-in-out infinite;\n border-radius: ${(null==(v=null==(h=null==(u=e.inbox)?void 0:u.loading)?void 0:h.animation)?void 0:v.barBorderRadius)??"14px"};\n }\n\n @keyframes ${c.id}-shimmer {\n 0% {\n background-position: 200% 0;\n }\n 100% {\n background-position: -200% 0;\n }\n }\n `}}i.registerElement(c);class v extends i.CourierFactoryElement{constructor(e){super(),o(this,"_theme"),o(this,"_style"),this._theme=e}static get id(){return"courier-inbox-skeleton-list"}onComponentMounted(){this._style=i.injectGlobalStyle(v.id,v.getStyles(this._theme))}onComponentUnmounted(){var e;null==(e=this._style)||e.remove()}defaultElement(){const e=document.createElement("div");e.className="list";for(let t=0;t<3;t++){const t=new h(this._theme);e.appendChild(t)}return this.appendChild(e),e}static getStyles(e){var t,i,n,o;return`\n ${v.id} {\n display: flex;\n height: 100%;\n width: 100%;\n align-items: flex-start;\n justify-content: flex-start;\n overflow: hidden;\n }\n\n ${v.id} .list {\n display: flex;\n flex-direction: column;\n width: 100%;\n overflow: hidden;\n }\n\n ${v.id} .list > * {\n border-bottom: ${(null==(i=null==(t=e.inbox)?void 0:t.loading)?void 0:i.divider)??"1px solid red"};\n opacity: 100%;\n }\n\n ${v.id} .list > *:nth-child(2) {\n border-bottom: ${(null==(o=null==(n=e.inbox)?void 0:n.loading)?void 0:o.divider)??"1px solid red"};\n opacity: 88%;\n }\n\n ${v.id} .list > *:nth-child(3) {\n border-bottom: none;\n opacity: 50%;\n }\n `}}i.registerElement(v);class p extends i.CourierBaseElement{constructor(e){super(),o(this,"_theme"),o(this,"_style"),o(this,"_skeletonLoadingList"),o(this,"_observer"),o(this,"_customItem"),o(this,"_onPaginationTrigger"),this._theme=e.theme,this._customItem=e.customItem,this._onPaginationTrigger=e.onPaginationTrigger}static get id(){return"courier-inbox-pagination-list-item"}onComponentMounted(){if(this._style=i.injectGlobalStyle(p.id,p.getStyles(this._theme)),this._customItem)this.appendChild(this._customItem);else{const e=document.createElement("div");e.className="skeleton-container",this._skeletonLoadingList=new v(this._theme),this._skeletonLoadingList.build(void 0),e.appendChild(this._skeletonLoadingList),this.appendChild(e)}this._observer=new IntersectionObserver((e=>{e.forEach((e=>{e.isIntersecting&&this._onPaginationTrigger()}))})),this._observer.observe(this)}onComponentUnmounted(){var e,t;null==(e=this._observer)||e.disconnect(),null==(t=this._style)||t.remove()}static getStyles(e){return`\n ${p.id} {\n padding: 0;\n margin: 0;\n box-sizing: border-box;\n }\n\n ${p.id} .skeleton-container {\n height: 150%;\n }\n `}}function g(e){return d.shared.openMessage({message:e})}i.registerElement(p);class m extends i.CourierBaseElement{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_messages",[]),o(this,"_feedType","inbox"),o(this,"_isLoading",!0),o(this,"_error",null),o(this,"_canPaginate",!1),o(this,"_canClickListItems",!1),o(this,"_canLongPressListItems",!1),o(this,"_onMessageClick",null),o(this,"_onMessageActionClick",null),o(this,"_onMessageLongPress",null),o(this,"_onRefresh"),o(this,"_onPaginationTrigger"),o(this,"_listItemFactory"),o(this,"_paginationItemFactory"),o(this,"_loadingStateFactory"),o(this,"_emptyStateFactory"),o(this,"_errorStateFactory"),o(this,"_listStyles"),o(this,"_listItemStyles"),o(this,"_listItemMenuStyles"),o(this,"_errorContainer"),o(this,"_emptyContainer"),this._onRefresh=e.onRefresh,this._onPaginationTrigger=e.onPaginationTrigger,this._onMessageClick=e.onMessageClick,this._onMessageActionClick=e.onMessageActionClick,this._onMessageLongPress=e.onMessageLongPress,this._themeSubscription=e.themeManager.subscribe((e=>{this.render()}))}static get id(){return"courier-inbox-list"}get messages(){return this._messages}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this._listStyles=i.injectGlobalStyle(m.id,m.getStyles(this.theme)),this._listItemStyles=i.injectGlobalStyle(u.id,u.getStyles(this.theme)),this._listItemMenuStyles=i.injectGlobalStyle(r.id,r.getStyles(this.theme)),this.render()}onComponentUnmounted(){var e,t,i;this._themeSubscription.unsubscribe(),null==(e=this._listStyles)||e.remove(),null==(t=this._listItemStyles)||t.remove(),null==(i=this._listItemMenuStyles)||i.remove()}setCanClickListItems(e){this._canClickListItems=e}setCanLongPressListItems(e){this._canLongPressListItems=e}static getStyles(e){var t;const i=null==(t=e.inbox)?void 0:t.list;return`\n ${m.id} {\n flex: 1;\n width: 100%;\n background-color: ${(null==i?void 0:i.backgroundColor)??"red"};\n }\n\n ${m.id} ul {\n list-style: none;\n padding: 0;\n margin: 0;\n height: 100%;\n }\n `}setDataSet(e){this._messages=[...e.messages],this._canPaginate=Boolean(e.canPaginate),this._error=null,this._isLoading=!1,this.render()}addPage(e){this._messages=[...this._messages,...e.messages],this._canPaginate=Boolean(e.canPaginate),this._error=null,this._isLoading=!1,this.render()}addMessage(e,t=0){this._messages.splice(t,0,e),this.render()}removeMessage(e=0){this._messages.splice(e,1),this.render()}updateMessage(e,t=0){this._messages[t]=e,this.render()}setFeedType(e){this._feedType=e,this._error=null,this._isLoading=!0,this.render()}setLoading(e){this._error=null,this._isLoading=e,this.render()}setError(e){this._error=e,this._isLoading=!1,this._messages=[],this.render()}setErrorNoClient(){this.setError(new Error("No user signed in"))}handleRetry(){this._onRefresh()}handleRefresh(){this._onRefresh()}refreshInfoStateThemes(){var e,t;null==(e=this._emptyContainer)||e.updateStyles(this.errorProps),null==(t=this._emptyContainer)||t.updateStyles(this.emptyProps)}get errorProps(){var e,t,i,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,C,x,f,y,S,k,I;const M=null==(e=this.theme.inbox)?void 0:e.error,w=this._themeSubscription.manager.mode;return{title:{text:(null==(t=null==M?void 0:M.title)?void 0:t.text)??(null==(i=this._error)?void 0:i.message),textColor:null==(o=null==(n=null==M?void 0:M.title)?void 0:n.font)?void 0:o.color,fontFamily:null==(l=null==(s=null==M?void 0:M.title)?void 0:s.font)?void 0:l.family,fontSize:null==(a=null==(r=null==M?void 0:M.title)?void 0:r.font)?void 0:a.size,fontWeight:null==(u=null==(d=null==M?void 0:M.title)?void 0:d.font)?void 0:u.weight},button:{mode:w,text:null==(h=null==M?void 0:M.button)?void 0:h.text,backgroundColor:null==(c=null==M?void 0:M.button)?void 0:c.backgroundColor,hoverBackgroundColor:null==(v=null==M?void 0:M.button)?void 0:v.hoverBackgroundColor,activeBackgroundColor:null==(p=null==M?void 0:M.button)?void 0:p.activeBackgroundColor,textColor:null==(m=null==(g=null==M?void 0:M.button)?void 0:g.font)?void 0:m.color,fontFamily:null==(_=null==(b=null==M?void 0:M.button)?void 0:b.font)?void 0:_.family,fontSize:null==(x=null==(C=null==M?void 0:M.button)?void 0:C.font)?void 0:x.size,fontWeight:null==(y=null==(f=null==M?void 0:M.button)?void 0:f.font)?void 0:y.weight,shadow:null==(S=null==M?void 0:M.button)?void 0:S.shadow,border:null==(k=null==M?void 0:M.button)?void 0:k.border,borderRadius:null==(I=null==M?void 0:M.button)?void 0:I.borderRadius,onClick:()=>this.handleRetry()}}}get emptyProps(){var e,t,i,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,C,x,f,y,S,k;const I=null==(e=this.theme.inbox)?void 0:e.empty,M=this._themeSubscription.manager.mode;return{title:{text:(null==(t=null==I?void 0:I.title)?void 0:t.text)??`No ${this._feedType} messages yet`,textColor:null==(n=null==(i=null==I?void 0:I.title)?void 0:i.font)?void 0:n.color,fontFamily:null==(s=null==(o=null==I?void 0:I.title)?void 0:o.font)?void 0:s.family,fontSize:null==(r=null==(l=null==I?void 0:I.title)?void 0:l.font)?void 0:r.size,fontWeight:null==(d=null==(a=null==I?void 0:I.title)?void 0:a.font)?void 0:d.weight},button:{mode:M,text:null==(u=null==I?void 0:I.button)?void 0:u.text,backgroundColor:null==(h=null==I?void 0:I.button)?void 0:h.backgroundColor,hoverBackgroundColor:null==(c=null==I?void 0:I.button)?void 0:c.hoverBackgroundColor,activeBackgroundColor:null==(v=null==I?void 0:I.button)?void 0:v.activeBackgroundColor,textColor:null==(g=null==(p=null==I?void 0:I.button)?void 0:p.font)?void 0:g.color,fontFamily:null==(b=null==(m=null==I?void 0:I.button)?void 0:m.font)?void 0:b.family,fontSize:null==(C=null==(_=null==I?void 0:I.button)?void 0:_.font)?void 0:C.size,fontWeight:null==(f=null==(x=null==I?void 0:I.button)?void 0:x.font)?void 0:f.weight,shadow:null==(y=null==I?void 0:I.button)?void 0:y.shadow,border:null==(S=null==I?void 0:I.button)?void 0:S.border,borderRadius:null==(k=null==I?void 0:I.button)?void 0:k.borderRadius,onClick:()=>this.handleRefresh()}}}render(){for(var e,t,n,o;this.firstChild;)this.removeChild(this.firstChild),this._errorContainer=void 0,this._emptyContainer=void 0;if(this._listStyles&&(this._listStyles.textContent=m.getStyles(this.theme)),this._listItemStyles&&(this._listItemStyles.textContent=u.getStyles(this.theme)),this._listItemMenuStyles&&(this._listItemMenuStyles.textContent=r.getStyles(this.theme)),this._error)return this._errorContainer=new i.CourierInfoState(this.errorProps),this._errorContainer.build(null==(e=this._errorStateFactory)?void 0:e.call(this,{feedType:this._feedType,error:this._error})),void this.appendChild(this._errorContainer);if(this._isLoading){const e=new v(this.theme);return e.build(null==(t=this._loadingStateFactory)?void 0:t.call(this,{feedType:this._feedType})),void this.appendChild(e)}if(0===this._messages.length)return this._emptyContainer=new i.CourierInfoState(this.emptyProps),this._emptyContainer.build(null==(n=this._emptyStateFactory)?void 0:n.call(this,{feedType:this._feedType})),void this.appendChild(this._emptyContainer);const s=document.createElement("ul");if(this.appendChild(s),this._messages.forEach(((e,t)=>{if(this._listItemFactory)return void s.appendChild(this._listItemFactory({message:e,index:t}));const i=new u(this._themeSubscription.manager,this._canClickListItems,this._canLongPressListItems);i.setMessage(e,this._feedType),i.setOnItemClick((e=>{var i;return null==(i=this._onMessageClick)?void 0:i.call(this,e,t)})),i.setOnItemActionClick(((e,i)=>{var n;return null==(n=this._onMessageActionClick)?void 0:n.call(this,e,i,t)})),i.setOnItemLongPress((e=>{var i;return null==(i=this._onMessageLongPress)?void 0:i.call(this,e,t)})),i.setOnItemVisible((e=>this.openVisibleMessage(e))),s.appendChild(i)})),this._canPaginate){const e=new p({theme:this.theme,customItem:null==(o=this._paginationItemFactory)?void 0:o.call(this,{feedType:this._feedType}),onPaginationTrigger:()=>{var e;return null==(e=this._onPaginationTrigger)?void 0:e.call(this,this._feedType)}});s.appendChild(e)}}async openVisibleMessage(e){try{await g(e)}catch(t){}}setLoadingStateFactory(e){this._loadingStateFactory=e,this.render()}setEmptyStateFactory(e){this._emptyStateFactory=e,this.render()}setErrorStateFactory(e){this._errorStateFactory=e,this.render()}setListItemFactory(e){this._listItemFactory=e,this.render()}setPaginationItemFactory(e){this._paginationItemFactory=e,this.render()}}i.registerElement(m);class b extends i.CourierBaseElement{constructor(e){super(),o(this,"_option"),o(this,"_isSelectedable"),o(this,"_isSelected"),o(this,"_content"),o(this,"_itemIcon"),o(this,"_title"),o(this,"_selectionIcon"),this._option=e.option,this._isSelected=e.isSelected,this._isSelectedable=e.selectable}static get id(){return"courier-inbox-option-menu-item"}onComponentMounted(){this._content=document.createElement("div"),this._content.className="menu-item",this._itemIcon=new i.CourierIcon(this._option.icon.svg??i.CourierIconSVGs.inbox),this._itemIcon.setAttribute("size","16"),this._title=document.createElement("p"),this._title.textContent=this._option.text;const e=document.createElement("div");e.className="spacer",this._selectionIcon=new i.CourierIcon(i.CourierIconSVGs.check),this._content.appendChild(this._itemIcon),this._content.appendChild(this._title),this._content.appendChild(e),this._isSelectedable&&this._content.appendChild(this._selectionIcon),this.appendChild(this._content),this._selectionIcon.style.display=this._isSelected?"block":"none",this.refreshTheme()}refreshTheme(){var e,t,n,o,s,l,r,a;null==(t=this._selectionIcon)||t.updateColor((null==(e=this._option.selectionIcon)?void 0:e.color)??"red"),null==(o=this._selectionIcon)||o.updateSVG((null==(n=this._option.selectionIcon)?void 0:n.svg)??i.CourierIconSVGs.check),this._title&&(this._title.textContent=this._option.text??"Missing Text"),null==(l=this._itemIcon)||l.updateColor((null==(s=this._option.icon)?void 0:s.color)??"red"),null==(a=this._itemIcon)||a.updateSVG((null==(r=this._option.icon)?void 0:r.svg)??i.CourierIconSVGs.inbox)}}i.registerElement(b);class _ extends i.CourierBaseElement{constructor(e,t,i,n,s){super(),o(this,"_themeSubscription"),o(this,"_type"),o(this,"_selectedIndex",0),o(this,"_options"),o(this,"_selectable"),o(this,"_onMenuOpen"),o(this,"_menuButton"),o(this,"_menu"),o(this,"_style"),this._type=t,this._selectable=i,this._options=n,this._selectedIndex=0,this._onMenuOpen=s,this._themeSubscription=e.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-option-menu"}onComponentMounted(){this._style=i.injectGlobalStyle(_.id,this.getStyles()),this._menuButton=new i.CourierIconButton("filters"===this._type?i.CourierIconSVGs.filter:i.CourierIconSVGs.overflow),this._menu=document.createElement("div"),this._menu.className=`menu ${this._type}`,this.appendChild(this._menuButton),this.appendChild(this._menu),this._menuButton.addEventListener("click",this.toggleMenu.bind(this)),document.addEventListener("click",this.handleOutsideClick.bind(this)),this.refreshTheme()}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}getStyles(){var e,t,i,n,o,s,l,r,a,d,u,h,c,v,p,g,m,C,x,f,y,S,k,I,M,w,E,D,$,T,L,P,B,A,F,R,G,O,V,z,U,N,H,j,J,W,q,X,Y,Z,K,Q,ee,te,ie;const ne=this._themeSubscription.manager.getTheme();return`\n ${_.id} {\n position: relative;\n display: inline-block;\n }\n\n ${_.id} .menu {\n display: none;\n position: absolute;\n top: 42px;\n right: -6px;\n border-radius: ${(null==(n=null==(i=null==(t=null==(e=ne.inbox)?void 0:e.header)?void 0:t.menus)?void 0:i.popup)?void 0:n.borderRadius)??"6px"};\n border: ${(null==(r=null==(l=null==(s=null==(o=ne.inbox)?void 0:o.header)?void 0:s.menus)?void 0:l.popup)?void 0:r.border)??"1px solid red"};\n background: ${(null==(h=null==(u=null==(d=null==(a=ne.inbox)?void 0:a.header)?void 0:d.menus)?void 0:u.popup)?void 0:h.backgroundColor)??"red"};\n box-shadow: ${(null==(g=null==(p=null==(v=null==(c=ne.inbox)?void 0:c.header)?void 0:v.menus)?void 0:p.popup)?void 0:g.shadow)??"0 4px 12px 0 red"};\n z-index: 1000;\n min-width: 200px;\n overflow: hidden;\n padding: 4px 0;\n }\n\n ${_.id} courier-inbox-filter-menu-item {\n border-bottom: ${(null==(y=null==(f=null==(x=null==(C=null==(m=ne.inbox)?void 0:m.header)?void 0:C.menus)?void 0:x.popup)?void 0:f.list)?void 0:y.divider)??"none"};\n }\n\n ${_.id} courier-inbox-filter-menu-item:last-child {\n border-bottom: none;\n }\n\n ${b.id} {\n display: flex;\n flex-direction: row;\n padding: 6px 12px;\n cursor: pointer;\n }\n\n ${b.id}:hover {\n background-color: ${(null==(w=null==(M=null==(I=null==(k=null==(S=ne.inbox)?void 0:S.header)?void 0:k.menus)?void 0:I.popup)?void 0:M.list)?void 0:w.hoverBackgroundColor)??"red"};\n }\n\n ${b.id}:active {\n background-color: ${(null==(L=null==(T=null==($=null==(D=null==(E=ne.inbox)?void 0:E.header)?void 0:D.menus)?void 0:$.popup)?void 0:T.list)?void 0:L.activeBackgroundColor)??"red"};\n }\n\n ${b.id} .menu-item {\n display: flex;\n align-items: center;\n width: 100%;\n gap: 12px;\n }\n\n ${b.id} .spacer {\n flex: 1;\n }\n\n ${b.id} p {\n margin: 0;\n font-family: ${(null==(G=null==(R=null==(F=null==(A=null==(B=null==(P=ne.inbox)?void 0:P.header)?void 0:B.menus)?void 0:A.popup)?void 0:F.list)?void 0:R.font)?void 0:G.family)??"inherit"};\n font-weight: ${(null==(H=null==(N=null==(U=null==(z=null==(V=null==(O=ne.inbox)?void 0:O.header)?void 0:V.menus)?void 0:z.popup)?void 0:U.list)?void 0:N.font)?void 0:H.weight)??"inherit"};\n font-size: ${(null==(Y=null==(X=null==(q=null==(W=null==(J=null==(j=ne.inbox)?void 0:j.header)?void 0:J.menus)?void 0:W.popup)?void 0:q.list)?void 0:X.font)?void 0:Y.size)??"14px"};\n color: ${(null==(ie=null==(te=null==(ee=null==(Q=null==(K=null==(Z=ne.inbox)?void 0:Z.header)?void 0:K.menus)?void 0:Q.popup)?void 0:ee.list)?void 0:te.font)?void 0:ie.color)??"red"};\n white-space: nowrap;\n }\n\n ${b.id} .check-icon {\n display: none;\n }\n `}refreshTheme(){var e,t,n,o,s,l,r,a,d,u,h;this._style&&(this._style.textContent=this.getStyles());const c=null==(t=null==(e=this._themeSubscription.manager.getTheme().inbox)?void 0:e.header)?void 0:t.menus,v="filters"===this._type,p=v?null==(n=null==c?void 0:c.filters)?void 0:n.button:null==(o=null==c?void 0:c.actions)?void 0:o.button,g=v?i.CourierIconSVGs.filter:i.CourierIconSVGs.overflow;null==(l=this._menuButton)||l.updateIconSVG((null==(s=null==p?void 0:p.icon)?void 0:s.svg)??g),null==(a=this._menuButton)||a.updateIconColor((null==(r=null==p?void 0:p.icon)?void 0:r.color)??"red"),null==(d=this._menuButton)||d.updateBackgroundColor((null==p?void 0:p.backgroundColor)??"transparent"),null==(u=this._menuButton)||u.updateHoverBackgroundColor((null==p?void 0:p.hoverBackgroundColor)??"red"),null==(h=this._menuButton)||h.updateActiveBackgroundColor((null==p?void 0:p.activeBackgroundColor)??"red"),this.refreshMenuItems()}setOptions(e){this._options=e,this.refreshMenuItems()}refreshMenuItems(){this._menu&&(this._menu.innerHTML=""),this._options.forEach(((e,t)=>{var i;const n=new b({option:e,selectable:this._selectable,isSelected:this._selectedIndex===t,themeManager:this._themeSubscription.manager});n.addEventListener("click",(()=>{this._selectedIndex=t,e.onClick(e),this.refreshMenuItems(),this.closeMenu()})),null==(i=this._menu)||i.appendChild(n)}))}toggleMenu(e){var t;e.stopPropagation();const i="block"!==(null==(t=this._menu)?void 0:t.style.display);this._menu&&(this._menu.style.display=i?"block":"none"),i&&this._onMenuOpen()}handleOutsideClick(e){this.contains(e.target)||this.closeMenu()}closeMenu(){this._menu&&(this._menu.style.display="none")}selectOption(e){this._selectedIndex=this._options.findIndex((t=>t.id===e.id)),this.refreshMenuItems()}}i.registerElement(_);class C extends i.CourierBaseElement{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_location"),o(this,"_count",0),o(this,"_badge"),o(this,"_style"),this._location=e.location,this._themeSubscription=e.themeBus.subscribe((e=>{this.refreshTheme(this._location)}))}static get id(){return"courier-unread-count-badge"}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this._badge=document.createElement("span"),this._badge.className=`unread-badge ${this._location}`,this.appendChild(this._badge),this.updateBadge()}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}static getStyles(e){var t,i,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,x,f,y,S;return`\n ${C.id} {\n display: inline-block;\n }\n\n ${C.id} .unread-badge {\n padding: 3px 8px;\n font-size: 12px;\n text-align: center;\n display: none;\n pointer-events: none;\n }\n\n ${C.id} .header {\n background-color: ${null==(o=null==(n=null==(i=null==(t=e.inbox)?void 0:t.header)?void 0:i.filters)?void 0:n.unreadIndicator)?void 0:o.backgroundColor};\n color: ${null==(d=null==(a=null==(r=null==(l=null==(s=e.inbox)?void 0:s.header)?void 0:l.filters)?void 0:r.unreadIndicator)?void 0:a.font)?void 0:d.color};\n border-radius: ${null==(v=null==(c=null==(h=null==(u=e.inbox)?void 0:u.header)?void 0:h.filters)?void 0:c.unreadIndicator)?void 0:v.borderRadius};\n font-size: ${null==(_=null==(b=null==(m=null==(g=null==(p=e.inbox)?void 0:p.header)?void 0:g.filters)?void 0:m.unreadIndicator)?void 0:b.font)?void 0:_.size};\n padding: ${null==(S=null==(y=null==(f=null==(x=e.inbox)?void 0:x.header)?void 0:f.filters)?void 0:y.unreadIndicator)?void 0:S.padding};\n }\n `}setCount(e){this._count=e,this.updateBadge()}refreshTheme(e){this._location=e,this.updateBadge()}updateBadge(){this._badge&&(this._count>0?(this._badge.textContent=this._count>99?"99+":this._count.toString(),this._badge.style.display="block"):this._badge.style.display="none")}}i.registerElement(C);class x extends i.CourierBaseElement{constructor(e,t){super(),o(this,"_themeSubscription"),o(this,"_option"),o(this,"_feedType"),o(this,"_style"),o(this,"_titleElement"),o(this,"_iconElement"),o(this,"_unreadBadge"),this._option=t,this._themeSubscription=e.subscribe((e=>{this.refreshTheme(this._feedType??"inbox")}))}static get id(){return"courier-inbox-header-title"}get theme(){return this._themeSubscription.manager.getTheme()}static getStyles(e){var t,i,n,o,s,l,r,a,d,u,h,c,v,p,g,m;return`\n ${x.id} {\n display: flex;\n align-items: center;\n gap: 8px;\n position: relative;\n }\n\n ${x.id} courier-icon {\n display: flex;\n align-items: center;\n }\n\n ${x.id} h2 {\n margin: 0;\n font-family: ${(null==(o=null==(n=null==(i=null==(t=e.inbox)?void 0:t.header)?void 0:i.filters)?void 0:n.font)?void 0:o.family)??"inherit"};\n font-size: ${(null==(a=null==(r=null==(l=null==(s=e.inbox)?void 0:s.header)?void 0:l.filters)?void 0:r.font)?void 0:a.size)??"18px"};\n font-weight: ${(null==(c=null==(h=null==(u=null==(d=e.inbox)?void 0:d.header)?void 0:u.filters)?void 0:h.font)?void 0:c.weight)??"500"};\n color: ${(null==(m=null==(g=null==(p=null==(v=e.inbox)?void 0:v.header)?void 0:p.filters)?void 0:g.font)?void 0:m.color)??"red"};\n }\n\n ${x.id} courier-unread-count-badge {\n margin-left: 4px;\n }\n `}onComponentMounted(){this._style=i.injectGlobalStyle(x.id,x.getStyles(this.theme)),this._iconElement=new i.CourierIcon(void 0,this._option.icon.svg),this._titleElement=document.createElement("h2"),this._unreadBadge=new C({themeBus:this._themeSubscription.manager,location:"header"}),this.appendChild(this._iconElement),this.appendChild(this._titleElement),this.appendChild(this._unreadBadge),this.refreshTheme(this._feedType??"inbox")}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}refreshTheme(e){var t;this._feedType=e,this._style&&(this._style.textContent=x.getStyles(this.theme)),null==(t=this._unreadBadge)||t.refreshTheme("header"),this.updateFilter()}updateSelectedOption(e,t,i){var n;this._option=e,this._feedType=t,null==(n=this._unreadBadge)||n.setCount(i),this.updateFilter()}updateFilter(){var e,t,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,C,x,f,y,S,k,I,M,w,E,D,$,T,L;const P=this._themeSubscription.manager.getTheme();switch(this._feedType){case"inbox":this._titleElement&&(this._titleElement.textContent=(null==(o=null==(n=null==(t=null==(e=P.inbox)?void 0:e.header)?void 0:t.filters)?void 0:n.inbox)?void 0:o.text)??"Inbox"),null==(u=this._iconElement)||u.updateSVG((null==(d=null==(a=null==(r=null==(l=null==(s=P.inbox)?void 0:s.header)?void 0:l.filters)?void 0:r.inbox)?void 0:a.icon)?void 0:d.svg)??i.CourierIconSVGs.inbox),null==(m=this._iconElement)||m.updateColor((null==(g=null==(p=null==(v=null==(c=null==(h=P.inbox)?void 0:h.header)?void 0:c.filters)?void 0:v.inbox)?void 0:p.icon)?void 0:g.color)??"red");break;case"archive":this._titleElement&&(this._titleElement.textContent=(null==(x=null==(C=null==(_=null==(b=P.inbox)?void 0:b.header)?void 0:_.filters)?void 0:C.archive)?void 0:x.text)??"Archive"),null==(M=this._iconElement)||M.updateSVG((null==(I=null==(k=null==(S=null==(y=null==(f=P.inbox)?void 0:f.header)?void 0:y.filters)?void 0:S.archive)?void 0:k.icon)?void 0:I.svg)??i.CourierIconSVGs.archive),null==(L=this._iconElement)||L.updateColor((null==(T=null==($=null==(D=null==(E=null==(w=P.inbox)?void 0:w.header)?void 0:E.filters)?void 0:D.archive)?void 0:$.icon)?void 0:T.color)??"red")}}}i.registerElement(x);class f extends i.CourierFactoryElement{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_feedType","inbox"),o(this,"_unreadCount",0),o(this,"_titleSection"),o(this,"_filterMenu"),o(this,"_actionMenu"),o(this,"_style"),o(this,"_onFeedTypeChange"),this._themeSubscription=e.themeManager.subscribe((e=>{this.refreshTheme()})),this._onFeedTypeChange=e.onFeedTypeChange}static get id(){return"courier-inbox-header"}static get observedAttributes(){return["icon","title","feed-type"]}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this._style=i.injectGlobalStyle(f.id,f.getStyles(this.theme))}onComponentUmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}getFilterOptions(){var e,t,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,C,x,f,y,S,k,I,M,w,E,D,$,T,L,P,B,A,F,R;const G=this._themeSubscription.manager.getTheme(),O=null==(n=null==(t=null==(e=G.inbox)?void 0:e.header)?void 0:t.menus)?void 0:n.filters;return[{id:"inbox",text:(null==(o=null==O?void 0:O.inbox)?void 0:o.text)??"Inbox",icon:{color:(null==(l=null==(s=null==O?void 0:O.inbox)?void 0:s.icon)?void 0:l.color)??"red",svg:(null==(a=null==(r=null==O?void 0:O.inbox)?void 0:r.icon)?void 0:a.svg)??i.CourierIconSVGs.inbox},selectionIcon:{color:(null==(p=null==(v=null==(c=null==(h=null==(u=null==(d=G.inbox)?void 0:d.header)?void 0:u.menus)?void 0:h.popup)?void 0:c.list)?void 0:v.selectionIcon)?void 0:p.color)??"red",svg:(null==(x=null==(C=null==(_=null==(b=null==(m=null==(g=G.inbox)?void 0:g.header)?void 0:m.menus)?void 0:b.popup)?void 0:_.list)?void 0:C.selectionIcon)?void 0:x.svg)??i.CourierIconSVGs.check},onClick:e=>{this.handleOptionMenuItemClick("inbox",e)}},{id:"archive",text:(null==(f=null==O?void 0:O.archive)?void 0:f.text)??"Archive",icon:{color:(null==(S=null==(y=null==O?void 0:O.archive)?void 0:y.icon)?void 0:S.color)??"red",svg:(null==(I=null==(k=null==O?void 0:O.archive)?void 0:k.icon)?void 0:I.svg)??i.CourierIconSVGs.archive},selectionIcon:{color:(null==(T=null==($=null==(D=null==(E=null==(w=null==(M=G.inbox)?void 0:M.header)?void 0:w.menus)?void 0:E.popup)?void 0:D.list)?void 0:$.selectionIcon)?void 0:T.color)??"red",svg:(null==(R=null==(F=null==(A=null==(B=null==(P=null==(L=G.inbox)?void 0:L.header)?void 0:P.menus)?void 0:B.popup)?void 0:A.list)?void 0:F.selectionIcon)?void 0:R.svg)??i.CourierIconSVGs.check},onClick:e=>{this.handleOptionMenuItemClick("archive",e)}}]}getActionOptions(){var e,t,n,o,s,l,r,a,u,h,c,v,p,g,m,b,_,C;const x=null==(n=null==(t=null==(e=this._themeSubscription.manager.getTheme().inbox)?void 0:e.header)?void 0:t.menus)?void 0:n.actions;return[{id:"markAllRead",text:(null==(o=null==x?void 0:x.markAllRead)?void 0:o.text)??"Mark All as Read",icon:{color:(null==(l=null==(s=null==x?void 0:x.markAllRead)?void 0:s.icon)?void 0:l.color)??"red",svg:(null==(a=null==(r=null==x?void 0:x.markAllRead)?void 0:r.icon)?void 0:a.svg)??i.CourierIconSVGs.inbox},selectionIcon:null,onClick:e=>{d.shared.readAllMessages({canCallApi:!0})}},{id:"archiveAll",text:(null==(u=null==x?void 0:x.archiveAll)?void 0:u.text)??"Archive All",icon:{color:(null==(c=null==(h=null==x?void 0:x.archiveAll)?void 0:h.icon)?void 0:c.color)??"red",svg:(null==(p=null==(v=null==x?void 0:x.archiveAll)?void 0:v.icon)?void 0:p.svg)??i.CourierIconSVGs.archive},selectionIcon:null,onClick:e=>{d.shared.archiveAllMessages({canCallApi:!0})}},{id:"archiveRead",text:(null==(g=null==x?void 0:x.archiveRead)?void 0:g.text)??"Archive Read",icon:{color:(null==(b=null==(m=null==x?void 0:x.archiveRead)?void 0:m.icon)?void 0:b.color)??"red",svg:(null==(C=null==(_=null==x?void 0:x.archiveRead)?void 0:_.icon)?void 0:C.svg)??i.CourierIconSVGs.archive},selectionIcon:null,onClick:e=>{d.shared.archiveReadMessages({canCallApi:!0})}}]}refreshTheme(){var e,t;this._style&&(this._style.textContent=f.getStyles(this.theme)),null==(e=this._filterMenu)||e.setOptions(this.getFilterOptions()),null==(t=this._actionMenu)||t.setOptions(this.getActionOptions())}handleOptionMenuItemClick(e,t){this._feedType=e,this._titleSection&&this._titleSection.updateSelectedOption(t,this._feedType,"inbox"===this._feedType?this._unreadCount:0),this._onFeedTypeChange(e)}render(e){var t,i;this._feedType=e.feedType,this._unreadCount=e.unreadCount;const n=this.getFilterOptions().find((e=>["inbox","archive"].includes(e.id)&&e.id===this._feedType));n&&(null==(t=this._titleSection)||t.updateSelectedOption(n,this._feedType,"inbox"===this._feedType?this._unreadCount:0),null==(i=this._filterMenu)||i.selectOption(n))}build(e){super.build(e),this.refreshTheme()}defaultElement(){const e=this.getFilterOptions();this._titleSection=new x(this._themeSubscription.manager,e[0]),this._filterMenu=new _(this._themeSubscription.manager,"filters",!0,e,(()=>{var e;null==(e=this._actionMenu)||e.closeMenu()})),this._actionMenu=new _(this._themeSubscription.manager,"actions",!1,this.getActionOptions(),(()=>{var e;null==(e=this._filterMenu)||e.closeMenu()})),this._filterMenu.selectOption(e[0]);const t=document.createElement("div");t.className="spacer";const i=document.createElement("div");i.className="actions",i.appendChild(this._filterMenu),i.appendChild(this._actionMenu);const n=document.createElement("div");return n.className="header-content",n.appendChild(this._titleSection),n.appendChild(t),n.appendChild(i),n}static getStyles(e){var t,n,o,s;return`\n ${f.id} {\n display: flex;\n align-items: center;\n flex-shrink: 0;\n }\n\n ${f.id} .header-content {\n padding: 10px 10px 10px 16px;\n background-color: ${(null==(n=null==(t=e.inbox)?void 0:t.header)?void 0:n.backgroundColor)??i.CourierColors.white[500]};\n box-shadow: ${(null==(s=null==(o=e.inbox)?void 0:o.header)?void 0:s.shadow)??"0px 1px 0px 0px red"};\n display: flex;\n align-items: center;\n justify-content: space-between;\n flex: 1;\n z-index: 100;\n }\n\n ${f.id} .spacer {\n flex: 1;\n }\n\n ${f.id} .actions {\n display: flex;\n align-items: center;\n gap: 4px;\n }\n `}}i.registerElement(f);class y{constructor(e){o(this,"events"),this.events=e}remove(){d.shared.removeDataStoreListener(this)}}const S={popup:{button:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.inbox},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.black[50010],activeBackgroundColor:i.CourierColors.black[50020],unreadDotIndicator:{backgroundColor:i.CourierColors.blue[500],borderRadius:"50%",height:"8px",width:"8px"}},window:{backgroundColor:i.CourierColors.white[500],borderRadius:"8px",border:`1px solid ${i.CourierColors.gray[500]}`,shadow:`0px 8px 16px -4px ${i.CourierColors.gray[500]}`}},inbox:{header:{backgroundColor:i.CourierColors.white[500],shadow:`0px 1px 0px 0px ${i.CourierColors.gray[500]}`,filters:{font:{color:i.CourierColors.black[500],family:void 0,size:"18px"},inbox:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.inbox},text:"Inbox"},archive:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.archive},text:"Archive"},unreadIndicator:{font:{color:i.CourierColors.white[500],family:void 0,size:"12px"},backgroundColor:i.CourierColors.blue[500],borderRadius:"4px",padding:"2px 6px"}},menus:{popup:{backgroundColor:i.CourierColors.white[500],border:`1px solid ${i.CourierColors.gray[500]}`,borderRadius:"4px",shadow:`0px 4px 8px -2px ${i.CourierColors.gray[500]}`,list:{hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],divider:"none",font:{color:i.CourierColors.black[500],family:void 0,size:"14px"},selectionIcon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.check}}},filters:{button:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.filter},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.black[50010],activeBackgroundColor:i.CourierColors.black[50020]},inbox:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.inbox},text:"Inbox"},archive:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.archive},text:"Archive"}},actions:{button:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.overflow},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.black[50010],activeBackgroundColor:i.CourierColors.black[50020]},markAllRead:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.read},text:"Read All"},archiveAll:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.archive},text:"Archive All"},archiveRead:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.archiveRead},text:"Archive Read"}}}},list:{backgroundColor:i.CourierColors.white[500],item:{backgroundColor:"transparent",unreadIndicatorColor:i.CourierColors.blue[500],hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],actions:{backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],border:`1px solid ${i.CourierColors.gray[500]}`,borderRadius:"4px",shadow:"0px 1px 2px 0px rgba(0, 0, 0, 0.06)",font:{color:i.CourierColors.black[500],family:void 0,size:"14px"}},title:{color:i.CourierColors.black[500],family:void 0,size:"14px"},subtitle:{color:i.CourierColors.gray[600],family:void 0,size:"14px"},time:{color:i.CourierColors.gray[600],family:void 0,size:"14px"},divider:`1px solid ${i.CourierColors.gray[200]}`,menu:{enabled:!0,backgroundColor:i.CourierColors.white[500],border:`1px solid ${i.CourierColors.gray[500]}`,borderRadius:"4px",shadow:`0px 2px 4px -2px ${i.CourierColors.gray[500]}`,longPress:{displayDuration:4e3,vibrationDuration:50},item:{hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],borderRadius:"0px",read:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.read},unread:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.unread},archive:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.archive},unarchive:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.unarchive}}}}},loading:{animation:{barColor:i.CourierColors.gray[500],barHeight:"14px",barBorderRadius:"14px",duration:"2s"},divider:`1px solid ${i.CourierColors.gray[200]}`},empty:{title:{font:{size:"16px",weight:"500",color:i.CourierColors.black[500]}},button:{text:"Refresh"}},error:{title:{font:{size:"16px",weight:"500",color:i.CourierColors.black[500]}},button:{text:"Retry"}}}},k={popup:{button:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.inbox},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],unreadDotIndicator:{backgroundColor:i.CourierColors.blue[500],borderRadius:"50%",height:"8px",width:"8px"}},window:{backgroundColor:i.CourierColors.black[500],borderRadius:"8px",border:`1px solid ${i.CourierColors.gray[400]}`,shadow:`0px 4px 8px -2px ${i.CourierColors.white[50020]}`}},inbox:{header:{backgroundColor:i.CourierColors.black[500],shadow:`0px 1px 0px 0px ${i.CourierColors.gray[400]}`,filters:{font:{color:i.CourierColors.white[500],family:void 0,size:"18px"},inbox:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.inbox},text:"Inbox"},archive:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.archive},text:"Archive"},unreadIndicator:{font:{color:i.CourierColors.white[500],family:void 0,size:"12px"},backgroundColor:i.CourierColors.blue[500],borderRadius:"4px",padding:"3px 8px"}},menus:{popup:{backgroundColor:i.CourierColors.black[500],border:`1px solid ${i.CourierColors.gray[400]}`,borderRadius:"4px",shadow:`0px 4px 8px -2px ${i.CourierColors.white[50020]}`,list:{hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],divider:"none",font:{color:i.CourierColors.white[500],family:void 0,size:"14px"},selectionIcon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.check}}},filters:{button:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.filter},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020]},inbox:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.inbox},text:"Inbox"},archive:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.archive},text:"Archive"}},actions:{button:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.overflow},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020]},markAllRead:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.read},text:"Read All"},archiveAll:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.archive},text:"Archive All"},archiveRead:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.archiveRead},text:"Archive Read"}}}},list:{backgroundColor:i.CourierColors.black[500],item:{backgroundColor:"transparent",unreadIndicatorColor:i.CourierColors.blue[500],hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],actions:{backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],border:`1px solid ${i.CourierColors.gray[400]}`,borderRadius:"4px",shadow:`0px 1px 2px 0px ${i.CourierColors.white[50010]}`,font:{color:i.CourierColors.white[500],family:void 0,size:"14px"}},title:{color:i.CourierColors.white[500],family:void 0,size:"14px"},subtitle:{color:i.CourierColors.gray[500],family:void 0,size:"14px"},time:{color:i.CourierColors.gray[500],family:void 0,size:"12px"},divider:`1px solid ${i.CourierColors.gray[400]}`,menu:{enabled:!0,backgroundColor:i.CourierColors.black[500],border:`1px solid ${i.CourierColors.gray[400]}`,borderRadius:"4px",shadow:`0px 2px 4px -2px ${i.CourierColors.white[50020]}`,longPress:{displayDuration:4e3,vibrationDuration:50},item:{hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],borderRadius:"0px",read:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.read},unread:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.unread},archive:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.archive},unarchive:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.unarchive}}}}},loading:{animation:{barColor:i.CourierColors.gray[400],barHeight:"14px",barBorderRadius:"14px",duration:"2s"},divider:`1px solid ${i.CourierColors.gray[400]}`},empty:{title:{font:{size:"16px",weight:"500",color:i.CourierColors.white[500]}},button:{text:"Refresh"}},error:{title:{font:{size:"16px",weight:"500",color:i.CourierColors.white[500]}},button:{text:"Retry"}}}},I=(e,t)=>{var i,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,C,x,f,y,I,M,w,E,D,$,T,L,P,B,A,F,R,G,O,V,z,U,N,H,j,J,W,q,X,Y,Z,K,Q,ee,te,ie,ne,oe,se,le,re,ae,de,ue,he,ce,ve,pe,ge,me,be,_e,Ce,xe,fe,ye,Se,ke,Ie,Me,we,Ee,De,$e,Te,Le,Pe,Be,Ae,Fe,Re,Ge,Oe,Ve,ze,Ue,Ne,He,je,Je,We,qe,Xe,Ye,Ze,Ke,Qe,et,tt,it,nt,ot,st,lt,rt,at,dt,ut,ht,ct,vt,pt,gt,mt,bt,_t,Ct,xt,ft,yt,St,kt,It,Mt,wt,Et,Dt,$t,Tt,Lt,Pt,Bt,At,Ft,Rt,Gt,Ot,Vt,zt,Ut,Nt,Ht,jt,Jt,Wt,qt,Xt,Yt,Zt,Kt,Qt,ei,ti,ii,ni,oi,si,li,ri,ai,di,ui,hi,ci,vi,pi,gi,mi,bi,_i,Ci,xi,fi,yi,Si,ki,Ii,Mi,wi,Ei,Di,$i,Ti,Li,Pi,Bi,Ai,Fi,Ri,Gi,Oi,Vi,zi,Ui,Ni,Hi,ji,Ji,Wi,qi,Xi,Yi,Zi,Ki,Qi,en,tn,nn,on,sn,ln,rn,an,dn,un,hn,cn,vn,pn,gn,mn,bn,_n,Cn,xn,fn,yn,Sn,kn,In,Mn,wn,En,Dn,$n,Tn,Ln,Pn,Bn,An,Fn,Rn,Gn,On,Vn,zn,Un,Nn,Hn,jn,Jn;const Wn="light"===e?S:k;return{popup:{button:{...null==(i=Wn.popup)?void 0:i.button,...null==(n=t.popup)?void 0:n.button,icon:{...null==(s=null==(o=Wn.popup)?void 0:o.button)?void 0:s.icon,...null==(r=null==(l=t.popup)?void 0:l.button)?void 0:r.icon},unreadDotIndicator:{...null==(d=null==(a=Wn.popup)?void 0:a.button)?void 0:d.unreadDotIndicator,...null==(h=null==(u=t.popup)?void 0:u.button)?void 0:h.unreadDotIndicator}},window:{...null==(c=Wn.popup)?void 0:c.window,...null==(v=t.popup)?void 0:v.window}},inbox:{header:{...null==(p=Wn.inbox)?void 0:p.header,...null==(g=t.inbox)?void 0:g.header,filters:{...null==(b=null==(m=Wn.inbox)?void 0:m.header)?void 0:b.filters,...null==(C=null==(_=t.inbox)?void 0:_.header)?void 0:C.filters,inbox:{...null==(y=null==(f=null==(x=Wn.inbox)?void 0:x.header)?void 0:f.filters)?void 0:y.inbox,...null==(w=null==(M=null==(I=t.inbox)?void 0:I.header)?void 0:M.filters)?void 0:w.inbox,icon:{...null==(T=null==($=null==(D=null==(E=Wn.inbox)?void 0:E.header)?void 0:D.filters)?void 0:$.inbox)?void 0:T.icon,...null==(A=null==(B=null==(P=null==(L=t.inbox)?void 0:L.header)?void 0:P.filters)?void 0:B.inbox)?void 0:A.icon}},archive:{...null==(G=null==(R=null==(F=Wn.inbox)?void 0:F.header)?void 0:R.filters)?void 0:G.archive,...null==(z=null==(V=null==(O=t.inbox)?void 0:O.header)?void 0:V.filters)?void 0:z.archive,icon:{...null==(j=null==(H=null==(N=null==(U=Wn.inbox)?void 0:U.header)?void 0:N.filters)?void 0:H.archive)?void 0:j.icon,...null==(X=null==(q=null==(W=null==(J=t.inbox)?void 0:J.header)?void 0:W.filters)?void 0:q.archive)?void 0:X.icon}},unreadIndicator:{...null==(K=null==(Z=null==(Y=Wn.inbox)?void 0:Y.header)?void 0:Z.filters)?void 0:K.unreadIndicator,...null==(te=null==(ee=null==(Q=t.inbox)?void 0:Q.header)?void 0:ee.filters)?void 0:te.unreadIndicator}},menus:{...null==(ne=null==(ie=Wn.inbox)?void 0:ie.header)?void 0:ne.menus,...null==(se=null==(oe=t.inbox)?void 0:oe.header)?void 0:se.menus,popup:{...null==(ae=null==(re=null==(le=Wn.inbox)?void 0:le.header)?void 0:re.menus)?void 0:ae.popup,...null==(he=null==(ue=null==(de=t.inbox)?void 0:de.header)?void 0:ue.menus)?void 0:he.popup,list:{...null==(ge=null==(pe=null==(ve=null==(ce=Wn.inbox)?void 0:ce.header)?void 0:ve.menus)?void 0:pe.popup)?void 0:ge.list,...null==(Ce=null==(_e=null==(be=null==(me=t.inbox)?void 0:me.header)?void 0:be.menus)?void 0:_e.popup)?void 0:Ce.list,font:{...null==(ke=null==(Se=null==(ye=null==(fe=null==(xe=Wn.inbox)?void 0:xe.header)?void 0:fe.menus)?void 0:ye.popup)?void 0:Se.list)?void 0:ke.font,...null==(De=null==(Ee=null==(we=null==(Me=null==(Ie=t.inbox)?void 0:Ie.header)?void 0:Me.menus)?void 0:we.popup)?void 0:Ee.list)?void 0:De.font},selectionIcon:{...null==(Be=null==(Pe=null==(Le=null==(Te=null==($e=Wn.inbox)?void 0:$e.header)?void 0:Te.menus)?void 0:Le.popup)?void 0:Pe.list)?void 0:Be.selectionIcon,...null==(Oe=null==(Ge=null==(Re=null==(Fe=null==(Ae=t.inbox)?void 0:Ae.header)?void 0:Fe.menus)?void 0:Re.popup)?void 0:Ge.list)?void 0:Oe.selectionIcon}}},filters:{...null==(Ue=null==(ze=null==(Ve=Wn.inbox)?void 0:Ve.header)?void 0:ze.menus)?void 0:Ue.filters,...null==(je=null==(He=null==(Ne=t.inbox)?void 0:Ne.header)?void 0:He.menus)?void 0:je.filters,inbox:{...null==(Xe=null==(qe=null==(We=null==(Je=Wn.inbox)?void 0:Je.header)?void 0:We.menus)?void 0:qe.filters)?void 0:Xe.inbox,...null==(Qe=null==(Ke=null==(Ze=null==(Ye=t.inbox)?void 0:Ye.header)?void 0:Ze.menus)?void 0:Ke.filters)?void 0:Qe.inbox,icon:{...null==(ot=null==(nt=null==(it=null==(tt=null==(et=Wn.inbox)?void 0:et.header)?void 0:tt.menus)?void 0:it.filters)?void 0:nt.inbox)?void 0:ot.icon,...null==(dt=null==(at=null==(rt=null==(lt=null==(st=t.inbox)?void 0:st.header)?void 0:lt.menus)?void 0:rt.filters)?void 0:at.inbox)?void 0:dt.icon}},archive:{...null==(vt=null==(ct=null==(ht=null==(ut=Wn.inbox)?void 0:ut.header)?void 0:ht.menus)?void 0:ct.filters)?void 0:vt.archive,...null==(bt=null==(mt=null==(gt=null==(pt=t.inbox)?void 0:pt.header)?void 0:gt.menus)?void 0:mt.filters)?void 0:bt.archive,icon:{...null==(yt=null==(ft=null==(xt=null==(Ct=null==(_t=Wn.inbox)?void 0:_t.header)?void 0:Ct.menus)?void 0:xt.filters)?void 0:ft.archive)?void 0:yt.icon,...null==(wt=null==(Mt=null==(It=null==(kt=null==(St=t.inbox)?void 0:St.header)?void 0:kt.menus)?void 0:It.filters)?void 0:Mt.archive)?void 0:wt.icon}}},actions:{...null==($t=null==(Dt=null==(Et=Wn.inbox)?void 0:Et.header)?void 0:Dt.menus)?void 0:$t.actions,...null==(Pt=null==(Lt=null==(Tt=t.inbox)?void 0:Tt.header)?void 0:Lt.menus)?void 0:Pt.actions,markAllRead:{...null==(Rt=null==(Ft=null==(At=null==(Bt=Wn.inbox)?void 0:Bt.header)?void 0:At.menus)?void 0:Ft.actions)?void 0:Rt.markAllRead,...null==(zt=null==(Vt=null==(Ot=null==(Gt=t.inbox)?void 0:Gt.header)?void 0:Ot.menus)?void 0:Vt.actions)?void 0:zt.markAllRead,icon:{...null==(Jt=null==(jt=null==(Ht=null==(Nt=null==(Ut=Wn.inbox)?void 0:Ut.header)?void 0:Nt.menus)?void 0:Ht.actions)?void 0:jt.markAllRead)?void 0:Jt.icon,...null==(Zt=null==(Yt=null==(Xt=null==(qt=null==(Wt=t.inbox)?void 0:Wt.header)?void 0:qt.menus)?void 0:Xt.actions)?void 0:Yt.markAllRead)?void 0:Zt.icon}},archiveAll:{...null==(ti=null==(ei=null==(Qt=null==(Kt=Wn.inbox)?void 0:Kt.header)?void 0:Qt.menus)?void 0:ei.actions)?void 0:ti.archiveAll,...null==(si=null==(oi=null==(ni=null==(ii=t.inbox)?void 0:ii.header)?void 0:ni.menus)?void 0:oi.actions)?void 0:si.archiveAll,icon:{...null==(ui=null==(di=null==(ai=null==(ri=null==(li=Wn.inbox)?void 0:li.header)?void 0:ri.menus)?void 0:ai.actions)?void 0:di.archiveAll)?void 0:ui.icon,...null==(gi=null==(pi=null==(vi=null==(ci=null==(hi=t.inbox)?void 0:hi.header)?void 0:ci.menus)?void 0:vi.actions)?void 0:pi.archiveAll)?void 0:gi.icon}},archiveRead:{...null==(Ci=null==(_i=null==(bi=null==(mi=Wn.inbox)?void 0:mi.header)?void 0:bi.menus)?void 0:_i.actions)?void 0:Ci.archiveRead,...null==(Si=null==(yi=null==(fi=null==(xi=t.inbox)?void 0:xi.header)?void 0:fi.menus)?void 0:yi.actions)?void 0:Si.archiveRead,icon:{...null==(Ei=null==(wi=null==(Mi=null==(Ii=null==(ki=Wn.inbox)?void 0:ki.header)?void 0:Ii.menus)?void 0:Mi.actions)?void 0:wi.archiveRead)?void 0:Ei.icon,...null==(Pi=null==(Li=null==(Ti=null==($i=null==(Di=t.inbox)?void 0:Di.header)?void 0:$i.menus)?void 0:Ti.actions)?void 0:Li.archiveRead)?void 0:Pi.icon}}}}},list:{...null==(Bi=Wn.inbox)?void 0:Bi.list,...null==(Ai=t.inbox)?void 0:Ai.list,item:{...null==(Ri=null==(Fi=Wn.inbox)?void 0:Fi.list)?void 0:Ri.item,...null==(Oi=null==(Gi=t.inbox)?void 0:Gi.list)?void 0:Oi.item,menu:{...null==(Ui=null==(zi=null==(Vi=Wn.inbox)?void 0:Vi.list)?void 0:zi.item)?void 0:Ui.menu,...null==(ji=null==(Hi=null==(Ni=t.inbox)?void 0:Ni.list)?void 0:Hi.item)?void 0:ji.menu,item:{...null==(Xi=null==(qi=null==(Wi=null==(Ji=Wn.inbox)?void 0:Ji.list)?void 0:Wi.item)?void 0:qi.menu)?void 0:Xi.item,...null==(Qi=null==(Ki=null==(Zi=null==(Yi=t.inbox)?void 0:Yi.list)?void 0:Zi.item)?void 0:Ki.menu)?void 0:Qi.item,read:{...null==(sn=null==(on=null==(nn=null==(tn=null==(en=Wn.inbox)?void 0:en.list)?void 0:tn.item)?void 0:nn.menu)?void 0:on.item)?void 0:sn.read,...null==(un=null==(dn=null==(an=null==(rn=null==(ln=t.inbox)?void 0:ln.list)?void 0:rn.item)?void 0:an.menu)?void 0:dn.item)?void 0:un.read},unread:{...null==(gn=null==(pn=null==(vn=null==(cn=null==(hn=Wn.inbox)?void 0:hn.list)?void 0:cn.item)?void 0:vn.menu)?void 0:pn.item)?void 0:gn.unread,...null==(xn=null==(Cn=null==(_n=null==(bn=null==(mn=t.inbox)?void 0:mn.list)?void 0:bn.item)?void 0:_n.menu)?void 0:Cn.item)?void 0:xn.unread},archive:{...null==(In=null==(kn=null==(Sn=null==(yn=null==(fn=Wn.inbox)?void 0:fn.list)?void 0:yn.item)?void 0:Sn.menu)?void 0:kn.item)?void 0:In.archive,...null==($n=null==(Dn=null==(En=null==(wn=null==(Mn=t.inbox)?void 0:Mn.list)?void 0:wn.item)?void 0:En.menu)?void 0:Dn.item)?void 0:$n.archive},unarchive:{...null==(An=null==(Bn=null==(Pn=null==(Ln=null==(Tn=Wn.inbox)?void 0:Tn.list)?void 0:Ln.item)?void 0:Pn.menu)?void 0:Bn.item)?void 0:An.unarchive,...null==(Vn=null==(On=null==(Gn=null==(Rn=null==(Fn=t.inbox)?void 0:Fn.list)?void 0:Rn.item)?void 0:Gn.menu)?void 0:On.item)?void 0:Vn.unarchive}}}}},loading:{...null==(zn=Wn.inbox)?void 0:zn.loading,...null==(Un=t.inbox)?void 0:Un.loading},empty:{...null==(Nn=Wn.inbox)?void 0:Nn.empty,...null==(Hn=t.inbox)?void 0:Hn.empty},error:{...null==(jn=Wn.inbox)?void 0:jn.error,...null==(Jn=t.inbox)?void 0:Jn.error}}}};class M extends i.CourierThemeManager{constructor(e){super(e),o(this,"THEME_CHANGE_EVENT","courier_inbox_theme_change")}getDefaultLightTheme(){return S}getDefaultDarkTheme(){return k}mergeTheme(e,t){return I(e,t)}subscribe(e){return{...super.subscribe(e),manager:this}}}class w extends i.CourierBaseElement{constructor(e){super(),o(this,"_currentFeed","inbox"),o(this,"_themeManager"),o(this,"_inboxStyle"),o(this,"_unreadIndicatorStyle"),o(this,"_list"),o(this,"_datastoreListener"),o(this,"_authListener"),o(this,"_header"),o(this,"_headerFactory"),o(this,"_onMessageClick"),o(this,"_onMessageActionClick"),o(this,"_onMessageLongPress"),o(this,"_defaultProps",{title:"Inbox",icon:i.CourierIconSVGs.inbox,feedType:this._currentFeed,height:"auto"}),this._themeManager=e??new M(S)}static get id(){return"courier-inbox"}get currentFeed(){return this._currentFeed}get theme(){return this._themeManager.getTheme()}setLightTheme(e){this._themeManager.setLightTheme(e)}setDarkTheme(e){this._themeManager.setDarkTheme(e)}setMode(e){this._themeManager.setMode(e)}static get observedAttributes(){return["height","light-theme","dark-theme","mode","message-click","message-action-click","message-long-press"]}onComponentMounted(){var e,n;this._inboxStyle=i.injectGlobalStyle(w.id,this.getStyles()),this._unreadIndicatorStyle=i.injectGlobalStyle(C.id,C.getStyles(this.theme)),this._header=new f({themeManager:this._themeManager,onFeedTypeChange:e=>{this.setFeedType(e)}}),this._header.build(void 0),this.appendChild(this._header),this._list=new m({themeManager:this._themeManager,canClickListItems:!1,canLongPressListItems:!1,onRefresh:()=>{this.refresh()},onPaginationTrigger:async e=>{var i,n;try{await d.shared.fetchNextPageOfMessages({feedType:e})}catch(o){null==(n=null==(i=t.Courier.shared.client)?void 0:i.options.logger)||n.error("Failed to fetch next page of messages:",o)}},onMessageClick:(e,t)=>{var i;d.shared.clickMessage({message:e}),this.dispatchEvent(new CustomEvent("message-click",{detail:{message:e,index:t},bubbles:!0,composed:!0})),null==(i=this._onMessageClick)||i.call(this,{message:e,index:t})},onMessageActionClick:(e,t,i)=>{var n;this.dispatchEvent(new CustomEvent("message-action-click",{detail:{message:e,action:t,index:i},bubbles:!0,composed:!0})),null==(n=this._onMessageActionClick)||n.call(this,{message:e,action:t,index:i})},onMessageLongPress:(e,t)=>{var i;this.dispatchEvent(new CustomEvent("message-long-press",{detail:{message:e,index:t},bubbles:!0,composed:!0})),null==(i=this._onMessageLongPress)||i.call(this,{message:e,index:t})}}),this.refreshTheme(),this.appendChild(this._list),this._datastoreListener=new y({onError:e=>{var t;null==(t=this._list)||t.setError(e)},onDataSetChange:(e,t)=>{var i;this._currentFeed===t&&(null==(i=this._list)||i.setDataSet(e),this.updateHeader())},onPageAdded:(e,t)=>{var i;this._currentFeed===t&&(null==(i=this._list)||i.addPage(e),this.updateHeader())},onMessageAdd:(e,t,i)=>{var n;this._currentFeed===i&&(null==(n=this._list)||n.addMessage(e,t),this.updateHeader())},onMessageRemove:(e,t,i)=>{var n;this._currentFeed===i&&(null==(n=this._list)||n.removeMessage(t),this.updateHeader())},onMessageUpdate:(e,t,i)=>{var n;this._currentFeed===i&&(null==(n=this._list)||n.updateMessage(e,t),this.updateHeader())},onUnreadCountChange:e=>{this.updateHeader()}}),d.shared.addDataStoreListener(this._datastoreListener),this._themeManager.subscribe((e=>{this.refreshTheme()})),this._authListener=t.Courier.shared.addAuthenticationListener((async({userId:e})=>{e&&await this.refresh()})),(null==(e=t.Courier.shared.client)?void 0:e.options.userId)?this.refresh():null==(n=t.Courier.shared.client)||n.options.logger.error("No user signed in. Please call Courier.shared.signIn(...) to load the inbox.")}onComponentUnmounted(){var e,t,i,n;this._themeManager.cleanup(),null==(e=this._datastoreListener)||e.remove(),null==(t=this._authListener)||t.remove(),null==(i=this._inboxStyle)||i.remove(),null==(n=this._unreadIndicatorStyle)||n.remove()}refreshTheme(){var e;null==(e=this._list)||e.refreshInfoStateThemes(),this._inboxStyle&&(this._inboxStyle.textContent=this.getStyles()),this._unreadIndicatorStyle&&(this._unreadIndicatorStyle.textContent=C.getStyles(this.theme))}getStyles(){return`\n ${w.id} {\n display: flex;\n flex-direction: column;\n width: 100%;\n height: ${this._defaultProps.height};\n }\n\n ${w.id} courier-inbox-list {\n flex: 1;\n overflow-y: auto;\n overflow-x: hidden;\n }\n `}setHeader(e){this._headerFactory=e,this.updateHeader()}removeHeader(){this._headerFactory=null,this.updateHeader()}setLoadingState(e){var t;null==(t=this._list)||t.setLoadingStateFactory(e)}setEmptyState(e){var t;null==(t=this._list)||t.setEmptyStateFactory(e)}setErrorState(e){var t;null==(t=this._list)||t.setErrorStateFactory(e)}setListItem(e){var t;null==(t=this._list)||t.setListItemFactory(e)}setPaginationItem(e){var t;null==(t=this._list)||t.setPaginationItemFactory(e)}onMessageClick(e){var t;this._onMessageClick=e,null==(t=this._list)||t.setCanClickListItems(void 0!==e)}onMessageActionClick(e){this._onMessageActionClick=e}onMessageLongPress(e){var t;this._onMessageLongPress=e,null==(t=this._list)||t.setCanLongPressListItems(void 0!==e)}setFeedType(e){var t;this._currentFeed!==e&&(this._currentFeed=e,null==(t=this._list)||t.setFeedType(e),this.updateHeader(),this.load({canUseCache:!0}))}updateHeader(){var e,t,i,n;const o={feedType:this._currentFeed,unreadCount:d.shared.unreadCount,messageCount:(null==(e=this._list)?void 0:e.messages.length)??0};switch(this._headerFactory){case void 0:null==(t=this._header)||t.render(o);break;case null:null==(i=this._header)||i.build(null);break;default:const e=this._headerFactory(o);null==(n=this._header)||n.build(e)}}async load(e){await d.shared.load(e),await d.shared.listenForUpdates()}refresh(){this.load({canUseCache:!1})}attributeChangedCallback(e,i,n){var o,s,l,r,a,d;if(i!==n)switch(e){case"height":const e=n||this._defaultProps.height;this.style.height=e;break;case"message-click":if(n)try{this._onMessageClick=new Function("props",n)}catch(u){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Failed to parse message-click handler:",u)}else this._onMessageClick=void 0;break;case"message-action-click":if(n)try{this._onMessageActionClick=new Function("props",n)}catch(u){null==(r=null==(l=t.Courier.shared.client)?void 0:l.options.logger)||r.error("Failed to parse message-action-click handler:",u)}else this._onMessageActionClick=void 0;break;case"message-long-press":if(n)try{this._onMessageLongPress=new Function("props",n)}catch(u){null==(d=null==(a=t.Courier.shared.client)?void 0:a.options.logger)||d.error("Failed to parse message-long-press handler:",u)}else this._onMessageLongPress=void 0;break;case"light-theme":n&&this.setLightTheme(JSON.parse(n));break;case"dark-theme":n&&this.setDarkTheme(JSON.parse(n));break;case"mode":this._themeManager.setMode(n)}}}i.registerElement(w);class E extends i.CourierFactoryElement{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_style"),o(this,"_container"),o(this,"_triggerButton"),o(this,"_unreadBadge"),this._themeSubscription=e.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-menu-button"}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this._style=i.injectGlobalStyle(E.id,E.getStyles(this.theme))}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}defaultElement(){return this._container=document.createElement("div"),this._container.className="menu-button-container",this._triggerButton=new i.CourierIconButton(i.CourierIconSVGs.inbox),this._unreadBadge=document.createElement("div"),this._unreadBadge.className="unread-badge",this._unreadBadge.style.display="none",this._container.appendChild(this._triggerButton),this._container.appendChild(this._unreadBadge),this.appendChild(this._container),this.refreshTheme(),this._container}static getStyles(e){var t,i,n,o,s,l,r,a,d,u,h,c;return`\n ${E.id} .menu-button-container {\n position: relative;\n display: inline-block;\n }\n \n ${E.id} .unread-badge {\n position: absolute;\n top: 2px;\n right: 2px;\n pointer-events: none;\n width: ${(null==(n=null==(i=null==(t=e.popup)?void 0:t.button)?void 0:i.unreadDotIndicator)?void 0:n.height)??"8px"};\n height: ${(null==(l=null==(s=null==(o=e.popup)?void 0:o.button)?void 0:s.unreadDotIndicator)?void 0:l.width)??"8px"};\n background: ${(null==(d=null==(a=null==(r=e.popup)?void 0:r.button)?void 0:a.unreadDotIndicator)?void 0:d.backgroundColor)??"red"};\n border-radius: ${(null==(c=null==(h=null==(u=e.popup)?void 0:u.button)?void 0:h.unreadDotIndicator)?void 0:c.borderRadius)??"50%"};\n display: none;\n z-index: 1;\n }\n `}onUnreadCountChange(e){this._unreadBadge&&(this._unreadBadge.style.display=e>0?"block":"none"),this.refreshTheme()}refreshTheme(){var e,t,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,C,x,f,y;null==(s=this._triggerButton)||s.updateIconColor((null==(o=null==(n=null==(t=null==(e=this.theme)?void 0:e.popup)?void 0:t.button)?void 0:n.icon)?void 0:o.color)??i.CourierColors.black[500]),null==(u=this._triggerButton)||u.updateIconSVG((null==(d=null==(a=null==(r=null==(l=this.theme)?void 0:l.popup)?void 0:r.button)?void 0:a.icon)?void 0:d.svg)??i.CourierIconSVGs.inbox),null==(p=this._triggerButton)||p.updateBackgroundColor((null==(v=null==(c=null==(h=this.theme)?void 0:h.popup)?void 0:c.button)?void 0:v.backgroundColor)??"transparent"),null==(_=this._triggerButton)||_.updateHoverBackgroundColor((null==(b=null==(m=null==(g=this.theme)?void 0:g.popup)?void 0:m.button)?void 0:b.hoverBackgroundColor)??i.CourierColors.black[50010]),null==(y=this._triggerButton)||y.updateActiveBackgroundColor((null==(f=null==(x=null==(C=this.theme)?void 0:C.popup)?void 0:x.button)?void 0:f.activeBackgroundColor)??i.CourierColors.black[50020])}}i.registerElement(E);class D extends i.CourierBaseElement{constructor(){super(),o(this,"_width","440px"),o(this,"_height","440px"),o(this,"_popupAlignment","top-left"),o(this,"_top"),o(this,"_right"),o(this,"_bottom"),o(this,"_left"),o(this,"_themeManager",new M(S)),o(this,"_triggerButton"),o(this,"_popup"),o(this,"_inbox"),o(this,"_style"),o(this,"_datastoreListener"),o(this,"_popupMenuButtonFactory"),o(this,"handleOutsideClick",(e=>{if(!this._popup)return;const t=["courier-inbox-option-menu"];e.composedPath().some((e=>e instanceof HTMLElement&&(!(e!==this._popup&&!this._popup.contains(e))||t.some((t=>e.matches(t))))))||(this._popup.style.display="none")})),this._themeManager.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-popup-menu"}get theme(){return this._themeManager.getTheme()}get currentFeed(){var e;return(null==(e=this._inbox)?void 0:e.currentFeed)??"inbox"}setLightTheme(e){this._themeManager.setLightTheme(e)}setDarkTheme(e){this._themeManager.setDarkTheme(e)}setMode(e){this._themeManager.setMode(e)}static get observedAttributes(){return["popup-alignment","message-click","message-action-click","message-long-press","popup-width","popup-height","top","right","bottom","left","light-theme","dark-theme","mode"]}onComponentMounted(){this._style=i.injectGlobalStyle(D.id,D.getStyles(this.theme,this._width,this._height)),this._triggerButton=new E(this._themeManager),this._triggerButton.build(void 0),this._popup=document.createElement("div"),this._popup.className="popup",this._inbox=new w(this._themeManager),this._inbox.setAttribute("height","100%"),this.refreshTheme(),this.appendChild(this._triggerButton),this.appendChild(this._popup),this._popup.appendChild(this._inbox),this._triggerButton.addEventListener("click",this.togglePopup.bind(this)),document.addEventListener("click",this.handleOutsideClick.bind(this)),this.updatePopupPosition(),this._datastoreListener=new y(this),d.shared.addDataStoreListener(this._datastoreListener)}onComponentUnmounted(){var e,t;null==(e=this._style)||e.remove(),null==(t=this._datastoreListener)||t.remove(),this._themeManager.cleanup()}refreshTheme(){this._style&&(this._style.textContent=D.getStyles(this.theme,this._width,this._height))}static getStyles(e,t,i){var n,o,s,l,r,a,d,u;return`\n ${D.id} {\n display: inline-block;\n position: relative;\n }\n\n ${D.id} .menu-button-container {\n position: relative;\n display: inline-block;\n }\n\n ${D.id} .popup {\n display: none;\n position: absolute;\n background: ${(null==(o=null==(n=e.popup)?void 0:n.window)?void 0:o.backgroundColor)??"red"};\n border-radius: ${(null==(l=null==(s=e.popup)?void 0:s.window)?void 0:l.borderRadius)??"8px"};\n border: ${(null==(a=null==(r=e.popup)?void 0:r.window)?void 0:a.border)??"1px solid red"};\n box-shadow: ${(null==(u=null==(d=e.popup)?void 0:d.window)?void 0:u.shadow)??"0px 8px 16px -4px red"};\n z-index: 1000;\n width: ${t};\n height: ${i};\n overflow: hidden;\n transform: translateZ(0);\n will-change: transform;\n }\n \n ${D.id} #unread-badge {\n position: absolute;\n top: -8px;\n left: 50%;\n pointer-events: none;\n }\n\n ${D.id} courier-inbox {\n height: 100%;\n }\n `}attributeChangedCallback(e,t,i){switch(e){case"popup-alignment":this.isValidPosition(i)&&(this._popupAlignment=i,this.updatePopupPosition());break;case"popup-width":this._width=i,this.setSize(i,this._height);break;case"popup-height":this._height=i,this.setSize(this._width,i);break;case"top":this._top=i,this.updatePopupPosition();break;case"right":this._right=i,this.updatePopupPosition();break;case"bottom":this._bottom=i,this.updatePopupPosition();break;case"left":this._left=i,this.updatePopupPosition();break;case"light-theme":i&&this.setLightTheme(JSON.parse(i));break;case"dark-theme":i&&this.setDarkTheme(JSON.parse(i));break;case"mode":this._themeManager.setMode(i)}}onUnreadCountChange(e){this.render()}onMessageClick(e){var t;null==(t=this._inbox)||t.onMessageClick((t=>{e&&e(t),this.closePopup()}))}onMessageActionClick(e){var t;null==(t=this._inbox)||t.onMessageActionClick((t=>{e&&e(t),this.closePopup()}))}onMessageLongPress(e){var t;null==(t=this._inbox)||t.onMessageLongPress((t=>{e&&e(t),this.closePopup()}))}isValidPosition(e){return["top-right","top-left","top-center","bottom-right","bottom-left","bottom-center","center-right","center-left","center-center"].includes(e)}updatePopupPosition(){if(this._popup)switch(this._popup.style.top="",this._popup.style.bottom="",this._popup.style.left="",this._popup.style.right="",this._popup.style.margin="",this._popup.style.transform="",this._popupAlignment){case"top-right":this._popup.style.top=this._top??"40px",this._popup.style.right=this._right??"0px";break;case"top-left":this._popup.style.top=this._top??"40px",this._popup.style.left=this._left??"0px";break;case"top-center":this._popup.style.top=this._top??"40px",this._popup.style.left="50%",this._popup.style.transform="translateX(-50%)";break;case"bottom-right":this._popup.style.bottom=this._bottom??"40px",this._popup.style.right=this._right??"0px";break;case"bottom-left":this._popup.style.bottom=this._bottom??"40px",this._popup.style.left=this._left??"0px";break;case"bottom-center":this._popup.style.bottom=this._bottom??"40px",this._popup.style.left="50%",this._popup.style.transform="translateX(-50%)";break;case"center-right":this._popup.style.top="50%",this._popup.style.right=this._right??"40px",this._popup.style.transform="translateY(-50%)";break;case"center-left":this._popup.style.top="50%",this._popup.style.left=this._left??"40px",this._popup.style.transform="translateY(-50%)";break;case"center-center":this._popup.style.top="50%",this._popup.style.left="50%",this._popup.style.transform="translate(-50%, -50%)"}}togglePopup(e){if(e.stopPropagation(),!this._popup)return;const t="block"===this._popup.style.display;this._popup.style.display=t?"none":"block"}closePopup(){this._popup&&(this._popup.style.display="none")}setContent(e){this._inbox&&(this._inbox.innerHTML="",this._inbox.appendChild(e))}setSize(e,t){this._width=e,this._height=t,this._popup&&(this._popup.style.width=e,this._popup.style.height=t)}setPosition(e){var i,n;this.isValidPosition(e)?(this._popupAlignment=e,this.updatePopupPosition()):null==(n=null==(i=t.Courier.shared.client)?void 0:i.options.logger)||n.error(`Invalid position: ${e}`)}setFeedType(e){var t;null==(t=this._inbox)||t.setFeedType(e)}setHeader(e){var t;null==(t=this._inbox)||t.setHeader(e)}removeHeader(){var e;null==(e=this._inbox)||e.removeHeader()}setLoadingState(e){var t;null==(t=this._inbox)||t.setLoadingState(e)}setEmptyState(e){var t;null==(t=this._inbox)||t.setEmptyState(e)}setErrorState(e){var t;null==(t=this._inbox)||t.setErrorState(e)}setListItem(e){var t;null==(t=this._inbox)||t.setListItem(e)}setPaginationItem(e){var t;null==(t=this._inbox)||t.setPaginationItem(e)}setMenuButton(e){this._popupMenuButtonFactory=e,this.render()}render(){const e=d.shared.unreadCount;if(this._triggerButton)switch(this._popupMenuButtonFactory){case void 0:case null:this._triggerButton.build(void 0),this._triggerButton.onUnreadCountChange(e);break;default:const t=this._popupMenuButtonFactory({unreadCount:e});this._triggerButton.build(t)}}}i.registerElement(D);t.Courier.shared.courierUserAgentName="courier-ui-inbox",t.Courier.shared.courierUserAgentVersion="1.2.1",Object.defineProperty(e,"Courier",{enumerable:!0,get:()=>t.Courier}),e.CourierInbox=w,e.CourierInboxDataStoreListener=y,e.CourierInboxDatastore=d,e.CourierInboxDatastoreEvents=class{onDataSetChange(e,t){}onPageAdded(e,t){}onUnreadCountChange(e){}onMessageAdd(e,t,i){}onMessageRemove(e,t,i){}onMessageUpdate(e,t,i){}onError(e){}},e.CourierInboxHeader=f,e.CourierInboxListItem=u,e.CourierInboxPopupMenu=D,e.CourierInboxThemeManager=M,e.archiveMessage=function(e){return d.shared.archiveMessage({message:e})},e.clickMessage=function(e){return d.shared.clickMessage({message:e})},e.defaultDarkTheme=k,e.defaultLightTheme=S,e.markAsRead=function(e){return d.shared.readMessage({message:e})},e.markAsUnread=function(e){return d.shared.unreadMessage({message:e})},e.mergeTheme=I,e.openMessage=g,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@trycourier/courier-js"),require("@trycourier/courier-ui-core")):"function"==typeof define&&define.amd?define(["exports","@trycourier/courier-js","@trycourier/courier-ui-core"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CourierUIInbox={},e.CourierJS,e.CourierUICore)}(this,(function(e,t,i){"use strict";var n=Object.defineProperty,o=(e,t,i)=>((e,t,i)=>t in e?n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,"symbol"!=typeof t?t+"":t,i);function s(e){const t={...e};return e.actions&&(t.actions=e.actions.map((e=>function(e){const t={...e};e.data&&(t.data=JSON.parse(JSON.stringify(e.data)));return t}(e)))),e.data&&(t.data=JSON.parse(JSON.stringify(e.data))),e.tags&&(t.tags=[...e.tags]),e.trackingIds&&(t.trackingIds={...e.trackingIds}),t}function l(e){if(e)return{...e,messages:e.messages.map((e=>s(e)))}}class r extends i.CourierBaseElement{constructor(e){super(),o(this,"_theme"),o(this,"_options",[]),this._theme=e}static get id(){return"courier-inbox-list-item-menu"}onComponentMounted(){const e=document.createElement("ul");e.className="menu",this.appendChild(e)}static getStyles(e){var t,i,n;const o=null==(n=null==(i=null==(t=e.inbox)?void 0:t.list)?void 0:i.item)?void 0:n.menu,s=null==o?void 0:o.animation,l=(null==s?void 0:s.initialTransform)??"translate3d(0, 0, 0)",a=(null==s?void 0:s.visibleTransform)??"translate3d(0, 0, 0)";return`\n ${r.id} {\n display: none;\n position: absolute;\n background: ${(null==o?void 0:o.backgroundColor)??"red"};\n border: ${(null==o?void 0:o.border)??"1px solid red"};\n border-radius: ${(null==o?void 0:o.borderRadius)??"0px"};\n box-shadow: ${(null==o?void 0:o.shadow)??"0 2px 8px red"};\n user-select: none;\n opacity: 0;\n pointer-events: none;\n transition: ${(null==s?void 0:s.transition)??"all 0.2s ease"};\n overflow: hidden;\n transform: ${l};\n will-change: transform, opacity;\n }\n\n ${r.id}.visible {\n opacity: 1;\n pointer-events: auto;\n transform: ${a};\n }\n\n ${r.id} ul.menu {\n list-style: none;\n margin: 0;\n padding: 0;\n display: flex;\n flex-direction: row;\n }\n\n ${r.id} li.menu-item {\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n border-bottom: none;\n background: transparent;\n touch-action: none;\n }\n `}setOptions(e){this._options=e,this.renderMenu()}renderMenu(){var e,t,n;const o=this.querySelector("ul.menu");if(!o)return;o.innerHTML="";const s=null==(n=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:n.menu,l=e=>{e.stopPropagation(),"touchstart"!==e.type&&"mousedown"!==e.type||e.preventDefault()};this._options.forEach((e=>{var t,n,r;const a=new i.CourierIconButton(e.icon.svg,e.icon.color,null==s?void 0:s.backgroundColor,null==(t=null==s?void 0:s.item)?void 0:t.hoverBackgroundColor,null==(n=null==s?void 0:s.item)?void 0:n.activeBackgroundColor,null==(r=null==s?void 0:s.item)?void 0:r.borderRadius),d=t=>{t.stopPropagation(),e.onClick()};a.addEventListener("click",d),a.addEventListener("touchstart",l,{passive:!1}),a.addEventListener("touchend",d,{passive:!0}),a.addEventListener("touchmove",(e=>{e.stopPropagation()}),{passive:!0}),a.addEventListener("mousedown",l),a.addEventListener("mouseup",l),o.appendChild(a)}))}show(){this.style.display="block",this.classList.remove("visible"),requestAnimationFrame((()=>{requestAnimationFrame((()=>{this.classList.add("visible")}))}))}hide(){this.classList.remove("visible");const e=t=>{t.target===this&&(this.classList.contains("visible")||(this.style.display="none",this.removeEventListener("transitionend",e)))};this.addEventListener("transitionend",e)}}i.registerElement(r);class a{constructor(e,t){o(this,"_id"),o(this,"_messages",[]),o(this,"_firstFetchComplete",!1),o(this,"_hasNextPage",!1),o(this,"_lastPaginationCursor"),o(this,"_filter"),o(this,"_datastoreListeners",[]),o(this,"_totalUnreadCount",0),this._id=e,this._filter={tags:t.tags?[...t.tags]:void 0,archived:t.archived||!1,status:t.status}}get totalUnreadCount(){return this._totalUnreadCount}set totalUnreadCount(e){this._totalUnreadCount=e>0?e:0}setUnreadCount(e){this.totalUnreadCount=e,this._datastoreListeners.forEach((t=>{var i,n,o,s;null==(n=(i=t.events).onUnreadCountChange)||n.call(i,e,this._id),null==(s=(o=t.events).onTotalUnreadCountChange)||s.call(o,u.shared.totalUnreadCount)}))}getFilter(){return{tags:this._filter.tags,archived:this._filter.archived,status:this._filter.status}}addMessage(e,t=0){const i=s(e);return!!this.messageQualifiesForDataset(i)&&(this._messages.splice(t,0,i),i.read||(this.totalUnreadCount+=1),this._datastoreListeners.forEach((e=>{var n,o,s,l,r,a;null==(o=(n=e.events).onMessageAdd)||o.call(n,i,t,this._id),null==(l=(s=e.events).onUnreadCountChange)||l.call(s,this.totalUnreadCount,this._id),null==(a=(r=e.events).onTotalUnreadCountChange)||a.call(r,u.shared.totalUnreadCount)})),!0)}updateWithMessageChange(e,t){const i=this.indexOfMessage(t),n=this._messages[i],o=s(t);if(n&&(r=o,(l=n).archived===r.archived&&l.read===r.read&&l.opened===r.opened))return!0;var l,r;if(n){if(this.messageQualifiesForDataset(o)){const e=this.calculateUnreadChange(n,o);return this._messages.splice(i,1,o),this.totalUnreadCount+=e,this._datastoreListeners.forEach((e=>{var t,n,s,l,r,a;null==(n=(t=e.events).onMessageUpdate)||n.call(t,o,i,this._id),null==(l=(s=e.events).onUnreadCountChange)||l.call(s,this.totalUnreadCount,this._id),null==(a=(r=e.events).onTotalUnreadCountChange)||a.call(r,u.shared.totalUnreadCount)})),!0}return this.removeMessage(n),!1}if(this.messageQualifiesForDataset(t)){const i=this.findInsertIndex(t);this._messages.splice(i,0,s(t));const n=this.messageQualifiesForDataset(e)?this.calculateUnreadChange(e,t):t.read?0:1;return this.totalUnreadCount+=n,this._datastoreListeners.forEach((e=>{var n,o,s,l,r,a;null==(o=(n=e.events).onMessageAdd)||o.call(n,t,i,this._id),null==(l=(s=e.events).onUnreadCountChange)||l.call(s,this.totalUnreadCount,this._id),null==(a=(r=e.events).onTotalUnreadCountChange)||a.call(r,u.shared.totalUnreadCount)})),!0}return this.messageQualifiesForDataset(e)&&(this.totalUnreadCount+=this.calculateUnreadChange(e,t),this._datastoreListeners.forEach((e=>{var t,n,s,l,r,a;null==(n=(t=e.events).onMessageUpdate)||n.call(t,o,i,this._id),null==(l=(s=e.events).onUnreadCountChange)||l.call(s,this.totalUnreadCount,this._id),null==(a=(r=e.events).onTotalUnreadCountChange)||a.call(r,u.shared.totalUnreadCount)}))),!1}calculateUnreadChange(e,t){return e.read&&!t.read?1:!e.read&&t.read?-1:0}removeMessage(e){const t=this.indexOfMessage(e);return t>-1&&(this._messages.splice(t,1),e.read||(this.totalUnreadCount-=1),this._datastoreListeners.forEach((i=>{var n,o,s,l,r,a;null==(o=(n=i.events).onMessageRemove)||o.call(n,e,t,this._id),null==(l=(s=i.events).onUnreadCountChange)||l.call(s,this.totalUnreadCount,this._id),null==(a=(r=i.events).onTotalUnreadCountChange)||a.call(r,u.shared.totalUnreadCount)})),!0)}getMessage(e){return this._messages.find((t=>t.messageId===e))}async loadDataset(e){if(e&&this._firstFetchComplete)return void this._datastoreListeners.forEach((e=>{var t,i,n,o,s,l;null==(i=(t=e.events).onDataSetChange)||i.call(t,this.toInboxDataset()),null==(o=(n=e.events).onUnreadCountChange)||o.call(n,this.totalUnreadCount,this._id),null==(l=(s=e.events).onTotalUnreadCountChange)||l.call(s,u.shared.totalUnreadCount)}));const t=await this.fetchMessages();this._messages=[...t.messages],this.totalUnreadCount=t.unreadCount,this._hasNextPage=t.canPaginate,this._lastPaginationCursor=t.paginationCursor??void 0,this._firstFetchComplete=!0,this._datastoreListeners.forEach((e=>{var t,i,n,o,s,l;null==(i=(t=e.events).onDataSetChange)||i.call(t,this.toInboxDataset()),null==(o=(n=e.events).onUnreadCountChange)||o.call(n,this.totalUnreadCount,this._id),null==(l=(s=e.events).onTotalUnreadCountChange)||l.call(s,u.shared.totalUnreadCount)}))}async fetchNextPageOfMessages(){if(!this._hasNextPage)return null;const e=await this.fetchMessages(this._lastPaginationCursor);return this._messages=[...this._messages,...e.messages],this._hasNextPage=e.canPaginate,this._lastPaginationCursor=e.paginationCursor??void 0,this._firstFetchComplete=!0,this._datastoreListeners.forEach((t=>{var i,n,o,s,l,r,a,d;null==(n=(i=t.events).onDataSetChange)||n.call(i,this.toInboxDataset()),null==(s=(o=t.events).onUnreadCountChange)||s.call(o,this.totalUnreadCount,this._id),null==(r=(l=t.events).onPageAdded)||r.call(l,e),null==(d=(a=t.events).onTotalUnreadCountChange)||d.call(a,u.shared.totalUnreadCount)})),e}addDatastoreListener(e){this._datastoreListeners.push(e)}removeDatastoreListener(e){const t=this._datastoreListeners.indexOf(e);t>-1&&this._datastoreListeners.splice(t,1)}toInboxDataset(){return{id:this._id,messages:[...this._messages],unreadCount:this.totalUnreadCount,canPaginate:this._hasNextPage,paginationCursor:this._lastPaginationCursor??null}}async fetchMessages(e){var i,n,o,s,l,r,a,d,u;const h=t.Courier.shared.client;if(!(null==h?void 0:h.options.userId))throw new Error("User is not signed in");const c=await h.inbox.getMessages({paginationLimit:t.Courier.shared.paginationLimit,startCursor:e,filter:this.getFilter()});return{id:this._id,messages:[...(null==(n=null==(i=c.data)?void 0:i.messages)?void 0:n.nodes)??[]],unreadCount:(null==(o=c.data)?void 0:o.unreadCount)??0,canPaginate:(null==(r=null==(l=null==(s=c.data)?void 0:s.messages)?void 0:l.pageInfo)?void 0:r.hasNextPage)??!1,paginationCursor:(null==(u=null==(d=null==(a=c.data)?void 0:a.messages)?void 0:d.pageInfo)?void 0:u.startCursor)??null}}indexOfMessage(e){return this._messages.findIndex((t=>t.messageId===e.messageId))}findInsertIndex(e){const t=this._messages;for(let i=0;i<t.length;i++){const n=t[i];if(n.created&&e.created&&n.created<e.created)return i}return t.length}messageQualifiesForDataset(e){if(e.archived&&!this._filter.archived||!e.archived&&this._filter.archived)return!1;if(e.read&&"unread"===this._filter.status||!e.read&&"read"===this._filter.status)return!1;if(this._filter.tags&&!e.tags)return!1;if(this._filter.tags&&e.tags){for(const t of this._filter.tags)if(e.tags.includes(t))return!0;return!1}return!0}restoreFromSnapshot(e){this._messages=e.messages.map((e=>s(e))),this.totalUnreadCount=e.unreadCount,this._hasNextPage=e.canPaginate,this._lastPaginationCursor=e.paginationCursor??void 0,this._datastoreListeners.forEach((t=>{var i,n,o,s,l,r;null==(n=(i=t.events).onDataSetChange)||n.call(i,e),null==(s=(o=t.events).onUnreadCountChange)||s.call(o,this.totalUnreadCount,this._id),null==(r=(l=t.events).onTotalUnreadCountChange)||r.call(l,u.shared.totalUnreadCount)}))}}const d=class e{constructor(){o(this,"_datasets",new Map),o(this,"_listeners",[]),o(this,"_removeMessageEventListener"),o(this,"_globalMessages",new Map)}registerFeeds(e){const t=new Map(e.flatMap((e=>e.tabs)).map((e=>[e.datasetId,e.filter])));this.createDatasetsFromFilters(t)}createDatasetsFromFilters(e){this.clearDatasets();for(let[t,i]of e){const e=new a(t,i);for(let t of this._listeners)e.addDatastoreListener(t);this._datasets.set(t,e)}}addMessage(e){this._globalMessages.set(e.messageId,e);for(let t of this._datasets.values())t.addMessage(e)}updateDatasetsWithMessageChange(e,t){for(let i of this._datasets.values())i.updateWithMessageChange(e,t)}async listenForUpdates(){var e,i,n,o,s,l,r,a,d,u,h;const c=null==(e=t.Courier.shared.client)?void 0:e.inbox.socket;if(c)try{if(this._removeMessageEventListener&&this._removeMessageEventListener(),this._removeMessageEventListener=c.addMessageEventListener((e=>this.handleMessageEvent(e))),c.isConnecting||c.isOpen)return void(null==(l=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||l.info(`Inbox socket already connecting or open for client ID: [${null==(s=t.Courier.shared.client)?void 0:s.options.connectionId}]`));await c.connect(),null==(d=null==(r=t.Courier.shared.client)?void 0:r.options.logger)||d.info(`Inbox socket connected for client ID: [${null==(a=t.Courier.shared.client)?void 0:a.options.connectionId}]`)}catch(v){null==(h=null==(u=t.Courier.shared.client)?void 0:u.options.logger)||h.error("Failed to connect socket:",v)}else null==(n=null==(i=t.Courier.shared.client)?void 0:i.options.logger)||n.info("CourierInbox socket not available")}async loadUnreadCountsForTabs(e){const i=t.Courier.shared.client;if(!i)return;const n={};for(const t of e){const e=this._datasets.get(t);e&&(n[t]=e.getFilter())}if(0===Object.keys(n).length)return;const o=await i.inbox.getUnreadCounts(n);for(const[t,s]of Object.entries(o)){const e=this._datasets.get(t);e&&e.setUnreadCount(s)}}addDataStoreListener(e){this._listeners.push(e);for(let t of this._datasets.values())t.addDatastoreListener(e)}removeDataStoreListener(e){this._listeners=this._listeners.filter((t=>t!==e));for(let t of this._datasets.values())t.removeDatastoreListener(e)}async readMessage({message:i}){if(i.read)return;const n=this._globalMessages.get(i.messageId);n&&await this.executeWithRollback((async()=>{var o;const l=s(n);l.read=e.getISONow(),this._globalMessages.set(i.messageId,l),this.updateDatasetsWithMessageChange(n,l),await(null==(o=t.Courier.shared.client)?void 0:o.inbox.read({messageId:i.messageId}))}))}async unreadMessage({message:e}){if(!e.read)return;const i=this._globalMessages.get(e.messageId);i&&await this.executeWithRollback((async()=>{var n;const o=s(i);o.read=void 0,this._globalMessages.set(e.messageId,o),this.updateDatasetsWithMessageChange(i,o),await(null==(n=t.Courier.shared.client)?void 0:n.inbox.unread({messageId:e.messageId}))}))}async openMessage({message:i}){if(i.opened)return;const n=this._globalMessages.get(i.messageId);n&&await this.executeWithRollback((async()=>{var o;const l=s(n);l.opened=e.getISONow(),this._globalMessages.set(i.messageId,l),this.updateDatasetsWithMessageChange(n,l),await(null==(o=t.Courier.shared.client)?void 0:o.inbox.open({messageId:i.messageId}))}))}async unarchiveMessage({message:e}){if(!e.archived)return;const i=this._globalMessages.get(e.messageId);i&&await this.executeWithRollback((async()=>{var n;const o=s(i);o.archived=void 0,this._globalMessages.set(e.messageId,o),this.updateDatasetsWithMessageChange(i,o),await(null==(n=t.Courier.shared.client)?void 0:n.inbox.unarchive({messageId:e.messageId}))}))}async archiveMessage({message:i}){if(i.archived)return;const n=this._globalMessages.get(i.messageId);n&&await this.executeWithRollback((async()=>{var o;const l=s(n);l.archived=e.getISONow(),this._globalMessages.set(i.messageId,l),this.updateDatasetsWithMessageChange(n,l),await(null==(o=t.Courier.shared.client)?void 0:o.inbox.archive({messageId:i.messageId}))}))}async clickMessage({message:i}){var n,o,s,l;if(null==(n=i.trackingIds)?void 0:n.clickTrackingId)try{await(null==(o=t.Courier.shared.client)?void 0:o.inbox.click({messageId:i.messageId,trackingId:i.trackingIds.clickTrackingId}))}catch(r){null==(l=null==(s=t.Courier.shared.client)?void 0:s.options.logger)||l.error(`[${e.TAG}] Error clicking message:`,r),this._listeners.forEach((e=>{var t,i;null==(i=(t=e.events).onError)||i.call(t,r)}))}}async archiveAllMessages(){await this.executeWithRollback((async()=>{var i;const n=e.getISONow();for(const[e,t]of this._globalMessages.entries())if(!t.archived){const i=s(t);i.archived=n,this._globalMessages.set(e,i),this.updateDatasetsWithMessageChange(t,i)}await(null==(i=t.Courier.shared.client)?void 0:i.inbox.archiveAll())}))}async readAllMessages(){await this.executeWithRollback((async()=>{var i;const n=e.getISONow();for(const[e,t]of this._globalMessages.entries())if(!t.read){const i=s(t);i.read=n,this._globalMessages.set(e,i),this.updateDatasetsWithMessageChange(t,i)}await(null==(i=t.Courier.shared.client)?void 0:i.inbox.readAll())}))}async archiveReadMessages(){await this.executeWithRollback((async()=>{var i;const n=e.getISONow();for(const[e,t]of this._globalMessages.entries())if(t.read&&!t.archived){const i=s(t);i.archived=n,this._globalMessages.set(e,i),this.updateDatasetsWithMessageChange(t,i)}await(null==(i=t.Courier.shared.client)?void 0:i.inbox.archiveRead())}))}async load(e){const i=t.Courier.shared.client;if(!(null==i?void 0:i.options.userId))throw new Error("[Datastore] User is not signed in");const n=(null==e?void 0:e.canUseCache)??!0;if(null==e?void 0:e.datasetIds){const t=e.datasetIds.flatMap((e=>{const t=this._datasets.get(e);return t?[t]:[]}));return await this.loadDatasets({canUseCache:n,datasets:t})}return await this.loadDatasets({canUseCache:n,datasets:Array.from(this._datasets.values())})}async loadDatasets(e){await Promise.all(e.datasets.map((async t=>{await t.loadDataset(e.canUseCache),this.syncDatasetMessagesToGlobalStore(t)})))}syncDatasetMessagesToGlobalStore(e){const t=e.toInboxDataset();for(const i of t.messages)this._globalMessages.has(i.messageId)||this._globalMessages.set(i.messageId,i)}async fetchNextPageOfMessages(i){var n;const o=t.Courier.shared.client;if(!(null==o?void 0:o.options.userId))throw new Error("User is not signed in");let s;if(i.feedType&&!i.datasetId)null==(n=t.Courier.shared.client)||n.options.logger.warn(`[${e.TAG}] feedType is deprecated andwill be removed in the next major version. Please update callers to use datasetIds.`),s=i.feedType;else{if(!i.datasetId)throw new Error(`[${e.TAG}] Exactly one of feedType or datasetId is required to call fetchNextPageOfMessages.`);s=i.datasetId}const l=this._datasets.get(s);if(!l)throw new Error(`[${e.TAG}] Attempted to fetch next page of messages for dataset ${s}, but the dataset does not exist.`);return this.fetchNextPageForDataset({dataset:l})}getDatasetById(e){var t;return null==(t=this._datasets.get(e))?void 0:t.toInboxDataset()}getDatasets(){const e={};for(const[t,i]of this._datasets.entries())e[t]=i.toInboxDataset();return e}get totalUnreadCount(){let e=0;for(let t of this._datasets.values())e+=t.totalUnreadCount;return e}async fetchNextPageForDataset(e){const t=await e.dataset.fetchNextPageOfMessages();return t&&this.syncDatasetMessagesToGlobalStore(e.dataset),t}handleMessageEvent(i){var n,o;const s=i.event;if(s===t.InboxMessageEvent.NewMessage){const e=i.data;this._globalMessages.set(e.messageId,e);for(let t of this._datasets.values())t.addMessage(e);return}if(s===t.InboxMessageEvent.ArchiveAll||s===t.InboxMessageEvent.ArchiveRead||s===t.InboxMessageEvent.MarkAllRead)return void this.updateAllMessages(s);const l=i.messageId;l?this.updateMessage(l,s):null==(o=null==(n=t.Courier.shared.client)?void 0:n.options.logger)||o.warn(`[${e.TAG}] Received unexpected event: ${s}`)}updateAllMessages(i){const n=e.getISONow();for(const[e,o]of this._globalMessages.entries()){let l=null;switch(i){case t.InboxMessageEvent.MarkAllRead:o.read||(l=s(o),l.read=n);break;case t.InboxMessageEvent.ArchiveAll:o.archived||(l=s(o),l.archived=n);break;case t.InboxMessageEvent.ArchiveRead:o.read&&!o.archived&&(l=s(o),l.archived=n)}l&&(this._globalMessages.set(e,l),this.updateDatasetsWithMessageChange(o,l))}}updateMessage(i,n){const o=this._globalMessages.get(i);if(!o)return;let l;switch(n){case t.InboxMessageEvent.Archive:l=s(o),l.archived=e.getISONow();break;case t.InboxMessageEvent.Opened:l=s(o),l.opened=e.getISONow();break;case t.InboxMessageEvent.Read:l=s(o),l.read=e.getISONow();break;case t.InboxMessageEvent.Unarchive:l=s(o),l.archived=void 0;break;case t.InboxMessageEvent.Unread:l=s(o),l.read=void 0;break;case t.InboxMessageEvent.Clicked:case t.InboxMessageEvent.Unopened:default:return}this._globalMessages.set(i,l),this.updateDatasetsWithMessageChange(o,l)}clearDatasets(){this._datasets.clear(),this._globalMessages.clear()}static getISONow(){return(new Date).toISOString()}createDatastoreSnapshot(){const e=[];for(const[i,n]of this._datasets.entries()){const t=n.toInboxDataset();if(t){const n=l(t);n&&e.push({id:i,dataset:n})}}const t=new Map;for(const[i,n]of this._globalMessages.entries())t.set(i,s(n));return{datasets:e,globalMessages:t}}restoreDatastoreSnapshot(e){this._globalMessages.clear();for(const[t,i]of e.globalMessages.entries())this._globalMessages.set(t,s(i));for(const t of e.datasets){const e=this._datasets.get(t.id);e&&e.restoreFromSnapshot(t.dataset)}}async executeWithRollback(i){var n,o;const s=this.createDatastoreSnapshot();try{return await i()}catch(l){null==(o=null==(n=t.Courier.shared.client)?void 0:n.options.logger)||o.error(`[${e.TAG}] Error during operation:`,l),this.restoreDatastoreSnapshot(s),this._listeners.forEach((e=>{var t,i;null==(i=(t=e.events).onError)||i.call(t,l)}))}}static get shared(){return e.instance||(e.instance=new e),e.instance}};o(d,"TAG","CourierInboxDatastore"),o(d,"instance");let u=d;class h extends i.CourierBaseElement{constructor(e,t,i,n){super(),o(this,"_themeManager"),o(this,"_theme"),o(this,"_message",null),o(this,"_isMobile",!1),o(this,"_canClick",!1),o(this,"_listItemActions",B.defaultListItemActions()),o(this,"_titleElement"),o(this,"_subtitleElement"),o(this,"_timeElement"),o(this,"_menu"),o(this,"_unreadIndicator"),o(this,"_actionsContainer"),o(this,"_longPressTimeout",null),o(this,"_isLongPress",!1),o(this,"_observer"),o(this,"onItemClick",null),o(this,"onItemLongPress",null),o(this,"onItemActionClick",null),o(this,"onItemVisible",null),this._canClick=t,this._themeManager=e,this._theme=e.getTheme(),this._isMobile="ontouchstart"in window,n&&(this._listItemActions=n),this.render(),this._setupIntersectionObserver()}static get id(){return"courier-inbox-list-item"}render(){const e=document.createElement("div");e.className="content-container",this._titleElement=document.createElement("p"),this._titleElement.className="title",this._subtitleElement=document.createElement("p"),this._subtitleElement.className="subtitle",this._actionsContainer=document.createElement("div"),this._actionsContainer.className="actions-container",e.appendChild(this._titleElement),e.appendChild(this._subtitleElement),e.appendChild(this._actionsContainer),this._timeElement=document.createElement("p"),this._timeElement.className="time",this._unreadIndicator=document.createElement("div"),this._unreadIndicator.className="unread-indicator",this._menu=new r(this._theme),this._menu.setOptions(this._getMenuOptions()),this.append(this._unreadIndicator,e,this._timeElement,this._menu);const t=e=>{e.stopPropagation(),e.preventDefault()};this._menu.addEventListener("mousedown",t),this._menu.addEventListener("pointerdown",t),this._menu.addEventListener("click",t),this.addEventListener("click",(e=>{this._canClick&&(this._menu&&(this._menu.contains(e.target)||e.composedPath().includes(this._menu))||!this._message||!this.onItemClick||e.target instanceof i.CourierIcon||this._isLongPress||this.onItemClick(this._message))})),this._setupHoverBehavior(),this._setupLongPressBehavior(),this._canClick&&this.classList.add("clickable")}_setupIntersectionObserver(){"undefined"!=typeof window&&"undefined"!=typeof IntersectionObserver&&(this._observer&&this._observer.disconnect(),this._observer=new IntersectionObserver((e=>{e.forEach((e=>{1===e.intersectionRatio&&this.onItemVisible&&this._message&&this.onItemVisible(this._message)}))}),{threshold:1}),this._observer.observe(this))}onComponentUnmounted(){var e;null==(e=this._observer)||e.disconnect()}static getStyles(e){var t,i,n,o,s,l,r,a,d,u,c,v,g,p,m,b,_,C,f,x,y,I,k,w,M,S,T;const $=null==(t=e.inbox)?void 0:t.list;return`\n ${h.id} {\n display: flex;\n flex-direction: row;\n align-items: flex-start;\n justify-content: space-between;\n border-bottom: ${(null==(i=null==$?void 0:$.item)?void 0:i.divider)??"1px solid red"};\n font-family: inherit;\n cursor: default;\n transition: ${(null==(n=null==$?void 0:$.item)?void 0:n.transition)??"all 0.2s ease"};\n margin: 0;\n width: 100%;\n box-sizing: border-box;\n padding: 12px 20px;\n position: relative;\n background-color: ${(null==(o=null==$?void 0:$.item)?void 0:o.backgroundColor)??"transparent"};\n user-select: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n touch-action: manipulation;\n }\n\n /* Only apply hover/active background if clickable */\n @media (hover: hover) {\n ${h.id}.clickable:hover {\n cursor: pointer;\n background-color: ${(null==(s=null==$?void 0:$.item)?void 0:s.hoverBackgroundColor)??"red"};\n }\n }\n\n ${h.id}.clickable:active {\n cursor: pointer;\n background-color: ${(null==(l=null==$?void 0:$.item)?void 0:l.activeBackgroundColor)??"red"};\n }\n\n /* Menu hover / active */\n @media (hover: hover) {\n ${h.id}.clickable:hover:has(courier-inbox-list-item-menu:hover, courier-inbox-list-item-menu *:hover, courier-button:hover, courier-button *:hover) {\n background-color: ${(null==(r=null==$?void 0:$.item)?void 0:r.backgroundColor)??"transparent"};\n }\n }\n\n ${h.id}.clickable:active:has(courier-inbox-list-item-menu:active, courier-inbox-list-item-menu *:active, courier-button:active, courier-button *:active) {\n background-color: ${(null==(a=null==$?void 0:$.item)?void 0:a.backgroundColor)??"transparent"};\n }\n\n ${h.id}:last-child {\n border-bottom: none;\n }\n\n ${h.id} .unread-indicator {\n position: absolute;\n top: 28px;\n left: 6px;\n width: 8px;\n height: 8px;\n border-radius: 50%;\n background-color: ${(null==(d=null==$?void 0:$.item)?void 0:d.unreadIndicatorColor)??"red"};\n display: none;\n }\n\n ${h.id}.unread .unread-indicator {\n display: block;\n }\n\n ${h.id} .content-container {\n flex: 1;\n display: flex;\n flex-direction: column;\n margin-right: 12px;\n }\n\n ${h.id} p {\n margin: 0;\n overflow-wrap: break-word;\n word-break: break-word;\n hyphens: auto;\n line-height: 1.4;\n user-select: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n text-align: left;\n }\n\n ${h.id} .title {\n font-family: ${(null==(c=null==(u=null==$?void 0:$.item)?void 0:u.title)?void 0:c.family)??"inherit"};\n font-size: ${(null==(g=null==(v=null==$?void 0:$.item)?void 0:v.title)?void 0:g.size)??"14px"};\n color: ${(null==(m=null==(p=null==$?void 0:$.item)?void 0:p.title)?void 0:m.color)??"red"};\n margin-bottom: 4px;\n }\n\n ${h.id} .subtitle {\n font-family: ${(null==(_=null==(b=null==$?void 0:$.item)?void 0:b.subtitle)?void 0:_.family)??"inherit"};\n font-size: ${(null==(f=null==(C=null==$?void 0:$.item)?void 0:C.subtitle)?void 0:f.size)??"14px"};\n color: ${(null==(y=null==(x=null==$?void 0:$.item)?void 0:x.subtitle)?void 0:y.color)??"red"};\n }\n\n ${h.id} .time {\n font-family: ${(null==(k=null==(I=null==$?void 0:$.item)?void 0:I.time)?void 0:k.family)??"inherit"};\n font-size: ${(null==(M=null==(w=null==$?void 0:$.item)?void 0:w.time)?void 0:M.size)??"14px"};\n color: ${(null==(T=null==(S=null==$?void 0:$.item)?void 0:S.time)?void 0:T.color)??"red"};\n text-align: right;\n white-space: nowrap;\n }\n\n ${h.id} courier-inbox-list-item-menu {\n z-index: 1;\n position: absolute;\n top: 8px;\n right: 8px;\n display: none;\n opacity: 0;\n transition: opacity 0.2s ease;\n }\n\n ${h.id} courier-inbox-list-item-menu.visible {\n opacity: 1;\n }\n\n /* Show menu on hover for non-mobile devices - CSS handles this reliably */\n @media (hover: hover) {\n ${h.id}.clickable:hover courier-inbox-list-item-menu {\n display: block;\n }\n ${h.id}.clickable:hover courier-inbox-list-item-menu.visible {\n display: block;\n }\n ${h.id}.clickable:hover .time {\n opacity: 0;\n transition: opacity 0.2s ease;\n }\n }\n\n ${h.id} .actions-container {\n display: flex;\n margin-top: 10px;\n flex-wrap: wrap;\n flex-direction: row;\n align-items: center;\n gap: 8px;\n display: none;\n }\n `}_setupHoverBehavior(){this._isMobile||(this.addEventListener("mouseenter",(()=>{this._isLongPress=!1;const e=this._getMenuOptions();e.length>0&&this._menu&&(this._menu.setOptions(e),this._menu.show(),this._timeElement&&(this._timeElement.style.opacity="0"))})),this.addEventListener("mouseleave",(()=>{this._menu&&this._menu.hide(),this._timeElement&&(this._timeElement.style.opacity="1")})))}_setupLongPressBehavior(){var e,t,i;const n=null==(i=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:i.menu;if(!(null==n?void 0:n.enabled))return;const o=n.longPress;this.addEventListener("touchstart",(()=>{this._longPressTimeout=window.setTimeout((()=>{this._isLongPress=!0,this._showMenu(),this._message&&this.onItemLongPress&&(this.onItemLongPress(this._message),navigator.vibrate&&navigator.vibrate((null==o?void 0:o.vibrationDuration)??50)),setTimeout((()=>{this._hideMenu(),this._isLongPress=!1}),(null==o?void 0:o.displayDuration)??2e3)}),650)}),{passive:!0}),this.addEventListener("touchend",(()=>{this._longPressTimeout&&(window.clearTimeout(this._longPressTimeout),this._longPressTimeout=null)}))}_getMenuOptions(){var e,t,n,o,s,l,r,a,d,h,c,v,g,p,m,b;const _=null==(o=null==(n=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:n.menu)?void 0:o.item;let C=[];const f=!!(null==(s=this._message)?void 0:s.archived);for(const x of this._listItemActions)switch(x.id){case"read_unread":C.push({id:(null==(l=this._message)?void 0:l.read)?"unread":"read",icon:{svg:(null==(r=this._message)?void 0:r.read)?x.unreadIconSVG??(null==(a=null==_?void 0:_.unread)?void 0:a.svg)??i.CourierIconSVGs.unread:x.readIconSVG??(null==(d=null==_?void 0:_.read)?void 0:d.svg)??i.CourierIconSVGs.read,color:(null==(h=this._message)?void 0:h.read)?null==(c=null==_?void 0:_.unread)?void 0:c.color:(null==(v=null==_?void 0:_.read)?void 0:v.color)??"red"},onClick:()=>{this._message&&(this._message.read?u.shared.unreadMessage({message:this._message}):u.shared.readMessage({message:this._message}))}});break;case"archive_unarchive":C.push({id:f?"unarchive":"archive",icon:{svg:f?x.unarchiveIconSVG??(null==(g=null==_?void 0:_.unarchive)?void 0:g.svg)??i.CourierIconSVGs.unarchive:x.archiveIconSVG??(null==(p=null==_?void 0:_.archive)?void 0:p.svg)??i.CourierIconSVGs.archive,color:f?null==(m=null==_?void 0:_.unarchive)?void 0:m.color:(null==(b=null==_?void 0:_.archive)?void 0:b.color)??"red"},onClick:()=>{this._message&&(f?u.shared.unarchiveMessage({message:this._message}):u.shared.archiveMessage({message:this._message}))}})}return C}_showMenu(){var e,t,i;const n=null==(i=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:i.menu,o=this._getMenuOptions();0!==o.length&&n&&n.enabled&&this._menu&&this._timeElement&&(this._menu.setOptions(o),this._menu.show(),this._timeElement.style.opacity="0")}_hideMenu(){var e,t,i;const n=null==(i=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:i.menu;n&&n.enabled&&this._menu&&this._timeElement&&(this._menu.hide(),this._timeElement.style.opacity="1")}setMessage(e){this._message=e,this._updateContent()}setOnItemClick(e){this.onItemClick=e}setOnItemActionClick(e){this.onItemActionClick=e}setOnItemLongPress(e){this.onItemLongPress=e}setOnItemVisible(e){this.onItemVisible=e}_updateContent(){var e,t,n;if(!this._message)return this._titleElement&&(this._titleElement.textContent=""),void(this._subtitleElement&&(this._subtitleElement.textContent=""));this.classList.toggle("unread",!this._message.read),this._titleElement&&(this._titleElement.textContent=this._message.title||"Untitled Message"),this._subtitleElement&&(this._subtitleElement.textContent=this._message.preview||this._message.body||""),this._timeElement&&(this._timeElement.textContent=function(e){if(!e.created)return"Now";const t=new Date,i=new Date(e.created),n=Math.floor((t.getTime()-i.getTime())/1e3);return n<5?"Now":n<60?`${n}s`:n<3600?`${Math.floor(n/60)}m`:n<86400?`${Math.floor(n/3600)}h`:n<604800?`${Math.floor(n/86400)}d`:n<31536e3?`${Math.floor(n/604800)}w`:`${Math.floor(n/31536e3)}y`}(this._message)),this._menu&&this._menu.setOptions(this._getMenuOptions());const o=this._message.actions&&this._message.actions.length>0;this._actionsContainer&&(this._actionsContainer.style.display=o?"flex":"none");const s=null==(n=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:n.actions;this._actionsContainer&&this._message.actions&&(this._actionsContainer.innerHTML="",this._message.actions.forEach((e=>{var t,n,o,l,r;const a=new i.CourierButton({mode:this._themeManager.mode,text:e.content,variant:"secondary",backgroundColor:null==s?void 0:s.backgroundColor,hoverBackgroundColor:null==s?void 0:s.hoverBackgroundColor,activeBackgroundColor:null==s?void 0:s.activeBackgroundColor,border:null==s?void 0:s.border,borderRadius:null==s?void 0:s.borderRadius,shadow:null==s?void 0:s.shadow,fontFamily:null==(t=null==s?void 0:s.font)?void 0:t.family,fontSize:null==(n=null==s?void 0:s.font)?void 0:n.size,fontWeight:null==(o=null==s?void 0:s.font)?void 0:o.weight,textColor:null==(l=null==s?void 0:s.font)?void 0:l.color,onClick:()=>{this._message&&this.onItemActionClick&&this.onItemActionClick(this._message,e)}});null==(r=this._actionsContainer)||r.appendChild(a)})))}}i.registerElement(h);class c extends i.CourierBaseElement{constructor(e){super(),o(this,"_theme"),o(this,"_style"),this._theme=e}static get id(){return"courier-inbox-skeleton-list-item"}onComponentMounted(){this._style=i.injectGlobalStyle(c.id,c.getStyles(this._theme)),this.render()}onComponentUnmounted(){var e;null==(e=this._style)||e.remove()}render(){const e=new v(this._theme),t=new v(this._theme),i=new v(this._theme);this.appendChild(e),this.appendChild(t),this.appendChild(i)}static getStyles(e){return`\n ${c.id} {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 16px 20px 16px 20px;\n width: 100%;\n box-sizing: border-box;\n }\n\n ${c.id} > *:first-child {\n width: 35%;\n }\n\n ${c.id} > *:nth-child(2) {\n width: 100%;\n }\n\n ${c.id} > *:nth-child(3) {\n width: 82%;\n }\n `}}i.registerElement(c);class v extends i.CourierBaseElement{constructor(e){super(),o(this,"_theme"),o(this,"_style"),this._theme=e}static get id(){return"courier-skeleton-animated-row"}onComponentMounted(){this._style=i.injectGlobalStyle(v.id,v.getStyles(this._theme)),this.render()}onComponentUnmounted(){var e;null==(e=this._style)||e.remove()}render(){const e=document.createElement("div");e.className="skeleton-item",this.appendChild(e)}static getStyles(e){var t,i,n,o,s,l,r,a,d,u,h,c;const g=(null==(n=null==(i=null==(t=e.inbox)?void 0:t.loading)?void 0:i.animation)?void 0:n.barColor)??"#000",p=4===g.length?`#${g[1]}${g[1]}${g[2]}${g[2]}${g[3]}${g[3]}`:g,m=parseInt(p.slice(1,3),16),b=parseInt(p.slice(3,5),16),_=parseInt(p.slice(5,7),16),C=`rgba(${m}, ${b}, ${_}, 0.8)`,f=`rgba(${m}, ${b}, ${_}, 0.4)`;return`\n ${v.id} {\n display: flex;\n height: 100%;\n width: 100%;\n align-items: flex-start;\n justify-content: flex-start;\n }\n\n ${v.id} .skeleton-item {\n height: ${(null==(l=null==(s=null==(o=e.inbox)?void 0:o.loading)?void 0:s.animation)?void 0:l.barHeight)??"14px"};\n width: 100%;\n background: linear-gradient(\n 90deg,\n ${C} 25%,\n ${f} 50%,\n ${C} 75%\n );\n background-size: 200% 100%;\n animation: ${v.id}-shimmer ${(null==(d=null==(a=null==(r=e.inbox)?void 0:r.loading)?void 0:a.animation)?void 0:d.duration)??"2s"} ease-in-out infinite;\n border-radius: ${(null==(c=null==(h=null==(u=e.inbox)?void 0:u.loading)?void 0:h.animation)?void 0:c.barBorderRadius)??"14px"};\n }\n\n @keyframes ${v.id}-shimmer {\n 0% {\n background-position: 200% 0;\n }\n 100% {\n background-position: -200% 0;\n }\n }\n `}}i.registerElement(v);class g extends i.CourierFactoryElement{constructor(e){super(),o(this,"_theme"),o(this,"_style"),this._theme=e}static get id(){return"courier-inbox-skeleton-list"}onComponentMounted(){this._style=i.injectGlobalStyle(g.id,g.getStyles(this._theme))}onComponentUnmounted(){var e;null==(e=this._style)||e.remove()}defaultElement(){const e=document.createElement("div");e.className="list";for(let t=0;t<3;t++){const t=new c(this._theme);e.appendChild(t)}return this.appendChild(e),e}static getStyles(e){var t,i,n,o;return`\n ${g.id} {\n display: flex;\n height: 100%;\n width: 100%;\n align-items: flex-start;\n justify-content: flex-start;\n overflow: hidden;\n }\n\n ${g.id} .list {\n display: flex;\n flex-direction: column;\n width: 100%;\n overflow: hidden;\n }\n\n ${g.id} .list > * {\n border-bottom: ${(null==(i=null==(t=e.inbox)?void 0:t.loading)?void 0:i.divider)??"1px solid red"};\n opacity: 100%;\n }\n\n ${g.id} .list > *:nth-child(2) {\n border-bottom: ${(null==(o=null==(n=e.inbox)?void 0:n.loading)?void 0:o.divider)??"1px solid red"};\n opacity: 88%;\n }\n\n ${g.id} .list > *:nth-child(3) {\n border-bottom: none;\n opacity: 50%;\n }\n `}}i.registerElement(g);class p extends i.CourierBaseElement{constructor(e){super(),o(this,"_theme"),o(this,"_style"),o(this,"_skeletonLoadingList"),o(this,"_observer"),o(this,"_customItem"),o(this,"_onPaginationTrigger"),this._theme=e.theme,this._customItem=e.customItem,this._onPaginationTrigger=e.onPaginationTrigger}static get id(){return"courier-inbox-pagination-list-item"}onComponentMounted(){if(this._style=i.injectGlobalStyle(p.id,p.getStyles(this._theme)),this._customItem)this.appendChild(this._customItem);else{const e=document.createElement("div");e.className="skeleton-container",this._skeletonLoadingList=new g(this._theme),this._skeletonLoadingList.build(void 0),e.appendChild(this._skeletonLoadingList),this.appendChild(e)}this._observer=new IntersectionObserver((e=>{e.forEach((e=>{e.isIntersecting&&this._onPaginationTrigger()}))})),this._observer.observe(this)}onComponentUnmounted(){var e,t;null==(e=this._observer)||e.disconnect(),null==(t=this._style)||t.remove()}static getStyles(e){return`\n ${p.id} {\n padding: 0;\n margin: 0;\n box-sizing: border-box;\n }\n\n ${p.id} .skeleton-container {\n height: 150%;\n }\n `}}function m(e){return u.shared.openMessage({message:e})}function b(){return[{feedId:"inbox_feed",title:"Inbox",iconSVG:i.CourierIconSVGs.inbox,tabs:[{datasetId:"all_messages",title:"All Messages",filter:{}}]},{feedId:"archive_feed",title:"Archive",iconSVG:i.CourierIconSVGs.archive,tabs:[{datasetId:"archived_messages",title:"Archived Messages",filter:{archived:!0}}]}]}function _(){return[{id:"readAll"},{id:"archiveRead"},{id:"archiveAll"}]}function C(){return[{id:"read_unread"},{id:"archive_unarchive"}]}i.registerElement(p);class f extends i.CourierBaseElement{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_messages",[]),o(this,"_datasetId",b()[0].tabs[0].datasetId),o(this,"_isLoading",!0),o(this,"_error",null),o(this,"_canPaginate",!1),o(this,"_canClickListItems",!1),o(this,"_canLongPressListItems",!1),o(this,"_listItemActions",B.defaultListItemActions()),o(this,"_onMessageClick",null),o(this,"_onMessageActionClick",null),o(this,"_onMessageLongPress",null),o(this,"_onRefresh"),o(this,"_onPaginationTrigger"),o(this,"_listItemFactory"),o(this,"_paginationItemFactory"),o(this,"_loadingStateFactory"),o(this,"_emptyStateFactory"),o(this,"_errorStateFactory"),o(this,"_listStyles"),o(this,"_listItemStyles"),o(this,"_listItemMenuStyles"),o(this,"_errorContainer"),o(this,"_emptyContainer"),this._onRefresh=e.onRefresh,this._onPaginationTrigger=e.onPaginationTrigger,this._onMessageClick=e.onMessageClick,this._onMessageActionClick=e.onMessageActionClick,this._onMessageLongPress=e.onMessageLongPress,e.listItemActions&&(this._listItemActions=e.listItemActions),this._themeSubscription=e.themeManager.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-list"}get messages(){return this._messages}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this._listStyles=i.injectGlobalStyle(f.id,f.getStyles(this.theme)),this._listItemStyles=i.injectGlobalStyle(h.id,h.getStyles(this.theme)),this._listItemMenuStyles=i.injectGlobalStyle(r.id,r.getStyles(this.theme)),this.render()}onComponentUnmounted(){var e,t,i;this._themeSubscription.unsubscribe(),null==(e=this._listStyles)||e.remove(),null==(t=this._listItemStyles)||t.remove(),null==(i=this._listItemMenuStyles)||i.remove()}setCanClickListItems(e){this._canClickListItems=e}setCanLongPressListItems(e){this._canLongPressListItems=e}setListItemActions(e){this._listItemActions=e,this.render()}static getStyles(e){var t;const i=null==(t=e.inbox)?void 0:t.list,n=null==i?void 0:i.scrollbar;return`\n ${f.id} {\n flex: 1;\n width: 100%;\n background-color: ${(null==i?void 0:i.backgroundColor)??"red"};\n scrollbar-width: ${(null==n?void 0:n.width)??"thin"};\n scrollbar-color: ${(null==n?void 0:n.thumbColor)??"rgba(0, 0, 0, 0.2)"} ${(null==n?void 0:n.trackBackgroundColor)??"transparent"};\n }\n\n ${f.id} ul {\n list-style: none;\n padding: 0;\n margin: 0;\n height: 100%;\n }\n\n /* Webkit scrollbar styling - show thumb, hide track background, overlay above content */\n ${f.id}::-webkit-scrollbar {\n width: ${(null==n?void 0:n.width)??"8px"};\n height: ${(null==n?void 0:n.height)??"8px"};\n }\n\n ${f.id}::-webkit-scrollbar-track {\n background: ${(null==n?void 0:n.trackBackgroundColor)??"transparent"};\n }\n\n ${f.id}::-webkit-scrollbar-thumb {\n background: ${(null==n?void 0:n.thumbColor)??"rgba(0, 0, 0, 0.2)"};\n border-radius: ${(null==n?void 0:n.borderRadius)??"4px"};\n }\n\n ${f.id}::-webkit-scrollbar-thumb:hover {\n background: ${(null==n?void 0:n.thumbHoverColor)??(null==n?void 0:n.thumbColor)??"rgba(0, 0, 0, 0.3)"};\n }\n `}setDataSet(e){this._messages=[...e.messages],this._canPaginate=Boolean(e.canPaginate),this._error=null,this._isLoading=!1,this.render()}addPage(e){this._messages=[...this._messages,...e.messages],this._canPaginate=Boolean(e.canPaginate),this._error=null,this._isLoading=!1,this.render()}addMessage(e,t=0){this._messages.splice(t,0,e),this.render()}removeMessage(e=0){this._messages.splice(e,1),this.render()}updateMessage(e,t=0){this._messages[t]=e,this.render()}selectDataset(e){this._datasetId=e,this._error=null,this._isLoading=!0,this.render()}setLoading(e){this._error=null,this._isLoading=e,this.render()}setError(e){this._error=e,this._isLoading=!1,this._messages=[],this.render()}setErrorNoClient(){this.setError(new Error("No user signed in"))}handleRetry(){this._onRefresh()}handleRefresh(){this._onRefresh()}refreshTheme(){this._listStyles&&(this._listStyles.textContent=f.getStyles(this.theme)),this._listItemStyles&&(this._listItemStyles.textContent=h.getStyles(this.theme)),this._listItemMenuStyles&&(this._listItemMenuStyles.textContent=r.getStyles(this.theme)),this.refreshInfoStateThemes()}refreshInfoStateThemes(){var e,t;null==(e=this._emptyContainer)||e.updateStyles(this.errorProps),null==(t=this._emptyContainer)||t.updateStyles(this.emptyProps)}get errorProps(){var e,t,i,n,o,s,l,r,a,d,u,h,c,v,g,p,m,b,_,C,f,x,y,I,k,w;const M=null==(e=this.theme.inbox)?void 0:e.error,S=this._themeSubscription.manager.mode;return{title:{text:(null==(t=null==M?void 0:M.title)?void 0:t.text)??(null==(i=this._error)?void 0:i.message),textColor:null==(o=null==(n=null==M?void 0:M.title)?void 0:n.font)?void 0:o.color,fontFamily:null==(l=null==(s=null==M?void 0:M.title)?void 0:s.font)?void 0:l.family,fontSize:null==(a=null==(r=null==M?void 0:M.title)?void 0:r.font)?void 0:a.size,fontWeight:null==(u=null==(d=null==M?void 0:M.title)?void 0:d.font)?void 0:u.weight},button:{mode:S,text:null==(h=null==M?void 0:M.button)?void 0:h.text,backgroundColor:null==(c=null==M?void 0:M.button)?void 0:c.backgroundColor,hoverBackgroundColor:null==(v=null==M?void 0:M.button)?void 0:v.hoverBackgroundColor,activeBackgroundColor:null==(g=null==M?void 0:M.button)?void 0:g.activeBackgroundColor,textColor:null==(m=null==(p=null==M?void 0:M.button)?void 0:p.font)?void 0:m.color,fontFamily:null==(_=null==(b=null==M?void 0:M.button)?void 0:b.font)?void 0:_.family,fontSize:null==(f=null==(C=null==M?void 0:M.button)?void 0:C.font)?void 0:f.size,fontWeight:null==(y=null==(x=null==M?void 0:M.button)?void 0:x.font)?void 0:y.weight,shadow:null==(I=null==M?void 0:M.button)?void 0:I.shadow,border:null==(k=null==M?void 0:M.button)?void 0:k.border,borderRadius:null==(w=null==M?void 0:M.button)?void 0:w.borderRadius,onClick:()=>this.handleRetry()}}}get emptyProps(){var e,t,i,n,o,s,l,r,a,d,u,h,c,v,g,p,m,b,_,C,f,x,y,I,k;const w=null==(e=this.theme.inbox)?void 0:e.empty,M=this._themeSubscription.manager.mode;return{title:{text:(null==(t=null==w?void 0:w.title)?void 0:t.text)??"No Messages",textColor:null==(n=null==(i=null==w?void 0:w.title)?void 0:i.font)?void 0:n.color,fontFamily:null==(s=null==(o=null==w?void 0:w.title)?void 0:o.font)?void 0:s.family,fontSize:null==(r=null==(l=null==w?void 0:w.title)?void 0:l.font)?void 0:r.size,fontWeight:null==(d=null==(a=null==w?void 0:w.title)?void 0:a.font)?void 0:d.weight},button:{mode:M,text:null==(u=null==w?void 0:w.button)?void 0:u.text,backgroundColor:null==(h=null==w?void 0:w.button)?void 0:h.backgroundColor,hoverBackgroundColor:null==(c=null==w?void 0:w.button)?void 0:c.hoverBackgroundColor,activeBackgroundColor:null==(v=null==w?void 0:w.button)?void 0:v.activeBackgroundColor,textColor:null==(p=null==(g=null==w?void 0:w.button)?void 0:g.font)?void 0:p.color,fontFamily:null==(b=null==(m=null==w?void 0:w.button)?void 0:m.font)?void 0:b.family,fontSize:null==(C=null==(_=null==w?void 0:w.button)?void 0:_.font)?void 0:C.size,fontWeight:null==(x=null==(f=null==w?void 0:w.button)?void 0:f.font)?void 0:x.weight,shadow:null==(y=null==w?void 0:w.button)?void 0:y.shadow,border:null==(I=null==w?void 0:w.button)?void 0:I.border,borderRadius:null==(k=null==w?void 0:w.button)?void 0:k.borderRadius,onClick:()=>this.handleRefresh()}}}render(){for(var e,t,n,o;this.firstChild;)this.removeChild(this.firstChild),this._errorContainer=void 0,this._emptyContainer=void 0;if(this.refreshTheme(),this._error)return this._errorContainer=new i.CourierInfoState(this.errorProps),this._errorContainer.build(null==(e=this._errorStateFactory)?void 0:e.call(this,{datasetId:this._datasetId,error:this._error})),void this.appendChild(this._errorContainer);if(this._isLoading){const e=new g(this.theme);return e.build(null==(t=this._loadingStateFactory)?void 0:t.call(this,{datasetId:this._datasetId})),void this.appendChild(e)}if(0===this._messages.length)return this._emptyContainer=new i.CourierInfoState(this.emptyProps),this._emptyContainer.build(null==(n=this._emptyStateFactory)?void 0:n.call(this,{datasetId:this._datasetId})),void this.appendChild(this._emptyContainer);const s=document.createElement("ul");if(this.appendChild(s),this._messages.forEach(((e,t)=>{if(this._listItemFactory)return void s.appendChild(this._listItemFactory({message:e,index:t}));const i=new h(this._themeSubscription.manager,this._canClickListItems,this._canLongPressListItems,this._listItemActions);i.setMessage(e),i.setOnItemClick((e=>{var i;return null==(i=this._onMessageClick)?void 0:i.call(this,e,t)})),i.setOnItemActionClick(((e,i)=>{var n;return null==(n=this._onMessageActionClick)?void 0:n.call(this,e,i,t)})),i.setOnItemLongPress((e=>{var i;return null==(i=this._onMessageLongPress)?void 0:i.call(this,e,t)})),i.setOnItemVisible((e=>this.openVisibleMessage(e))),s.appendChild(i)})),this._canPaginate){const e=new p({theme:this.theme,customItem:null==(o=this._paginationItemFactory)?void 0:o.call(this,{datasetId:this._datasetId}),onPaginationTrigger:()=>{var e;return null==(e=this._onPaginationTrigger)?void 0:e.call(this,this._datasetId)}});s.appendChild(e)}}async openVisibleMessage(e){try{await m(e)}catch(t){}}setLoadingStateFactory(e){this._loadingStateFactory=e,this.render()}setEmptyStateFactory(e){this._emptyStateFactory=e,this.render()}setErrorStateFactory(e){this._errorStateFactory=e,this.render()}setListItemFactory(e){this._listItemFactory=e,this.render()}setPaginationItemFactory(e){this._paginationItemFactory=e,this.render()}scrollToTop(e=!0){this.scrollTo({top:0,behavior:e?"smooth":"instant"})}}i.registerElement(f);class x extends i.CourierBaseElement{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_location"),o(this,"_count",0),o(this,"_style"),o(this,"_shadowRoot"),o(this,"_container"),this._location=e.location,this._themeSubscription=e.themeBus.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-unread-count-badge"}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this.attachElements(),this.setActive(!0),this.updateBadge()}attachElements(){this._shadowRoot=this.attachShadow({mode:"closed"}),this._container=document.createElement("div"),this._container.className="badge-container",this._style=document.createElement("style"),this._style.textContent=this.getStyles(),this._shadowRoot.appendChild(this._style),this._shadowRoot.appendChild(this._container)}onComponentUnmounted(){this._themeSubscription.unsubscribe()}static getThemePath(e,t,i){var n,o,s,l,r,a,d,u;if("tab"===t){const t=null==(o=null==(n=e.inbox)?void 0:n.header)?void 0:o.tabs;return i?null==(s=null==t?void 0:t.selected)?void 0:s.unreadIndicator:null==(l=null==t?void 0:t.default)?void 0:l.unreadIndicator}return null==(u=null==(d=null==(a=null==(r=e.inbox)?void 0:r.header)?void 0:a.feeds)?void 0:d.button)?void 0:u.unreadCountIndicator}static getStyles(e,t="feed"){var i,n,o,s,l,r,a,d,u,h,c,v,g,p,m,b,_,C,f,y;const I=x.getThemePath(e,t,!0),k=x.getThemePath(e,t,!1),w=null==(s=null==(o=null==(n=null==(i=e.inbox)?void 0:i.header)?void 0:n.feeds)?void 0:o.button)?void 0:s.unreadCountIndicator;return`\n :host {\n display: inline-block;\n }\n\n .badge-container {\n display: none;\n pointer-events: none;\n }\n\n :host(.active) .badge-container {\n display: inline-block;\n background-color: ${(null==I?void 0:I.backgroundColor)??(null==w?void 0:w.backgroundColor)};\n color: ${(null==(l=null==I?void 0:I.font)?void 0:l.color)??(null==(r=null==w?void 0:w.font)?void 0:r.color)};\n border-radius: ${(null==I?void 0:I.borderRadius)??(null==w?void 0:w.borderRadius)};\n font-size: ${(null==(a=null==I?void 0:I.font)?void 0:a.size)??(null==(d=null==w?void 0:w.font)?void 0:d.size)};\n font-family: ${(null==(u=null==I?void 0:I.font)?void 0:u.family)??(null==(h=null==w?void 0:w.font)?void 0:h.family)??"inherit"};\n font-weight: ${(null==(c=null==I?void 0:I.font)?void 0:c.weight)??(null==(v=null==w?void 0:w.font)?void 0:v.weight)??"inherit"};\n padding: ${(null==I?void 0:I.padding)??(null==w?void 0:w.padding)};\n }\n\n :host(.inactive) .badge-container {\n display: inline-block;\n background-color: ${(null==k?void 0:k.backgroundColor)??(null==w?void 0:w.backgroundColor)};\n color: ${(null==(g=null==k?void 0:k.font)?void 0:g.color)??(null==(p=null==w?void 0:w.font)?void 0:p.color)};\n border-radius: ${(null==k?void 0:k.borderRadius)??(null==w?void 0:w.borderRadius)};\n font-size: ${(null==(m=null==k?void 0:k.font)?void 0:m.size)??(null==(b=null==w?void 0:w.font)?void 0:b.size)};\n font-family: ${(null==(_=null==k?void 0:k.font)?void 0:_.family)??(null==(C=null==w?void 0:w.font)?void 0:C.family)??"inherit"};\n font-weight: ${(null==(f=null==k?void 0:k.font)?void 0:f.weight)??(null==(y=null==w?void 0:w.font)?void 0:y.weight)??"inherit"};\n padding: ${(null==k?void 0:k.padding)??(null==w?void 0:w.padding)};\n }\n `}getStyles(){return x.getStyles(this.theme,this._location)}setCount(e){this._count=e,this.updateBadge()}setActive(e){this.className=e?"active":"inactive",this._style&&(this._style.textContent=this.getStyles()),this.updateBadge()}refreshTheme(){this._style&&(this._style.textContent=this.getStyles()),this.updateBadge()}updateBadge(){this._container&&(this._count>0?(this.style.display="inline-block",this._container.textContent=this._count>99?"99+":this._count.toString()):(this.style.display="none",this._container.textContent=""))}}i.registerElement(x);class y extends i.CourierBaseElement{constructor(e,t){super(),o(this,"_themeSubscription"),o(this,"_feeds"),o(this,"_selectedFeed"),o(this,"_style"),o(this,"_iconElement"),o(this,"_titleElement"),o(this,"_switchIconElement"),o(this,"_unreadBadge"),this._feeds=t,this._themeSubscription=e.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-header-title"}get selectedFeed(){return this._selectedFeed}get theme(){return this._themeSubscription.manager.getTheme()}getStyles(e){var t,i,n,o,s,l,r,a,d,u,h,c,v,g,p,m,b,_,C,f,x,I,k,w,M,S,T,$,E,L,B,F;const A=this._feeds.length>1,P=A?`${y.id}:hover {\n background: ${(null==(o=null==(n=null==(i=null==(t=e.inbox)?void 0:t.header)?void 0:i.feeds)?void 0:n.button)?void 0:o.hoverBackgroundColor)??"red"};\n }`:"",R=A?`${y.id}:active {\n background: ${(null==(a=null==(r=null==(l=null==(s=e.inbox)?void 0:s.header)?void 0:l.feeds)?void 0:r.button)?void 0:a.activeBackgroundColor)??"red"};\n }`:"";return`\n ${y.id} {\n display: flex;\n align-items: center;\n gap: 8px;\n position: relative;\n transition: ${(null==(c=null==(h=null==(u=null==(d=e.inbox)?void 0:d.header)?void 0:u.feeds)?void 0:h.button)?void 0:c.transition)??"all 0.2s ease"};\n border-radius: 6px;\n padding-top: 4px;\n padding-bottom: 4px;\n padding-left: 4px;\n padding-right: 8px;\n }\n\n ${P}\n\n ${R}\n\n ${y.id} courier-icon {\n display: flex;\n align-items: center;\n }\n\n ${y.id} .title-container {\n display: flex;\n flex-direction: row;\n align-items: center;\n gap: 0px;\n }\n\n ${y.id} .title-container h2 {\n margin: 0;\n font-family: ${(null==(b=null==(m=null==(p=null==(g=null==(v=e.inbox)?void 0:v.header)?void 0:g.feeds)?void 0:p.button)?void 0:m.font)?void 0:b.family)??"inherit"};\n font-size: ${(null==(I=null==(x=null==(f=null==(C=null==(_=e.inbox)?void 0:_.header)?void 0:C.feeds)?void 0:f.button)?void 0:x.font)?void 0:I.size)??"16px"};\n font-weight: ${(null==(T=null==(S=null==(M=null==(w=null==(k=e.inbox)?void 0:k.header)?void 0:w.feeds)?void 0:M.button)?void 0:S.font)?void 0:T.weight)??"500"};\n color: ${(null==(F=null==(B=null==(L=null==(E=null==($=e.inbox)?void 0:$.header)?void 0:E.feeds)?void 0:L.button)?void 0:B.font)?void 0:F.color)??"red"};\n }\n\n `}onComponentMounted(){this.render()}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}render(){var e,t,n,o;this._style=i.injectGlobalStyle(y.id,this.getStyles(this.theme)),this._iconElement=new i.CourierIcon,this.appendChild(this._iconElement);const s=document.createElement("div");s.className="title-container",this._titleElement=document.createElement("h2"),s.appendChild(this._titleElement);const l=null==(o=null==(n=null==(t=null==(e=this.theme.inbox)?void 0:e.header)?void 0:t.feeds)?void 0:n.button)?void 0:o.changeFeedIcon;this._switchIconElement=new i.CourierIcon((null==l?void 0:l.color)??"red",(null==l?void 0:l.svg)??i.CourierIconSVGs.chevronDown),this._switchIconElement.style.display=this._feeds.length>1?"flex":"none",s.appendChild(this._switchIconElement),this.appendChild(s),this._unreadBadge=new x({themeBus:this._themeSubscription.manager,location:"feed"}),this.appendChild(this._unreadBadge),this.refreshTheme()}setUnreadCount(e){var t;null==(t=this._unreadBadge)||t.setCount(e)}setFeeds(e){this._feeds=e,this._switchIconElement&&(this._switchIconElement.style.display=this._feeds.length>1?"flex":"none"),this.refreshTheme()}setSelectedFeed(e){this._selectedFeed=this._feeds.find((t=>t.feedId===e)),this.refreshSelectedFeed()}refreshTheme(){this._style&&(this._style.textContent=this.getStyles(this.theme)),this.refreshSelectedFeed(),this.refreshSwitchIcon(),this.refreshUnreadBadge()}refreshSelectedFeed(){var e,t,n,o,s,l;this._selectedFeed&&(null==(e=this._iconElement)||e.updateSVG(this._selectedFeed.iconSVG??i.CourierIconSVGs.inbox),null==(l=this._iconElement)||l.updateColor((null==(s=null==(o=null==(n=null==(t=this.theme.inbox)?void 0:t.header)?void 0:n.feeds)?void 0:o.button)?void 0:s.selectedFeedIconColor)??"red"),this._titleElement&&(this._titleElement.textContent=this._selectedFeed.title))}refreshSwitchIcon(){var e,t,n,o;if(this._switchIconElement){const s=null==(o=null==(n=null==(t=null==(e=this.theme.inbox)?void 0:e.header)?void 0:t.feeds)?void 0:n.button)?void 0:o.changeFeedIcon;this._switchIconElement.updateSVG((null==s?void 0:s.svg)??i.CourierIconSVGs.chevronDown),this._switchIconElement.updateColor((null==s?void 0:s.color)??"red")}}refreshUnreadBadge(){this._unreadBadge&&this._unreadBadge.refreshTheme()}}i.registerElement(y);class I extends i.CourierBaseElement{constructor(e){super(),o(this,"_themeManager"),o(this,"_themeSubscription"),o(this,"_selectedTabId"),o(this,"_tabs",[]),o(this,"_onTabClick"),o(this,"_onTabReselected"),o(this,"_tabBadges",new Map),o(this,"_style"),this._themeManager=e.themeManager,this._onTabClick=e.onTabClick,this._onTabReselected=e.onTabReselected,this._themeSubscription=e.themeManager.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-tabs"}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this._style=i.injectGlobalStyle(I.id,I.getStyles(this.theme)),this.render()}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}render(){this.innerHTML="";const e=document.createElement("div");e.className="tab-container";for(let t of this._tabs){const i=this.createTab(t);e.appendChild(i)}this.appendChild(e),this.refreshTheme()}static getStyles(e){var t,i,n,o,s,l,r,a,d,u,h,c,v,g,p,m,b,_,C,f;const x=null==(i=null==(t=e.inbox)?void 0:t.header)?void 0:i.tabs;return`\n ${I.id} {\n position: relative;\n width: 100%;\n max-width: 100%;\n min-width: 0;\n margin-top: -5px;\n overflow-x: auto;\n scrollbar-width: none; /* Firefox */\n -ms-overflow-style: none; /* IE and Edge */\n height: 41px;\n }\n\n ${I.id}::-webkit-scrollbar {\n display: none;\n }\n\n ${I.id} .tab-container {\n display: flex;\n flex-direction: row;\n gap: 4px;\n padding: 0 10px;\n width: fit-content;\n height: 100%;\n }\n\n ${I.id} .tab-item {\n position: relative;\n display: flex;\n align-items: center;\n cursor: pointer;\n transition: ${(null==x?void 0:x.transition)??"all 0.2s ease"};\n user-select: none;\n padding: 0 10px;\n flex-shrink: 0;\n height: 100%;\n ${(e=>{if(!e)return"";if("string"==typeof e)return`border-radius: ${e};`;const t=[];return e.topLeft?t.push(e.topLeft):t.push("0"),e.topRight?t.push(e.topRight):t.push("0"),e.bottomRight?t.push(e.bottomRight):t.push("0"),e.bottomLeft?t.push(e.bottomLeft):t.push("0"),`border-radius: ${t.join(" ")};`})(null==x?void 0:x.borderRadius)}\n }\n\n ${I.id} .tab {\n position: relative;\n display: flex;\n align-items: center;\n gap: 8px;\n border-bottom: ${(null==(n=null==x?void 0:x.default)?void 0:n.indicatorHeight)??"1px"} solid ${(null==(o=null==x?void 0:x.default)?void 0:o.indicatorColor)??"transparent"};\n height: 40px;\n min-width: 40px;\n justify-content: center;\n position: relative;\n }\n\n ${I.id} .tab-item:hover {\n background-color: ${(null==(s=null==x?void 0:x.default)?void 0:s.hoverBackgroundColor)??"transparent"};\n }\n\n ${I.id} .tab-item:active {\n background-color: ${(null==(l=null==x?void 0:x.default)?void 0:l.activeBackgroundColor)??"transparent"};\n }\n\n ${I.id} .tab.selected {\n border-bottom: ${(null==(r=null==x?void 0:x.selected)?void 0:r.indicatorHeight)??"1px"} solid ${(null==(a=null==x?void 0:x.selected)?void 0:a.indicatorColor)??"transparent"};\n }\n\n ${I.id} .tab-item:hover.selected {\n background-color: ${(null==(d=null==x?void 0:x.selected)?void 0:d.hoverBackgroundColor)??"transparent"};\n }\n\n ${I.id} .tab-item:active.selected {\n background-color: ${(null==(u=null==x?void 0:x.selected)?void 0:u.activeBackgroundColor)??"transparent"};\n }\n\n ${I.id} .tab-label {\n font-size: ${(null==(c=null==(h=null==x?void 0:x.default)?void 0:h.font)?void 0:c.size)??"14px"};\n font-family: ${(null==(g=null==(v=null==x?void 0:x.default)?void 0:v.font)?void 0:g.family)??"inherit"};\n font-weight: ${(null==(m=null==(p=null==x?void 0:x.default)?void 0:p.font)?void 0:m.weight)??"inherit"};\n color: ${(null==(_=null==(b=null==x?void 0:x.default)?void 0:b.font)?void 0:_.color)??"red"};\n user-select: none;\n white-space: nowrap;\n }\n\n ${I.id} .tab.selected .tab-label {\n color: ${(null==(f=null==(C=null==x?void 0:x.selected)?void 0:C.font)?void 0:f.color)??"red"};\n }\n `}setTabs(e){this._tabs=e,this._tabBadges.clear(),this.render()}setSelectedTab(e){this._selectedTabId=e,this.reloadTabs(),this.updateBadgeStates()}updateTabUnreadCount(e,t){const i=this._tabBadges.get(e);i&&i.setCount(t)}scrollToStart(e=!0){e?this.scrollTo({left:0,behavior:"smooth"}):this.scrollLeft=0}refreshTheme(){this._style&&(this._style.textContent=I.getStyles(this.theme))}reloadTabs(){const e=this.querySelector(".tab-container");if(e)for(let t of Array.from(e.children))if(t instanceof HTMLElement&&t.classList.contains("tab-item")){const e=t.getAttribute("data-tab-id"),i=t.querySelector(".tab");i instanceof HTMLElement&&(e===this._selectedTabId?i.classList.add("selected"):i.classList.remove("selected"))}}updateBadgeStates(){for(let[e,t]of this._tabBadges)t.setActive(e===this._selectedTabId)}createTab(e){const t=document.createElement("div");t.className="tab-item",t.setAttribute("data-tab-id",e.datasetId);const i=document.createElement("div");i.className="tab",e.datasetId===this._selectedTabId&&i.classList.add("selected");const n=document.createElement("div");n.className="tab-label",n.innerText=e.title;const o=new x({themeBus:this._themeManager,location:"tab"});return this._tabBadges.set(e.datasetId,o),i.appendChild(n),i.appendChild(o),t.appendChild(i),t.addEventListener("click",(()=>{e.datasetId===this._selectedTabId?this._onTabReselected(e):this._onTabClick(e)})),t}}i.registerElement(I);class k extends i.CourierBaseElement{constructor(e){super(),o(this,"_option"),o(this,"_isSelectedable"),o(this,"_isSelected"),o(this,"_theme"),o(this,"_content"),o(this,"_itemIcon"),o(this,"_title"),o(this,"_selectionIcon"),this._option=e.option,this._isSelected=e.isSelected,this._isSelectedable=e.selectable,this._theme=e.themeManager}static get id(){return"courier-inbox-option-menu-item"}onComponentMounted(){this._content=document.createElement("div"),this._content.className="menu-item",this._itemIcon=new i.CourierIcon(this._option.icon.svg??i.CourierIconSVGs.inbox),this._itemIcon.setAttribute("size","16"),this._title=document.createElement("p"),this._title.textContent=this._option.text;const e=document.createElement("div");e.className="spacer",this._selectionIcon=new i.CourierIcon(i.CourierIconSVGs.check),this._selectionIcon.classList.add("check-icon"),this._content.appendChild(this._itemIcon),this._content.appendChild(this._title),this._content.appendChild(e),this._isSelectedable&&this._content.appendChild(this._selectionIcon),this.appendChild(this._content),this.updateSelectionState(),this.refreshTheme()}refreshTheme(){var e,t,n,o,s,l,r,a,d,u,h,c,v,g,p,m,b,_;this._title&&(this._title.textContent=this._option.text??"Missing Text");const C=this._theme.getTheme();null==(r=this._selectionIcon)||r.updateColor((null==(l=null==(s=null==(o=null==(n=null==(t=null==(e=C.inbox)?void 0:e.header)?void 0:t.feeds)?void 0:n.menu)?void 0:o.list)?void 0:s.selectedIcon)?void 0:l.color)??"red"),null==(g=this._selectionIcon)||g.updateSVG((null==(v=null==(c=null==(h=null==(u=null==(d=null==(a=C.inbox)?void 0:a.header)?void 0:d.feeds)?void 0:u.menu)?void 0:h.list)?void 0:c.selectedIcon)?void 0:v.svg)??i.CourierIconSVGs.check),null==(m=this._itemIcon)||m.updateColor((null==(p=this._option.icon)?void 0:p.color)??"red"),null==(_=this._itemIcon)||_.updateSVG((null==(b=this._option.icon)?void 0:b.svg)??i.CourierIconSVGs.inbox)}setSelected(e){this._isSelected=e,this.updateSelectionState()}updateSelectionState(){this._selectionIcon&&(this._selectionIcon.style.display=this._isSelected?"block":"none")}}i.registerElement(k);class w extends i.CourierBaseElement{constructor(e,t,i,n,s){super(),o(this,"_themeSubscription"),o(this,"_selectedIndex",0),o(this,"_options"),o(this,"_selectable"),o(this,"_onMenuOpen"),o(this,"_isOpen",!1),o(this,"_menuType"),o(this,"_style"),o(this,"_shadowRoot"),o(this,"_container"),this._selectable=t,this._options=i,this._onMenuOpen=s,this._menuType=n,this._themeSubscription=e.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-option-menu"}onComponentMounted(){this.attachElements(),document.addEventListener("click",this.handleOutsideClick.bind(this)),this.refreshTheme()}onComponentUnmounted(){this._themeSubscription.unsubscribe()}attachElements(){this._shadowRoot=this.attachShadow({mode:"closed"}),this._container=document.createElement("div"),this._container.className="menu-container",this._style=document.createElement("style"),this._style.textContent=this.getStyles(),this._shadowRoot.appendChild(this._style),this._shadowRoot.appendChild(this._container)}getStyles(){var e,t,i,n,o,s,l,r,a,d,u,h,c,v,g,p,m,b,_,C,f,x,y,I,w,M,S;const T=this._themeSubscription.manager.getTheme(),$="feed"===this._menuType?null==(n=null==(i=null==(t=null==(e=T.inbox)?void 0:e.header)?void 0:t.feeds)?void 0:i.menu)?void 0:n.animation:null==(l=null==(s=null==(o=T.inbox)?void 0:o.header)?void 0:s.actions)?void 0:l.animation,E="feed"===this._menuType?null==(d=null==(a=null==(r=T.inbox)?void 0:r.header)?void 0:a.feeds)?void 0:d.menu:(null==(c=null==(h=null==(u=T.inbox)?void 0:u.header)?void 0:h.actions)?void 0:c.menu)??(null==(p=null==(g=null==(v=T.inbox)?void 0:v.header)?void 0:g.feeds)?void 0:p.menu),L=(null==$?void 0:$.initialTransform)??"translate3d(0, 0, 0)",B=(null==$?void 0:$.visibleTransform)??"translate3d(0, 0, 0)";return`\n :host {\n position: absolute;\n top: 42px;\n z-index: 1000;\n min-width: 200px;\n user-select: none;\n opacity: 0;\n pointer-events: none;\n transition: ${(null==$?void 0:$.transition)??"all 0.2s ease"};\n transform: ${L};\n will-change: transform, opacity;\n display: none;\n }\n\n :host(.displayed) {\n display: block;\n }\n\n :host(.visible) {\n opacity: 1;\n pointer-events: auto;\n transform: ${B};\n }\n\n .menu-container {\n display: flex;\n flex-direction: column;\n border-radius: ${(null==E?void 0:E.borderRadius)??"6px"};\n border: ${(null==E?void 0:E.border)??"1px solid red"};\n background: ${(null==E?void 0:E.backgroundColor)??"red"};\n box-shadow: ${(null==E?void 0:E.shadow)??"0 4px 12px 0 red"};\n overflow: hidden;\n padding: 4px 0;\n }\n\n courier-inbox-option-menu-item {\n border-bottom: ${(null==(m=null==E?void 0:E.list)?void 0:m.divider)??"none"};\n }\n\n courier-inbox-option-menu-item:last-child {\n border-bottom: none;\n }\n\n ${k.id} {\n display: flex;\n flex-direction: row;\n padding: 6px 12px;\n cursor: pointer;\n }\n\n ${k.id}:hover {\n background-color: ${(null==(b=null==E?void 0:E.list)?void 0:b.hoverBackgroundColor)??"red"};\n }\n\n ${k.id}:active {\n background-color: ${(null==(_=null==E?void 0:E.list)?void 0:_.activeBackgroundColor)??"red"};\n }\n\n ${k.id} .menu-item {\n display: flex;\n align-items: center;\n width: 100%;\n gap: 12px;\n }\n\n ${k.id} .spacer {\n flex: 1;\n }\n\n ${k.id} p {\n margin: 0;\n font-family: ${(null==(f=null==(C=null==E?void 0:E.list)?void 0:C.font)?void 0:f.family)??"inherit"};\n font-weight: ${(null==(y=null==(x=null==E?void 0:E.list)?void 0:x.font)?void 0:y.weight)??"inherit"};\n font-size: ${(null==(w=null==(I=null==E?void 0:E.list)?void 0:I.font)?void 0:w.size)??"14px"};\n color: ${(null==(S=null==(M=null==E?void 0:E.list)?void 0:M.font)?void 0:S.color)??"red"};\n white-space: nowrap;\n }\n\n ${k.id} .check-icon {\n display: block;\n }\n `}setPosition(e){this.style.left=e.left??"auto",this.style.right=e.right??"auto",this.style.top=e.top??"auto"}refreshTheme(){this._style&&(this._style.textContent=this.getStyles()),this.refreshMenuItems()}setOptions(e){this._options=e,this.refreshMenuItems()}refreshMenuItems(){if(!this._container)return;const e=this._container;e.innerHTML="",this._options.forEach(((t,i)=>{const n=new k({option:t,selectable:this._selectable,isSelected:this._selectedIndex===i,themeManager:this._themeSubscription.manager});n.addEventListener("click",(()=>{this._selectable&&this.selectionItemAtIndex(i),t.onClick(t),this.closeMenu()})),e.appendChild(n)}))}toggleMenu(){var e;this._isOpen=!this._isOpen,this._isOpen?(this.showMenu(),null==(e=this._onMenuOpen)||e.call(this)):this.hideMenu()}showMenu(){this.classList.remove("visible"),this.classList.add("displayed"),requestAnimationFrame((()=>{requestAnimationFrame((()=>{this.classList.add("visible")}))}))}hideMenu(){this.classList.remove("visible");if(!window.getComputedStyle(this).transitionDuration.split(",").map((e=>parseFloat(e)||0)).some((e=>e>0)))return void this.classList.remove("displayed");const e=t=>{t.target===this&&(this.classList.contains("visible")||(this.classList.remove("displayed"),this.removeEventListener("transitionend",e)))};this.addEventListener("transitionend",e)}closeMenu(){this._isOpen=!1,this.hideMenu()}handleOutsideClick(e){const t=e.target;this.contains(t)||this.closeMenu()}selectionItemAtIndex(e){this._selectable&&this._container&&(this._selectedIndex=e,this._options.forEach(((t,i)=>{var n;const o=null==(n=this._container)?void 0:n.children[i];o&&o.setSelected&&o.setSelected(i===e)})))}}i.registerElement(w);class M extends i.CourierFactoryElement{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_feeds",[]),o(this,"_currentFeedId"),o(this,"_actions",B.defaultActions()),o(this,"_feedButton"),o(this,"_feedMenu"),o(this,"_actionMenuButton"),o(this,"_actionMenu"),o(this,"tabs"),o(this,"_style"),o(this,"_feedButtonClickHandler"),o(this,"_onFeedChange"),o(this,"_onFeedReselected"),o(this,"_onTabChange"),o(this,"_onTabReselected"),this._themeSubscription=e.themeManager.subscribe((e=>{this.refreshTheme()})),e.actions&&(this._actions=e.actions),this._onFeedChange=e.onFeedChange,this._onFeedReselected=e.onFeedReselected,this._onTabChange=e.onTabChange,this._onTabReselected=e.onTabReselected}static get id(){return"courier-inbox-header"}get theme(){return this._themeSubscription.manager.getTheme()}get showTabs(){var e;const t=this._feeds.find((e=>e.feedId===this._currentFeedId));return((null==(e=null==t?void 0:t.tabs)?void 0:e.length)??0)>1}onComponentMounted(){this._style=i.injectGlobalStyle(M.id,M.getStyles(this.theme))}onComponentUmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}getActionOptions(){var e,t,n,o,s,l,r,a,d,h,c,v,g,p,m,b,_;const C=null==(t=null==(e=this._themeSubscription.manager.getTheme().inbox)?void 0:e.header)?void 0:t.actions,f=[];for(const x of this._actions)switch(x.id){case"readAll":f.push({id:"make_all_read",text:x.text??(null==(n=null==C?void 0:C.markAllRead)?void 0:n.text)??"Mark All as Read",icon:{color:(null==(s=null==(o=null==C?void 0:C.markAllRead)?void 0:o.icon)?void 0:s.color)??"red",svg:x.iconSVG??(null==(r=null==(l=null==C?void 0:C.markAllRead)?void 0:l.icon)?void 0:r.svg)??i.CourierIconSVGs.read},onClick:e=>{u.shared.readAllMessages()}});break;case"archiveAll":f.push({id:"archive_all",text:x.text??(null==(a=null==C?void 0:C.archiveAll)?void 0:a.text)??"Archive All",icon:{color:(null==(h=null==(d=null==C?void 0:C.archiveAll)?void 0:d.icon)?void 0:h.color)??"red",svg:x.iconSVG??(null==(v=null==(c=null==C?void 0:C.archiveAll)?void 0:c.icon)?void 0:v.svg)??i.CourierIconSVGs.archive},onClick:e=>{u.shared.archiveAllMessages()}});break;case"archiveRead":f.push({id:"archive_read",text:x.text??(null==(g=null==C?void 0:C.archiveRead)?void 0:g.text)??"Archive Read",icon:{color:(null==(m=null==(p=null==C?void 0:C.archiveRead)?void 0:p.icon)?void 0:m.color)??"red",svg:x.iconSVG??(null==(_=null==(b=null==C?void 0:C.archiveRead)?void 0:b.icon)?void 0:_.svg)??i.CourierIconSVGs.archiveRead},onClick:e=>{u.shared.archiveReadMessages()}})}return f}refreshTheme(){var e,t;this._style&&(this._style.textContent=M.getStyles(this.theme)),this.refreshActionMenuButton(),null==(e=this._actionMenu)||e.setOptions(this.getActionOptions()),null==(t=this._feedMenu)||t.setOptions(this.getFeedMenuOptions()),this._actionMenuButton&&(this._actionMenuButton.style.display=this._actions.length>0?"":"none"),this._actionMenu&&(this._actionMenu.style.display=this._actions.length>0?"":"none")}getFeedMenuOptions(){return this._feeds.map(((e,t)=>{var n,o,s,l;return{id:e.feedId,text:e.title,icon:{color:(null==(l=null==(s=null==(o=null==(n=this.theme.inbox)?void 0:n.header)?void 0:o.feeds)?void 0:s.button)?void 0:l.selectedFeedIconColor)??"red",svg:e.iconSVG??i.CourierIconSVGs.inbox},onClick:t=>{e.feedId===this._currentFeedId?this._onFeedReselected(e):this._onFeedChange(e)}}}))}render(e){const t=e.feeds.find((e=>e.isSelected)),i=null==t?void 0:t.tabs.find((e=>e.isSelected)),n=((null==t?void 0:t.tabs.length)??0)>1;this._feedButton&&(this._feedButton.setSelectedFeed((null==t?void 0:t.feedId)??""),this._feedButton.setUnreadCount(n?0:(null==i?void 0:i.unreadCount)??0),this.updateFeedButtonInteraction()),this.tabs&&(this.tabs.style.display=n?"flex":"none",this.tabs.setSelectedTab((null==i?void 0:i.datasetId)??""),this.tabs.updateTabUnreadCount((null==i?void 0:i.datasetId)??"",(null==i?void 0:i.unreadCount)??0))}build(e){super.build(e),this.refreshTheme()}defaultElement(){this._feedButton=new y(this._themeSubscription.manager,this._feeds),this._feedMenu=new w(this._themeSubscription.manager,!0,this.getFeedMenuOptions(),"feed"),this._feedMenu.setPosition({left:"12px",top:"51px"}),this._feedButtonClickHandler=e=>{var t,i;e.stopPropagation(),null==(t=this._feedMenu)||t.toggleMenu(),null==(i=this._actionMenu)||i.closeMenu()},this.updateFeedButtonInteraction(),this._actionMenu=new w(this._themeSubscription.manager,!1,this.getActionOptions(),"action"),this._actionMenu.setPosition({right:"12px",top:"51px"}),this._actionMenuButton=new i.CourierIconButton(i.CourierIconSVGs.overflow),this.refreshActionMenuButton(),this._actionMenuButton.addEventListener("click",(e=>{var t,i;e.stopPropagation(),null==(t=this._actionMenu)||t.toggleMenu(),null==(i=this._feedMenu)||i.closeMenu()}));const e=document.createElement("div");e.className="title",e.appendChild(this._feedButton);const t=document.createElement("div");t.className="spacer";const n=document.createElement("div");n.className="header-content",n.appendChild(e),n.appendChild(t),this._actions.length>0&&(n.appendChild(this._actionMenuButton),n.appendChild(this._actionMenu)),n.appendChild(this._feedMenu),this.tabs=new I({themeManager:this._themeSubscription.manager,onTabClick:e=>{this._onTabChange(e)},onTabReselected:e=>{this._onTabReselected(e)}});const o=document.createElement("div");return o.className="header",o.appendChild(n),o.appendChild(this.tabs),o}refreshActionMenuButton(){var e,t,n,o,s,l,r,a,d,u,h;const c=null==(o=null==(n=null==(t=null==(e=this.theme)?void 0:e.inbox)?void 0:t.header)?void 0:n.actions)?void 0:o.button;null==(l=this._actionMenuButton)||l.updateIconSVG((null==(s=null==c?void 0:c.icon)?void 0:s.svg)??i.CourierIconSVGs.overflow),null==(a=this._actionMenuButton)||a.updateIconColor((null==(r=null==c?void 0:c.icon)?void 0:r.color)??"red"),null==(d=this._actionMenuButton)||d.updateBackgroundColor((null==c?void 0:c.backgroundColor)??"transparent"),null==(u=this._actionMenuButton)||u.updateHoverBackgroundColor((null==c?void 0:c.hoverBackgroundColor)??i.CourierColors.black[50010]),null==(h=this._actionMenuButton)||h.updateActiveBackgroundColor((null==c?void 0:c.activeBackgroundColor)??i.CourierColors.black[50020])}updateFeedButtonInteraction(){if(!this._feedButton||!this._feedButtonClickHandler)return;this._feedButton.removeEventListener("click",this._feedButtonClickHandler);this._feeds.length>1?(this._feedButton.style.cursor="pointer",this._feedButton.addEventListener("click",this._feedButtonClickHandler)):this._feedButton.style.cursor="default"}setFeeds(e){var t,i;if(0===e.length)throw new Error("[CourierInboxHeader] Cannot set feeds to an empty array.");if(!e[0].tabs.length)throw new Error("[CourierInboxHeader] First feed does not have a tab.");this._feeds=e,null==(t=this._feedButton)||t.setFeeds(e),this.selectFeed(e[0].feedId,e[0].tabs[0].datasetId),null==(i=this._feedMenu)||i.setOptions(this.getFeedMenuOptions()),this.updateFeedButtonInteraction()}setActions(e){var t;this._actions=e,null==(t=this._actionMenu)||t.setOptions(this.getActionOptions()),this._actionMenuButton&&(this._actionMenuButton.style.display=this._actions.length>0?"":"none"),this._actionMenu&&(this._actionMenu.style.display=this._actions.length>0?"":"none")}selectFeed(e,t){var i,n,o;this._currentFeedId=e,null==(i=this._feedButton)||i.setSelectedFeed(e);const s=this._feeds.findIndex((t=>t.feedId===e));null==(n=this._feedMenu)||n.selectionItemAtIndex(s);const l=(null==(o=this._feeds.find((t=>t.feedId===e)))?void 0:o.tabs)??[];if(l.length>0&&this.tabs){this.tabs.style.display=l.length>1?"flex":"none",this.tabs.setTabs(l),this.tabs.setSelectedTab(t);for(const e of l){const t=u.shared.getDatasetById(e.datasetId);t&&this.tabs.updateTabUnreadCount(e.datasetId,t.unreadCount)}}}static getStyles(e){var t,n,o,s,l,r;return`\n ${M.id} {\n display: flex;\n }\n\n ${M.id} > .header {\n display: flex;\n flex-direction: column;\n flex: 1;\n width: 100%;\n max-width: 100%;\n min-width: 0;\n position: relative;\n overflow-y: visible;\n background-color: ${(null==(n=null==(t=e.inbox)?void 0:t.header)?void 0:n.backgroundColor)??i.CourierColors.white[500]};\n box-shadow: ${(null==(s=null==(o=e.inbox)?void 0:o.header)?void 0:s.shadow)??"0px 1px 0px 0px red"};\n border-bottom: ${(null==(r=null==(l=e.inbox)?void 0:l.header)?void 0:r.border)??"1px solid red"};\n z-index: 100;\n }\n\n ${M.id} .header-content {\n padding-top: 10px;\n padding-right: 12px;\n padding-bottom: 10px;\n padding-left: 12px;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: space-between;\n flex: 1;\n width: 100%;\n max-width: 100%;\n min-width: 0;\n position: relative;\n box-sizing: border-box;\n }\n\n ${M.id} .title {\n display: flex;\n align-items: center;\n gap: 4px;\n }\n\n ${M.id} .spacer {\n flex: 1;\n }\n\n ${M.id} .actions {\n display: flex;\n align-items: center;\n gap: 4px;\n }\n `}}i.registerElement(M);class S{constructor(e){o(this,"events"),this.events=e}remove(){u.shared.removeDataStoreListener(this)}}const T={popup:{button:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.inbox},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.black[50010],activeBackgroundColor:i.CourierColors.black[50020],unreadDotIndicator:{backgroundColor:i.CourierColors.blue[500],borderRadius:"50%",height:"8px",width:"8px"}},window:{backgroundColor:i.CourierColors.white[500],borderRadius:"8px",border:`1px solid ${i.CourierColors.gray[500]}`,shadow:`0px 8px 16px -4px ${i.CourierColors.gray[500]}`,animation:{transition:"none",initialTransform:"translate3d(0, 0, 0)",visibleTransform:"translate3d(0, 0, 0)"}}},inbox:{header:{backgroundColor:i.CourierColors.white[500],shadow:"none",border:`1px solid ${i.CourierColors.gray[500]}`,feeds:{button:{selectedFeedIconColor:i.CourierColors.black[500],hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],transition:"all 0.2s ease",font:{color:i.CourierColors.black[500],family:void 0,size:"16px"},changeFeedIcon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.chevronDown},unreadCountIndicator:{font:{color:i.CourierColors.white[500],family:void 0,size:"12px"},backgroundColor:i.CourierColors.blue[500],borderRadius:"4px",padding:"2px 6px"}},menu:{backgroundColor:i.CourierColors.white[500],border:`1px solid ${i.CourierColors.gray[500]}`,borderRadius:"6px",shadow:`0px 4px 8px -2px ${i.CourierColors.gray[500]}`,animation:{transition:"none",initialTransform:"translate3d(0, 0, 0)",visibleTransform:"translate3d(0, 0, 0)"},list:{hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],divider:"none",font:{color:i.CourierColors.black[500],family:void 0,size:"14px"},selectedIcon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.check}}},tabs:{borderRadius:{topLeft:"4px",topRight:"4px"},transition:"all 0.2s ease",default:{indicatorHeight:"1px",indicatorColor:"transparent",backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],font:{color:i.CourierColors.gray[600],family:void 0,size:"14px"},unreadIndicator:{font:{color:i.CourierColors.gray[600],family:void 0,size:"12px"},backgroundColor:i.CourierColors.black[50010],borderRadius:"4px",padding:"2px 6px"}},selected:{indicatorHeight:"1px",indicatorColor:i.CourierColors.blue[500],backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],font:{color:i.CourierColors.blue[500],family:void 0,size:"14px"},unreadIndicator:{font:{color:i.CourierColors.white[500],family:void 0,size:"12px"},backgroundColor:i.CourierColors.blue[500],borderRadius:"4px",padding:"2px 6px"}}}},tabs:{borderRadius:{topLeft:"4px",topRight:"4px"},transition:"all 0.2s ease",default:{indicatorHeight:"1px",indicatorColor:"transparent",backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],font:{color:i.CourierColors.gray[600],family:void 0,size:"14px"},unreadIndicator:{font:{color:i.CourierColors.gray[600],family:void 0,size:"12px"},backgroundColor:i.CourierColors.black[50010],borderRadius:"4px",padding:"2px 6px"}},selected:{indicatorHeight:"1px",indicatorColor:i.CourierColors.blue[500],backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],font:{color:i.CourierColors.blue[500],family:void 0,size:"14px"},unreadIndicator:{font:{color:i.CourierColors.white[500],family:void 0,size:"12px"},backgroundColor:i.CourierColors.blue[500],borderRadius:"4px",padding:"2px 6px"}}},actions:{button:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.overflow},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500]},markAllRead:{icon:{color:i.CourierColors.black[500]},text:"Read All"},archiveAll:{icon:{color:i.CourierColors.black[500]},text:"Archive All"},archiveRead:{icon:{color:i.CourierColors.black[500]},text:"Archive Read"},animation:{transition:"none",initialTransform:"translate3d(0, 0, 0)",visibleTransform:"translate3d(0, 0, 0)"}}},list:{backgroundColor:i.CourierColors.white[500],scrollbar:{trackBackgroundColor:"transparent",thumbColor:i.CourierColors.black[50020],thumbHoverColor:i.CourierColors.black[50020],width:"8px",height:"8px",borderRadius:"4px"},item:{backgroundColor:"transparent",unreadIndicatorColor:i.CourierColors.blue[500],hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],transition:"all 0.2s ease",actions:{backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],border:`1px solid ${i.CourierColors.gray[500]}`,borderRadius:"4px",shadow:"0px 1px 2px 0px rgba(0, 0, 0, 0.06)",font:{color:i.CourierColors.black[500],family:void 0,size:"14px"}},title:{color:i.CourierColors.black[500],family:void 0,size:"14px"},subtitle:{color:i.CourierColors.gray[600],family:void 0,size:"14px"},time:{color:i.CourierColors.gray[600],family:void 0,size:"14px"},divider:`1px solid ${i.CourierColors.gray[200]}`,menu:{enabled:!0,backgroundColor:i.CourierColors.white[500],border:`1px solid ${i.CourierColors.gray[500]}`,borderRadius:"4px",shadow:`0px 2px 4px -2px ${i.CourierColors.gray[500]}`,animation:{transition:"none",initialTransform:"translate3d(0, 0, 0)",visibleTransform:"translate3d(0, 0, 0)"},longPress:{displayDuration:4e3,vibrationDuration:50},item:{hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],borderRadius:"0px",read:{color:i.CourierColors.black[500]},unread:{color:i.CourierColors.black[500]},archive:{color:i.CourierColors.black[500]},unarchive:{color:i.CourierColors.black[500]}}}}},loading:{animation:{barColor:i.CourierColors.gray[500],barHeight:"14px",barBorderRadius:"14px",duration:"2s"},divider:`1px solid ${i.CourierColors.gray[200]}`},empty:{title:{font:{size:"16px",weight:"500",color:i.CourierColors.black[500]}},button:{text:"Refresh"}},error:{title:{font:{size:"16px",weight:"500",color:i.CourierColors.black[500]}},button:{text:"Retry"}}}},$={popup:{button:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.inbox},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],unreadDotIndicator:{backgroundColor:i.CourierColors.blue[500],borderRadius:"50%",height:"8px",width:"8px"}},window:{backgroundColor:i.CourierColors.black[500],borderRadius:"8px",border:`1px solid ${i.CourierColors.gray[400]}`,shadow:`0px 4px 8px -2px ${i.CourierColors.white[50020]}`,animation:{transition:"none",initialTransform:"translate3d(0, 0, 0)",visibleTransform:"translate3d(0, 0, 0)"}}},inbox:{header:{backgroundColor:i.CourierColors.black[500],shadow:"none",border:`1px solid ${i.CourierColors.gray[400]}`,feeds:{button:{selectedFeedIconColor:i.CourierColors.white[500],hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],transition:"all 0.2s ease",font:{color:i.CourierColors.white[500],family:void 0,size:"16px"},changeFeedIcon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.chevronDown},unreadCountIndicator:{font:{color:i.CourierColors.white[500],family:void 0,size:"12px"},backgroundColor:i.CourierColors.blue[500],borderRadius:"4px",padding:"3px 8px"}},menu:{backgroundColor:i.CourierColors.black[500],border:`1px solid ${i.CourierColors.gray[400]}`,borderRadius:"6px",shadow:`0px 4px 8px -2px ${i.CourierColors.white[50020]}`,animation:{transition:"none",initialTransform:"translate3d(0, 0, 0)",visibleTransform:"translate3d(0, 0, 0)"},list:{hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],divider:"none",font:{color:i.CourierColors.white[500],family:void 0,size:"14px"},selectedIcon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.check}}},tabs:{borderRadius:{topLeft:"4px",topRight:"4px"},transition:"all 0.2s ease",default:{indicatorHeight:"1px",indicatorColor:"transparent",backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],font:{color:i.CourierColors.white[500],family:void 0,size:"14px"},unreadIndicator:{font:{color:i.CourierColors.white[500],family:void 0,size:"12px"},backgroundColor:i.CourierColors.white[50010],borderRadius:"4px",padding:"3px 8px"}},selected:{indicatorHeight:"1px",indicatorColor:i.CourierColors.blue[500],backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],font:{color:i.CourierColors.blue[500],family:void 0,size:"14px"},unreadIndicator:{font:{color:i.CourierColors.white[500],family:void 0,size:"12px"},backgroundColor:i.CourierColors.blue[500],borderRadius:"4px",padding:"3px 8px"}}}},tabs:{borderRadius:{topLeft:"4px",topRight:"4px"},transition:"all 0.2s ease",default:{indicatorHeight:"1px",indicatorColor:"transparent",backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],font:{color:i.CourierColors.white[500],family:void 0,size:"14px"},unreadIndicator:{font:{color:i.CourierColors.white[500],family:void 0,size:"12px"},backgroundColor:i.CourierColors.white[50010],borderRadius:"4px",padding:"3px 8px"}},selected:{indicatorHeight:"1px",indicatorColor:i.CourierColors.blue[500],backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],font:{color:i.CourierColors.blue[500],family:void 0,size:"14px"},unreadIndicator:{font:{color:i.CourierColors.white[500],family:void 0,size:"12px"},backgroundColor:i.CourierColors.blue[500],borderRadius:"4px",padding:"3px 8px"}}},actions:{button:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.overflow},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020]},markAllRead:{icon:{color:i.CourierColors.white[500]},text:"Read All"},archiveAll:{icon:{color:i.CourierColors.white[500]},text:"Archive All"},archiveRead:{icon:{color:i.CourierColors.white[500]},text:"Archive Read"},animation:{transition:"none",initialTransform:"translate3d(0, 0, 0)",visibleTransform:"translate3d(0, 0, 0)"}}},list:{backgroundColor:i.CourierColors.black[500],scrollbar:{trackBackgroundColor:"transparent",thumbColor:i.CourierColors.white[50020],thumbHoverColor:i.CourierColors.white[50020],width:"8px",height:"8px",borderRadius:"4px"},item:{backgroundColor:"transparent",unreadIndicatorColor:i.CourierColors.blue[500],hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],transition:"all 0.2s ease",actions:{backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],border:`1px solid ${i.CourierColors.gray[400]}`,borderRadius:"4px",shadow:`0px 1px 2px 0px ${i.CourierColors.white[50010]}`,font:{color:i.CourierColors.white[500],family:void 0,size:"14px"}},title:{color:i.CourierColors.white[500],family:void 0,size:"14px"},subtitle:{color:i.CourierColors.gray[500],family:void 0,size:"14px"},time:{color:i.CourierColors.gray[500],family:void 0,size:"12px"},divider:`1px solid ${i.CourierColors.gray[400]}`,menu:{enabled:!0,backgroundColor:i.CourierColors.black[500],border:`1px solid ${i.CourierColors.gray[400]}`,borderRadius:"4px",shadow:`0px 2px 4px -2px ${i.CourierColors.white[50020]}`,animation:{transition:"none",initialTransform:"translate3d(0, 0, 0)",visibleTransform:"translate3d(0, 0, 0)"},longPress:{displayDuration:4e3,vibrationDuration:50},item:{hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],borderRadius:"0px",read:{color:i.CourierColors.white[500]},unread:{color:i.CourierColors.white[500]},archive:{color:i.CourierColors.white[500]},unarchive:{color:i.CourierColors.white[500]}}}}},loading:{animation:{barColor:i.CourierColors.gray[400],barHeight:"14px",barBorderRadius:"14px",duration:"2s"},divider:`1px solid ${i.CourierColors.gray[400]}`},empty:{title:{font:{size:"16px",weight:"500",color:i.CourierColors.white[500]}},button:{text:"Refresh"}},error:{title:{font:{size:"16px",weight:"500",color:i.CourierColors.white[500]}},button:{text:"Retry"}}}},E=(e,t)=>{var i,n,o,s,l,r,a,d,u,h,c,v,g,p,m,b,_,C,f,x,y,I,k,w,M,S,E,L,B,F,A,P,R,U,D,O,z,N,G,V,H,j,W,J,q,Q,Y,X,K,Z,ee,te,ie,ne,oe,se,le,re,ae,de,ue,he,ce,ve,ge,pe,me,be,_e,Ce,fe,xe,ye,Ie,ke,we,Me,Se,Te,$e,Ee,Le,Be,Fe,Ae,Pe,Re,Ue,De,Oe,ze,Ne,Ge,Ve,He,je,We,Je,qe,Qe,Ye,Xe,Ke,Ze,et,tt,it,nt,ot,st,lt,rt,at,dt,ut,ht,ct,vt,gt,pt,mt,bt,_t,Ct,ft,xt,yt,It,kt,wt,Mt,St,Tt,$t,Et,Lt,Bt,Ft,At,Pt,Rt,Ut,Dt,Ot,zt,Nt,Gt,Vt,Ht,jt,Wt,Jt,qt,Qt,Yt,Xt,Kt,Zt,ei,ti,ii,ni,oi,si,li,ri,ai,di,ui,hi,ci,vi,gi,pi,mi,bi,_i,Ci,fi,xi,yi,Ii,ki,wi,Mi,Si,Ti,$i,Ei,Li,Bi,Fi,Ai,Pi,Ri,Ui,Di,Oi,zi,Ni,Gi,Vi,Hi,ji,Wi,Ji,qi,Qi,Yi,Xi,Ki,Zi,en,tn,nn,on,sn,ln,rn,an,dn,un,hn,cn,vn,gn,pn,mn,bn,_n,Cn,fn,xn,yn,In,kn,wn,Mn,Sn,Tn,$n,En,Ln,Bn,Fn,An,Pn,Rn,Un,Dn,On,zn,Nn,Gn,Vn,Hn,jn,Wn,Jn,qn,Qn,Yn,Xn,Kn,Zn,eo,to,io,no,oo,so,lo,ro,ao,uo,ho,co,vo,go,po,mo,bo,_o,Co,fo,xo,yo,Io,ko,wo,Mo,So,To,$o,Eo,Lo,Bo,Fo,Ao,Po,Ro,Uo,Do,Oo,zo,No,Go,Vo,Ho,jo,Wo,Jo,qo,Qo,Yo,Xo,Ko,Zo,es,ts,is,ns,os,ss,ls,rs,as,ds,us,hs,cs,vs,gs,ps,ms,bs,_s,Cs,fs,xs,ys,Is,ks,ws,Ms,Ss,Ts,$s,Es,Ls,Bs,Fs,As,Ps,Rs,Us,Ds,Os,zs,Ns,Gs,Vs,Hs,js,Ws,Js,qs,Qs,Ys,Xs,Ks,Zs,el,tl,il,nl,ol,sl,ll,rl,al,dl,ul,hl,cl,vl,gl,pl,ml,bl,_l,Cl,fl,xl,yl,Il,kl,wl,Ml,Sl,Tl,$l,El,Ll,Bl,Fl,Al,Pl,Rl,Ul,Dl,Ol,zl,Nl,Gl,Vl,Hl,jl,Wl,Jl,ql,Ql,Yl,Xl,Kl,Zl,er,tr,ir,nr,or,sr,lr,rr,ar,dr,ur,hr,cr,vr,gr,pr,mr,br,_r,Cr,fr,xr,yr,Ir,kr,wr,Mr,Sr,Tr,$r,Er,Lr,Br,Fr,Ar,Pr,Rr,Ur,Dr,Or,zr,Nr,Gr,Vr,Hr,jr,Wr,Jr,qr,Qr,Yr,Xr;const Kr="light"===e?T:$;return{popup:{button:{...null==(i=Kr.popup)?void 0:i.button,...null==(n=t.popup)?void 0:n.button,icon:{...null==(s=null==(o=Kr.popup)?void 0:o.button)?void 0:s.icon,...null==(r=null==(l=t.popup)?void 0:l.button)?void 0:r.icon},unreadDotIndicator:{...null==(d=null==(a=Kr.popup)?void 0:a.button)?void 0:d.unreadDotIndicator,...null==(h=null==(u=t.popup)?void 0:u.button)?void 0:h.unreadDotIndicator}},window:{...null==(c=Kr.popup)?void 0:c.window,...null==(v=t.popup)?void 0:v.window,animation:{...null==(p=null==(g=Kr.popup)?void 0:g.window)?void 0:p.animation,...null==(b=null==(m=t.popup)?void 0:m.window)?void 0:b.animation}}},inbox:{header:{...null==(_=Kr.inbox)?void 0:_.header,...null==(C=t.inbox)?void 0:C.header,feeds:{...null==(x=null==(f=Kr.inbox)?void 0:f.header)?void 0:x.feeds,...null==(I=null==(y=t.inbox)?void 0:y.header)?void 0:I.feeds,button:{...null==(M=null==(w=null==(k=Kr.inbox)?void 0:k.header)?void 0:w.feeds)?void 0:M.button,...null==(L=null==(E=null==(S=t.inbox)?void 0:S.header)?void 0:E.feeds)?void 0:L.button,font:{...null==(P=null==(A=null==(F=null==(B=Kr.inbox)?void 0:B.header)?void 0:F.feeds)?void 0:A.button)?void 0:P.font,...null==(O=null==(D=null==(U=null==(R=t.inbox)?void 0:R.header)?void 0:U.feeds)?void 0:D.button)?void 0:O.font},changeFeedIcon:{...null==(V=null==(G=null==(N=null==(z=Kr.inbox)?void 0:z.header)?void 0:N.feeds)?void 0:G.button)?void 0:V.changeFeedIcon,...null==(J=null==(W=null==(j=null==(H=t.inbox)?void 0:H.header)?void 0:j.feeds)?void 0:W.button)?void 0:J.changeFeedIcon},unreadCountIndicator:{...null==(X=null==(Y=null==(Q=null==(q=Kr.inbox)?void 0:q.header)?void 0:Q.feeds)?void 0:Y.button)?void 0:X.unreadCountIndicator,...null==(te=null==(ee=null==(Z=null==(K=t.inbox)?void 0:K.header)?void 0:Z.feeds)?void 0:ee.button)?void 0:te.unreadCountIndicator,font:{...null==(le=null==(se=null==(oe=null==(ne=null==(ie=Kr.inbox)?void 0:ie.header)?void 0:ne.feeds)?void 0:oe.button)?void 0:se.unreadCountIndicator)?void 0:le.font,...null==(he=null==(ue=null==(de=null==(ae=null==(re=t.inbox)?void 0:re.header)?void 0:ae.feeds)?void 0:de.button)?void 0:ue.unreadCountIndicator)?void 0:he.font}}},menu:{...null==(ge=null==(ve=null==(ce=Kr.inbox)?void 0:ce.header)?void 0:ve.feeds)?void 0:ge.menu,...null==(be=null==(me=null==(pe=t.inbox)?void 0:pe.header)?void 0:me.feeds)?void 0:be.menu,animation:{...null==(xe=null==(fe=null==(Ce=null==(_e=Kr.inbox)?void 0:_e.header)?void 0:Ce.feeds)?void 0:fe.menu)?void 0:xe.animation,...null==(we=null==(ke=null==(Ie=null==(ye=t.inbox)?void 0:ye.header)?void 0:Ie.feeds)?void 0:ke.menu)?void 0:we.animation},list:{...null==($e=null==(Te=null==(Se=null==(Me=Kr.inbox)?void 0:Me.header)?void 0:Se.feeds)?void 0:Te.menu)?void 0:$e.list,...null==(Fe=null==(Be=null==(Le=null==(Ee=t.inbox)?void 0:Ee.header)?void 0:Le.feeds)?void 0:Be.menu)?void 0:Fe.list,font:{...null==(De=null==(Ue=null==(Re=null==(Pe=null==(Ae=Kr.inbox)?void 0:Ae.header)?void 0:Pe.feeds)?void 0:Re.menu)?void 0:Ue.list)?void 0:De.font,...null==(Ve=null==(Ge=null==(Ne=null==(ze=null==(Oe=t.inbox)?void 0:Oe.header)?void 0:ze.feeds)?void 0:Ne.menu)?void 0:Ge.list)?void 0:Ve.font},selectedIcon:{...null==(qe=null==(Je=null==(We=null==(je=null==(He=Kr.inbox)?void 0:He.header)?void 0:je.feeds)?void 0:We.menu)?void 0:Je.list)?void 0:qe.selectedIcon,...null==(Ze=null==(Ke=null==(Xe=null==(Ye=null==(Qe=t.inbox)?void 0:Qe.header)?void 0:Ye.feeds)?void 0:Xe.menu)?void 0:Ke.list)?void 0:Ze.selectedIcon}}},tabs:{...null==(it=null==(tt=null==(et=Kr.inbox)?void 0:et.header)?void 0:tt.feeds)?void 0:it.tabs,...null==(st=null==(ot=null==(nt=t.inbox)?void 0:nt.header)?void 0:ot.feeds)?void 0:st.tabs,default:{...null==(dt=null==(at=null==(rt=null==(lt=Kr.inbox)?void 0:lt.header)?void 0:rt.feeds)?void 0:at.tabs)?void 0:dt.default,...null==(vt=null==(ct=null==(ht=null==(ut=t.inbox)?void 0:ut.header)?void 0:ht.feeds)?void 0:ct.tabs)?void 0:vt.default,font:{...null==(_t=null==(bt=null==(mt=null==(pt=null==(gt=Kr.inbox)?void 0:gt.header)?void 0:pt.feeds)?void 0:mt.tabs)?void 0:bt.default)?void 0:_t.font,...null==(It=null==(yt=null==(xt=null==(ft=null==(Ct=t.inbox)?void 0:Ct.header)?void 0:ft.feeds)?void 0:xt.tabs)?void 0:yt.default)?void 0:It.font},unreadIndicator:{...null==(Tt=null==(St=null==(Mt=null==(wt=null==(kt=Kr.inbox)?void 0:kt.header)?void 0:wt.feeds)?void 0:Mt.tabs)?void 0:St.default)?void 0:Tt.unreadIndicator,...null==(Ft=null==(Bt=null==(Lt=null==(Et=null==($t=t.inbox)?void 0:$t.header)?void 0:Et.feeds)?void 0:Lt.tabs)?void 0:Bt.default)?void 0:Ft.unreadIndicator,font:{...null==(Ot=null==(Dt=null==(Ut=null==(Rt=null==(Pt=null==(At=Kr.inbox)?void 0:At.header)?void 0:Pt.feeds)?void 0:Rt.tabs)?void 0:Ut.default)?void 0:Dt.unreadIndicator)?void 0:Ot.font,...null==(jt=null==(Ht=null==(Vt=null==(Gt=null==(Nt=null==(zt=t.inbox)?void 0:zt.header)?void 0:Nt.feeds)?void 0:Gt.tabs)?void 0:Vt.default)?void 0:Ht.unreadIndicator)?void 0:jt.font}}},selected:{...null==(Qt=null==(qt=null==(Jt=null==(Wt=Kr.inbox)?void 0:Wt.header)?void 0:Jt.feeds)?void 0:qt.tabs)?void 0:Qt.selected,...null==(Zt=null==(Kt=null==(Xt=null==(Yt=t.inbox)?void 0:Yt.header)?void 0:Xt.feeds)?void 0:Kt.tabs)?void 0:Zt.selected,font:{...null==(oi=null==(ni=null==(ii=null==(ti=null==(ei=Kr.inbox)?void 0:ei.header)?void 0:ti.feeds)?void 0:ii.tabs)?void 0:ni.selected)?void 0:oi.font,...null==(di=null==(ai=null==(ri=null==(li=null==(si=t.inbox)?void 0:si.header)?void 0:li.feeds)?void 0:ri.tabs)?void 0:ai.selected)?void 0:di.font},unreadIndicator:{...null==(gi=null==(vi=null==(ci=null==(hi=null==(ui=Kr.inbox)?void 0:ui.header)?void 0:hi.feeds)?void 0:ci.tabs)?void 0:vi.selected)?void 0:gi.unreadIndicator,...null==(Ci=null==(_i=null==(bi=null==(mi=null==(pi=t.inbox)?void 0:pi.header)?void 0:mi.feeds)?void 0:bi.tabs)?void 0:_i.selected)?void 0:Ci.unreadIndicator,font:{...null==(wi=null==(ki=null==(Ii=null==(yi=null==(xi=null==(fi=Kr.inbox)?void 0:fi.header)?void 0:xi.feeds)?void 0:yi.tabs)?void 0:Ii.selected)?void 0:ki.unreadIndicator)?void 0:wi.font,...null==(Li=null==(Ei=null==($i=null==(Ti=null==(Si=null==(Mi=t.inbox)?void 0:Mi.header)?void 0:Si.feeds)?void 0:Ti.tabs)?void 0:$i.selected)?void 0:Ei.unreadIndicator)?void 0:Li.font}}}}},tabs:{...null==(Fi=null==(Bi=Kr.inbox)?void 0:Bi.header)?void 0:Fi.tabs,...null==(Pi=null==(Ai=t.inbox)?void 0:Ai.header)?void 0:Pi.tabs,default:{...null==(Di=null==(Ui=null==(Ri=Kr.inbox)?void 0:Ri.header)?void 0:Ui.tabs)?void 0:Di.default,...null==(Ni=null==(zi=null==(Oi=t.inbox)?void 0:Oi.header)?void 0:zi.tabs)?void 0:Ni.default,font:{...null==(ji=null==(Hi=null==(Vi=null==(Gi=Kr.inbox)?void 0:Gi.header)?void 0:Vi.tabs)?void 0:Hi.default)?void 0:ji.font,...null==(Qi=null==(qi=null==(Ji=null==(Wi=t.inbox)?void 0:Wi.header)?void 0:Ji.tabs)?void 0:qi.default)?void 0:Qi.font},unreadIndicator:{...null==(Zi=null==(Ki=null==(Xi=null==(Yi=Kr.inbox)?void 0:Yi.header)?void 0:Xi.tabs)?void 0:Ki.default)?void 0:Zi.unreadIndicator,...null==(on=null==(nn=null==(tn=null==(en=t.inbox)?void 0:en.header)?void 0:tn.tabs)?void 0:nn.default)?void 0:on.unreadIndicator,font:{...null==(dn=null==(an=null==(rn=null==(ln=null==(sn=Kr.inbox)?void 0:sn.header)?void 0:ln.tabs)?void 0:rn.default)?void 0:an.unreadIndicator)?void 0:dn.font,...null==(gn=null==(vn=null==(cn=null==(hn=null==(un=t.inbox)?void 0:un.header)?void 0:hn.tabs)?void 0:cn.default)?void 0:vn.unreadIndicator)?void 0:gn.font}}},selected:{...null==(bn=null==(mn=null==(pn=Kr.inbox)?void 0:pn.header)?void 0:mn.tabs)?void 0:bn.selected,...null==(fn=null==(Cn=null==(_n=t.inbox)?void 0:_n.header)?void 0:Cn.tabs)?void 0:fn.selected,font:{...null==(kn=null==(In=null==(yn=null==(xn=Kr.inbox)?void 0:xn.header)?void 0:yn.tabs)?void 0:In.selected)?void 0:kn.font,...null==(Tn=null==(Sn=null==(Mn=null==(wn=t.inbox)?void 0:wn.header)?void 0:Mn.tabs)?void 0:Sn.selected)?void 0:Tn.font},unreadIndicator:{...null==(Bn=null==(Ln=null==(En=null==($n=Kr.inbox)?void 0:$n.header)?void 0:En.tabs)?void 0:Ln.selected)?void 0:Bn.unreadIndicator,...null==(Rn=null==(Pn=null==(An=null==(Fn=t.inbox)?void 0:Fn.header)?void 0:An.tabs)?void 0:Pn.selected)?void 0:Rn.unreadIndicator,font:{...null==(Nn=null==(zn=null==(On=null==(Dn=null==(Un=Kr.inbox)?void 0:Un.header)?void 0:Dn.tabs)?void 0:On.selected)?void 0:zn.unreadIndicator)?void 0:Nn.font,...null==(Wn=null==(jn=null==(Hn=null==(Vn=null==(Gn=t.inbox)?void 0:Gn.header)?void 0:Vn.tabs)?void 0:Hn.selected)?void 0:jn.unreadIndicator)?void 0:Wn.font}}}},actions:{...null==(qn=null==(Jn=Kr.inbox)?void 0:Jn.header)?void 0:qn.actions,...null==(Yn=null==(Qn=t.inbox)?void 0:Qn.header)?void 0:Yn.actions,button:{...null==(Zn=null==(Kn=null==(Xn=Kr.inbox)?void 0:Xn.header)?void 0:Kn.actions)?void 0:Zn.button,...null==(io=null==(to=null==(eo=t.inbox)?void 0:eo.header)?void 0:to.actions)?void 0:io.button,icon:{...null==(lo=null==(so=null==(oo=null==(no=Kr.inbox)?void 0:no.header)?void 0:oo.actions)?void 0:so.button)?void 0:lo.icon,...null==(ho=null==(uo=null==(ao=null==(ro=t.inbox)?void 0:ro.header)?void 0:ao.actions)?void 0:uo.button)?void 0:ho.icon}},markAllRead:{...null==(go=null==(vo=null==(co=Kr.inbox)?void 0:co.header)?void 0:vo.actions)?void 0:go.markAllRead,...null==(bo=null==(mo=null==(po=t.inbox)?void 0:po.header)?void 0:mo.actions)?void 0:bo.markAllRead,icon:{...null==(xo=null==(fo=null==(Co=null==(_o=Kr.inbox)?void 0:_o.header)?void 0:Co.actions)?void 0:fo.markAllRead)?void 0:xo.icon,...null==(wo=null==(ko=null==(Io=null==(yo=t.inbox)?void 0:yo.header)?void 0:Io.actions)?void 0:ko.markAllRead)?void 0:wo.icon}},archiveAll:{...null==(To=null==(So=null==(Mo=Kr.inbox)?void 0:Mo.header)?void 0:So.actions)?void 0:To.archiveAll,...null==(Lo=null==(Eo=null==($o=t.inbox)?void 0:$o.header)?void 0:Eo.actions)?void 0:Lo.archiveAll,icon:{...null==(Po=null==(Ao=null==(Fo=null==(Bo=Kr.inbox)?void 0:Bo.header)?void 0:Fo.actions)?void 0:Ao.archiveAll)?void 0:Po.icon,...null==(Oo=null==(Do=null==(Uo=null==(Ro=t.inbox)?void 0:Ro.header)?void 0:Uo.actions)?void 0:Do.archiveAll)?void 0:Oo.icon}},archiveRead:{...null==(Go=null==(No=null==(zo=Kr.inbox)?void 0:zo.header)?void 0:No.actions)?void 0:Go.archiveRead,...null==(jo=null==(Ho=null==(Vo=t.inbox)?void 0:Vo.header)?void 0:Ho.actions)?void 0:jo.archiveRead,icon:{...null==(Qo=null==(qo=null==(Jo=null==(Wo=Kr.inbox)?void 0:Wo.header)?void 0:Jo.actions)?void 0:qo.archiveRead)?void 0:Qo.icon,...null==(Zo=null==(Ko=null==(Xo=null==(Yo=t.inbox)?void 0:Yo.header)?void 0:Xo.actions)?void 0:Ko.archiveRead)?void 0:Zo.icon}},animation:{...null==(is=null==(ts=null==(es=Kr.inbox)?void 0:es.header)?void 0:ts.actions)?void 0:is.animation,...null==(ss=null==(os=null==(ns=t.inbox)?void 0:ns.header)?void 0:os.actions)?void 0:ss.animation}}},list:{...null==(ls=Kr.inbox)?void 0:ls.list,...null==(rs=t.inbox)?void 0:rs.list,scrollbar:{...null==(ds=null==(as=Kr.inbox)?void 0:as.list)?void 0:ds.scrollbar,...null==(hs=null==(us=t.inbox)?void 0:us.list)?void 0:hs.scrollbar},item:{...null==(vs=null==(cs=Kr.inbox)?void 0:cs.list)?void 0:vs.item,...null==(ps=null==(gs=t.inbox)?void 0:gs.list)?void 0:ps.item,actions:{...null==(_s=null==(bs=null==(ms=Kr.inbox)?void 0:ms.list)?void 0:bs.item)?void 0:_s.actions,...null==(xs=null==(fs=null==(Cs=t.inbox)?void 0:Cs.list)?void 0:fs.item)?void 0:xs.actions,font:{...null==(ws=null==(ks=null==(Is=null==(ys=Kr.inbox)?void 0:ys.list)?void 0:Is.item)?void 0:ks.actions)?void 0:ws.font,...null==($s=null==(Ts=null==(Ss=null==(Ms=t.inbox)?void 0:Ms.list)?void 0:Ss.item)?void 0:Ts.actions)?void 0:$s.font}},title:{...null==(Bs=null==(Ls=null==(Es=Kr.inbox)?void 0:Es.list)?void 0:Ls.item)?void 0:Bs.title,...null==(Ps=null==(As=null==(Fs=t.inbox)?void 0:Fs.list)?void 0:As.item)?void 0:Ps.title},subtitle:{...null==(Ds=null==(Us=null==(Rs=Kr.inbox)?void 0:Rs.list)?void 0:Us.item)?void 0:Ds.subtitle,...null==(Ns=null==(zs=null==(Os=t.inbox)?void 0:Os.list)?void 0:zs.item)?void 0:Ns.subtitle},time:{...null==(Hs=null==(Vs=null==(Gs=Kr.inbox)?void 0:Gs.list)?void 0:Vs.item)?void 0:Hs.time,...null==(Js=null==(Ws=null==(js=t.inbox)?void 0:js.list)?void 0:Ws.item)?void 0:Js.time},menu:{...null==(Ys=null==(Qs=null==(qs=Kr.inbox)?void 0:qs.list)?void 0:Qs.item)?void 0:Ys.menu,...null==(Zs=null==(Ks=null==(Xs=t.inbox)?void 0:Xs.list)?void 0:Ks.item)?void 0:Zs.menu,animation:{...null==(nl=null==(il=null==(tl=null==(el=Kr.inbox)?void 0:el.list)?void 0:tl.item)?void 0:il.menu)?void 0:nl.animation,...null==(rl=null==(ll=null==(sl=null==(ol=t.inbox)?void 0:ol.list)?void 0:sl.item)?void 0:ll.menu)?void 0:rl.animation},item:{...null==(hl=null==(ul=null==(dl=null==(al=Kr.inbox)?void 0:al.list)?void 0:dl.item)?void 0:ul.menu)?void 0:hl.item,...null==(pl=null==(gl=null==(vl=null==(cl=t.inbox)?void 0:cl.list)?void 0:vl.item)?void 0:gl.menu)?void 0:pl.item,read:{...null==(fl=null==(Cl=null==(_l=null==(bl=null==(ml=Kr.inbox)?void 0:ml.list)?void 0:bl.item)?void 0:_l.menu)?void 0:Cl.item)?void 0:fl.read,...null==(wl=null==(kl=null==(Il=null==(yl=null==(xl=t.inbox)?void 0:xl.list)?void 0:yl.item)?void 0:Il.menu)?void 0:kl.item)?void 0:wl.read},unread:{...null==(El=null==($l=null==(Tl=null==(Sl=null==(Ml=Kr.inbox)?void 0:Ml.list)?void 0:Sl.item)?void 0:Tl.menu)?void 0:$l.item)?void 0:El.unread,...null==(Pl=null==(Al=null==(Fl=null==(Bl=null==(Ll=t.inbox)?void 0:Ll.list)?void 0:Bl.item)?void 0:Fl.menu)?void 0:Al.item)?void 0:Pl.unread},archive:{...null==(zl=null==(Ol=null==(Dl=null==(Ul=null==(Rl=Kr.inbox)?void 0:Rl.list)?void 0:Ul.item)?void 0:Dl.menu)?void 0:Ol.item)?void 0:zl.archive,...null==(jl=null==(Hl=null==(Vl=null==(Gl=null==(Nl=t.inbox)?void 0:Nl.list)?void 0:Gl.item)?void 0:Vl.menu)?void 0:Hl.item)?void 0:jl.archive},unarchive:{...null==(Yl=null==(Ql=null==(ql=null==(Jl=null==(Wl=Kr.inbox)?void 0:Wl.list)?void 0:Jl.item)?void 0:ql.menu)?void 0:Ql.item)?void 0:Yl.unarchive,...null==(tr=null==(er=null==(Zl=null==(Kl=null==(Xl=t.inbox)?void 0:Xl.list)?void 0:Kl.item)?void 0:Zl.menu)?void 0:er.item)?void 0:tr.unarchive}}}}},loading:{...null==(ir=Kr.inbox)?void 0:ir.loading,...null==(nr=t.inbox)?void 0:nr.loading,animation:{...null==(sr=null==(or=Kr.inbox)?void 0:or.loading)?void 0:sr.animation,...null==(rr=null==(lr=t.inbox)?void 0:lr.loading)?void 0:rr.animation}},empty:{...null==(ar=Kr.inbox)?void 0:ar.empty,...null==(dr=t.inbox)?void 0:dr.empty,title:{...null==(hr=null==(ur=Kr.inbox)?void 0:ur.empty)?void 0:hr.title,...null==(vr=null==(cr=t.inbox)?void 0:cr.empty)?void 0:vr.title,font:{...null==(mr=null==(pr=null==(gr=Kr.inbox)?void 0:gr.empty)?void 0:pr.title)?void 0:mr.font,...null==(Cr=null==(_r=null==(br=t.inbox)?void 0:br.empty)?void 0:_r.title)?void 0:Cr.font}},button:{...null==(xr=null==(fr=Kr.inbox)?void 0:fr.empty)?void 0:xr.button,...null==(Ir=null==(yr=t.inbox)?void 0:yr.empty)?void 0:Ir.button,font:{...null==(Mr=null==(wr=null==(kr=Kr.inbox)?void 0:kr.empty)?void 0:wr.button)?void 0:Mr.font,...null==($r=null==(Tr=null==(Sr=t.inbox)?void 0:Sr.empty)?void 0:Tr.button)?void 0:$r.font}}},error:{...null==(Er=Kr.inbox)?void 0:Er.error,...null==(Lr=t.inbox)?void 0:Lr.error,title:{...null==(Fr=null==(Br=Kr.inbox)?void 0:Br.error)?void 0:Fr.title,...null==(Pr=null==(Ar=t.inbox)?void 0:Ar.error)?void 0:Pr.title,font:{...null==(Dr=null==(Ur=null==(Rr=Kr.inbox)?void 0:Rr.error)?void 0:Ur.title)?void 0:Dr.font,...null==(Nr=null==(zr=null==(Or=t.inbox)?void 0:Or.error)?void 0:zr.title)?void 0:Nr.font}},button:{...null==(Vr=null==(Gr=Kr.inbox)?void 0:Gr.error)?void 0:Vr.button,...null==(jr=null==(Hr=t.inbox)?void 0:Hr.error)?void 0:jr.button,font:{...null==(qr=null==(Jr=null==(Wr=Kr.inbox)?void 0:Wr.error)?void 0:Jr.button)?void 0:qr.font,...null==(Xr=null==(Yr=null==(Qr=t.inbox)?void 0:Qr.error)?void 0:Yr.button)?void 0:Xr.font}}}}}};class L extends i.CourierThemeManager{constructor(e){super(e),o(this,"THEME_CHANGE_EVENT","courier_inbox_theme_change")}getDefaultLightTheme(){return T}getDefaultDarkTheme(){return $}mergeTheme(e,t){return E(e,t)}subscribe(e){return{...super.subscribe(e),manager:this}}}class B extends i.CourierBaseElement{constructor(e){super(),o(this,"_currentFeedId",b()[0].feedId),o(this,"_feedTabMap",new Map),o(this,"_themeManager"),o(this,"_inboxStyle"),o(this,"_list"),o(this,"_datastoreListener"),o(this,"_authListener"),o(this,"_feeds",b()),o(this,"_header"),o(this,"_headerFactory"),o(this,"_actions",B.defaultActions()),o(this,"_onMessageClick"),o(this,"_onMessageActionClick"),o(this,"_onMessageLongPress"),o(this,"_listItemActions",B.defaultListItemActions()),o(this,"_defaultProps",{height:"auto"}),this._themeManager=e??new L(T)}static get id(){return"courier-inbox"}static defaultFeeds(){return b()}static defaultActions(){return[{id:"readAll"},{id:"archiveRead"},{id:"archiveAll"}]}static defaultListItemActions(){return[{id:"read_unread"},{id:"archive_unarchive"}]}get currentFeedId(){return this._currentFeedId}get _currentTabId(){return this.getSelectedTabIdForFeed(this._currentFeedId)}getSelectedTabIdForFeed(e){return this._feedTabMap.get(e)??"unknown_tab"}get theme(){return this._themeManager.getTheme()}setLightTheme(e){this._themeManager.setLightTheme(e)}setDarkTheme(e){this._themeManager.setDarkTheme(e)}setMode(e){this._themeManager.setMode(e)}static get observedAttributes(){return["height","light-theme","dark-theme","mode","message-click","message-action-click","message-long-press"]}resetInitialFeedAndTab(){if(!this._feeds.length)throw new Error("No feeds are available to initialize.");this._feedTabMap.clear();for(const e of this._feeds){if(!e.tabs||!e.tabs.length)throw new Error(`Feed "${e.feedId}" does not contain any tabs. You must have at least one tab in each feed.`);this._feedTabMap.set(e.feedId,e.tabs[0].datasetId)}this._currentFeedId=this._feeds[0].feedId}onComponentMounted(){this.readInitialThemeAttributes(),this.attachElements(),this.setupThemeSubscription(),this.setupAuthListener(),this.initializeInboxData()}readInitialThemeAttributes(){var e,i,n,o;const s=this.getAttribute("light-theme");if(s)try{this.setLightTheme(JSON.parse(s))}catch(a){null==(i=null==(e=t.Courier.shared.client)?void 0:e.options.logger)||i.error("Failed to parse light-theme attribute:",a)}const l=this.getAttribute("dark-theme");if(l)try{this.setDarkTheme(JSON.parse(l))}catch(a){null==(o=null==(n=t.Courier.shared.client)?void 0:n.options.logger)||o.error("Failed to parse dark-theme attribute:",a)}const r=this.getAttribute("mode");r&&this._themeManager.setMode(r)}setupThemeSubscription(){this._themeManager.subscribe((e=>{this.refreshTheme()})),this.refreshTheme()}setupAuthListener(){this._authListener=t.Courier.shared.addAuthenticationListener((async({userId:e})=>{e&&await this.refresh()}))}initializeInboxData(){this.resetInitialFeedAndTab(),u.shared.registerFeeds(this._feeds),this._datastoreListener=new S({onError:e=>{var t;null==(t=this._list)||t.setError(e)},onDataSetChange:e=>{var t;this._currentTabId===e.id&&(null==(t=this._list)||t.setDataSet(e),this.updateHeader())},onPageAdded:e=>{var t;this._currentTabId===e.id&&(null==(t=this._list)||t.addPage(e),this.updateHeader())},onMessageAdd:(e,t,i)=>{var n;this._currentTabId===i&&(null==(n=this._list)||n.addMessage(e,t),this.updateHeader())},onMessageRemove:(e,t,i)=>{var n;this._currentTabId===i&&(null==(n=this._list)||n.removeMessage(t),this.updateHeader())},onMessageUpdate:(e,t,i)=>{var n;this._currentTabId===i&&(null==(n=this._list)||n.updateMessage(e,t),this.updateHeader())},onUnreadCountChange:(e,t)=>{var i,n;null==(n=null==(i=this._header)?void 0:i.tabs)||n.updateTabUnreadCount(t,e),this._currentTabId===t&&this.updateHeader()},onTotalUnreadCountChange:e=>{this.updateHeader()}}),u.shared.addDataStoreListener(this._datastoreListener),this.refresh()}attachElements(){var e,n;this._inboxStyle=i.injectGlobalStyle(B.id,this.getStyles()),this._header=new M({themeManager:this._themeManager,actions:this._actions,onFeedChange:e=>{this.selectFeed(e.feedId)},onFeedReselected:e=>{var t,i,n;this.selectTab(e.tabs[0].datasetId),null==(t=this._list)||t.scrollToTop(),null==(n=null==(i=this._header)?void 0:i.tabs)||n.scrollToStart()},onTabChange:e=>{this.selectTab(e.datasetId)},onTabReselected:e=>{var t;null==(t=this._list)||t.scrollToTop()}}),null==(e=this._header)||e.build(void 0),null==(n=this._header)||n.setFeeds(this._feeds),this.appendChild(this._header),this._list=new f({themeManager:this._themeManager,listItemActions:this._listItemActions,canClickListItems:!1,canLongPressListItems:!1,onRefresh:()=>{this.refresh()},onPaginationTrigger:async e=>{var i,n;try{await u.shared.fetchNextPageOfMessages({datasetId:e})}catch(o){null==(n=null==(i=t.Courier.shared.client)?void 0:i.options.logger)||n.error("Failed to fetch next page of messages:",o)}},onMessageClick:(e,t)=>{var i;u.shared.clickMessage({message:e}),this.dispatchEvent(new CustomEvent("message-click",{detail:{message:e,index:t},bubbles:!0,composed:!0})),null==(i=this._onMessageClick)||i.call(this,{message:e,index:t})},onMessageActionClick:(e,t,i)=>{var n;this.dispatchEvent(new CustomEvent("message-action-click",{detail:{message:e,action:t,index:i},bubbles:!0,composed:!0})),null==(n=this._onMessageActionClick)||n.call(this,{message:e,action:t,index:i})},onMessageLongPress:(e,t)=>{var i;this.dispatchEvent(new CustomEvent("message-long-press",{detail:{message:e,index:t},bubbles:!0,composed:!0})),null==(i=this._onMessageLongPress)||i.call(this,{message:e,index:t})}}),this.appendChild(this._list)}onComponentUnmounted(){var e,t,i;this._themeManager.cleanup(),null==(e=this._datastoreListener)||e.remove(),null==(t=this._authListener)||t.remove(),null==(i=this._inboxStyle)||i.remove()}refreshTheme(){var e;null==(e=this._list)||e.refreshInfoStateThemes(),this._inboxStyle&&(this._inboxStyle.textContent=this.getStyles())}getStyles(){return`\n ${B.id} {\n display: flex;\n flex-direction: column;\n width: 100%;\n height: ${this._defaultProps.height};\n }\n\n ${B.id} courier-inbox-list {\n flex: 1;\n overflow-y: auto;\n overflow-x: hidden;\n }\n `}setHeader(e){this._headerFactory=e,this.updateHeader()}removeHeader(){this._headerFactory=null,this.updateHeader()}setLoadingState(e){var t;null==(t=this._list)||t.setLoadingStateFactory(e)}setEmptyState(e){var t;null==(t=this._list)||t.setEmptyStateFactory(e)}setErrorState(e){var t;null==(t=this._list)||t.setErrorStateFactory(e)}setListItem(e){var t;null==(t=this._list)||t.setListItemFactory(e)}setPaginationItem(e){var t;null==(t=this._list)||t.setPaginationItemFactory(e)}onMessageClick(e){var t;this._onMessageClick=e,null==(t=this._list)||t.setCanClickListItems(void 0!==e)}onMessageActionClick(e){this._onMessageActionClick=e}onMessageLongPress(e){var t;this._onMessageLongPress=e,null==(t=this._list)||t.setCanLongPressListItems(void 0!==e)}async reloadListForTab(){var e;null==(e=this._list)||e.selectDataset(this._currentTabId),await u.shared.load({canUseCache:!0,datasetIds:[this._currentTabId]})}selectFeed(e){var t,i;const n=this._feeds.find((t=>t.feedId===e));if(!n)throw new Error(`Feed "${e}" does not exist.`);if(this._currentFeedId===e){if(!n.tabs||0===n.tabs.length)throw new Error(`Feed "${e}" does not contain any tabs. You must have at least one tab in each feed.`);const i=n.tabs[0].datasetId;return null==(t=this._header)||t.selectFeed(e,i),void this.selectTab(i)}this._currentFeedId=e,null==(i=this._header)||i.selectFeed(e,this._currentTabId),this.selectTab(this._currentTabId)}selectTab(e){var t,i,n;const o=this._feeds.find((e=>e.feedId===this._currentFeedId));if(!o)throw new Error(`Feed "${this._currentFeedId}" does not exist.`);if(!(null==(t=o.tabs)?void 0:t.some((t=>t.datasetId===e))))throw new Error(`Tab "${e}" does not exist in feed "${o.feedId}".`);this._feedTabMap.set(this._currentFeedId,e),null==(n=null==(i=this._header)?void 0:i.tabs)||n.setSelectedTab(e),this.reloadListForTab()}updateTabUnreadCounts(e){var t,i;for(const n of e){const e=u.shared.getDatasetById(n.datasetId);e&&(null==(i=null==(t=this._header)?void 0:t.tabs)||i.updateTabUnreadCount(n.datasetId,e.unreadCount))}}setActions(e){var t;this._actions=e,null==(t=this._header)||t.setActions(this._actions)}setListItemActions(e){var t;this._listItemActions=e,null==(t=this._list)||t.setListItemActions(this._listItemActions)}setFeeds(e){var t,i,n,o;this._feeds=e,this.resetInitialFeedAndTab(),u.shared.registerFeeds(this._feeds),null==(t=this._header)||t.setFeeds(this._feeds),null==(i=this._header)||i.selectFeed(this._currentFeedId,this._currentTabId),this.updateHeader(),null==(n=this._list)||n.selectDataset(this._currentTabId),null==(o=this._list)||o.scrollToTop(!1),this.refresh()}getFeeds(){return this._feeds}getHeaderFeeds(){return this._feeds.map((e=>({feedId:e.feedId,title:e.title,iconSVG:e.iconSVG,tabs:e.tabs.map((e=>{var t;return{datasetId:e.datasetId,title:e.title,unreadCount:(null==(t=u.shared.getDatasetById(e.datasetId))?void 0:t.unreadCount)??0,isSelected:e.datasetId===this._currentTabId,filter:e.filter}})),isSelected:e.feedId===this._currentFeedId})))}updateHeader(){var e,t,i;if(!this._currentTabId)return;const n={feeds:this.getHeaderFeeds()};switch(this._headerFactory){case void 0:null==(e=this._header)||e.render(n);break;case null:null==(t=this._header)||t.build(null);break;default:const o=this._headerFactory(n);null==(i=this._header)||i.build(o)}}async load(e){await u.shared.load(e);for(const t of this._feeds)this.updateTabUnreadCounts(t.tabs);await u.shared.listenForUpdates()}async refresh(){var e,i;if(null==(e=t.Courier.shared.client)?void 0:e.options.userId)return this.load({canUseCache:!1});null==(i=t.Courier.shared.client)||i.options.logger.error("No user signed in. Please call Courier.shared.signIn(...) to load the inbox.")}attributeChangedCallback(e,i,n){var o,s,l,r,a,d;if(i!==n)switch(e){case"height":const e=n||this._defaultProps.height;this.style.height=e;break;case"message-click":if(n)try{this._onMessageClick=new Function("props",n)}catch(u){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Failed to parse message-click handler:",u)}else this._onMessageClick=void 0;break;case"message-action-click":if(n)try{this._onMessageActionClick=new Function("props",n)}catch(u){null==(r=null==(l=t.Courier.shared.client)?void 0:l.options.logger)||r.error("Failed to parse message-action-click handler:",u)}else this._onMessageActionClick=void 0;break;case"message-long-press":if(n)try{this._onMessageLongPress=new Function("props",n)}catch(u){null==(d=null==(a=t.Courier.shared.client)?void 0:a.options.logger)||d.error("Failed to parse message-long-press handler:",u)}else this._onMessageLongPress=void 0;break;case"light-theme":n&&this.setLightTheme(JSON.parse(n));break;case"dark-theme":n&&this.setDarkTheme(JSON.parse(n));break;case"mode":this._themeManager.setMode(n)}}}i.registerElement(B);class F extends i.CourierFactoryElement{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_style"),o(this,"_container"),o(this,"_triggerButton"),o(this,"_unreadBadge"),this._themeSubscription=e.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-menu-button"}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this.refreshTheme()}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}defaultElement(){return this._container=document.createElement("div"),this._container.className="menu-button-container",this._triggerButton=new i.CourierIconButton(i.CourierIconSVGs.inbox),this._unreadBadge=document.createElement("div"),this._unreadBadge.id="unread-badge",this._unreadBadge.style.display="none",this._container.appendChild(this._triggerButton),this._container.appendChild(this._unreadBadge),this._container}static getStyles(e){var t,i,n,o,s,l,r,a,d,u,h,c;return`\n ${F.id} {\n display: inline-block;\n }\n\n ${F.id} .menu-button-container {\n position: relative;\n display: inline-block;\n }\n \n ${F.id} .menu-button-container #unread-badge {\n position: absolute;\n top: 2px;\n right: 2px;\n pointer-events: none;\n width: ${(null==(n=null==(i=null==(t=e.popup)?void 0:t.button)?void 0:i.unreadDotIndicator)?void 0:n.width)??"8px"};\n height: ${(null==(l=null==(s=null==(o=e.popup)?void 0:o.button)?void 0:s.unreadDotIndicator)?void 0:l.height)??"8px"};\n background: ${(null==(d=null==(a=null==(r=e.popup)?void 0:r.button)?void 0:a.unreadDotIndicator)?void 0:d.backgroundColor)??"red"};\n border-radius: ${(null==(c=null==(h=null==(u=e.popup)?void 0:u.button)?void 0:h.unreadDotIndicator)?void 0:c.borderRadius)??"50%"};\n display: none;\n z-index: 1;\n }\n `}onUnreadCountChange(e){this._unreadBadge&&(this._unreadBadge.style.display=e>0?"block":"none"),this.refreshTheme()}refreshTheme(){var e,t,n,o,s,l,r,a,d,u,h,c,v,g,p,m,b,_,C,f,x,y,I;null==(e=this._style)||e.remove(),this._style=i.injectGlobalStyle(F.id,F.getStyles(this.theme)),null==(l=this._triggerButton)||l.updateIconColor((null==(s=null==(o=null==(n=null==(t=this.theme)?void 0:t.popup)?void 0:n.button)?void 0:o.icon)?void 0:s.color)??i.CourierColors.black[500]),null==(h=this._triggerButton)||h.updateIconSVG((null==(u=null==(d=null==(a=null==(r=this.theme)?void 0:r.popup)?void 0:a.button)?void 0:d.icon)?void 0:u.svg)??i.CourierIconSVGs.inbox),null==(p=this._triggerButton)||p.updateBackgroundColor((null==(g=null==(v=null==(c=this.theme)?void 0:c.popup)?void 0:v.button)?void 0:g.backgroundColor)??"transparent"),null==(C=this._triggerButton)||C.updateHoverBackgroundColor((null==(_=null==(b=null==(m=this.theme)?void 0:m.popup)?void 0:b.button)?void 0:_.hoverBackgroundColor)??i.CourierColors.black[50010]),null==(I=this._triggerButton)||I.updateActiveBackgroundColor((null==(y=null==(x=null==(f=this.theme)?void 0:f.popup)?void 0:x.button)?void 0:y.activeBackgroundColor)??i.CourierColors.black[50020])}}i.registerElement(F);class A extends i.CourierBaseElement{constructor(){super(),o(this,"_width","440px"),o(this,"_height","440px"),o(this,"_popupAlignment","top-left"),o(this,"_top"),o(this,"_right"),o(this,"_bottom"),o(this,"_left"),o(this,"_themeManager",new L(T)),o(this,"_triggerButton"),o(this,"_popup"),o(this,"_inbox"),o(this,"_style"),o(this,"_datastoreListener"),o(this,"_totalUnreadCount",0),o(this,"_popupMenuButtonFactory"),o(this,"handleOutsideClick",(e=>{if(!this._popup)return;const t=["courier-inbox-option-menu"];e.composedPath().some((e=>e instanceof HTMLElement&&(!(e!==this._popup&&!this._popup.contains(e))||t.some((t=>e.matches(t))))))||this.hidePopup()})),this._themeManager.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-popup-menu"}get theme(){return this._themeManager.getTheme()}setLightTheme(e){this._themeManager.setLightTheme(e)}setDarkTheme(e){this._themeManager.setDarkTheme(e)}setMode(e){this._themeManager.setMode(e)}static get observedAttributes(){return["popup-alignment","message-click","message-action-click","message-long-press","popup-width","popup-height","top","right","bottom","left","light-theme","dark-theme","mode"]}onComponentMounted(){this.readInitialThemeAttributes(),this._style=i.injectGlobalStyle(A.id,A.getStyles(this.theme,this._width,this._height)),this._triggerButton=new F(this._themeManager),this._popup=document.createElement("div"),this._popup.className="popup",this._inbox=new B(this._themeManager),this._inbox.setAttribute("height","100%"),this.refreshTheme(),this.appendChild(this._triggerButton),this.appendChild(this._popup),this._popup.appendChild(this._inbox),this._triggerButton.addEventListener("click",this.togglePopup.bind(this)),document.addEventListener("click",this.handleOutsideClick.bind(this)),this.updatePopupPosition(),this._datastoreListener=new S(this),u.shared.addDataStoreListener(this._datastoreListener),this.render()}onComponentUnmounted(){var e,t;null==(e=this._style)||e.remove(),null==(t=this._datastoreListener)||t.remove(),this._themeManager.cleanup()}readInitialThemeAttributes(){var e,i,n,o;const s=this.getAttribute("light-theme");if(s)try{this.setLightTheme(JSON.parse(s))}catch(a){null==(i=null==(e=t.Courier.shared.client)?void 0:e.options.logger)||i.error("Failed to parse light-theme attribute:",a)}const l=this.getAttribute("dark-theme");if(l)try{this.setDarkTheme(JSON.parse(l))}catch(a){null==(o=null==(n=t.Courier.shared.client)?void 0:n.options.logger)||o.error("Failed to parse dark-theme attribute:",a)}const r=this.getAttribute("mode");r&&this._themeManager.setMode(r)}refreshTheme(){this._style&&(this._style.textContent=A.getStyles(this.theme,this._width,this._height))}static getStyles(e,t,i){var n,o,s,l,r,a,d,u,h,c;const v=null==(o=null==(n=e.popup)?void 0:n.window)?void 0:o.animation,g=(null==v?void 0:v.initialTransform)??"translate3d(-10px, -10px, 0) scale(0.9)",p=(null==v?void 0:v.visibleTransform)??"translate3d(0, 0, 0) scale(1)";return`\n ${A.id} {\n display: inline-block;\n position: relative;\n }\n\n ${A.id} .popup {\n display: none;\n position: absolute;\n background: ${(null==(l=null==(s=e.popup)?void 0:s.window)?void 0:l.backgroundColor)??"red"};\n border-radius: ${(null==(a=null==(r=e.popup)?void 0:r.window)?void 0:a.borderRadius)??"8px"};\n border: ${(null==(u=null==(d=e.popup)?void 0:d.window)?void 0:u.border)??"1px solid red"};\n box-shadow: ${(null==(c=null==(h=e.popup)?void 0:h.window)?void 0:c.shadow)??"0px 8px 16px -4px red"};\n z-index: 1000;\n width: ${t};\n height: ${i};\n overflow: hidden;\n transform: ${g};\n will-change: transform, opacity;\n transition: ${(null==v?void 0:v.transition)??"all 0.2s ease"};\n opacity: 0;\n }\n\n ${A.id} .popup.displayed {\n display: block;\n }\n\n ${A.id} .popup.visible {\n opacity: 1;\n transform: ${p};\n }\n\n ${A.id} courier-inbox {\n height: 100%;\n }\n `}attributeChangedCallback(e,t,i){switch(e){case"popup-alignment":this.isValidPosition(i)&&(this._popupAlignment=i,this.updatePopupPosition());break;case"popup-width":this._width=i,this.setSize(i,this._height);break;case"popup-height":this._height=i,this.setSize(this._width,i);break;case"top":this._top=i,this.updatePopupPosition();break;case"right":this._right=i,this.updatePopupPosition();break;case"bottom":this._bottom=i,this.updatePopupPosition();break;case"left":this._left=i,this.updatePopupPosition();break;case"light-theme":i&&this.setLightTheme(JSON.parse(i));break;case"dark-theme":i&&this.setDarkTheme(JSON.parse(i));break;case"mode":this._themeManager.setMode(i)}}onUnreadCountChange(e){this.render()}onTotalUnreadCountChange(e){this._totalUnreadCount=e,this.render()}onMessageClick(e){var t;null==(t=this._inbox)||t.onMessageClick((t=>{e&&e(t),this.closePopup()}))}onMessageActionClick(e){var t;null==(t=this._inbox)||t.onMessageActionClick((t=>{e&&e(t),this.closePopup()}))}onMessageLongPress(e){var t;null==(t=this._inbox)||t.onMessageLongPress((t=>{e&&e(t),this.closePopup()}))}isValidPosition(e){return["top-right","top-left","top-center","bottom-right","bottom-left","bottom-center","center-right","center-left","center-center"].includes(e)}updatePopupPosition(){if(this._popup)switch(this._popup.style.top="",this._popup.style.bottom="",this._popup.style.left="",this._popup.style.right="",this._popup.style.margin="",this._popup.style.transform="",this._popupAlignment){case"top-right":this._popup.style.top=this._top??"40px",this._popup.style.right=this._right??"0px";break;case"top-left":this._popup.style.top=this._top??"40px",this._popup.style.left=this._left??"0px";break;case"top-center":this._popup.style.top=this._top??"40px",this._popup.style.left="50%",this._popup.style.transform="translateX(-50%)";break;case"bottom-right":this._popup.style.bottom=this._bottom??"40px",this._popup.style.right=this._right??"0px";break;case"bottom-left":this._popup.style.bottom=this._bottom??"40px",this._popup.style.left=this._left??"0px";break;case"bottom-center":this._popup.style.bottom=this._bottom??"40px",this._popup.style.left="50%",this._popup.style.transform="translateX(-50%)";break;case"center-right":this._popup.style.top="50%",this._popup.style.right=this._right??"40px",this._popup.style.transform="translateY(-50%)";break;case"center-left":this._popup.style.top="50%",this._popup.style.left=this._left??"40px",this._popup.style.transform="translateY(-50%)";break;case"center-center":this._popup.style.top="50%",this._popup.style.left="50%",this._popup.style.transform="translate(-50%, -50%)"}}togglePopup(e){if(e.stopPropagation(),!this._popup)return;this._popup.classList.contains("visible")?this.hidePopup():this.showPopup()}showPopup(){this._popup&&(this._popup.classList.remove("visible"),this._popup.classList.add("displayed"),requestAnimationFrame((()=>{requestAnimationFrame((()=>{this._popup&&this._popup.classList.add("visible")}))})))}hidePopup(){if(!this._popup)return;this._popup.classList.remove("visible");if(!window.getComputedStyle(this._popup).transitionDuration.split(",").map((e=>parseFloat(e)||0)).some((e=>e>0)))return void this._popup.classList.remove("displayed");const e=t=>{t.target===this._popup&&"opacity"===t.propertyName&&this._popup&&!this._popup.classList.contains("visible")&&(this._popup.classList.remove("displayed"),this._popup.removeEventListener("transitionend",e))};this._popup.addEventListener("transitionend",e)}closePopup(){this.hidePopup()}setContent(e){this._inbox&&(this._inbox.innerHTML="",this._inbox.appendChild(e))}setSize(e,t){this._width=e,this._height=t,this._popup&&(this._popup.style.width=e,this._popup.style.height=t)}setPosition(e){var i,n;this.isValidPosition(e)?(this._popupAlignment=e,this.updatePopupPosition()):null==(n=null==(i=t.Courier.shared.client)?void 0:i.options.logger)||n.error(`Invalid position: ${e}`)}setHeader(e){var t;null==(t=this._inbox)||t.setHeader(e)}removeHeader(){var e;null==(e=this._inbox)||e.removeHeader()}setLoadingState(e){var t;null==(t=this._inbox)||t.setLoadingState(e)}setEmptyState(e){var t;null==(t=this._inbox)||t.setEmptyState(e)}setErrorState(e){var t;null==(t=this._inbox)||t.setErrorState(e)}setListItem(e){var t;null==(t=this._inbox)||t.setListItem(e)}setPaginationItem(e){var t;null==(t=this._inbox)||t.setPaginationItem(e)}setMenuButton(e){this._popupMenuButtonFactory=e,this.render()}selectFeed(e){var t;null==(t=this._inbox)||t.selectFeed(e)}selectTab(e){var t;null==(t=this._inbox)||t.selectTab(e)}setFeeds(e){var t;null==(t=this._inbox)||t.setFeeds(e)}getFeeds(){var e;return(null==(e=this._inbox)?void 0:e.getFeeds())??[]}setActions(e){var t;null==(t=this._inbox)||t.setActions(e)}setListItemActions(e){var t;null==(t=this._inbox)||t.setListItemActions(e)}get currentFeedId(){var e;return(null==(e=this._inbox)?void 0:e.currentFeedId)??""}async refresh(){var e;return null==(e=this._inbox)?void 0:e.refresh()}render(){var e;const t=this._totalUnreadCount;if(!this._triggerButton)return;const i=(null==(e=this._inbox)?void 0:e.getHeaderFeeds())??[];switch(this._popupMenuButtonFactory){case void 0:case null:this._triggerButton.build(void 0),this._triggerButton.onUnreadCountChange(t);break;default:const e=this._popupMenuButtonFactory({totalUnreadCount:t,feeds:i});this._triggerButton.build(e)}}}i.registerElement(A);t.Courier.shared.courierUserAgentName="courier-ui-inbox",t.Courier.shared.courierUserAgentVersion="2.0.0",Object.defineProperty(e,"Courier",{enumerable:!0,get:()=>t.Courier}),e.CourierInbox=B,e.CourierInboxDataStoreListener=S,e.CourierInboxDatastore=u,e.CourierInboxDatastoreEvents=class{onDataSetChange(e){}onPageAdded(e){}onUnreadCountChange(e,t){}onTotalUnreadCountChange(e){}onMessageAdd(e,t,i){}onMessageRemove(e,t,i){}onMessageUpdate(e,t,i){}onError(e){}},e.CourierInboxHeader=M,e.CourierInboxListItem=h,e.CourierInboxPopupMenu=A,e.CourierInboxThemeManager=L,e.archiveMessage=function(e){return u.shared.archiveMessage({message:e})},e.clickMessage=function(e){return u.shared.clickMessage({message:e})},e.defaultActions=_,e.defaultDarkTheme=$,e.defaultFeeds=b,e.defaultLightTheme=T,e.defaultListItemActions=C,e.markAsRead=function(e){return u.shared.readMessage({message:e})},e.markAsUnread=function(e){return u.shared.unreadMessage({message:e})},e.mergeTheme=E,e.openMessage=m,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
2
2
  //# sourceMappingURL=index.js.map