@trycourier/courier-ui-inbox 1.2.0 → 1.2.1
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.
- package/dist/datastore/datastore.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
|
@@ -8,6 +8,7 @@ export declare class CourierInboxDatastore {
|
|
|
8
8
|
private _archiveDataSet?;
|
|
9
9
|
private _dataStoreListeners;
|
|
10
10
|
private _unreadCount?;
|
|
11
|
+
private _removeMessageEventListener?;
|
|
11
12
|
private isPaginatingInbox;
|
|
12
13
|
private isPaginatingArchive;
|
|
13
14
|
static get shared(): CourierInboxDatastore;
|
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,"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(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((e=>{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.0",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;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"})}));
|
|
2
2
|
//# sourceMappingURL=index.js.map
|