@trycourier/courier-react 8.0.16-beta ā 8.0.18-beta
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/components/courier-client-component.d.ts +1 -1
- package/dist/components/courier-inbox.d.ts +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +10 -5727
- package/dist/index.mjs.map +1 -1
- package/dist/utils/utils.d.ts +1 -1
- package/package.json +15 -7
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
package/dist/utils/utils.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trycourier/courier-react",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.18-beta",
|
|
4
4
|
"description": "The React components for the Courier web UI",
|
|
5
|
-
"main": "dist/index.
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"prepare": "npm run build",
|
|
14
14
|
"test": "echo \"courier-react has no tests\""
|
|
15
15
|
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
16
19
|
"keywords": [
|
|
17
20
|
"courier",
|
|
18
21
|
"ui",
|
|
@@ -22,9 +25,6 @@
|
|
|
22
25
|
],
|
|
23
26
|
"author": "Courier",
|
|
24
27
|
"license": "MIT",
|
|
25
|
-
"files": [
|
|
26
|
-
"dist"
|
|
27
|
-
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@trycourier/courier-js": "2.0.3-beta",
|
|
30
30
|
"@trycourier/courier-ui-core": "1.0.5-beta",
|
|
@@ -40,9 +40,17 @@
|
|
|
40
40
|
"@types/react-dom": "19.1.0",
|
|
41
41
|
"@vitejs/plugin-react": "4.4.1",
|
|
42
42
|
"cross-env": "^7.0.3",
|
|
43
|
-
"react": "
|
|
44
|
-
"react-dom": "
|
|
43
|
+
"react": "18.2.0",
|
|
44
|
+
"react-dom": "18.2.0",
|
|
45
45
|
"vite": "6.2.6",
|
|
46
46
|
"vite-plugin-dts": "4.5.3"
|
|
47
|
+
},
|
|
48
|
+
"overrides": {
|
|
49
|
+
"react": "18.2.0",
|
|
50
|
+
"react-dom": "18.2.0"
|
|
51
|
+
},
|
|
52
|
+
"resolutions": {
|
|
53
|
+
"react": "18.2.0",
|
|
54
|
+
"react-dom": "18.2.0"
|
|
47
55
|
}
|
|
48
56
|
}
|
package/dist/index.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-dom/client"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-dom/client","react-dom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CourierReact={},e.React,e.ReactDOMClient,e.ReactDOM)}(this,(function(e,t,n,i){"use strict";var o=Object.defineProperty,s=(e,t,n)=>((e,t,n)=>t in e?o(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);const r=1e3,a=class e{constructor(e){s(this,"webSocket",null),s(this,"retryAttempt",0),s(this,"retryTimeoutId",null),s(this,"url"),s(this,"options"),this.url=e.apiUrls.inbox.webSocket,this.options=e}async connect(){var t;return this.clearRetryTimeout(),this.isConnecting||this.isOpen?(null==(t=this.options.logger)||t.info("Attempted to open a WebSocket connection, but one already exists."),Promise.reject(new Error("WebSocket connection already exists"))):new Promise(((t,n)=>{this.webSocket=new WebSocket(this.getWebSocketUrl()),this.webSocket.addEventListener("open",(e=>{this.retryAttempt=0,this.onOpen(e),t()})),this.webSocket.addEventListener("message",(async e=>{var t;try{const t=JSON.parse(e.data);if("event"in t&&"reconnect"===t.event)return this.close(r),void(await this.retryConnection(1e3*t.retryAfter));this.onMessageReceived(t)}catch(n){null==(t=this.options.logger)||t.error("Error parsing socket message",n)}})),this.webSocket.addEventListener("close",(t=>{if(t.code!==r){const n=e.parseCloseEvent(t);n.retryAfterSeconds?this.retryConnection(1e3*n.retryAfterSeconds):this.retryConnection()}this.onClose(t)})),this.webSocket.addEventListener("error",(e=>{this.retryConnection(),this.onError(e),n(e)}))}))}close(e=1e3,t){null!==this.webSocket&&(this.webSocket.close(e,t),this.webSocket=null)}send(e){var t;if(null===this.webSocket||this.isConnecting)return void(null==(t=this.options.logger)||t.info("Attempted to send a message, but the WebSocket is not yet open."));const n=JSON.stringify(e);this.webSocket.send(n)}get userId(){return this.options.userId}get logger(){return this.options.logger}get isConnecting(){return null!==this.webSocket&&this.webSocket.readyState===WebSocket.CONNECTING}get isOpen(){return null!==this.webSocket&&this.webSocket.readyState===WebSocket.OPEN}getWebSocketUrl(){const e=this.options.accessToken,t=this.options.connectionId,n=this.userId;return`${this.url}?auth=${e}&cid=${t}&iwpv=v1&userId=${n}`}static parseCloseEvent(t){if(null===t.reason||""===t.reason)return t;try{const n=JSON.parse(t.reason);if(!n[e.RETRY_AFTER_KEY])return t;const i=parseInt(n[e.RETRY_AFTER_KEY]);return Number.isNaN(i)||i<0?t:{...t,retryAfterSeconds:i}}catch(n){return t}}getBackoffTimeInMillis(){const t=e.BACKOFF_INTERVALS_IN_MILLIS[this.retryAttempt],n=t-t*e.BACKOFF_JITTER_FACTOR,i=t+t*e.BACKOFF_JITTER_FACTOR;return Math.floor(Math.random()*(i-n)+n)}async retryConnection(t){var n,i,o;if(null!==this.retryTimeoutId)return void(null==(n=this.logger)||n.debug("Skipping retry attempt because a previous retry is already scheduled."));if(this.retryAttempt>=e.MAX_RETRY_ATTEMPTS)return void(null==(i=this.logger)||i.error(`Max retry attempts (${e.MAX_RETRY_ATTEMPTS}) reached.`));const s=t??this.getBackoffTimeInMillis();this.retryTimeoutId=window.setTimeout((async()=>{try{await this.connect()}catch(e){}}),s),null==(o=this.logger)||o.debug(`Retrying connection in ${Math.floor(s/1e3)}s. Retry attempt ${this.retryAttempt+1} of ${e.MAX_RETRY_ATTEMPTS}.`),this.retryAttempt++}clearRetryTimeout(){null!==this.retryTimeoutId&&(window.clearTimeout(this.retryTimeoutId),this.retryTimeoutId=null)}};s(a,"BACKOFF_JITTER_FACTOR",.5),s(a,"MAX_RETRY_ATTEMPTS",5),s(a,"BACKOFF_INTERVALS_IN_MILLIS",[3e4,6e4,12e4,24e4,48e4]),s(a,"RETRY_AFTER_KEY","Retry-After");let l=a;var d=(e=>(e.Subscribe="subscribe",e.Unsubscribe="unsubscribe",e.Pong="pong",e.Ping="ping",e))(d||{}),h=(e=>(e.Ack="ack",e.Ping="ping",e.Pong="pong",e))(h||{}),u=(e=>(e.NewMessage="message",e.Archive="archive",e.ArchiveAll="archive-all",e.ArchiveRead="archive-read",e.Clicked="clicked",e.MarkAllRead="mark-all-read",e.Opened="opened",e.Read="read",e.Unarchive="unarchive",e.Unopened="unopened",e.Unread="unread",e))(u||{});const c=e=>({courier:{rest:(null==e?void 0:e.courier.rest)||"https://api.courier.com",graphql:(null==e?void 0:e.courier.graphql)||"https://api.courier.com/client/q"},inbox:{graphql:(null==e?void 0:e.inbox.graphql)||"https://inbox.courier.com/q",webSocket:(null==e?void 0:e.inbox.webSocket)||"wss://realtime.courier.io"}});class p{constructor(e){s(this,"PREFIX","[COURIER]"),this.showLogs=e}warn(e,...t){this.showLogs&&console.warn(`${this.PREFIX} ${e}`,...t)}log(e,...t){this.showLogs&&console.log(`${this.PREFIX} ${e}`,...t)}error(e,...t){this.showLogs&&console.error(`${this.PREFIX} ${e}`,...t)}debug(e,...t){this.showLogs&&console.debug(`${this.PREFIX} ${e}`,...t)}info(e,...t){this.showLogs&&console.info(`${this.PREFIX} ${e}`,...t)}}const v=class e{static nanoid(t=21){let n="",i=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)n+=e.ALPHABET[63&i[t]];return n}};s(v,"ALPHABET","useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict");let g=v;class m extends Error{constructor(e,t,n){super(t),this.code=e,this.type=n,this.name="CourierRequestError"}}function b(e,t,n,i){e.log(`\nš” New Courier ${n} Request: ${t}\nURL: ${i.url}\n${i.method?`Method: ${i.method}`:""}\n${i.query?`Query: ${i.query}`:""}\n${i.variables?`Variables: ${JSON.stringify(i.variables,null,2)}`:""}\nHeaders: ${JSON.stringify(i.headers,null,2)}\nBody: ${i.body?JSON.stringify(i.body,null,2):"Empty"}\n `)}function _(e,t,n,i){e.log(`\nš” New Courier ${n} Response: ${t}\nStatus Code: ${i.status}\nResponse JSON: ${JSON.stringify(i.response,null,2)}\n `)}async function x(e){const t=e.validCodes??[200],n=e.options.showLogs?g.nanoid():void 0,i=new Request(e.url,{method:e.method,headers:{"Content-Type":"application/json",...e.headers},body:e.body?JSON.stringify(e.body):void 0});n&&b(e.options.logger,n,"HTTP",{url:i.url,method:i.method,headers:Object.fromEntries(i.headers.entries()),body:e.body});const o=await fetch(i);if(204===o.status)return;let s;try{s=await o.json()}catch(r){if(200===o.status)return;throw new m(o.status,"Failed to parse response as JSON","PARSE_ERROR")}if(n&&_(e.options.logger,n,"HTTP",{status:o.status,response:s}),!t.includes(o.status))throw new m(o.status,(null==s?void 0:s.message)||"Unknown Error",null==s?void 0:s.type);return s}async function f(e){const t=e.options.showLogs?g.nanoid():void 0;t&&b(e.options.logger,t,"GraphQL",{url:e.url,headers:e.headers,query:e.query,variables:e.variables});const n=await fetch(e.url,{method:"POST",headers:{"Content-Type":"application/json",...e.headers},body:JSON.stringify({query:e.query,variables:e.variables})});let i;try{i=await n.json()}catch(o){throw new m(n.status,"Failed to parse response as JSON","PARSE_ERROR")}if(t&&_(e.options.logger,t,"GraphQL",{status:n.status,response:i}),!n.ok)throw new m(n.status,(null==i?void 0:i.message)||"Unknown Error",null==i?void 0:i.type);return i}class C{constructor(e){this.options=e}}class y extends C{async getBrand(e){const t=`\n query GetBrand {\n brand(brandId: "${e.brandId}") {\n settings {\n colors {\n primary\n secondary\n tertiary\n }\n inapp {\n borderRadius\n disableCourierFooter\n }\n }\n }\n }\n `;return(await f({options:this.options,url:this.options.apiUrls.courier.graphql,headers:{"x-courier-user-id":this.options.userId,"x-courier-client-key":"empty",Authorization:`Bearer ${this.options.accessToken}`},query:t,variables:{brandId:e.brandId}})).data.brand}}const k=class e extends l{constructor(e){super(e),s(this,"pingIntervalId",null),s(this,"messageEventListeners",[])}onOpen(e){return this.restartPingInterval(),Promise.resolve()}onMessageReceived(e){if("action"in e&&e.action===h.Ping){const t=e;this.sendPong(t)}if("event"in e)for(const t of this.messageEventListeners)t(e);return this.restartPingInterval(),Promise.resolve()}onClose(e){return Promise.resolve()}onError(e){return Promise.resolve()}sendSubscribe(){const e={tid:g.nanoid(),action:d.Subscribe,data:{channel:this.userId,event:"*"}};this.send(e)}sendUnsubscribe(){const e={tid:g.nanoid(),action:d.Unsubscribe,data:{channel:this.userId}};this.send(e)}addMessageEventListener(e){this.messageEventListeners.push(e)}sendPing(){const e={tid:g.nanoid(),action:d.Ping};this.send(e)}sendPong(e){const t={tid:e.tid,action:d.Pong};this.send(t)}restartPingInterval(){this.pingIntervalId&&window.clearInterval(this.pingIntervalId),this.pingIntervalId=window.setInterval((()=>{this.sendPing()}),e.PING_INTERVAL_MILLIS)}};s(k,"PING_INTERVAL_MILLIS",6e4);let w=k;class S extends C{constructor(e){super(e),s(this,"socket"),this.socket=new w(e)}async getMessages(e){const t=`\n query GetInboxMessages(\n $params: FilterParamsInput = { ${this.options.tenantId?`accountId: "${this.options.tenantId}"`:""} }\n $limit: Int = ${(null==e?void 0:e.paginationLimit)??24}\n $after: String ${(null==e?void 0:e.startCursor)?`= "${e.startCursor}"`:""}\n ) {\n count(params: $params)\n messages(params: $params, limit: $limit, after: $after) {\n totalCount\n pageInfo {\n startCursor\n hasNextPage\n }\n nodes {\n messageId\n read\n archived\n created\n opened\n title\n preview\n data\n tags\n trackingIds {\n clickTrackingId\n }\n actions {\n content\n data\n href\n }\n }\n }\n }\n `;return await f({options:this.options,query:t,headers:{"x-courier-user-id":this.options.userId,Authorization:`Bearer ${this.options.accessToken}`},url:this.options.apiUrls.inbox.graphql})}async getArchivedMessages(e){const t=`\n query GetInboxMessages(\n $params: FilterParamsInput = { ${this.options.tenantId?`accountId: "${this.options.tenantId}"`:""}, archived: true }\n $limit: Int = ${(null==e?void 0:e.paginationLimit)??24}\n $after: String ${(null==e?void 0:e.startCursor)?`= "${e.startCursor}"`:""}\n ) {\n count(params: $params)\n messages(params: $params, limit: $limit, after: $after) {\n totalCount\n pageInfo {\n startCursor\n hasNextPage\n }\n nodes {\n messageId\n read\n archived\n created\n opened\n title\n preview\n data\n tags\n trackingIds {\n clickTrackingId\n }\n actions {\n content\n data\n href\n }\n }\n }\n }\n `;return f({options:this.options,query:t,headers:{"x-courier-user-id":this.options.userId,Authorization:`Bearer ${this.options.accessToken}`},url:this.options.apiUrls.inbox.graphql})}async getUnreadMessageCount(){var e;const t=`\n query GetMessages {\n count(params: { status: "unread" ${this.options.tenantId?`, accountId: "${this.options.tenantId}"`:""} })\n }\n `;return(null==(e=(await f({options:this.options,query:t,headers:{"x-courier-user-id":this.options.userId,Authorization:`Bearer ${this.options.accessToken}`},url:this.options.apiUrls.inbox.graphql})).data)?void 0:e.count)??0}async click(e){const t=`\n mutation TrackEvent {\n clicked(messageId: "${e.messageId}", trackingId: "${e.trackingId}")\n }\n `,n={"x-courier-user-id":this.options.userId,Authorization:`Bearer ${this.options.accessToken}`};this.options.connectionId&&(n["x-courier-client-source-id"]=this.options.connectionId),await f({options:this.options,query:t,headers:n,url:this.options.apiUrls.inbox.graphql})}async read(e){const t=`\n mutation TrackEvent {\n read(messageId: "${e.messageId}")\n }\n `,n={"x-courier-user-id":this.options.userId,Authorization:`Bearer ${this.options.accessToken}`};this.options.connectionId&&(n["x-courier-client-source-id"]=this.options.connectionId),await f({options:this.options,query:t,headers:n,url:this.options.apiUrls.inbox.graphql})}async unread(e){const t=`\n mutation TrackEvent {\n unread(messageId: "${e.messageId}")\n }\n `,n={"x-courier-user-id":this.options.userId,Authorization:`Bearer ${this.options.accessToken}`};this.options.connectionId&&(n["x-courier-client-source-id"]=this.options.connectionId),await f({options:this.options,query:t,headers:n,url:this.options.apiUrls.inbox.graphql})}async readAll(){const e={"x-courier-user-id":this.options.userId,Authorization:`Bearer ${this.options.accessToken}`};this.options.connectionId&&(e["x-courier-client-source-id"]=this.options.connectionId),await f({options:this.options,query:"\n mutation TrackEvent {\n markAllRead\n }\n ",headers:e,url:this.options.apiUrls.inbox.graphql})}async open(e){const t=`\n mutation TrackEvent {\n opened(messageId: "${e.messageId}")\n }\n `,n={"x-courier-user-id":this.options.userId,Authorization:`Bearer ${this.options.accessToken}`};this.options.connectionId&&(n["x-courier-client-source-id"]=this.options.connectionId),await f({options:this.options,query:t,headers:n,url:this.options.apiUrls.inbox.graphql})}async archive(e){const t=`\n mutation TrackEvent {\n archive(messageId: "${e.messageId}")\n }\n `,n={"x-courier-user-id":this.options.userId,Authorization:`Bearer ${this.options.accessToken}`};this.options.connectionId&&(n["x-courier-client-source-id"]=this.options.connectionId),await f({options:this.options,query:t,headers:n,url:this.options.apiUrls.inbox.graphql})}async unarchive(e){const t=`\n mutation TrackEvent {\n unarchive(messageId: "${e.messageId}")\n }\n `,n={"x-courier-user-id":this.options.userId,Authorization:`Bearer ${this.options.accessToken}`};this.options.connectionId&&(n["x-courier-client-source-id"]=this.options.connectionId),await f({options:this.options,query:t,headers:n,url:this.options.apiUrls.inbox.graphql})}async archiveRead(){const e={"x-courier-user-id":this.options.userId,Authorization:`Bearer ${this.options.accessToken}`};this.options.connectionId&&(e["x-courier-client-source-id"]=this.options.connectionId),await f({options:this.options,query:"\n mutation TrackEvent {\n archiveRead\n }\n ",headers:e,url:this.options.apiUrls.inbox.graphql})}async archiveAll(){const e={"x-courier-user-id":this.options.userId,Authorization:`Bearer ${this.options.accessToken}`};this.options.connectionId&&(e["x-courier-client-source-id"]=this.options.connectionId),await f({options:this.options,query:"\n mutation TrackEvent {\n archiveAll\n }\n ",headers:e,url:this.options.apiUrls.inbox.graphql})}}class I{transformItem(e){return{topicId:e.topic_id,topicName:e.topic_name,sectionId:e.section_id,sectionName:e.section_name,status:e.status,defaultStatus:e.default_status,hasCustomRouting:e.has_custom_routing,customRouting:e.custom_routing||[]}}*transform(e){for(const t of e)yield this.transformItem(t)}}class M extends C{constructor(){super(...arguments),s(this,"transformer",new I)}async getUserPreferences(e){let t=`${this.options.apiUrls.courier.rest}/users/${this.options.userId}/preferences`;(null==e?void 0:e.paginationCursor)&&(t+=`?cursor=${e.paginationCursor}`);const n=await x({options:this.options,url:t,method:"GET",headers:{Authorization:`Bearer ${this.options.accessToken}`}});return{items:[...this.transformer.transform(n.items)],paging:n.paging}}async getUserPreferenceTopic(e){const t=await x({options:this.options,url:`${this.options.apiUrls.courier.rest}/users/${this.options.userId}/preferences/${e.topicId}`,method:"GET",headers:{Authorization:`Bearer ${this.options.accessToken}`}});return this.transformer.transformItem(t.topic)}async putUserPreferenceTopic(e){const t={topic:{status:e.status,has_custom_routing:e.hasCustomRouting,custom_routing:e.customRouting}};await x({options:this.options,url:`${this.options.apiUrls.courier.rest}/users/${this.options.userId}/preferences/${e.topicId}`,method:"PUT",headers:{Authorization:`Bearer ${this.options.accessToken}`},body:t})}getNotificationCenterUrl(e){return`https://view.notificationcenter.app/p/${function(e){const t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return btoa(String.fromCharCode(...t))}(`${function(e){const t=atob(e),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);return String.fromCharCode(...n)}(e.clientKey)}#${this.options.userId}${this.options.tenantId?`#${this.options.tenantId}`:""}#false`)}`}}class T extends C{async putUserToken(e){const t={provider_key:e.provider,...e.device&&{device:{app_id:e.device.appId,ad_id:e.device.adId,device_id:e.device.deviceId,platform:e.device.platform,manufacturer:e.device.manufacturer,model:e.device.model}}};await x({options:this.options,url:`${this.options.apiUrls.courier.rest}/users/${this.options.userId}/tokens/${e.token}`,method:"PUT",headers:{Authorization:`Bearer ${this.options.accessToken}`},body:t,validCodes:[200,204]})}async deleteUserToken(e){await x({options:this.options,url:`${this.options.apiUrls.courier.rest}/users/${this.options.userId}/tokens/${e.token}`,method:"DELETE",headers:{Authorization:`Bearer ${this.options.accessToken}`},validCodes:[200,204]})}}class E extends C{async putSubscription(e){return await x({url:`${this.options.apiUrls.courier.rest}/lists/${e.listId}/subscriptions/${this.options.userId}`,options:this.options,method:"PUT",headers:{Authorization:`Bearer ${this.options.accessToken}`}})}async deleteSubscription(e){return await x({url:`${this.options.apiUrls.courier.rest}/lists/${e.listId}/subscriptions/${this.options.userId}`,options:this.options,method:"DELETE",headers:{Authorization:`Bearer ${this.options.accessToken}`}})}}class A extends C{async postInboundCourier(e){return await x({url:`${this.options.apiUrls.courier.rest}/inbound/courier`,options:this.options,method:"POST",headers:{Authorization:`Bearer ${this.options.accessToken}`},body:{...e,userId:this.options.userId},validCodes:[200,202]})}async postTrackingUrl(e){return await x({url:e.url,options:this.options,method:"POST",body:{event:e.event}})}}class P extends C{constructor(e){var t,n;const i=void 0!==e.showLogs&&e.showLogs,o={...e,showLogs:i,apiUrls:e.apiUrls||c(),accessToken:e.jwt??e.publicApiKey};super({...o,logger:new p(o.showLogs),apiUrls:c(o.apiUrls)}),s(this,"tokens"),s(this,"brands"),s(this,"preferences"),s(this,"inbox"),s(this,"lists"),s(this,"tracking"),this.tokens=new T(this.options),this.brands=new y(this.options),this.preferences=new M(this.options),this.inbox=new S(this.options),this.lists=new E(this.options),this.tracking=new A(this.options),this.options.jwt||this.options.publicApiKey||this.options.logger.warn("Courier Client initialized with no authentication method. Please provide a JWT or public API key."),this.options.publicApiKey&&(null==(t=this.options.logger)||t.warn("Courier Warning: Public API Keys are for testing only. Please use JWTs for production.\nYou can generate a JWT with this endpoint: https://www.courier.com/docs/reference/auth/issue-token\nThis endpoint should be called from your backend server, not the SDK.")),this.options.jwt&&this.options.publicApiKey&&(null==(n=this.options.logger)||n.warn("Courier Warning: Both a JWT and a Public API Key were provided. The Public API Key will be ignored."))}}class ${constructor(e){s(this,"callback"),this.callback=e}remove(){B.shared.removeAuthenticationListener(this)}}const L=class e{constructor(){s(this,"id",g.nanoid()),s(this,"instanceClient"),s(this,"_paginationLimit",24),s(this,"authenticationListeners",[])}get paginationLimit(){return this._paginationLimit}set paginationLimit(e){this._paginationLimit=Math.min(Math.max(e,1),100)}get client(){return this.instanceClient}static get shared(){return e.instance||(e.instance=new e),e.instance}signIn(e){const t=e.connectionId??g.nanoid();this.instanceClient=new P({...e,connectionId:t}),this.notifyAuthenticationListeners({userId:e.userId})}signOut(){this.instanceClient=void 0,this.notifyAuthenticationListeners({userId:void 0})}addAuthenticationListener(e){var t;null==(t=this.instanceClient)||t.options.logger.info("Adding authentication listener");const n=new $(e);return this.authenticationListeners.push(n),n}removeAuthenticationListener(e){var t;null==(t=this.instanceClient)||t.options.logger.info("Removing authentication listener"),this.authenticationListeners=this.authenticationListeners.filter((t=>t!==e))}notifyAuthenticationListeners(e){this.authenticationListeners.forEach((t=>t.callback(e)))}};s(L,"instance");let B=L;var R=Object.defineProperty,D=(e,t,n)=>((e,t,n)=>t in e?R(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n),F=Object.defineProperty,O=(e,t,n)=>((e,t,n)=>t in e?F(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);const H={500:"#171717",50010:"#1717171A",50020:"#17171733"},z={200:"#F5F5F5",400:"#3A3A3A",500:"#E5E5E5",600:"#737373"},U={500:"#FFFFFF",50010:"#FFFFFF1A",50020:"#FFFFFF33"},N={400:"#60A5FA",500:"#2563EB"},q={light:{colors:{primary:H[500],secondary:U[500],border:z[500],link:N[500],icon:H[500]},button:{cornerRadius:"4px"}},dark:{colors:{primary:U[500],secondary:H[500],border:z[400],link:N[400],icon:U[500]},button:{cornerRadius:"4px"}}},V=()=>"undefined"==typeof window?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",J=e=>{if("undefined"==typeof window)return()=>{};const t=window.matchMedia("(prefers-color-scheme: dark)"),n=t=>{e(t.matches?"dark":"light")};return t.addEventListener("change",n),()=>{t.removeEventListener("change",n)}},j="undefined"==typeof window?class{constructor(){}}:class extends HTMLElement{constructor(){super()}};class Z extends j{constructor(){super(),O(this,"_currentSystemTheme"),O(this,"_systemThemeCleanup"),this._currentSystemTheme=V(),this._systemThemeCleanup=J((e=>{this._currentSystemTheme=e,this.onSystemThemeChange(e)}))}get currentSystemTheme(){return this._currentSystemTheme}disconnectedCallback(){this._systemThemeCleanup&&this._systemThemeCleanup()}onSystemThemeChange(e){}}const W={borderRadius:"4px",fontSize:"14px"},G=e=>({...W,backgroundColor:q[e].colors.secondary,textColor:q[e].colors.primary,fontWeight:"500",border:`1px solid ${q[e].colors.border}`,shadow:"light"===e?"0px 1px 2px 0px rgba(0, 0, 0, 0.06)":"0px 1px 2px 0px rgba(255, 255, 255, 0.1)"});class K extends Z{constructor(e){super(),O(this,"_button"),O(this,"_style");const t=this.attachShadow({mode:"open"});this._button=document.createElement("button"),this._button.setAttribute("part","button"),this._style=document.createElement("style"),this._style.textContent=this.getStyles(e),t.appendChild(this._style),t.appendChild(this._button),this.updateButton(e),this._button.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation(),e.onClick&&e.onClick()}))}getStyles(e){return`\n :host {\n display: inline-block;\n }\n\n button {\n border: none;\n border-radius: ${e.borderRadius??(()=>G(this.currentSystemTheme).borderRadius)()};\n font-weight: ${e.fontWeight??(()=>G(this.currentSystemTheme).fontWeight)()};\n font-family: ${e.fontFamily??"inherit"};\n font-size: ${e.fontSize??(()=>G(this.currentSystemTheme).fontSize)()};\n padding: 6px 10px;\n cursor: pointer;\n width: 100%;\n height: 100%;\n background-color: ${e.backgroundColor??(()=>G(this.currentSystemTheme).backgroundColor)()};\n color: ${e.textColor??(()=>G(this.currentSystemTheme).textColor)()};\n border: ${e.border??(()=>G(this.currentSystemTheme).border)()};\n box-shadow: ${e.shadow??(()=>G(this.currentSystemTheme).shadow)()};\n touch-action: manipulation;\n }\n\n button:hover {\n ${e.hoverBackgroundColor?`background-color: ${e.hoverBackgroundColor};`:"filter: brightness(0.9);"}\n }\n\n button:active {\n ${e.activeBackgroundColor?`background-color: ${e.activeBackgroundColor};`:"filter: brightness(0.8);"}\n }\n\n button:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n }\n `}updateButton(e){e.text&&(this._button.textContent=e.text),this._style.textContent=this.getStyles(e)}}const Y={inbox:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.5 14.5V17C5.5 17.2812 5.71875 17.5 6 17.5H18C18.25 17.5 18.5 17.2812 18.5 17V14.5H15.9375L15.2812 15.8125C15.0938 16.25 14.6562 16.5 14.1875 16.5H9.78125C9.3125 16.5 8.875 16.25 8.6875 15.8125L8.03125 14.5H5.5ZM18.1875 13L16.6562 6.90625C16.5938 6.65625 16.4062 6.5 16.1875 6.5H7.8125C7.5625 6.5 7.375 6.65625 7.3125 6.90625L5.78125 13H8.1875C8.65625 13 9.09375 13.2812 9.3125 13.7188L9.9375 15H14.0312L14.6875 13.7188C14.875 13.2812 15.3125 13 15.7812 13H18.1875ZM4 14.25C4 14.0938 4 13.9375 4.03125 13.7812L5.84375 6.53125C6.09375 5.625 6.875 5 7.8125 5H16.1875C17.0938 5 17.9062 5.625 18.125 6.53125L19.9375 13.7812C19.9688 13.9375 20 14.0938 20 14.25V17C20 18.125 19.0938 19 18 19H6C4.875 19 4 18.125 4 17V14.25Z" fill="currentColor"/>\n</svg>',archive:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.5 6.5V8H18.5V6.5H5.5ZM5 5H19C19.5312 5 20 5.46875 20 6V8.5C20 9.0625 19.5312 9.5 19 9.5H5C4.4375 9.5 4 9.0625 4 8.5V6C4 5.46875 4.4375 5 5 5ZM9 11.75C9 11.3438 9.3125 11 9.75 11H14.25C14.6562 11 15 11.3438 15 11.75C15 12.1875 14.6562 12.5 14.25 12.5H9.75C9.3125 12.5 9 12.1875 9 11.75ZM5 17V10.5H6.5V17C6.5 17.2812 6.71875 17.5 7 17.5H17C17.25 17.5 17.5 17.2812 17.5 17V10.5H19V17C19 18.125 18.0938 19 17 19H7C5.875 19 5 18.125 5 17Z" fill="currentColor"/>\n</svg>',check:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M18.793 7.33203C19.0742 7.64453 19.0742 8.11328 18.793 8.39453L10.543 16.6445C10.2305 16.957 9.76172 16.957 9.48047 16.6445L5.23047 12.3945C4.91797 12.1133 4.91797 11.6445 5.23047 11.3633C5.51172 11.0508 5.98047 11.0508 6.26172 11.3633L9.98047 15.082L17.7305 7.33203C18.0117 7.05078 18.4805 7.05078 18.7617 7.33203H18.793Z" fill="currentColor"/>\n</svg>',filter:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5 7C5 6.59375 5.3125 6.25 5.75 6.25H18.25C18.6562 6.25 19 6.59375 19 7C19 7.4375 18.6562 7.75 18.25 7.75H5.75C5.3125 7.75 5 7.4375 5 7ZM7 12C7 11.5938 7.3125 11.25 7.75 11.25H16.25C16.6562 11.25 17 11.5938 17 12C17 12.4375 16.6562 12.75 16.25 12.75H7.75C7.3125 12.75 7 12.4375 7 12ZM14 17C14 17.4375 13.6562 17.75 13.25 17.75H10.75C10.3125 17.75 10 17.4375 10 17C10 16.5938 10.3125 16.25 10.75 16.25H13.25C13.6562 16.25 14 16.5938 14 17Z" fill="currentColor"/>\n</svg>',overflow:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M18.5117 11.9883C18.5117 12.5508 18.1992 13.0195 17.7617 13.3008C17.293 13.582 16.6992 13.582 16.2617 13.3008C15.793 13.0195 15.5117 12.5508 15.5117 11.9883C15.5117 11.457 15.793 10.9883 16.2617 10.707C16.6992 10.4258 17.293 10.4258 17.7617 10.707C18.1992 10.9883 18.5117 11.457 18.5117 11.9883ZM13.5117 11.9883C13.5117 12.5508 13.1992 13.0195 12.7617 13.3008C12.293 13.582 11.6992 13.582 11.2617 13.3008C10.793 13.0195 10.5117 12.5508 10.5117 11.9883C10.5117 11.457 10.793 10.9883 11.2617 10.707C11.6992 10.4258 12.293 10.4258 12.7617 10.707C13.1992 10.9883 13.5117 11.457 13.5117 11.9883ZM7.01172 13.4883C6.44922 13.4883 5.98047 13.207 5.69922 12.7383C5.41797 12.3008 5.41797 11.707 5.69922 11.2383C5.98047 10.8008 6.44922 10.4883 7.01172 10.4883C7.54297 10.4883 8.01172 10.8008 8.29297 11.2383C8.57422 11.707 8.57422 12.3008 8.29297 12.7383C8.01172 13.207 7.54297 13.4883 7.01172 13.4883Z" fill="currentColor"/>\n</svg>',read:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M7 6.5C6.71875 6.5 6.5 6.75 6.5 7V17C6.5 17.2812 6.71875 17.5 7 17.5H17C17.25 17.5 17.5 17.2812 17.5 17V7C17.5 6.75 17.25 6.5 17 6.5H7ZM5 7C5 5.90625 5.875 5 7 5H17C18.0938 5 19 5.90625 19 7V17C19 18.125 18.0938 19 17 19H7C5.875 19 5 18.125 5 17V7ZM15.5312 10.5312L11.5312 14.5312C11.2188 14.8438 10.75 14.8438 10.4688 14.5312L8.46875 12.5312C8.15625 12.25 8.15625 11.7812 8.46875 11.5C8.75 11.1875 9.21875 11.1875 9.53125 11.5L11 12.9688L14.4688 9.46875C14.75 9.1875 15.2188 9.1875 15.5 9.46875C15.8125 9.78125 15.8125 10.25 15.5 10.5312H15.5312Z" fill="currentColor"/>\n</svg>',archiveRead:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M7.5 6.5V15.25H16.5V6.5H7.5ZM6 15.25V6.5C6 5.6875 6.65625 5 7.5 5H16.5C17.3125 5 18 5.6875 18 6.5V15.25C18.4062 15.25 18.75 15.5938 18.75 16C18.75 16.4375 18.4062 16.75 18 16.75H6C5.5625 16.75 5.25 16.4375 5.25 16C5.25 15.5938 5.5625 15.25 6 15.25ZM5 13V14.5H4.5V17.5H19.5V14.5H19V13H19.5C20.3125 13 21 13.6875 21 14.5V17.5C21 18.3438 20.3125 19 19.5 19H4.5C3.65625 19 3 18.3438 3 17.5V14.5C3 13.6875 3.65625 13 4.5 13H5ZM15.0312 9.625L11.6875 12.9688C11.5312 13.0938 11.3438 13.1875 11.1562 13.1875C10.9375 13.1875 10.75 13.0938 10.625 12.9688L8.96875 11.2812C8.65625 11 8.65625 10.5312 8.96875 10.25C9.25 9.9375 9.71875 9.9375 10 10.25L11.1562 11.375L13.9688 8.5625C14.25 8.28125 14.7188 8.28125 15 8.5625C15.3125 8.875 15.3125 9.34375 15 9.625H15.0312Z" fill="currentColor"/>\n</svg>',unread:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M17 6.5H7C6.71875 6.5 6.5 6.75 6.5 7V17C6.5 17.2812 6.71875 17.5 7 17.5H17C17.25 17.5 17.5 17.2812 17.5 17V7C17.5 6.75 17.25 6.5 17 6.5ZM7 5H17C18.0938 5 19 5.90625 19 7V17C19 18.125 18.0938 19 17 19H7C5.875 19 5 18.125 5 17V7C5 5.90625 5.875 5 7 5Z" fill="currentColor"/>\n</svg>',unarchive:'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n<path d="M5.5 11C5.0625 11 4.75 10.6875 4.75 10.25V5.75C4.75 5.34375 5.0625 5 5.5 5C5.90625 5 6.25 5.34375 6.25 5.75V8.28125L6.875 7.53125C8.15625 6 10.0625 5 12.25 5C16.0938 5 19.25 8.15625 19.25 12C19.25 15.875 16.0938 19 12.25 19C10.6562 19 9.21875 18.5 8.03125 17.625C7.71875 17.375 7.625 16.9062 7.875 16.5625C8.125 16.2188 8.59375 16.1562 8.9375 16.4062C9.84375 17.0938 11 17.5 12.25 17.5C15.2812 17.5 17.75 15.0625 17.75 12C17.75 8.96875 15.2812 6.5 12.25 6.5C10.5312 6.5 9.03125 7.28125 8 8.5L7.15625 9.5H10C10.4062 9.5 10.75 9.84375 10.75 10.25C10.75 10.6875 10.4062 11 10 11H5.5Z" fill="currentColor"/>\n</svg>'};class X extends j{constructor(e,t){super(),O(this,"_color"),O(this,"_svg"),O(this,"_iconContainer"),O(this,"_style"),this._color=e??H[500],this._svg=t;const n=this.attachShadow({mode:"open"});this._iconContainer=document.createElement("div"),n.appendChild(this._iconContainer),this._style=document.createElement("style"),this._style.textContent=this.getStyles(this._color),n.appendChild(this._style),this.refresh()}getStyles(e){return`\n :host {\n display: inline-block;\n line-height: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n }\n\n svg {\n width: 24px;\n height: 24px;\n color: ${e};\n }\n `}refresh(){this._svg&&(this._iconContainer.innerHTML=this._svg),this._color&&(this._style.textContent=this.getStyles(this._color))}updateColor(e){this._color=e,this.refresh()}updateSVG(e){this._svg=e,this.refresh()}}class Q extends j{constructor(){super(),O(this,"link");const e=this.attachShadow({mode:"open"});this.link=document.createElement("a"),this.link.setAttribute("part","link");const t=document.createElement("style");t.textContent=`\n :host {\n display: inline-block;\n }\n\n a {\n text-decoration: none;\n border-radius: 4px;\n cursor: pointer;\n font-weight: 500;\n transition: all 0.2s ease;\n font-family: var(--courier-link-font-family, inherit);\n font-size: var(--courier-link-font-size, inherit);\n }\n\n /* Variants */\n a[data-variant="primary"][data-mode="light"] {\n color: var(--courier-link-color, ${q.light.colors.link});\n }\n\n a[data-variant="primary"][data-mode="light"]:hover {\n opacity: 0.8;\n }\n\n a[data-variant="primary"][data-mode="light"]:active {\n opacity: 0.6;\n }\n\n a[data-variant="primary"][data-mode="dark"] {\n color: var(--courier-link-color, ${q.dark.colors.link});\n }\n\n a[data-variant="primary"][data-mode="dark"]:hover {\n opacity: 0.8;\n }\n\n a[data-variant="primary"][data-mode="dark"]:active {\n opacity: 0.6;\n }\n\n a[data-underline="true"] {\n text-decoration: underline;\n }\n\n a:disabled {\n opacity: 0.6;\n cursor: not-allowed;\n pointer-events: none;\n }\n `,e.appendChild(t),e.appendChild(this.link),this.updateVariant(),this.updateUnderline(),this.updateMode()}connectedCallback(){const e=document.createElement("slot");this.link.appendChild(e),this.updateHref()}attributeChangedCallback(e,t,n){if(t!==n)switch(e){case"href":this.updateHref();break;case"variant":case"mode":this.updateVariant();break;case"disabled":this.link.style.pointerEvents=this.hasAttribute("disabled")?"none":"auto",this.link.style.opacity=this.hasAttribute("disabled")?"0.6":"1";break;case"color":this.updateColor();break;case"underline":this.updateUnderline();break;case"target":this.updateTarget();break;case"font-family":this.updateFontFamily();break;case"font-size":this.updateFontSize()}}updateHref(){const e=this.getAttribute("href");e&&(this.link.href=e)}updateVariant(){const e=this.getAttribute("variant")||"primary",t=this.getAttribute("mode")||"light";this.link.setAttribute("data-variant",e),this.link.setAttribute("data-mode",t)}updateColor(){const e=this.getAttribute("color");e?this.link.style.setProperty("--courier-link-color",e):this.link.style.removeProperty("--courier-link-color")}updateUnderline(){const e="true"===this.getAttribute("underline");this.link.setAttribute("data-underline",e.toString())}updateMode(){const e=this.getAttribute("mode")||"light";this.link.setAttribute("data-mode",e)}updateTarget(){const e=this.getAttribute("target");e&&(this.link.target=e)}updateFontFamily(){const e=this.getAttribute("font-family");e?this.link.style.setProperty("--courier-link-font-family",e):this.link.style.removeProperty("--courier-link-font-family")}updateFontSize(){const e=this.getAttribute("font-size");e?this.link.style.setProperty("--courier-link-font-size",e):this.link.style.removeProperty("--courier-link-font-size")}}O(Q,"observedAttributes",["href","variant","disabled","color","underline","mode","target","font-family","font-size"]);class ee extends Z{constructor(){super(),O(this,"shadow"),this.shadow=this.attachShadow({mode:"open"})}build(e){if(null===e)return void this.shadow.replaceChildren();const t=e??this.defaultElement();this.shadow.replaceChildren(t)}defaultElement(){const e=document.createElement("div");return e.textContent="Default Element Factory",e.style.cssText="\n background-color: red;\n text-align: center;\n padding: 12px;\n ",e}}class te extends ee{constructor(e){super(),O(this,"_props"),O(this,"_title"),O(this,"_button"),O(this,"_style"),O(this,"_buttonClickCallback",null),this._props=e}defaultElement(){var e,t;const n=document.createElement("div");return this._title=document.createElement("h2"),(null==(e=this._props.title)?void 0:e.text)&&(this._title.textContent=this._props.title.text),this._button=new K(this._props.button??G(this.currentSystemTheme)),this._style=document.createElement("style"),this._style.textContent=this.getStyles(this._props),n.className="container",n.appendChild(this._style),n.appendChild(this._title),n.appendChild(this._button),this.shadow.appendChild(n),null==(t=this._button)||t.addEventListener("click",(()=>{this._buttonClickCallback&&this._buttonClickCallback()})),n}onSystemThemeChange(e){this.updateStyles(this._props)}getStyles(e){var t,n,i,o;return`\n :host {\n display: flex;\n align-items: center;\n justify-content: center;\n height: 100%;\n width: 100%;\n }\n\n .container {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n gap: 16px;\n text-align: center;\n padding: 24px;\n }\n\n .container h2 {\n margin: 0;\n color: ${(null==(t=e.title)?void 0:t.textColor)??"red"};\n font-size: ${(null==(n=e.title)?void 0:n.fontSize)??"16px"};\n font-weight: ${(null==(i=e.title)?void 0:i.fontWeight)??"500"};\n font-family: ${(null==(o=e.title)?void 0:o.fontFamily)??"inherit"};\n }\n `}updateStyles(e){this._props=e,this._style&&(this._style.textContent=this.getStyles(e)),this._button&&this._button.updateButton(e.button)}setButtonClickCallback(e){this._buttonClickCallback=e}}class ne extends j{constructor(e,t,n,i,o,s,r,a){super(),O(this,"_backgroundColor"),O(this,"_hoverBackgroundColor"),O(this,"_activeBackgroundColor"),O(this,"_borderRadius"),O(this,"_height"),O(this,"_width"),O(this,"_style"),O(this,"_button"),O(this,"_icon"),this._borderRadius=s,this._backgroundColor=n,this._hoverBackgroundColor=i,this._activeBackgroundColor=o,this._height=r,this._width=a;const l=this.attachShadow({mode:"open"});this._button=document.createElement("button"),this._button.setAttribute("part","button"),this._icon=new X(t,e),this._style=document.createElement("style"),this.refresh(),l.appendChild(this._style),this._button.appendChild(this._icon),l.appendChild(this._button)}refresh(){this._style.textContent=this.getStyles()}getStyles(){return`\n :host {\n display: inline-block;\n border-radius: ${this._borderRadius??"50%"};\n }\n\n button {\n border: none;\n border-radius: ${this._borderRadius??"50%"};\n cursor: pointer;\n width: ${this._width??"36px"};\n height: ${this._height??"36px"};\n display: flex;\n align-items: center;\n justify-content: center;\n background: ${this._backgroundColor??"transparent"};\n transition: background-color 0.2s ease;\n touch-action: manipulation;\n }\n\n button:hover {\n background-color: ${this._hoverBackgroundColor??"red"};\n }\n\n button:active {\n background-color: ${this._activeBackgroundColor??"red"};\n }\n\n button:disabled {\n opacity: 0.6;\n cursor: not-allowed;\n }\n\n [part="icon"] {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 24px;\n height: 24px;\n }\n `}updateIconColor(e){this._icon.updateColor(e)}updateIconSVG(e){this._icon.updateSVG(e)}updateBackgroundColor(e){this._backgroundColor=e,this.refresh()}updateHoverBackgroundColor(e){this._hoverBackgroundColor=e,this.refresh()}updateActiveBackgroundColor(e){this._activeBackgroundColor=e,this.refresh()}}function ie(e,t){"undefined"==typeof window||customElements.get(e)||customElements.define(e,t)}function oe(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 se(e){return{...e,messages:e.messages.map((e=>oe(e)))}}[{name:"courier-button",class:K},{name:"courier-icon",class:X},{name:"courier-link",class:Q},{name:"courier-info-state",class:te},{name:"courier-icon-button",class:ne},{name:"courier-system-theme",class:Z}].forEach((({name:e,class:t})=>ie(e,t)));class re extends j{constructor(e){super(),D(this,"_theme"),D(this,"_options",[]),D(this,"_style"),this._theme=e;const t=this.attachShadow({mode:"open"});this._style=document.createElement("style"),this._style.textContent=this.getStyles(),t.appendChild(this._style);const n=document.createElement("ul");n.className="menu",t.appendChild(n)}getStyles(){var e,t,n;const i=null==(n=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:n.menu;return`\n :host {\n display: block;\n position: absolute;\n background: ${(null==i?void 0:i.backgroundColor)??"red"};\n border: ${(null==i?void 0:i.border)??"1px solid red"};\n border-radius: ${(null==i?void 0:i.borderRadius)??"0px"};\n box-shadow: ${(null==i?void 0:i.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 :host(.visible) {\n opacity: 1;\n pointer-events: auto;\n }\n\n ul.menu {\n list-style: none;\n margin: 0;\n padding: 0;\n display: flex;\n flex-direction: row;\n }\n\n 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,i;const o=null==(e=this.shadowRoot)?void 0:e.querySelector("ul.menu");if(!o)return;o.innerHTML="";const s=null==(i=null==(n=null==(t=this._theme.inbox)?void 0:t.list)?void 0:n.item)?void 0:i.menu,r=e=>{e.stopPropagation(),e.preventDefault()};this._options.forEach((e=>{var t,n,i;const a=new ne(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==(i=null==s?void 0:s.item)?void 0:i.borderRadius),l=t=>{r(t),e.onClick()};a.addEventListener("click",l),a.addEventListener("touchstart",r),a.addEventListener("touchend",l),a.addEventListener("touchmove",r),a.addEventListener("mousedown",r),a.addEventListener("mouseup",r),o.appendChild(a)}))}show(){this.classList.add("visible")}hide(){this.classList.remove("visible")}}ie("courier-inbox-list-item-menu",re);const ae=class e{constructor(){D(this,"_inboxDataSet"),D(this,"_archiveDataSet"),D(this,"_dataStoreListeners",[]),D(this,"_unreadCount"),D(this,"isPaginatingInbox",!1),D(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 fetchDataSet(e){var t,n,i,o,s,r,a,l,d,h;if(e.canUseCache)switch(e.feedType){case"inbox":if(this._inboxDataSet)return this._inboxDataSet;break;case"archive":if(this._archiveDataSet)return this._archiveDataSet}const u="inbox"===e.feedType?await(null==(t=B.shared.client)?void 0:t.inbox.getMessages()):await(null==(n=B.shared.client)?void 0:n.inbox.getArchivedMessages());return{feedType:e.feedType,messages:(null==(o=null==(i=null==u?void 0:u.data)?void 0:i.messages)?void 0:o.nodes)??[],canPaginate:(null==(a=null==(r=null==(s=null==u?void 0:u.data)?void 0:s.messages)?void 0:r.pageInfo)?void 0:a.hasNextPage)??!1,paginationCursor:(null==(h=null==(d=null==(l=null==u?void 0:u.data)?void 0:l.messages)?void 0:d.pageInfo)?void 0:h.startCursor)??null}}async fetchUnreadCount(e){var t;if(e.canUseCache&&void 0!==this._unreadCount)return this._unreadCount;return await(null==(t=B.shared.client)?void 0:t.inbox.getUnreadMessageCount())??0}async load(e){var t,n,i;try{if(!(null==(t=B.shared.client)?void 0:t.options.userId))throw new Error("User is not signed in");const n=e??{feedType:"inbox",canUseCache:!0},[i,o]=await Promise.all([this.fetchDataSet(n),this.fetchUnreadCount(n)]);switch(n.feedType){case"inbox":this._inboxDataSet=i;break;case"archive":this._archiveDataSet=i}this._unreadCount=o,this._dataStoreListeners.forEach((e=>{var t,o,s,r;null==(o=(t=e.events).onDataSetChange)||o.call(t,i,n.feedType),null==(r=(s=e.events).onUnreadCountChange)||r.call(s,this._unreadCount??0)}))}catch(o){null==(i=null==(n=B.shared.client)?void 0:n.options.logger)||i.error("Error loading inbox:",o),this._dataStoreListeners.forEach((e=>{var t,n;null==(n=(t=e.events).onError)||n.call(t,o)}))}}async listenForUpdates(){var e,t;try{await this.ensureDataSetsLoaded(),await this.connectSocket()}catch(n){null==(t=null==(e=B.shared.client)?void 0:e.options.logger)||t.error("Error listening for updates:",n),this._dataStoreListeners.forEach((e=>{var t,i;null==(i=(t=e.events).onError)||i.call(t,n)}))}}async ensureDataSetsLoaded(){let e=[];this._inboxDataSet||e.push(this.load({feedType:"inbox",canUseCache:!0})),this._archiveDataSet||e.push(this.load({feedType:"archive",canUseCache:!0})),await Promise.all(e)}async connectSocket(){var e,t,n,i,o,s,r,a,l,d,h;const c=null==(e=B.shared.client)?void 0:e.inbox.socket;try{if(!c)return void(null==(n=null==(t=B.shared.client)?void 0:t.options.logger)||n.info("CourierInbox socket not available"));if(c.isConnecting||c.isOpen)return void(null==(s=null==(i=B.shared.client)?void 0:i.options.logger)||s.info(`Inbox socket already connecting or open for client ID: [${null==(o=B.shared.client)?void 0:o.options.connectionId}]`));c.addMessageEventListener((e=>{if(e.event===u.NewMessage){const t=e.data;return void this.addMessage(t,0,"inbox")}const t=this.getMessage({messageId:e.messageId});switch(e.event){case u.MarkAllRead:this.readAllMessages({canCallApi:!1});break;case u.Read:t&&this.readMessage({message:t,canCallApi:!1});break;case u.Unread:t&&this.unreadMessage({message:t,canCallApi:!1});break;case u.Opened:t&&this.openMessage({message:t,canCallApi:!1});break;case u.Archive:t&&this.archiveMessage({message:t,canCallApi:!1});break;case u.ArchiveRead:this.archiveReadMessages({canCallApi:!1});break;case u.Clicked:t&&this.clickMessage({message:t,canCallApi:!1});break;case u.Unarchive:t&&this.unarchiveMessage({message:t,canCallApi:!1});case u.Unopened:}})),await c.connect(),await c.sendSubscribe(),null==(l=null==(r=B.shared.client)?void 0:r.options.logger)||l.info(`Inbox socket connected for client ID: [${null==(a=B.shared.client)?void 0:a.options.connectionId}]`)}catch(p){null==(h=null==(d=B.shared.client)?void 0:d.options.logger)||h.error("Failed to connect socket:",p)}}getMessage(e){var t,n;if(e.messageId)return(null==(t=this._inboxDataSet)?void 0:t.messages.find((t=>t.messageId===e.messageId)))??(null==(n=this._archiveDataSet)?void 0:n.messages.find((t=>t.messageId===e.messageId)))}async fetchNextPageOfMessages(e){var t,n,i,o,s,r,a,l,d,h,u,c,p,v,g,m,b,_,x,f,C,y,k,w;switch(e.feedType){case"inbox":if(this.isPaginatingInbox)return null;if((null==(t=this._inboxDataSet)?void 0:t.canPaginate)&&this._inboxDataSet.paginationCursor)try{this.isPaginatingInbox=!0;const e=await(null==(n=B.shared.client)?void 0:n.inbox.getMessages({paginationLimit:B.shared.paginationLimit,startCursor:this._inboxDataSet.paginationCursor})),t={feedType:"inbox",messages:(null==(o=null==(i=null==e?void 0:e.data)?void 0:i.messages)?void 0:o.nodes)??[],canPaginate:(null==(a=null==(r=null==(s=null==e?void 0:e.data)?void 0:s.messages)?void 0:r.pageInfo)?void 0:a.hasNextPage)??!1,paginationCursor:(null==(h=null==(d=null==(l=null==e?void 0:e.data)?void 0:l.messages)?void 0:d.pageInfo)?void 0:h.startCursor)??null};return this.addPage(t),t}catch(S){return null==(c=null==(u=B.shared.client)?void 0:u.options.logger)||c.error("Error fetching next page of inbox messages:",S),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==(v=B.shared.client)?void 0:v.inbox.getArchivedMessages({paginationLimit:B.shared.paginationLimit,startCursor:this._archiveDataSet.paginationCursor})),t={feedType:"archive",messages:(null==(m=null==(g=null==e?void 0:e.data)?void 0:g.messages)?void 0:m.nodes)??[],canPaginate:(null==(x=null==(_=null==(b=null==e?void 0:e.data)?void 0:b.messages)?void 0:_.pageInfo)?void 0:x.hasNextPage)??!1,paginationCursor:(null==(y=null==(C=null==(f=null==e?void 0:e.data)?void 0:f.messages)?void 0:C.pageInfo)?void 0:y.startCursor)??null};return this.addPage(t),t}catch(S){return null==(w=null==(k=B.shared.client)?void 0:k.options.logger)||w.error("Error fetching next page of archived messages:",S),null}finally{this.isPaginatingArchive=!1}}return null}canMutate(){return!!(B.shared.client&&this._inboxDataSet&&this._archiveDataSet)}async readMessage({message:e,canCallApi:t=!0}){var n,i,o;if(!this.canMutate())return;const s=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=s.unreadCount-1,this._dataStoreListeners.forEach((e=>{var t,n;null==(n=(t=e.events).onUnreadCountChange)||n.call(t,this._unreadCount)})),t&&await(null==(n=B.shared.client)?void 0:n.inbox.read({messageId:e.messageId}))}catch(a){null==(o=null==(i=B.shared.client)?void 0:i.options.logger)||o.error("Error reading message:",a),this.applyDatastoreSnapshot(s)}}async unreadMessage({message:e,canCallApi:t=!0}){var n,i,o;if(!this.canMutate())return;const s=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=s.unreadCount+1,this._dataStoreListeners.forEach((e=>{var t,n;null==(n=(t=e.events).onUnreadCountChange)||n.call(t,this._unreadCount)})),t&&await(null==(n=B.shared.client)?void 0:n.inbox.unread({messageId:e.messageId}))}catch(a){null==(o=null==(i=B.shared.client)?void 0:i.options.logger)||o.error("Error unreading message:",a),this.applyDatastoreSnapshot(s)}}async openMessage({message:e,canCallApi:t=!0}){var n,i,o;if(!this.canMutate())return;const s=this.getMessageSnapshot(e);if((void 0!==s.inboxIndex||void 0!==s.archiveIndex)&&!s.message.opened)try{e.opened=(new Date).toISOString(),this.applyMessageSnapshot(s),t&&await(null==(n=B.shared.client)?void 0:n.inbox.open({messageId:e.messageId}))}catch(r){this.applyMessageSnapshot(s),null==(o=null==(i=B.shared.client)?void 0:i.options.logger)||o.error("Error opening message:",r)}}async clickMessage({message:e,canCallApi:t=!0}){var n,i,o,s,r;if(this.canMutate())try{(null==(n=e.trackingIds)?void 0:n.clickTrackingId)&&t&&await(null==(o=B.shared.client)?void 0:o.inbox.click({messageId:e.messageId,trackingId:null==(i=e.trackingIds)?void 0:i.clickTrackingId}))}catch(a){null==(r=null==(s=B.shared.client)?void 0:s.options.logger)||r.error("Error clicking message:",a)}}async archiveMessage({message:e,canCallApi:t=!0}){var n,i,o,s;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")}t&&await(null==(i=B.shared.client)?void 0:i.inbox.archive({messageId:e.messageId}))}catch(l){null==(s=null==(o=B.shared.client)?void 0:o.options.logger)||s.error("Error archiving message:",l),this.applyDatastoreSnapshot(a)}}async unarchiveMessage({message:e,canCallApi:t=!0}){var n,i,o,s;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")}t&&await(null==(i=B.shared.client)?void 0:i.inbox.unarchive({messageId:e.messageId}))}catch(l){null==(s=null==(o=B.shared.client)?void 0:o.options.logger)||s.error("Error unarchiving message:",l),this.applyDatastoreSnapshot(r)}}async archiveReadMessages({canCallApi:e=!0}={}){var t,n,i,o;if(!this.canMutate())return;const s=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{const i=(new Date).toISOString();((null==(t=this._inboxDataSet)?void 0:t.messages.filter((e=>e.read)))??[]).forEach((e=>{var t,n,o;e.archived=i;const s=null==(t=this._inboxDataSet)?void 0:t.messages.findIndex((t=>t.messageId===e.messageId));if(void 0!==s&&-1!==s&&(null==(n=this._inboxDataSet)||n.messages.splice(s,1)),null==(o=this._archiveDataSet)?void 0:o.messages){const t=this.findInsertIndex(e,this._archiveDataSet);this._archiveDataSet.messages.splice(t,0,e)}})),this._dataStoreListeners.forEach((e=>{var t,n,i,o;this._inboxDataSet&&(null==(n=(t=e.events).onDataSetChange)||n.call(t,this._inboxDataSet,"inbox")),this._archiveDataSet&&(null==(o=(i=e.events).onDataSetChange)||o.call(i,this._archiveDataSet,"archive"))})),e&&await(null==(n=B.shared.client)?void 0:n.inbox.archiveRead())}catch(r){null==(o=null==(i=B.shared.client)?void 0:i.options.logger)||o.error("Error archiving read messages:",r),this.applyDatastoreSnapshot(s)}}async archiveAllMessages({canCallApi:e=!0}={}){var t,n,i,o;if(!this.canMutate())return;const s=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{const i=(new Date).toISOString();null==(t=this._inboxDataSet)||t.messages.forEach((e=>{var t;if(e.archived=i,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,n,i,o,s,r;this._inboxDataSet&&(null==(n=(t=e.events).onDataSetChange)||n.call(t,this._inboxDataSet,"inbox")),this._archiveDataSet&&(null==(o=(i=e.events).onDataSetChange)||o.call(i,this._archiveDataSet,"archive")),null==(r=(s=e.events).onUnreadCountChange)||r.call(s,this._unreadCount)})),e&&await(null==(n=B.shared.client)?void 0:n.inbox.archiveAll())}catch(r){null==(o=null==(i=B.shared.client)?void 0:i.options.logger)||o.error("Error archiving all messages:",r),this.applyDatastoreSnapshot(s)}}async readAllMessages({canCallApi:e=!0}={}){var t,n,i,o,s;if(!this.canMutate())return;const r=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{const o=(new Date).toISOString();null==(t=this._inboxDataSet)||t.messages.forEach((e=>{e.read||(e.read=o)})),null==(n=this._archiveDataSet)||n.messages.forEach((e=>{e.read||(e.read=o)})),this._unreadCount=0,this._dataStoreListeners.forEach((e=>{var t,n,i,o,s,r;this._inboxDataSet&&(null==(n=(t=e.events).onDataSetChange)||n.call(t,this._inboxDataSet,"inbox")),this._archiveDataSet&&(null==(o=(i=e.events).onDataSetChange)||o.call(i,this._archiveDataSet,"archive")),null==(r=(s=e.events).onUnreadCountChange)||r.call(s,this._unreadCount)})),e&&await(null==(i=B.shared.client)?void 0:i.inbox.readAll())}catch(a){null==(s=null==(o=B.shared.client)?void 0:o.options.logger)||s.error("Error reading all messages:",a),this.applyDatastoreSnapshot(r)}}findInsertIndex(e,t){const n=t.messages;for(let i=0;i<n.length;i++){const t=n[i];if(t.created&&e.created&&t.created<e.created)return i}return n.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 n,i;return null==(i=(n=t.events).onPageAdded)?void 0:i.call(n,e,e.feedType)}))}addMessage(e,t,n){var i,o;switch(n){case"inbox":e.read||void 0===this._unreadCount||(this._unreadCount=this._unreadCount+1),null==(i=this._inboxDataSet)||i.messages.splice(t,0,e);break;case"archive":null==(o=this._archiveDataSet)||o.messages.splice(t,0,e)}this._dataStoreListeners.forEach((i=>{var o,s,r,a;null==(s=(o=i.events).onMessageAdd)||s.call(o,e,t,n),null==(a=(r=i.events).onUnreadCountChange)||a.call(r,this._unreadCount??0)}))}removeMessage(e,t,n){var i,o;switch(n){case"inbox":e.read||void 0===this._unreadCount||(this._unreadCount=this._unreadCount-1),null==(i=this._inboxDataSet)||i.messages.splice(t,1);break;case"archive":null==(o=this._archiveDataSet)||o.messages.splice(t,1)}this._dataStoreListeners.forEach((i=>{var o,s,r,a;null==(s=(o=i.events).onMessageRemove)||s.call(o,e,t,n),null==(a=(r=i.events).onUnreadCountChange)||a.call(r,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:n,archive:i}=e;this._inboxDataSet=n,this._archiveDataSet=i,this._dataStoreListeners.forEach((e=>{var o,s,r,a,l,d;null==(s=(o=e.events).onDataSetChange)||s.call(o,n,"inbox"),null==(a=(r=e.events).onDataSetChange)||a.call(r,i,"archive"),null==(d=(l=e.events).onUnreadCountChange)||d.call(l,t)}))}updateMessage(e,t,n){switch(n){case"inbox":void 0===this._unreadCount||e.archived||(e.read&&(this._unreadCount=Math.max(0,this._unreadCount-1)),e.read||(this._unreadCount=this._unreadCount+1)),this._inboxDataSet&&(this._inboxDataSet.messages[t]=e);break;case"archive":this._archiveDataSet&&(this._archiveDataSet.messages[t]=e)}this._dataStoreListeners.forEach((i=>{var o,s,r,a;null==(s=(o=i.events).onMessageUpdate)||s.call(o,e,t,n),null==(a=(r=i.events).onUnreadCountChange)||a.call(r,this._unreadCount??0)}))}getDatastoreSnapshot(e,t,n){return{unreadCount:e,inbox:se(t),archive:se(n)}}getMessageSnapshot(e){const t=this._archiveDataSet?this._archiveDataSet.messages.findIndex((t=>t.messageId===e.messageId)):void 0,n=this._inboxDataSet?this._inboxDataSet.messages.findIndex((t=>t.messageId===e.messageId)):void 0;return{message:oe(e),archiveIndex:t,inboxIndex:n}}};D(ae,"instance");let le=ae;class de extends j{constructor(e){super(),D(this,"_theme"),D(this,"_message",null),D(this,"_feedType","inbox"),D(this,"_isMobile",!1),D(this,"_titleElement"),D(this,"_subtitleElement"),D(this,"_timeElement"),D(this,"_style"),D(this,"_menu"),D(this,"_unreadIndicator"),D(this,"_actionsContainer"),D(this,"_longPressTimeout",null),D(this,"_isLongPress",!1),D(this,"onItemClick",null),D(this,"onItemLongPress",null),D(this,"onItemActionClick",null),this._theme=e,this._isMobile="ontouchstart"in window;const t=this.attachShadow({mode:"open"}),n=document.createElement("div");n.className="content-container",this._titleElement=document.createElement("p"),this._titleElement.setAttribute("part","title"),this._subtitleElement=document.createElement("p"),this._subtitleElement.setAttribute("part","subtitle"),this._actionsContainer=document.createElement("div"),this._actionsContainer.className="actions-container",n.appendChild(this._titleElement),n.appendChild(this._subtitleElement),n.appendChild(this._actionsContainer),this._timeElement=document.createElement("p"),this._timeElement.setAttribute("part","time"),this._unreadIndicator=document.createElement("div"),this._unreadIndicator.className="unread-indicator",this._style=document.createElement("style"),this._refreshStyles(),this._menu=new re(this._theme),this._menu.setOptions(this._getMenuOptions()),t.append(this._style,this._unreadIndicator,n,this._timeElement,this._menu);const i=e=>{e.stopPropagation(),e.preventDefault()};this._menu.addEventListener("mousedown",i),this._menu.addEventListener("pointerdown",i),this._menu.addEventListener("click",i),this.addEventListener("click",(e=>{this._menu.contains(e.target)||e.composedPath().includes(this._menu)||!this._message||!this.onItemClick||e.target instanceof X||this._isLongPress||this.onItemClick(this._message)})),this._setupHoverBehavior(),this._setupLongPressBehavior()}_setupHoverBehavior(){this._isMobile||(this.addEventListener("mouseenter",(()=>{this._isLongPress=!1,this._showMenu()})),this.addEventListener("mouseleave",(()=>this._hideMenu())))}_setupLongPressBehavior(){var e,t,n;const i=null==(n=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:n.menu;if(!(null==i?void 0:i.enabled))return;const o=i.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)}))}setOnLongPress(e){this.onItemLongPress=e}_getMenuOptions(){var e,t,n,i,o,s,r,a,l,d,h,u,c,p,v;const g=null==(i=null==(n=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:n.menu)?void 0:i.item;let m=[];const b="archive"===this._feedType;return b||m.push({id:(null==(o=this._message)?void 0:o.read)?"unread":"read",icon:{svg:(null==(s=this._message)?void 0:s.read)?null==(r=null==g?void 0:g.unread)?void 0:r.svg:null==(a=null==g?void 0:g.read)?void 0:a.svg,color:(null==(l=this._message)?void 0:l.read)?null==(d=null==g?void 0:g.unread)?void 0:d.color:(null==(h=null==g?void 0:g.read)?void 0:h.color)??"red"},onClick:()=>{this._message&&(this._message.read?le.shared.unreadMessage({message:this._message}):le.shared.readMessage({message:this._message}))}}),m.push({id:b?"unarchive":"archive",icon:{svg:b?null==(u=null==g?void 0:g.unarchive)?void 0:u.svg:null==(c=null==g?void 0:g.archive)?void 0:c.svg,color:b?null==(p=null==g?void 0:g.unarchive)?void 0:p.color:(null==(v=null==g?void 0:g.archive)?void 0:v.color)??"red"},onClick:()=>{this._message&&(b?le.shared.unarchiveMessage({message:this._message}):le.shared.archiveMessage({message:this._message}))}}),m}_showMenu(){var e,t,n;const i=null==(n=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:n.menu;i&&i.enabled&&(this._menu.setOptions(this._getMenuOptions()),this._menu.style.display="block",this._menu.show(),this._timeElement.style.opacity="0")}_hideMenu(){var e,t,n;const i=null==(n=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:n.menu;i&&i.enabled&&(this._menu.hide(),this._menu.style.display="none",this._timeElement.style.opacity="1")}_getStyles(){var e,t,n,i,o,s,r,a,l,d,h;const u=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item;return`\n :host {\n display: flex;\n flex-direction: row;\n align-items: flex-start;\n justify-content: space-between;\n border-bottom: ${(null==u?void 0:u.divider)??"1px solid red"};\n font-family: inherit;\n cursor: pointer;\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==u?void 0:u.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 /* āāāāāāāāāāāāāāāāāāāāāāāāā Base hover / active āāāāāāāāāāāāāāāāāā */\n @media (hover: hover) {\n :host(:hover) {\n background-color: ${(null==u?void 0:u.hoverBackgroundColor)??"red"};\n }\n }\n :host(:active) {\n background-color: ${(null==u?void 0:u.activeBackgroundColor)??"red"};\n }\n\n /* āāāāāāāāāāāāāāāāāāāāāāāāā Menu hover / active āāāāāāāāāāāāāāāāāā */\n @media (hover: hover) {\n :host(:hover):has(courier-inbox-list-item-menu:hover, courier-inbox-list-item-menu *:hover, courier-button:hover, courier-button *:hover) {\n background-color: ${(null==u?void 0:u.backgroundColor)??"transparent"};\n }\n }\n :host(:active):has(courier-inbox-list-item-menu:active, courier-inbox-list-item-menu *:active, courier-button:active, courier-button *:active) {\n background-color: ${(null==u?void 0:u.backgroundColor)??"transparent"};\n }\n\n :host(:last-child) {\n border-bottom: none;\n }\n\n .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==u?void 0:u.unreadIndicatorColor)??"red"};\n display: none;\n }\n\n :host(.unread) .unread-indicator {\n display: block;\n }\n\n .content-container {\n flex: 1;\n display: flex;\n flex-direction: column;\n margin-right: 12px;\n }\n\n 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 p[part='title'] {\n font-family: ${(null==(n=null==u?void 0:u.title)?void 0:n.family)??"inherit"};\n font-size: ${(null==(i=null==u?void 0:u.title)?void 0:i.size)??"14px"};\n color: ${(null==(o=null==u?void 0:u.title)?void 0:o.color)??"red"};\n margin-bottom: 4px;\n }\n\n p[part='subtitle'] {\n font-family: ${(null==(s=null==u?void 0:u.subtitle)?void 0:s.family)??"inherit"};\n font-size: ${(null==(r=null==u?void 0:u.subtitle)?void 0:r.size)??"14px"};\n color: ${(null==(a=null==u?void 0:u.subtitle)?void 0:a.color)??"red"};\n }\n\n p[part='time'] {\n font-family: ${(null==(l=null==u?void 0:u.time)?void 0:l.family)??"inherit"};\n font-size: ${(null==(d=null==u?void 0:u.time)?void 0:d.size)??"14px"};\n color: ${(null==(h=null==u?void 0:u.time)?void 0:h.color)??"red"};\n text-align: right;\n white-space: nowrap;\n }\n\n courier-inbox-list-item-menu {\n z-index: 1;\n position: absolute;\n top: 8px;\n right: 8px;\n display: none; /* becomes block while visible */\n }\n\n .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\n `}_refreshStyles(){this._style.textContent=this._getStyles()}connectedCallback(){var e,t;const n=this.getAttribute("message"),i=this.getAttribute("feed-type");if(i&&(this._feedType=i),n)try{this._message=JSON.parse(n),this._updateContent()}catch(o){null==(t=null==(e=B.shared.client)?void 0:e.options.logger)||t.error("CourierListItem ā failed to parse message:",o)}}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}_updateContent(){var e,t,n,i,o,s;if(!this._message)return this._titleElement.textContent="",void(this._subtitleElement.textContent="");this.classList.toggle("unread",!this._message.read&&"archive"!==this._feedType),this._titleElement.textContent=this._message.title||"Untitled Message",this._subtitleElement.textContent=this._message.preview||this._message.body||"",this._timeElement.textContent=function(e){if(!e.created)return"Now";const t=new Date,n=new Date(e.created),i=Math.floor((t.getTime()-n.getTime())/1e3);return i<60?`${i}s`:i<3600?`${Math.floor(i/60)}m`:i<86400?`${Math.floor(i/3600)}h`:i<604800?`${Math.floor(i/86400)}d`:i<31536e3?`${Math.floor(i/604800)}w`:`${Math.floor(i/31536e3)}y`}(this._message),this._menu.setOptions(this._getMenuOptions());const r=(null==(e=this._message)?void 0:e.actions)&&this._message.actions.length>0;this._actionsContainer.style.display=r?"flex":"none";const a=null==(i=null==(n=null==(t=this._theme.inbox)?void 0:t.list)?void 0:n.item)?void 0:i.actions;null==(s=null==(o=this._message)?void 0:o.actions)||s.forEach((e=>{var t,n,i,o;const s=new K({text:e.content,variant:"secondary",backgroundColor:null==a?void 0:a.backgroundColor,hoverBackgroundColor:null==a?void 0:a.hoverBackgroundColor,activeBackgroundColor:null==a?void 0:a.activeBackgroundColor,border:null==a?void 0:a.border,borderRadius:null==a?void 0:a.borderRadius,shadow:null==a?void 0:a.shadow,fontFamily:null==(t=null==a?void 0:a.font)?void 0:t.family,fontSize:null==(n=null==a?void 0:a.font)?void 0:n.size,fontWeight:null==(i=null==a?void 0:a.font)?void 0:i.weight,textColor:null==(o=null==a?void 0:a.font)?void 0:o.color,onClick:()=>{this._message&&this.onItemActionClick&&this.onItemActionClick(this._message,e)}});this._actionsContainer.appendChild(s)}))}}ie("courier-inbox-list-item",de);class he extends j{constructor(e,t){super(),D(this,"_shadow"),this._shadow=this.attachShadow({mode:"open"});const n=document.createElement("style");n.textContent=this.getStyles(t),this._shadow.appendChild(n);const i=new ue(e,35),o=new ue(e,100),s=new ue(e,82);this._shadow.appendChild(i),this._shadow.appendChild(o),this._shadow.appendChild(s)}getStyles(e){return`\n :host {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n width: 100%;\n box-sizing: border-box;\n opacity: ${e};\n }\n `}}ie("courier-inbox-skeleton-list-item",he);class ue extends j{constructor(e,t){super(),D(this,"_shadow"),this._shadow=this.attachShadow({mode:"open"});const n=document.createElement("style");n.textContent=this.getStyles(e,t),this._shadow.appendChild(n);const i=document.createElement("div");i.className="skeleton-item",this._shadow.appendChild(i)}getStyles(e,t){var n,i,o,s,r,a,l,d,h,u,c,p;const v=(null==(o=null==(i=null==(n=e.inbox)?void 0:n.loading)?void 0:i.animation)?void 0:o.barColor)??"#000",g=4===v.length?`#${v[1]}${v[1]}${v[2]}${v[2]}${v[3]}${v[3]}`:v,m=parseInt(g.slice(1,3),16),b=parseInt(g.slice(3,5),16),_=parseInt(g.slice(5,7),16),x=`rgba(${m}, ${b}, ${_}, 0.8)`,f=`rgba(${m}, ${b}, ${_}, 0.4)`;return`\n :host {\n display: flex;\n height: 100%;\n width: ${t}%;\n align-items: flex-start;\n justify-content: flex-start;\n }\n\n .skeleton-item {\n height: ${(null==(a=null==(r=null==(s=e.inbox)?void 0:s.loading)?void 0:r.animation)?void 0:a.barHeight)??"14px"};\n width: 100%;\n background: linear-gradient(\n 90deg,\n ${x} 25%,\n ${f} 50%,\n ${x} 75%\n );\n background-size: 200% 100%;\n animation: shimmer ${(null==(h=null==(d=null==(l=e.inbox)?void 0:l.loading)?void 0:d.animation)?void 0:h.duration)??"2s"} ease-in-out infinite;\n border-radius: ${(null==(p=null==(c=null==(u=e.inbox)?void 0:u.loading)?void 0:c.animation)?void 0:p.barBorderRadius)??"14px"};\n }\n\n @keyframes shimmer {\n 0% {\n background-position: 200% 0;\n }\n 100% {\n background-position: -200% 0;\n }\n }\n `}}ie("courier-skeleton-animated-row",ue);class ce extends ee{constructor(e){super(),D(this,"_theme"),this._theme=e}defaultElement(){const e=document.createElement("div");e.className="list";const t=document.createElement("style");t.textContent=this.getStyles(),e.appendChild(t);for(let n=0;n<3;n++){const t=new he(this._theme,1/(n+1));e.appendChild(t)}return this.shadow.appendChild(e),e}getStyles(){var e,t;return`\n :host {\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 .list {\n display: flex;\n flex-direction: column;\n gap: 8px;\n width: 100%;\n overflow: hidden;\n }\n\n .list > * {\n border-bottom: ${(null==(t=null==(e=this._theme.inbox)?void 0:e.loading)?void 0:t.divider)??"1px solid red"};\n }\n\n .list > *:last-child {\n border-bottom: none;\n }\n `}}ie("courier-inbox-skeleton-list",ce);class pe extends j{constructor(e){super(),D(this,"skeletonLoadingList"),D(this,"observer"),D(this,"customItem"),D(this,"onPaginationTrigger"),this.onPaginationTrigger=e.onPaginationTrigger,this.customItem=e.customItem;const t=this.attachShadow({mode:"open"}),n=document.createElement("style");if(n.textContent=this.getStyles(),t.appendChild(n),this.customItem)t.appendChild(this.customItem);else{const n=document.createElement("div");n.className="skeleton-container",this.skeletonLoadingList=new ce(e.theme),this.skeletonLoadingList.build(void 0),n.appendChild(this.skeletonLoadingList),t.appendChild(n)}this.observer=new IntersectionObserver((e=>{e.forEach((e=>{e.isIntersecting&&this.onPaginationTrigger()}))})),this.observer.observe(this)}getStyles(){return"\n :host {\n padding: 0;\n margin: 0;\n box-sizing: border-box;\n }\n\n .skeleton-container {\n height: 150%;\n }\n "}disconnectedCallback(){this.observer.disconnect()}}ie("courier-inbox-pagination-list-item",pe);class ve extends j{constructor(e){super(),D(this,"_themeSubscription"),D(this,"_messages",[]),D(this,"_feedType","inbox"),D(this,"_isLoading",!0),D(this,"_error",null),D(this,"_canPaginate",!1),D(this,"_onMessageClick",null),D(this,"_onMessageActionClick",null),D(this,"_onMessageLongPress",null),D(this,"_onRefresh"),D(this,"_onPaginationTrigger"),D(this,"_listItemFactory"),D(this,"_paginationItemFactory"),D(this,"_loadingStateFactory"),D(this,"_emptyStateFactory"),D(this,"_errorStateFactory"),this._themeSubscription=e.themeManager.subscribe((e=>{this.refreshTheme()})),this._onRefresh=e.onRefresh,this._onPaginationTrigger=e.onPaginationTrigger,this._onMessageClick=e.onMessageClick,this._onMessageActionClick=e.onMessageActionClick,this._onMessageLongPress=e.onMessageLongPress;const t=this.attachShadow({mode:"open"}),n=document.createElement("style");n.textContent=this.getStyles(),t.appendChild(n)}get messages(){return this._messages}getStyles(){var e;const t=null==(e=this._themeSubscription.manager.getTheme().inbox)?void 0:e.list;return`\n :host {\n flex: 1;\n width: 100%;\n background-color: ${(null==t?void 0:t.backgroundColor)??U[500]};\n }\n\n ul {\n list-style: none;\n padding: 0;\n margin: 0;\n height: 100%;\n }\n `}reset(){for(var e,t;null==(e=this.shadowRoot)?void 0:e.firstChild;)this.shadowRoot.removeChild(this.shadowRoot.firstChild);const n=document.createElement("style");n.textContent=this.getStyles(),null==(t=this.shadowRoot)||t.appendChild(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()}render(){var e,t,n,i,o,s,r,a,l,d,h,u,c,p,v,g,m,b,_,x,f,C,y,k,w,S,I,M,T,E,A,P,$,L,B,R,D,F,O,H,z,U,N,q,V,J,j,Z,W,G,K,Y,X,Q,ee,ne,ie,oe;this.reset();const se=this._themeSubscription.manager.getTheme();if(this._error){const M=null==(e=se.inbox)?void 0:e.error,T=new te({title:{text:(null==(t=null==M?void 0:M.title)?void 0:t.text)??this._error.message,textColor:null==(i=null==(n=null==M?void 0:M.title)?void 0:n.font)?void 0:i.color,fontFamily:null==(s=null==(o=null==M?void 0:M.title)?void 0:o.font)?void 0:s.family,fontSize:null==(a=null==(r=null==M?void 0:M.title)?void 0:r.font)?void 0:a.size,fontWeight:null==(d=null==(l=null==M?void 0:M.title)?void 0:l.font)?void 0:d.weight},button:{text:null==(h=null==M?void 0:M.button)?void 0:h.text,backgroundColor:null==(u=null==M?void 0:M.button)?void 0:u.backgroundColor,hoverBackgroundColor:null==(c=null==M?void 0:M.button)?void 0:c.hoverBackgroundColor,activeBackgroundColor:null==(p=null==M?void 0:M.button)?void 0:p.activeBackgroundColor,textColor:null==(g=null==(v=null==M?void 0:M.button)?void 0:v.font)?void 0:g.color,fontFamily:null==(b=null==(m=null==M?void 0:M.button)?void 0:m.font)?void 0:b.family,fontSize:null==(x=null==(_=null==M?void 0:M.button)?void 0:_.font)?void 0:x.size,fontWeight:null==(C=null==(f=null==M?void 0:M.button)?void 0:f.font)?void 0:C.weight,shadow:null==(y=null==M?void 0:M.button)?void 0:y.shadow,border:null==(k=null==M?void 0:M.button)?void 0:k.border,borderRadius:null==(w=null==M?void 0:M.button)?void 0:w.borderRadius}});return T.build(null==(S=this._errorStateFactory)?void 0:S.call(this,{feedType:this._feedType,error:this._error})),T.setButtonClickCallback((()=>this.handleRetry())),void(null==(I=this.shadowRoot)||I.appendChild(T))}if(this._isLoading){const e=new ce(se);return e.build(null==(M=this._loadingStateFactory)?void 0:M.call(this,{feedType:this._feedType})),void(null==(T=this.shadowRoot)||T.appendChild(e))}if(0===this._messages.length){const e=null==(E=se.inbox)?void 0:E.empty,t=new te({title:{text:(null==(A=null==e?void 0:e.title)?void 0:A.text)??`No ${this._feedType} messages yet`,textColor:null==($=null==(P=null==e?void 0:e.title)?void 0:P.font)?void 0:$.color,fontFamily:null==(B=null==(L=null==e?void 0:e.title)?void 0:L.font)?void 0:B.family,fontSize:null==(D=null==(R=null==e?void 0:e.title)?void 0:R.font)?void 0:D.size,fontWeight:null==(O=null==(F=null==e?void 0:e.title)?void 0:F.font)?void 0:O.weight},button:{text:null==(H=null==e?void 0:e.button)?void 0:H.text,backgroundColor:null==(z=null==e?void 0:e.button)?void 0:z.backgroundColor,hoverBackgroundColor:null==(U=null==e?void 0:e.button)?void 0:U.hoverBackgroundColor,activeBackgroundColor:null==(N=null==e?void 0:e.button)?void 0:N.activeBackgroundColor,textColor:null==(V=null==(q=null==e?void 0:e.button)?void 0:q.font)?void 0:V.color,fontFamily:null==(j=null==(J=null==e?void 0:e.button)?void 0:J.font)?void 0:j.family,fontSize:null==(W=null==(Z=null==e?void 0:e.button)?void 0:Z.font)?void 0:W.size,fontWeight:null==(K=null==(G=null==e?void 0:e.button)?void 0:G.font)?void 0:K.weight,shadow:null==(Y=null==e?void 0:e.button)?void 0:Y.shadow,border:null==(X=null==e?void 0:e.button)?void 0:X.border,borderRadius:null==(Q=null==e?void 0:e.button)?void 0:Q.borderRadius}});return t.build(null==(ee=this._emptyStateFactory)?void 0:ee.call(this,{feedType:this._feedType})),t.setButtonClickCallback((()=>this.handleRefresh())),void(null==(ne=this.shadowRoot)||ne.appendChild(t))}const re=document.createElement("ul");if(null==(ie=this.shadowRoot)||ie.appendChild(re),this._messages.forEach(((e,t)=>{if(this._listItemFactory)return void re.appendChild(this._listItemFactory({message:e,index:t}));const n=new de(se);n.setMessage(e,this._feedType),n.setOnItemClick((e=>{var n;return null==(n=this._onMessageClick)?void 0:n.call(this,e,t)})),n.setOnItemActionClick(((e,n)=>{var i;return null==(i=this._onMessageActionClick)?void 0:i.call(this,e,n,t)})),n.setOnItemLongPress((e=>{var n;return null==(n=this._onMessageLongPress)?void 0:n.call(this,e,t)})),re.appendChild(n)})),this._canPaginate){const e=new pe({theme:se,customItem:null==(oe=this._paginationItemFactory)?void 0:oe.call(this,{feedType:this._feedType}),onPaginationTrigger:()=>{var e;return null==(e=this._onPaginationTrigger)?void 0:e.call(this,this._feedType)}});re.appendChild(e)}}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()}refreshTheme(){this.render()}disconnectedCallback(){this._themeSubscription.unsubscribe()}}ie("courier-inbox-list",ve);class ge extends j{constructor(e){super(),D(this,"_option"),D(this,"_isSelected"),D(this,"_content"),D(this,"_itemIcon"),D(this,"_title"),D(this,"_selectionIcon"),D(this,"_style"),D(this,"_themeManager"),this._option=e.option,this._isSelected=e.isSelected,this._themeManager=e.themeManager;const t=this.attachShadow({mode:"open"});this._style=document.createElement("style"),this._content=document.createElement("div"),this._content.className="menu-item",this._itemIcon=new X(this._option.icon.svg??Y.inbox),this._itemIcon.setAttribute("size","16"),this._title=document.createElement("p"),this._title.textContent=this._option.text;const n=document.createElement("div");n.className="spacer",this._selectionIcon=new X(Y.check),this._content.appendChild(this._itemIcon),this._content.appendChild(this._title),this._content.appendChild(n),e.selectable&&this._content.appendChild(this._selectionIcon),t.appendChild(this._style),t.appendChild(this._content),this._selectionIcon.style.display=this._isSelected?"block":"none",this.refreshTheme()}getStyles(){var e,t,n,i,o,s,r,a,l,d,h,u,c,p,v,g,m,b,_,x,f,C,y,k,w,S,I,M,T,E,A,P,$,L;const B=this._themeManager.getTheme();return`\n :host {\n display: flex;\n flex-direction: row;\n padding: 6px 12px;\n cursor: pointer;\n }\n\n :host(:hover) {\n background-color: ${(null==(o=null==(i=null==(n=null==(t=null==(e=B.inbox)?void 0:e.header)?void 0:t.menus)?void 0:n.popup)?void 0:i.list)?void 0:o.hoverBackgroundColor)??"red"};\n }\n\n :host(:active) {\n background-color: ${(null==(d=null==(l=null==(a=null==(r=null==(s=B.inbox)?void 0:s.header)?void 0:r.menus)?void 0:a.popup)?void 0:l.list)?void 0:d.activeBackgroundColor)??"red"};\n }\n\n .menu-item {\n display: flex;\n align-items: center;\n width: 100%;\n gap: 12px;\n }\n\n .spacer {\n flex: 1;\n }\n\n p {\n margin: 0;\n font-family: ${(null==(g=null==(v=null==(p=null==(c=null==(u=null==(h=B.inbox)?void 0:h.header)?void 0:u.menus)?void 0:c.popup)?void 0:p.list)?void 0:v.font)?void 0:g.family)??"inherit"};\n font-weight: ${(null==(C=null==(f=null==(x=null==(_=null==(b=null==(m=B.inbox)?void 0:m.header)?void 0:b.menus)?void 0:_.popup)?void 0:x.list)?void 0:f.font)?void 0:C.weight)??"inherit"};\n font-size: ${(null==(M=null==(I=null==(S=null==(w=null==(k=null==(y=B.inbox)?void 0:y.header)?void 0:k.menus)?void 0:w.popup)?void 0:S.list)?void 0:I.font)?void 0:M.size)??"14px"};\n color: ${(null==(L=null==($=null==(P=null==(A=null==(E=null==(T=B.inbox)?void 0:T.header)?void 0:E.menus)?void 0:A.popup)?void 0:P.list)?void 0:$.font)?void 0:L.color)??"red"};\n white-space: nowrap;\n }\n\n .check-icon {\n display: none;\n }\n `}refreshTheme(){var e,t,n,i;this._style.textContent=this.getStyles(),this._selectionIcon.updateColor((null==(e=this._option.selectionIcon)?void 0:e.color)??"red"),this._selectionIcon.updateSVG((null==(t=this._option.selectionIcon)?void 0:t.svg)??Y.check),this._title.textContent=this._option.text??"Missing Text",this._itemIcon.updateColor((null==(n=this._option.icon)?void 0:n.color)??"red"),this._itemIcon.updateSVG((null==(i=this._option.icon)?void 0:i.svg)??Y.inbox)}}ie("courier-inbox-filter-menu-item",ge);class me extends j{constructor(e,t,n,i,o){super(),D(this,"_themeSubscription"),D(this,"_type"),D(this,"_selectedIndex",0),D(this,"_options"),D(this,"_selectable"),D(this,"_onMenuOpen"),D(this,"_menuButton"),D(this,"_menu"),D(this,"_style"),this._type=t,this._selectable=n,this._options=i,this._selectedIndex=0,this._onMenuOpen=o;const s=this.attachShadow({mode:"open"});this._menuButton=new ne("filters"===t?Y.filter:Y.overflow),this._menu=document.createElement("div"),this._menu.className=`menu ${t}`,this._style=document.createElement("style"),s.appendChild(this._style),s.appendChild(this._menuButton),s.appendChild(this._menu),this._menuButton.addEventListener("click",this.toggleMenu.bind(this)),document.addEventListener("click",this.handleOutsideClick.bind(this)),this._themeSubscription=e.subscribe((e=>{this.refreshTheme()})),this.refreshTheme()}getStyles(){var e,t,n,i,o,s,r,a,l,d,h,u,c,p,v,g,m,b,_,x,f;const C=this._themeSubscription.manager.getTheme();return`\n :host {\n position: relative;\n display: inline-block;\n }\n\n .menu {\n display: none;\n position: absolute;\n top: 42px;\n right: -6px;\n border-radius: ${(null==(i=null==(n=null==(t=null==(e=C.inbox)?void 0:e.header)?void 0:t.menus)?void 0:n.popup)?void 0:i.borderRadius)??"6px"};\n border: ${(null==(a=null==(r=null==(s=null==(o=C.inbox)?void 0:o.header)?void 0:s.menus)?void 0:r.popup)?void 0:a.border)??"1px solid red"};\n background: ${(null==(u=null==(h=null==(d=null==(l=C.inbox)?void 0:l.header)?void 0:d.menus)?void 0:h.popup)?void 0:u.backgroundColor)??"red"};\n box-shadow: ${(null==(g=null==(v=null==(p=null==(c=C.inbox)?void 0:c.header)?void 0:p.menus)?void 0:v.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 courier-inbox-filter-menu-item {\n border-bottom: ${(null==(f=null==(x=null==(_=null==(b=null==(m=C.inbox)?void 0:m.header)?void 0:b.menus)?void 0:_.popup)?void 0:x.list)?void 0:f.divider)??"none"};\n }\n\n courier-inbox-filter-menu-item:last-child {\n border-bottom: none;\n }\n `}refreshTheme(){var e,t,n,i,o,s;this._style.textContent=this.getStyles();const r=null==(t=null==(e=this._themeSubscription.manager.getTheme().inbox)?void 0:e.header)?void 0:t.menus,a="filters"===this._type,l=a?null==(n=null==r?void 0:r.filters)?void 0:n.button:null==(i=null==r?void 0:r.actions)?void 0:i.button,d=a?Y.filter:Y.overflow;this._menuButton.updateIconSVG((null==(o=null==l?void 0:l.icon)?void 0:o.svg)??d),this._menuButton.updateIconColor((null==(s=null==l?void 0:l.icon)?void 0:s.color)??"red"),this._menuButton.updateBackgroundColor((null==l?void 0:l.backgroundColor)??"transparent"),this._menuButton.updateHoverBackgroundColor((null==l?void 0:l.hoverBackgroundColor)??"red"),this._menuButton.updateActiveBackgroundColor((null==l?void 0:l.activeBackgroundColor)??"red"),this.refreshMenuItems()}setOptions(e){this._options=e,this.refreshMenuItems()}refreshMenuItems(){this._menu.innerHTML="",this._options.forEach(((e,t)=>{const n=new ge({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()})),this._menu.appendChild(n)}))}toggleMenu(e){e.stopPropagation();const t="block"!==this._menu.style.display;this._menu.style.display=t?"block":"none",t&&this._onMenuOpen()}handleOutsideClick(e){this.contains(e.target)||this.closeMenu()}closeMenu(){this._menu.style.display="none"}selectOption(e){this._selectedIndex=this._options.findIndex((t=>t.id===e.id)),this.refreshMenuItems()}disconnectedCallback(){this._themeSubscription.unsubscribe()}}ie("courier-inbox-option-menu",me);class be extends j{constructor(e){super(),D(this,"_themeSubscription"),D(this,"_location"),D(this,"_count",0),D(this,"_badge"),D(this,"_style"),this._location=e.location,this._themeSubscription=e.themeBus.subscribe((e=>{this.refreshTheme(this._location)}));const t=this.attachShadow({mode:"open"});this._badge=document.createElement("span"),this._badge.className="unread-badge",this._style=document.createElement("style"),this._style.textContent=this.getStyles(this._location),t.appendChild(this._style),t.appendChild(this._badge)}getStyles(e){var t,n,i,o,s,r,a;const l=this._themeSubscription.manager.getTheme(),d="button"===e?null==(n=null==(t=l.popup)?void 0:t.button)?void 0:n.unreadIndicator:null==(s=null==(o=null==(i=l.inbox)?void 0:i.header)?void 0:o.filters)?void 0:s.unreadIndicator,h=null==d?void 0:d.backgroundColor,u=null==d?void 0:d.borderRadius;return`\n :host {\n display: inline-block;\n }\n\n .unread-badge {\n background-color: ${h};\n color: ${null==(r=null==d?void 0:d.font)?void 0:r.color};\n border-radius: ${u};\n padding: 4px 8px;\n font-size: ${null==(a=null==d?void 0:d.font)?void 0:a.size};\n text-align: center;\n display: none;\n pointer-events: none;\n }\n `}setCount(e){this._count=e,this.updateBadge()}refreshTheme(e){this._location=e,this.updateBadge()}updateBadge(){this._style.textContent=this.getStyles(this._location),this._count>0?(this._badge.textContent=this._count.toString(),this._badge.style.display="block"):this._badge.style.display="none"}disconnectedCallback(){this._themeSubscription.unsubscribe()}}ie("courier-unread-count-badge",be);class _e extends j{constructor(e,t){super(),D(this,"_themeSubscription"),D(this,"_option"),D(this,"_feedType"),D(this,"_titleElement"),D(this,"_iconElement"),D(this,"_unreadBadge"),D(this,"_container"),D(this,"_style"),this._option=t;const n=this.attachShadow({mode:"open"});this._style=document.createElement("style"),this._container=document.createElement("div"),this._container.className="title-section",this._iconElement=new X(void 0,this._option.icon.svg),this._titleElement=document.createElement("h2"),this._unreadBadge=new be({themeBus:e,location:"header"}),this._container.appendChild(this._iconElement),this._container.appendChild(this._titleElement),this._container.appendChild(this._unreadBadge),n.appendChild(this._style),n.appendChild(this._container),this._themeSubscription=e.subscribe((e=>{this.refreshTheme(this._feedType??"inbox")})),this.refreshTheme(this._feedType??"inbox")}getStyles(){var e,t,n,i,o,s,r,a,l,d,h,u,c,p,v,g;const m=this._themeSubscription.manager.getTheme();return`\n .title-section {\n display: flex;\n align-items: center;\n gap: 8px;\n position: relative;\n }\n\n courier-icon {\n display: flex;\n align-items: center;\n }\n\n h2 {\n margin: 0;\n font-family: ${(null==(i=null==(n=null==(t=null==(e=m.inbox)?void 0:e.header)?void 0:t.filters)?void 0:n.font)?void 0:i.family)??"inherit"};\n font-size: ${(null==(a=null==(r=null==(s=null==(o=m.inbox)?void 0:o.header)?void 0:s.filters)?void 0:r.font)?void 0:a.size)??"18px"};\n font-weight: ${(null==(u=null==(h=null==(d=null==(l=m.inbox)?void 0:l.header)?void 0:d.filters)?void 0:h.font)?void 0:u.weight)??"500"};\n color: ${(null==(g=null==(v=null==(p=null==(c=m.inbox)?void 0:c.header)?void 0:p.filters)?void 0:v.font)?void 0:g.color)??"red"};\n }\n\n courier-unread-count-badge {\n margin-left: 4px;\n }\n `}refreshTheme(e){this._feedType=e,this._style.textContent=this.getStyles(),this._unreadBadge.refreshTheme("header"),this.updateFilter()}updateSelectedOption(e,t,n){this._option=e,this._feedType=t,this._unreadBadge.setCount(n),this.updateFilter()}updateFilter(){var e,t,n,i,o,s,r,a,l,d,h,u,c,p,v,g,m,b,_,x,f,C,y,k,w,S,I,M;const T=this._themeSubscription.manager.getTheme();switch(this._feedType){case"inbox":this._titleElement.textContent=(null==(i=null==(n=null==(t=null==(e=T.inbox)?void 0:e.header)?void 0:t.filters)?void 0:n.inbox)?void 0:i.text)??"Inbox",this._iconElement.updateSVG((null==(l=null==(a=null==(r=null==(s=null==(o=T.inbox)?void 0:o.header)?void 0:s.filters)?void 0:r.inbox)?void 0:a.icon)?void 0:l.svg)??Y.inbox),this._iconElement.updateColor((null==(p=null==(c=null==(u=null==(h=null==(d=T.inbox)?void 0:d.header)?void 0:h.filters)?void 0:u.inbox)?void 0:c.icon)?void 0:p.color)??"red");break;case"archive":this._titleElement.textContent=(null==(b=null==(m=null==(g=null==(v=T.inbox)?void 0:v.header)?void 0:g.filters)?void 0:m.archive)?void 0:b.text)??"Archive",this._iconElement.updateSVG((null==(y=null==(C=null==(f=null==(x=null==(_=T.inbox)?void 0:_.header)?void 0:x.filters)?void 0:f.archive)?void 0:C.icon)?void 0:y.svg)??Y.archive),this._iconElement.updateColor((null==(M=null==(I=null==(S=null==(w=null==(k=T.inbox)?void 0:k.header)?void 0:w.filters)?void 0:S.archive)?void 0:I.icon)?void 0:M.color)??"red")}}disconnectedCallback(){this._themeSubscription.unsubscribe()}}ie("courier-inbox-header-title",_e);class xe extends ee{constructor(e){super(),D(this,"_themeSubscription"),D(this,"_feedType","inbox"),D(this,"_unreadCount",0),D(this,"_titleSection"),D(this,"_filterMenu"),D(this,"_actionMenu"),D(this,"_style"),D(this,"_onFeedTypeChange"),this._themeSubscription=e.themeManager.subscribe((e=>{this.refreshTheme()})),this._onFeedTypeChange=e.onFeedTypeChange}getFilterOptions(){var e,t,n,i,o,s,r,a,l,d,h,u,c,p,v,g,m,b,_,x,f,C,y,k,w,S,I,M,T,E,A,P,$,L,B,R,D;const F=this._themeSubscription.manager.getTheme(),O=null==(n=null==(t=null==(e=F.inbox)?void 0:e.header)?void 0:t.menus)?void 0:n.filters;return[{id:"inbox",text:(null==(i=null==O?void 0:O.inbox)?void 0:i.text)??"Inbox",icon:{color:(null==(s=null==(o=null==O?void 0:O.inbox)?void 0:o.icon)?void 0:s.color)??"red",svg:(null==(a=null==(r=null==O?void 0:O.inbox)?void 0:r.icon)?void 0:a.svg)??Y.inbox},selectionIcon:{color:(null==(p=null==(c=null==(u=null==(h=null==(d=null==(l=F.inbox)?void 0:l.header)?void 0:d.menus)?void 0:h.popup)?void 0:u.list)?void 0:c.selectionIcon)?void 0:p.color)??"red",svg:(null==(x=null==(_=null==(b=null==(m=null==(g=null==(v=F.inbox)?void 0:v.header)?void 0:g.menus)?void 0:m.popup)?void 0:b.list)?void 0:_.selectionIcon)?void 0:x.svg)??Y.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==(y=null==(C=null==O?void 0:O.archive)?void 0:C.icon)?void 0:y.color)??"red",svg:(null==(w=null==(k=null==O?void 0:O.archive)?void 0:k.icon)?void 0:w.svg)??Y.archive},selectionIcon:{color:(null==(A=null==(E=null==(T=null==(M=null==(I=null==(S=F.inbox)?void 0:S.header)?void 0:I.menus)?void 0:M.popup)?void 0:T.list)?void 0:E.selectionIcon)?void 0:A.color)??"red",svg:(null==(D=null==(R=null==(B=null==(L=null==($=null==(P=F.inbox)?void 0:P.header)?void 0:$.menus)?void 0:L.popup)?void 0:B.list)?void 0:R.selectionIcon)?void 0:D.svg)??Y.check},onClick:e=>{this.handleOptionMenuItemClick("archive",e)}}]}getActionOptions(){var e,t,n,i,o,s,r,a,l,d,h,u,c,p,v,g,m,b;const _=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==(i=null==_?void 0:_.markAllRead)?void 0:i.text)??"Mark All as Read",icon:{color:(null==(s=null==(o=null==_?void 0:_.markAllRead)?void 0:o.icon)?void 0:s.color)??"red",svg:(null==(a=null==(r=null==_?void 0:_.markAllRead)?void 0:r.icon)?void 0:a.svg)??Y.inbox},selectionIcon:null,onClick:e=>{le.shared.readAllMessages({canCallApi:!0})}},{id:"archiveAll",text:(null==(l=null==_?void 0:_.archiveAll)?void 0:l.text)??"Archive All",icon:{color:(null==(h=null==(d=null==_?void 0:_.archiveAll)?void 0:d.icon)?void 0:h.color)??"red",svg:(null==(c=null==(u=null==_?void 0:_.archiveAll)?void 0:u.icon)?void 0:c.svg)??Y.archive},selectionIcon:null,onClick:e=>{le.shared.archiveAllMessages({canCallApi:!0})}},{id:"archiveRead",text:(null==(p=null==_?void 0:_.archiveRead)?void 0:p.text)??"Archive Read",icon:{color:(null==(g=null==(v=null==_?void 0:_.archiveRead)?void 0:v.icon)?void 0:g.color)??"red",svg:(null==(b=null==(m=null==_?void 0:_.archiveRead)?void 0:m.icon)?void 0:b.svg)??Y.archive},selectionIcon:null,onClick:e=>{le.shared.archiveReadMessages({canCallApi:!0})}}]}static get observedAttributes(){return["icon","title","feed-type"]}refreshTheme(){var e,t,n,i,o,s,r;const a=this._themeSubscription.manager.getTheme(),l=null==(e=this.shadow)?void 0:e.querySelector(".courier-inbox-header");l&&(l.style.backgroundColor=(null==(n=null==(t=a.inbox)?void 0:t.header)?void 0:n.backgroundColor)??U[500],l.style.boxShadow=(null==(o=null==(i=a.inbox)?void 0:i.header)?void 0:o.shadow)??`0px 1px 0px 0px ${z[500]}`),null==(s=this._filterMenu)||s.setOptions(this.getFilterOptions()),null==(r=this._actionMenu)||r.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){this._feedType=e.feedType,this._unreadCount=e.unreadCount,this.refreshTitleSection()}refreshTitleSection(){var e,t;const n=this.getFilterOptions().find((e=>["inbox","archive"].includes(e.id)&&e.id===this._feedType));n&&(null==(e=this._titleSection)||e.updateSelectedOption(n,this._feedType,"inbox"===this._feedType?this._unreadCount:0),null==(t=this._filterMenu)||t.selectOption(n))}build(e){var t;super.build(e),this._style=document.createElement("style"),this._style.textContent=this.getStyles(),null==(t=this.shadow)||t.appendChild(this._style),this.refreshTheme()}defaultElement(){const e=this.getFilterOptions();this._titleSection=new _e(this._themeSubscription.manager,e[0]),this._filterMenu=new me(this._themeSubscription.manager,"filters",!0,e,(()=>{var e;null==(e=this._actionMenu)||e.closeMenu()})),this._actionMenu=new me(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 n=document.createElement("div");n.className="actions",n.appendChild(this._filterMenu),n.appendChild(this._actionMenu);const i=document.createElement("div");return i.className="courier-inbox-header",i.appendChild(this._titleSection),i.appendChild(t),i.appendChild(n),i}getStyles(){return`\n :host {\n z-index: 100;\n }\n\n .courier-inbox-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 10px 10px 10px 16px;\n background-color: ${U[500]};\n box-shadow: 0px 1px 0px 0px ${z[500]};\n }\n\n .header-content {\n display: flex;\n align-items: center;\n flex: 1;\n }\n\n .spacer {\n flex: 1;\n }\n\n .actions {\n display: flex;\n align-items: center;\n gap: 4px;\n }\n `}disconnectedCallback(){this._themeSubscription.unsubscribe()}}ie("courier-inbox-header",xe);class fe{constructor(e){D(this,"events"),this.events=e}remove(){le.shared.removeDataStoreListener(this)}}const Ce={popup:{button:{icon:{color:H[500],svg:Y.inbox},backgroundColor:"transparent",hoverBackgroundColor:H[50010],activeBackgroundColor:H[50020],unreadIndicator:{font:{color:U[500],size:"14px",family:void 0,weight:void 0},backgroundColor:N[500],borderRadius:"12px"}},window:{backgroundColor:U[500],borderRadius:"8px",border:`1px solid ${z[500]}`,shadow:`0px 8px 16px -4px ${z[500]}`}},inbox:{header:{backgroundColor:U[500],shadow:`0px 1px 0px 0px ${z[500]}`,filters:{font:{color:H[500],family:void 0,size:"18px"},inbox:{icon:{color:H[500],svg:Y.inbox},text:"Inbox"},archive:{icon:{color:H[500],svg:Y.archive},text:"Archive"},unreadIndicator:{font:{color:U[500],family:void 0,size:"14px"},backgroundColor:N[500],borderRadius:"12px"}},menus:{popup:{backgroundColor:U[500],border:`1px solid ${z[500]}`,borderRadius:"4px",shadow:`0px 4px 8px -2px ${z[500]}`,list:{hoverBackgroundColor:z[200],activeBackgroundColor:z[500],divider:"none",font:{color:H[500],family:void 0,size:"14px"},selectionIcon:{color:H[500],svg:Y.check}}},filters:{button:{icon:{color:H[500],svg:Y.filter},backgroundColor:"transparent",hoverBackgroundColor:H[50010],activeBackgroundColor:H[50020]},inbox:{icon:{color:H[500],svg:Y.inbox},text:"Inbox"},archive:{icon:{color:H[500],svg:Y.archive},text:"Archive"}},actions:{button:{icon:{color:H[500],svg:Y.overflow},backgroundColor:"transparent",hoverBackgroundColor:H[50010],activeBackgroundColor:H[50020]},markAllRead:{icon:{color:H[500],svg:Y.read},text:"Read All"},archiveAll:{icon:{color:H[500],svg:Y.archive},text:"Archive All"},archiveRead:{icon:{color:H[500],svg:Y.archiveRead},text:"Archive Read"}}}},list:{backgroundColor:U[500],item:{backgroundColor:"transparent",unreadIndicatorColor:N[500],hoverBackgroundColor:z[200],activeBackgroundColor:z[500],actions:{backgroundColor:"transparent",hoverBackgroundColor:z[200],activeBackgroundColor:z[500],border:`1px solid ${z[500]}`,borderRadius:"4px",shadow:"0px 1px 2px 0px rgba(0, 0, 0, 0.06)",font:{color:H[500],family:void 0,size:"14px"}},title:{color:H[500],family:void 0,size:"14px"},subtitle:{color:z[600],family:void 0,size:"14px"},time:{color:z[600],family:void 0,size:"14px"},divider:`1px solid ${z[200]}`,menu:{enabled:!0,backgroundColor:U[500],border:`1px solid ${z[500]}`,borderRadius:"4px",shadow:`0px 2px 4px -2px ${z[500]}`,longPress:{displayDuration:4e3,vibrationDuration:50},item:{hoverBackgroundColor:z[200],activeBackgroundColor:z[500],borderRadius:"0px",read:{color:H[500],svg:Y.read},unread:{color:H[500],svg:Y.unread},archive:{color:H[500],svg:Y.archive},unarchive:{color:H[500],svg:Y.unarchive}}}}},loading:{animation:{barColor:z[500],barHeight:"14px",barBorderRadius:"14px",duration:"2s"},divider:`1px solid ${z[200]}`},empty:{title:{font:{size:"16px",weight:"500",color:H[500]}},button:{text:"Refresh"}},error:{title:{font:{size:"16px",weight:"500",color:H[500]}},button:{text:"Retry"}}}},ye={popup:{button:{icon:{color:U[500],svg:Y.inbox},backgroundColor:"transparent",hoverBackgroundColor:U[50010],activeBackgroundColor:U[50020],unreadIndicator:{font:{color:U[500],size:"14px",family:void 0,weight:void 0},backgroundColor:N[500],borderRadius:"12px"}},window:{backgroundColor:H[500],borderRadius:"8px",border:`1px solid ${z[400]}`,shadow:`0px 4px 8px -2px ${U[50020]}`}},inbox:{header:{backgroundColor:H[500],shadow:`0px 1px 0px 0px ${z[400]}`,filters:{font:{color:U[500],family:void 0,size:"18px"},inbox:{icon:{color:U[500],svg:Y.inbox},text:"Inbox"},archive:{icon:{color:U[500],svg:Y.archive},text:"Archive"},unreadIndicator:{font:{color:U[500],family:void 0,size:"14px"},backgroundColor:N[500],borderRadius:"12px"}},menus:{popup:{backgroundColor:H[500],border:`1px solid ${z[400]}`,borderRadius:"4px",shadow:`0px 4px 8px -2px ${U[50020]}`,list:{hoverBackgroundColor:U[50010],activeBackgroundColor:U[50020],divider:"none",font:{color:U[500],family:void 0,size:"14px"},selectionIcon:{color:U[500],svg:Y.check}}},filters:{button:{icon:{color:U[500],svg:Y.filter},backgroundColor:"transparent",hoverBackgroundColor:U[50010],activeBackgroundColor:U[50020]},inbox:{icon:{color:U[500],svg:Y.inbox},text:"Inbox"},archive:{icon:{color:U[500],svg:Y.archive},text:"Archive"}},actions:{button:{icon:{color:U[500],svg:Y.overflow},backgroundColor:"transparent",hoverBackgroundColor:U[50010],activeBackgroundColor:U[50020]},markAllRead:{icon:{color:U[500],svg:Y.read},text:"Read All"},archiveAll:{icon:{color:U[500],svg:Y.archive},text:"Archive All"},archiveRead:{icon:{color:U[500],svg:Y.archiveRead},text:"Archive Read"}}}},list:{backgroundColor:H[500],item:{backgroundColor:"transparent",unreadIndicatorColor:N[500],hoverBackgroundColor:U[50010],activeBackgroundColor:U[50020],actions:{backgroundColor:"transparent",hoverBackgroundColor:U[50010],activeBackgroundColor:U[50020],border:`1px solid ${z[400]}`,borderRadius:"4px",shadow:`0px 1px 2px 0px ${U[50010]}`,font:{color:U[500],family:void 0,size:"14px"}},title:{color:U[500],family:void 0,size:"14px"},subtitle:{color:z[500],family:void 0,size:"14px"},time:{color:z[500],family:void 0,size:"12px"},divider:`1px solid ${z[400]}`,menu:{enabled:!0,backgroundColor:H[500],border:`1px solid ${z[400]}`,borderRadius:"4px",shadow:`0px 2px 4px -2px ${U[50020]}`,longPress:{displayDuration:4e3,vibrationDuration:50},item:{hoverBackgroundColor:U[50010],activeBackgroundColor:U[50020],borderRadius:"0px",read:{color:U[500],svg:Y.read},unread:{color:U[500],svg:Y.unread},archive:{color:U[500],svg:Y.archive},unarchive:{color:U[500],svg:Y.unarchive}}}}},loading:{animation:{barColor:U[500],barHeight:"14px",barBorderRadius:"14px",duration:"2s"},divider:`1px solid ${z[400]}`},empty:{title:{font:{size:"16px",weight:"500",color:U[500]}},button:{text:"Refresh"}},error:{title:{font:{size:"16px",weight:"500",color:U[500]}},button:{text:"Retry"}}}};class ke{constructor(e){D(this,"THEME_CHANGE_EVENT","courier_inbox_theme_change"),D(this,"_theme"),D(this,"_lightTheme",Ce),D(this,"_darkTheme",ye),D(this,"_target"),D(this,"_subscriptions",[]),D(this,"_userMode"),D(this,"_systemMode"),D(this,"_systemThemeCleanup"),this._theme=e,this._target=new EventTarget,this._userMode="system",this._systemMode=V(),this.setLightTheme(Ce),this.setDarkTheme(ye),this._systemThemeCleanup=J((e=>{this._systemMode=e,this.updateTheme()}))}setLightTheme(e){this._lightTheme=e,"light"===this._systemMode&&this.updateTheme()}setDarkTheme(e){this._darkTheme=e,"dark"===this._systemMode&&this.updateTheme()}get currentSystemTheme(){return this._systemMode}getTheme(){return this._theme}updateTheme(){const e="system"===this._userMode?this._systemMode:this._userMode,t=((e,t)=>{var n,i,o,s,r,a,l,d,h,u,c,p,v,g,m,b,_,x,f,C,y,k,w,S,I,M,T,E,A,P,$,L,B,R,D,F,O,H,z,U,N,q,V,J,j,Z,W,G,K,Y,X,Q,ee,te,ne,ie,oe,se,re,ae,le,de,he,ue,ce,pe,ve,ge,me,be,_e,xe,fe,ke,we,Se,Ie,Me,Te,Ee,Ae,Pe,$e,Le,Be,Re,De,Fe,Oe,He,ze,Ue,Ne,qe,Ve,Je,je,Ze,We,Ge,Ke,Ye,Xe,Qe,et,tt,nt,it,ot,st,rt,at,lt,dt,ht,ut,ct,pt,vt,gt,mt,bt,_t,xt,ft,Ct,yt,kt,wt,St,It,Mt,Tt,Et,At,Pt,$t,Lt,Bt,Rt,Dt,Ft,Ot,Ht,zt,Ut,Nt,qt,Vt,Jt,jt,Zt,Wt,Gt,Kt,Yt,Xt,Qt,en,tn,nn,on,sn,rn,an,ln,dn,hn,un,cn,pn,vn,gn,mn,bn,_n,xn,fn,Cn,yn,kn,wn,Sn,In,Mn,Tn,En,An,Pn,$n,Ln,Bn,Rn,Dn,Fn,On,Hn,zn,Un,Nn,qn,Vn,Jn,jn,Zn,Wn,Gn,Kn,Yn,Xn,Qn,ei,ti,ni,ii,oi,si,ri,ai,li,di,hi,ui,ci,pi,vi,gi,mi,bi,_i,xi,fi,Ci,yi,ki,wi,Si,Ii,Mi,Ti,Ei,Ai,Pi,$i,Li,Bi,Ri,Di,Fi,Oi,Hi,zi,Ui,Ni,qi,Vi,Ji,ji;const Zi="light"===e?Ce:ye;return{popup:{button:{...null==(n=Zi.popup)?void 0:n.button,...null==(i=t.popup)?void 0:i.button,icon:{...null==(s=null==(o=Zi.popup)?void 0:o.button)?void 0:s.icon,...null==(a=null==(r=t.popup)?void 0:r.button)?void 0:a.icon},unreadIndicator:{...null==(d=null==(l=Zi.popup)?void 0:l.button)?void 0:d.unreadIndicator,...null==(u=null==(h=t.popup)?void 0:h.button)?void 0:u.unreadIndicator}},window:{...null==(c=Zi.popup)?void 0:c.window,...null==(p=t.popup)?void 0:p.window}},inbox:{header:{...null==(v=Zi.inbox)?void 0:v.header,...null==(g=t.inbox)?void 0:g.header,filters:{...null==(b=null==(m=Zi.inbox)?void 0:m.header)?void 0:b.filters,...null==(x=null==(_=t.inbox)?void 0:_.header)?void 0:x.filters,inbox:{...null==(y=null==(C=null==(f=Zi.inbox)?void 0:f.header)?void 0:C.filters)?void 0:y.inbox,...null==(S=null==(w=null==(k=t.inbox)?void 0:k.header)?void 0:w.filters)?void 0:S.inbox,icon:{...null==(E=null==(T=null==(M=null==(I=Zi.inbox)?void 0:I.header)?void 0:M.filters)?void 0:T.inbox)?void 0:E.icon,...null==(L=null==($=null==(P=null==(A=t.inbox)?void 0:A.header)?void 0:P.filters)?void 0:$.inbox)?void 0:L.icon}},archive:{...null==(D=null==(R=null==(B=Zi.inbox)?void 0:B.header)?void 0:R.filters)?void 0:D.archive,...null==(H=null==(O=null==(F=t.inbox)?void 0:F.header)?void 0:O.filters)?void 0:H.archive,icon:{...null==(q=null==(N=null==(U=null==(z=Zi.inbox)?void 0:z.header)?void 0:U.filters)?void 0:N.archive)?void 0:q.icon,...null==(Z=null==(j=null==(J=null==(V=t.inbox)?void 0:V.header)?void 0:J.filters)?void 0:j.archive)?void 0:Z.icon}},unreadIndicator:{...null==(K=null==(G=null==(W=Zi.inbox)?void 0:W.header)?void 0:G.filters)?void 0:K.unreadIndicator,...null==(Q=null==(X=null==(Y=t.inbox)?void 0:Y.header)?void 0:X.filters)?void 0:Q.unreadIndicator}},menus:{...null==(te=null==(ee=Zi.inbox)?void 0:ee.header)?void 0:te.menus,...null==(ie=null==(ne=t.inbox)?void 0:ne.header)?void 0:ie.menus,popup:{...null==(re=null==(se=null==(oe=Zi.inbox)?void 0:oe.header)?void 0:se.menus)?void 0:re.popup,...null==(de=null==(le=null==(ae=t.inbox)?void 0:ae.header)?void 0:le.menus)?void 0:de.popup,list:{...null==(pe=null==(ce=null==(ue=null==(he=Zi.inbox)?void 0:he.header)?void 0:ue.menus)?void 0:ce.popup)?void 0:pe.list,...null==(be=null==(me=null==(ge=null==(ve=t.inbox)?void 0:ve.header)?void 0:ge.menus)?void 0:me.popup)?void 0:be.list,font:{...null==(we=null==(ke=null==(fe=null==(xe=null==(_e=Zi.inbox)?void 0:_e.header)?void 0:xe.menus)?void 0:fe.popup)?void 0:ke.list)?void 0:we.font,...null==(Ee=null==(Te=null==(Me=null==(Ie=null==(Se=t.inbox)?void 0:Se.header)?void 0:Ie.menus)?void 0:Me.popup)?void 0:Te.list)?void 0:Ee.font},selectionIcon:{...null==(Be=null==(Le=null==($e=null==(Pe=null==(Ae=Zi.inbox)?void 0:Ae.header)?void 0:Pe.menus)?void 0:$e.popup)?void 0:Le.list)?void 0:Be.selectionIcon,...null==(He=null==(Oe=null==(Fe=null==(De=null==(Re=t.inbox)?void 0:Re.header)?void 0:De.menus)?void 0:Fe.popup)?void 0:Oe.list)?void 0:He.selectionIcon}}},filters:{...null==(Ne=null==(Ue=null==(ze=Zi.inbox)?void 0:ze.header)?void 0:Ue.menus)?void 0:Ne.filters,...null==(Je=null==(Ve=null==(qe=t.inbox)?void 0:qe.header)?void 0:Ve.menus)?void 0:Je.filters,inbox:{...null==(Ge=null==(We=null==(Ze=null==(je=Zi.inbox)?void 0:je.header)?void 0:Ze.menus)?void 0:We.filters)?void 0:Ge.inbox,...null==(Qe=null==(Xe=null==(Ye=null==(Ke=t.inbox)?void 0:Ke.header)?void 0:Ye.menus)?void 0:Xe.filters)?void 0:Qe.inbox,icon:{...null==(ot=null==(it=null==(nt=null==(tt=null==(et=Zi.inbox)?void 0:et.header)?void 0:tt.menus)?void 0:nt.filters)?void 0:it.inbox)?void 0:ot.icon,...null==(dt=null==(lt=null==(at=null==(rt=null==(st=t.inbox)?void 0:st.header)?void 0:rt.menus)?void 0:at.filters)?void 0:lt.inbox)?void 0:dt.icon}},archive:{...null==(pt=null==(ct=null==(ut=null==(ht=Zi.inbox)?void 0:ht.header)?void 0:ut.menus)?void 0:ct.filters)?void 0:pt.archive,...null==(bt=null==(mt=null==(gt=null==(vt=t.inbox)?void 0:vt.header)?void 0:gt.menus)?void 0:mt.filters)?void 0:bt.archive,icon:{...null==(yt=null==(Ct=null==(ft=null==(xt=null==(_t=Zi.inbox)?void 0:_t.header)?void 0:xt.menus)?void 0:ft.filters)?void 0:Ct.archive)?void 0:yt.icon,...null==(Mt=null==(It=null==(St=null==(wt=null==(kt=t.inbox)?void 0:kt.header)?void 0:wt.menus)?void 0:St.filters)?void 0:It.archive)?void 0:Mt.icon}}},actions:{...null==(At=null==(Et=null==(Tt=Zi.inbox)?void 0:Tt.header)?void 0:Et.menus)?void 0:At.actions,...null==(Lt=null==($t=null==(Pt=t.inbox)?void 0:Pt.header)?void 0:$t.menus)?void 0:Lt.actions,markAllRead:{...null==(Ft=null==(Dt=null==(Rt=null==(Bt=Zi.inbox)?void 0:Bt.header)?void 0:Rt.menus)?void 0:Dt.actions)?void 0:Ft.markAllRead,...null==(Ut=null==(zt=null==(Ht=null==(Ot=t.inbox)?void 0:Ot.header)?void 0:Ht.menus)?void 0:zt.actions)?void 0:Ut.markAllRead,icon:{...null==(jt=null==(Jt=null==(Vt=null==(qt=null==(Nt=Zi.inbox)?void 0:Nt.header)?void 0:qt.menus)?void 0:Vt.actions)?void 0:Jt.markAllRead)?void 0:jt.icon,...null==(Yt=null==(Kt=null==(Gt=null==(Wt=null==(Zt=t.inbox)?void 0:Zt.header)?void 0:Wt.menus)?void 0:Gt.actions)?void 0:Kt.markAllRead)?void 0:Yt.icon}},archiveAll:{...null==(tn=null==(en=null==(Qt=null==(Xt=Zi.inbox)?void 0:Xt.header)?void 0:Qt.menus)?void 0:en.actions)?void 0:tn.archiveAll,...null==(rn=null==(sn=null==(on=null==(nn=t.inbox)?void 0:nn.header)?void 0:on.menus)?void 0:sn.actions)?void 0:rn.archiveAll,icon:{...null==(un=null==(hn=null==(dn=null==(ln=null==(an=Zi.inbox)?void 0:an.header)?void 0:ln.menus)?void 0:dn.actions)?void 0:hn.archiveAll)?void 0:un.icon,...null==(mn=null==(gn=null==(vn=null==(pn=null==(cn=t.inbox)?void 0:cn.header)?void 0:pn.menus)?void 0:vn.actions)?void 0:gn.archiveAll)?void 0:mn.icon}},archiveRead:{...null==(fn=null==(xn=null==(_n=null==(bn=Zi.inbox)?void 0:bn.header)?void 0:_n.menus)?void 0:xn.actions)?void 0:fn.archiveRead,...null==(wn=null==(kn=null==(yn=null==(Cn=t.inbox)?void 0:Cn.header)?void 0:yn.menus)?void 0:kn.actions)?void 0:wn.archiveRead,icon:{...null==(En=null==(Tn=null==(Mn=null==(In=null==(Sn=Zi.inbox)?void 0:Sn.header)?void 0:In.menus)?void 0:Mn.actions)?void 0:Tn.archiveRead)?void 0:En.icon,...null==(Bn=null==(Ln=null==($n=null==(Pn=null==(An=t.inbox)?void 0:An.header)?void 0:Pn.menus)?void 0:$n.actions)?void 0:Ln.archiveRead)?void 0:Bn.icon}}}}},list:{...null==(Rn=Zi.inbox)?void 0:Rn.list,...null==(Dn=t.inbox)?void 0:Dn.list,item:{...null==(On=null==(Fn=Zi.inbox)?void 0:Fn.list)?void 0:On.item,...null==(zn=null==(Hn=t.inbox)?void 0:Hn.list)?void 0:zn.item,menu:{...null==(qn=null==(Nn=null==(Un=Zi.inbox)?void 0:Un.list)?void 0:Nn.item)?void 0:qn.menu,...null==(jn=null==(Jn=null==(Vn=t.inbox)?void 0:Vn.list)?void 0:Jn.item)?void 0:jn.menu,item:{...null==(Kn=null==(Gn=null==(Wn=null==(Zn=Zi.inbox)?void 0:Zn.list)?void 0:Wn.item)?void 0:Gn.menu)?void 0:Kn.item,...null==(ei=null==(Qn=null==(Xn=null==(Yn=t.inbox)?void 0:Yn.list)?void 0:Xn.item)?void 0:Qn.menu)?void 0:ei.item,read:{...null==(si=null==(oi=null==(ii=null==(ni=null==(ti=Zi.inbox)?void 0:ti.list)?void 0:ni.item)?void 0:ii.menu)?void 0:oi.item)?void 0:si.read,...null==(hi=null==(di=null==(li=null==(ai=null==(ri=t.inbox)?void 0:ri.list)?void 0:ai.item)?void 0:li.menu)?void 0:di.item)?void 0:hi.read},unread:{...null==(gi=null==(vi=null==(pi=null==(ci=null==(ui=Zi.inbox)?void 0:ui.list)?void 0:ci.item)?void 0:pi.menu)?void 0:vi.item)?void 0:gi.unread,...null==(fi=null==(xi=null==(_i=null==(bi=null==(mi=t.inbox)?void 0:mi.list)?void 0:bi.item)?void 0:_i.menu)?void 0:xi.item)?void 0:fi.unread},archive:{...null==(Si=null==(wi=null==(ki=null==(yi=null==(Ci=Zi.inbox)?void 0:Ci.list)?void 0:yi.item)?void 0:ki.menu)?void 0:wi.item)?void 0:Si.archive,...null==(Ai=null==(Ei=null==(Ti=null==(Mi=null==(Ii=t.inbox)?void 0:Ii.list)?void 0:Mi.item)?void 0:Ti.menu)?void 0:Ei.item)?void 0:Ai.archive},unarchive:{...null==(Ri=null==(Bi=null==(Li=null==($i=null==(Pi=Zi.inbox)?void 0:Pi.list)?void 0:$i.item)?void 0:Li.menu)?void 0:Bi.item)?void 0:Ri.unarchive,...null==(zi=null==(Hi=null==(Oi=null==(Fi=null==(Di=t.inbox)?void 0:Di.list)?void 0:Fi.item)?void 0:Oi.menu)?void 0:Hi.item)?void 0:zi.unarchive}}}}},loading:{...null==(Ui=Zi.inbox)?void 0:Ui.loading,...null==(Ni=t.inbox)?void 0:Ni.loading},empty:{...null==(qi=Zi.inbox)?void 0:qi.empty,...null==(Vi=t.inbox)?void 0:Vi.empty},error:{...null==(Ji=Zi.inbox)?void 0:Ji.error,...null==(ji=t.inbox)?void 0:ji.error}}}})(e,"light"===e?this._lightTheme:this._darkTheme);this.setTheme(t)}setTheme(e){e!==this._theme&&(this._theme=e,this._target.dispatchEvent(new CustomEvent(this.THEME_CHANGE_EVENT,{detail:{theme:e}})))}setMode(e){this._userMode=e,this.updateTheme()}subscribe(e){const t=new AbortController;this._target.addEventListener(this.THEME_CHANGE_EVENT,(t=>{e(t.detail.theme)}),{signal:t.signal});const n={manager:this,unsubscribe:()=>{t.abort();const e=this._subscriptions.indexOf(n);e>-1&&this._subscriptions.splice(e,1)}};return this._subscriptions.push(n),n}cleanup(){this._systemThemeCleanup&&this._systemThemeCleanup(),this._subscriptions.forEach((e=>e.unsubscribe())),this._subscriptions=[]}}let we=class extends j{constructor(e){var t;super(),D(this,"_currentFeed","inbox"),D(this,"_themeManager"),D(this,"_shadow"),D(this,"_list"),D(this,"_datastoreListener"),D(this,"_authListener"),D(this,"_style"),D(this,"_header"),D(this,"_headerFactory"),D(this,"_onMessageClick"),D(this,"_onMessageActionClick"),D(this,"_onMessageLongPress"),D(this,"_defaultProps",{title:"Inbox",icon:Y.inbox,feedType:this._currentFeed,height:"768px"}),this._shadow=this.attachShadow({mode:"open"}),this._themeManager=e??new ke(Ce),this._header=new xe({themeManager:this._themeManager,onFeedTypeChange:e=>{this.setFeedType(e)}}),this._header.build(void 0),this._shadow.appendChild(this._header),this._list=new ve({themeManager:this._themeManager,onRefresh:()=>{this.refresh()},onPaginationTrigger:async e=>{var t,n;try{await le.shared.fetchNextPageOfMessages({feedType:e})}catch(i){null==(n=null==(t=B.shared.client)?void 0:t.options.logger)||n.error("Failed to fetch next page of messages:",i)}},onMessageClick:(e,t)=>{var n;le.shared.clickMessage({message:e}),this.dispatchEvent(new CustomEvent("message-click",{detail:{message:e,index:t},bubbles:!0,composed:!0})),null==(n=this._onMessageClick)||n.call(this,{message:e,index:t})},onMessageActionClick:(e,t,n)=>{var i;this.dispatchEvent(new CustomEvent("message-action-click",{detail:{message:e,action:t,index:n},bubbles:!0,composed:!0})),null==(i=this._onMessageActionClick)||i.call(this,{message:e,action:t,index:n})},onMessageLongPress:(e,t)=>{var n;this.dispatchEvent(new CustomEvent("message-long-press",{detail:{message:e,index:t},bubbles:!0,composed:!0})),null==(n=this._onMessageLongPress)||n.call(this,{message:e,index:t})}}),this._style=document.createElement("style"),this.refreshTheme(),this._shadow.appendChild(this._style),this._shadow.appendChild(this._list),this._datastoreListener=new fe({onError:e=>{this._list.setError(e)},onDataSetChange:(e,t)=>{this._currentFeed===t&&(this._list.setDataSet(e),this.updateHeader())},onPageAdded:(e,t)=>{this._currentFeed===t&&(this._list.addPage(e),this.updateHeader())},onMessageAdd:(e,t,n)=>{this._currentFeed===n&&(this._list.addMessage(e,t),this.updateHeader())},onMessageRemove:(e,t,n)=>{this._currentFeed===n&&(this._list.removeMessage(t),this.updateHeader())},onMessageUpdate:(e,t,n)=>{this._currentFeed===n&&(this._list.updateMessage(e,t),this.updateHeader())},onUnreadCountChange:e=>{this.updateHeader()}}),le.shared.addDataStoreListener(this._datastoreListener),this._themeManager.subscribe((e=>{this.refreshTheme()})),this._authListener=B.shared.addAuthenticationListener((e=>{this.refresh()})),(null==(t=B.shared.client)?void 0:t.options.userId)&&this.refresh()}get theme(){return this._themeManager.getTheme()}setLightTheme(e){this._themeManager.setLightTheme(e)}setDarkTheme(e){this._themeManager.setDarkTheme(e)}static get observedAttributes(){return["height","light-theme","dark-theme","mode","message-click","message-action-click","message-long-press"]}refreshTheme(){this._style.textContent=this.getStyles()}getStyles(){return`\n :host {\n display: flex;\n flex-direction: column;\n width: 100%;\n height: ${this._defaultProps.height};\n }\n\n courier-inbox-header {\n flex-shrink: 0;\n }\n\n 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){this._list.setLoadingStateFactory(e)}setEmptyState(e){this._list.setEmptyStateFactory(e)}setErrorState(e){this._list.setErrorStateFactory(e)}setListItem(e){this._list.setListItemFactory(e)}setPaginationItem(e){this._list.setPaginationItemFactory(e)}onMessageClick(e){this._onMessageClick=e}onMessageActionClick(e){this._onMessageActionClick=e}onMessageLongPress(e){this._onMessageLongPress=e}setFeedType(e){this._currentFeed=e,this._list.setFeedType(e),this.updateHeader(),this.load({feedType:this._currentFeed,canUseCache:!0})}updateHeader(){const e={feedType:this._currentFeed,unreadCount:le.shared.unreadCount,messageCount:this._list.messages.length};switch(this._headerFactory){case void 0:this._header.render(e);break;case null:this._header.build(null);break;default:const t=this._headerFactory(e);this._header.build(t)}}async load(e){await le.shared.load(e),await le.shared.listenForUpdates()}refresh(){this.load({feedType:this._currentFeed,canUseCache:!1})}connectedCallback(){this.refresh()}disconnectedCallback(){var e,t;this._themeManager.cleanup(),null==(e=this._datastoreListener)||e.remove(),null==(t=this._authListener)||t.remove()}attributeChangedCallback(e,t,n){var i,o,s,r,a,l;if(t!==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(d){null==(o=null==(i=B.shared.client)?void 0:i.options.logger)||o.error("Failed to parse message-click handler:",d)}else this._onMessageClick=void 0;break;case"message-action-click":if(n)try{this._onMessageActionClick=new Function("props",n)}catch(d){null==(r=null==(s=B.shared.client)?void 0:s.options.logger)||r.error("Failed to parse message-action-click handler:",d)}else this._onMessageActionClick=void 0;break;case"message-long-press":if(n)try{this._onMessageLongPress=new Function("props",n)}catch(d){null==(l=null==(a=B.shared.client)?void 0:a.options.logger)||l.error("Failed to parse message-long-press handler:",d)}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)}}};ie("courier-inbox",we);class Se extends ee{constructor(e){super(),D(this,"_themeSubscription"),D(this,"_container"),D(this,"_triggerButton"),D(this,"_unreadCountBadge"),this._themeSubscription=e.subscribe((e=>{this.updateTheme()}))}defaultElement(){this._container=document.createElement("div"),this._container.className="menu-button-container",this._triggerButton=new ne(Y.inbox),this._unreadCountBadge=new be({themeBus:this._themeSubscription.manager,location:"button"}),this._unreadCountBadge.id="unread-badge";const e=document.createElement("style");return e.textContent=this.getStyles(),this._container.appendChild(e),this._container.appendChild(this._triggerButton),this._container.appendChild(this._unreadCountBadge),this.shadow.appendChild(this._container),this.updateTheme(),this._container}getStyles(){return"\n .menu-button-container {\n position: relative;\n display: inline-block;\n }\n \n #unread-badge {\n position: absolute;\n top: -8px;\n left: 50%;\n pointer-events: none;\n }\n "}onUnreadCountChange(e){var t;null==(t=this._unreadCountBadge)||t.setCount(e),this.updateTheme()}updateTheme(){var e,t,n,i,o,s,r,a,l,d,h,u,c,p,v,g,m,b;const _=this._themeSubscription.manager.getTheme();null==(i=this._triggerButton)||i.updateIconColor((null==(n=null==(t=null==(e=null==_?void 0:_.popup)?void 0:e.button)?void 0:t.icon)?void 0:n.color)??H[500]),null==(a=this._triggerButton)||a.updateIconSVG((null==(r=null==(s=null==(o=null==_?void 0:_.popup)?void 0:o.button)?void 0:s.icon)?void 0:r.svg)??Y.inbox),null==(h=this._triggerButton)||h.updateBackgroundColor((null==(d=null==(l=null==_?void 0:_.popup)?void 0:l.button)?void 0:d.backgroundColor)??"transparent"),null==(p=this._triggerButton)||p.updateHoverBackgroundColor((null==(c=null==(u=null==_?void 0:_.popup)?void 0:u.button)?void 0:c.hoverBackgroundColor)??H[50010]),null==(m=this._triggerButton)||m.updateActiveBackgroundColor((null==(g=null==(v=null==_?void 0:_.popup)?void 0:v.button)?void 0:g.activeBackgroundColor)??H[50020]),null==(b=this._unreadCountBadge)||b.refreshTheme("button")}disconnectedCallback(){this._themeSubscription.unsubscribe()}}ie("courier-inbox-menu-button",Se);ie("courier-inbox-popup-menu",class extends j{constructor(){super(),D(this,"_width","440px"),D(this,"_height","440px"),D(this,"_popupAlignment","top-right"),D(this,"_top","40px"),D(this,"_right","0"),D(this,"_bottom","40px"),D(this,"_left","0"),D(this,"_themeManager",new ke(Ce)),D(this,"_triggerButton"),D(this,"_popup"),D(this,"_inbox"),D(this,"_style"),D(this,"_datastoreListener"),D(this,"_popupMenuButtonFactory");const e=this.attachShadow({mode:"open"});this._triggerButton=new Se(this._themeManager),this._triggerButton.build(void 0),this._popup=document.createElement("div"),this._popup.className="popup",this._inbox=new we(this._themeManager),this._inbox.setAttribute("height","100%"),this._style=document.createElement("style"),this.refreshTheme(),e.appendChild(this._style),e.appendChild(this._triggerButton),e.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 fe(this),le.shared.addDataStoreListener(this._datastoreListener),this._themeManager.subscribe((e=>{this.refreshTheme()}))}get theme(){return this._themeManager.getTheme()}setLightTheme(e){this._themeManager.setLightTheme(e)}setDarkTheme(e){this._themeManager.setDarkTheme(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"]}refreshTheme(){this._style.textContent=this.getStyles()}getStyles(){var e,t,n,i,o,s,r,a;return`\n :host {\n display: inline-block;\n position: relative;\n }\n\n .menu-button-container {\n position: relative;\n display: inline-block;\n }\n\n .popup {\n display: none;\n position: absolute;\n background: ${(null==(t=null==(e=this.theme.popup)?void 0:e.window)?void 0:t.backgroundColor)??"red"};\n border-radius: ${(null==(i=null==(n=this.theme.popup)?void 0:n.window)?void 0:i.borderRadius)??"8px"};\n border: ${(null==(s=null==(o=this.theme.popup)?void 0:o.window)?void 0:s.border)??"1px solid red"};\n box-shadow: ${(null==(a=null==(r=this.theme.popup)?void 0:r.window)?void 0:a.shadow)??"0px 8px 16px -4px red"};\n z-index: 1000;\n width: ${this._width};\n height: ${this._height};\n overflow: hidden;\n transform: translateZ(0);\n will-change: transform;\n }\n \n #unread-badge {\n position: absolute;\n top: -8px;\n left: 50%;\n pointer-events: none;\n }\n\n courier-inbox {\n height: 100%;\n }\n `}attributeChangedCallback(e,t,n){switch(e){case"popup-alignment":this.isValidPosition(n)&&(this._popupAlignment=n,this.updatePopupPosition());break;case"popup-width":this._width=n,this.setSize(n,this._height);break;case"popup-height":this._height=n,this.setSize(this._width,n);break;case"top":this._top=n,this.updatePopupPosition();break;case"right":this._right=n,this.updatePopupPosition();break;case"bottom":this._bottom=n,this.updatePopupPosition();break;case"left":this._left=n,this.updatePopupPosition();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)}}onUnreadCountChange(e){this.render()}onMessageClick(e){this._inbox.onMessageClick(e)}onMessageActionClick(e){this._inbox.onMessageActionClick(e)}onMessageLongPress(e){this._inbox.onMessageLongPress(e)}isValidPosition(e){return["top-right","top-left","top-center","bottom-right","bottom-left","bottom-center","center-right","center-left","center-center"].includes(e)}updatePopupPosition(){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,this._popup.style.right=this._right;break;case"top-left":this._popup.style.top=this._top,this._popup.style.left=this._left;break;case"top-center":this._popup.style.top=this._top,this._popup.style.left="50%",this._popup.style.transform="translateX(-50%)";break;case"bottom-right":this._popup.style.bottom=this._bottom,this._popup.style.right=this._right;break;case"bottom-left":this._popup.style.bottom=this._bottom,this._popup.style.left=this._left;break;case"bottom-center":this._popup.style.bottom=this._bottom,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,this._popup.style.transform="translateY(-50%)";break;case"center-left":this._popup.style.top="50%",this._popup.style.left=this._left,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){e.stopPropagation();const t="block"===this._popup.style.display;this._popup.style.display=t?"none":"block"}handleOutsideClick(e){this.contains(e.target)||(this._popup.style.display="none")}setContent(e){this._inbox.innerHTML="",this._inbox.appendChild(e)}setSize(e,t){this._width=e,this._height=t,this._popup.style.width=e,this._popup.style.height=t}setPosition(e){var t,n;this.isValidPosition(e)?(this._popupAlignment=e,this.updatePopupPosition()):null==(n=null==(t=B.shared.client)?void 0:t.options.logger)||n.error(`Invalid position: ${e}`)}setFeedType(e){this._inbox.setFeedType(e)}setPopupHeader(e){this._inbox.setHeader(e)}removePopupHeader(){this._inbox.removeHeader()}setPopupLoadingState(e){this._inbox.setLoadingState(e)}setPopupEmptyState(e){this._inbox.setEmptyState(e)}setPopupErrorState(e){this._inbox.setErrorState(e)}setPopupListItem(e){this._inbox.setListItem(e)}setPopupPaginationItem(e){this._inbox.setPaginationItem(e)}setPopupMenuButton(e){this._popupMenuButtonFactory=e,this.render()}render(){const e=le.shared.unreadCount;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)}}disconnectedCallback(){var e;null==(e=this._datastoreListener)||e.remove(),this._themeManager.cleanup()}});var Ie,Me,Te={exports:{}},Ee={};var Ae=(Me||(Me=1,Te.exports=function(){if(Ie)return Ee;Ie=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function n(t,n,i){var o=null;if(void 0!==i&&(o=""+i),void 0!==n.key&&(o=""+n.key),"key"in n)for(var s in i={},n)"key"!==s&&(i[s]=n[s]);else i=n;return n=i.ref,{$$typeof:e,type:t,key:o,ref:void 0!==n?n:null,props:i}}return Ee.Fragment=t,Ee.jsx=n,Ee.jsxs=n,Ee}()),Te.exports);function Pe(e){const t=document.createElement("div");return i.flushSync((()=>{!function(e,t){const i=n.createRoot(t);i.render(e)}(e,t)})),t}const $e=({children:e})=>{const[n,i]=t.useState(!1);return t.useEffect((()=>{i(!0)}),[]),"undefined"==typeof window?null:n?Ae.jsx(Ae.Fragment,{children:e}):null};e.CourierInbox=e=>{const n=t.useRef(null);return t.useEffect((()=>{const t=n.current;t&&t.onMessageClick(e.onMessageClick)}),[e.onMessageClick,n]),t.useEffect((()=>{const t=n.current;t&&t.onMessageActionClick(e.onMessageActionClick)}),[e.onMessageActionClick,n]),t.useEffect((()=>{const t=n.current;t&&t.onMessageLongPress(e.onMessageLongPress)}),[e.onMessageLongPress,n]),t.useEffect((()=>{const t=n.current;t&&e.renderHeader&&queueMicrotask((()=>{t.setHeader((t=>Pe(e.renderHeader(t))))}))}),[e.renderHeader,n]),t.useEffect((()=>{const t=n.current;t&&e.renderListItem&&queueMicrotask((()=>{t.setListItem((t=>Pe(e.renderListItem(t))))}))}),[e.renderListItem,n]),t.useEffect((()=>{const t=n.current;t&&e.renderEmptyState&&queueMicrotask((()=>{t.setEmptyState((t=>Pe(e.renderEmptyState(t))))}))}),[e.renderEmptyState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderLoadingState&&queueMicrotask((()=>{t.setLoadingState((t=>Pe(e.renderLoadingState(t))))}))}),[e.renderLoadingState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderErrorState&&queueMicrotask((()=>{t.setErrorState((t=>Pe(e.renderErrorState(t))))}))}),[e.renderErrorState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPaginationItem&&queueMicrotask((()=>{t.setPaginationItem((t=>Pe(e.renderPaginationItem(t))))}))}),[e.renderPaginationItem,n]),t.useEffect((()=>{const t=n.current;t&&queueMicrotask((()=>{t.setFeedType(e.feedType||"inbox")}))}),[e.feedType,n]),Ae.jsx($e,{children:Ae.jsx("courier-inbox",{ref:n,height:e.height,"light-theme":e.lightTheme?JSON.stringify(e.lightTheme):void 0,"dark-theme":e.darkTheme?JSON.stringify(e.darkTheme):void 0,mode:e.mode})})},e.CourierInboxPopupMenu=e=>{const n=t.useRef(null);return t.useEffect((()=>{const t=n.current;t&&t.onMessageClick(e.onMessageClick)}),[e.onMessageClick,n]),t.useEffect((()=>{const t=n.current;t&&t.onMessageActionClick(e.onMessageActionClick)}),[e.onMessageActionClick,n]),t.useEffect((()=>{const t=n.current;t&&t.onMessageLongPress(e.onMessageLongPress)}),[e.onMessageLongPress,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupHeader&&queueMicrotask((()=>{t.setPopupHeader((t=>Pe(e.renderPopupHeader(t))))}))}),[e.renderPopupHeader,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupListItem&&queueMicrotask((()=>{t.setPopupListItem((t=>Pe(e.renderPopupListItem(t))))}))}),[e.renderPopupListItem,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupEmptyState&&queueMicrotask((()=>{t.setPopupEmptyState((t=>Pe(e.renderPopupEmptyState(t))))}))}),[e.renderPopupEmptyState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupLoadingState&&queueMicrotask((()=>{t.setPopupLoadingState((t=>Pe(e.renderPopupLoadingState(t))))}))}),[e.renderPopupLoadingState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupErrorState&&queueMicrotask((()=>{t.setPopupErrorState((t=>Pe(e.renderPopupErrorState(t))))}))}),[e.renderPopupErrorState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupPaginationItem&&queueMicrotask((()=>{t.setPopupPaginationItem((t=>Pe(e.renderPopupPaginationItem(t))))}))}),[e.renderPopupPaginationItem,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupMenuButton&&queueMicrotask((()=>{t.setPopupMenuButton((t=>Pe(e.renderPopupMenuButton(t))))}))}),[e.renderPopupMenuButton,n]),t.useEffect((()=>{const t=n.current;t&&queueMicrotask((()=>{t.setFeedType(e.feedType||"inbox")}))}),[e.feedType,n]),Ae.jsx($e,{children:Ae.jsx("courier-inbox-popup-menu",{ref:n,"popup-alignment":e.popupAlignment,"popup-width":e.popupWidth,"popup-height":e.popupHeight,left:e.left,top:e.top,right:e.right,bottom:e.bottom,"light-theme":e.lightTheme?JSON.stringify(e.lightTheme):void 0,"dark-theme":e.darkTheme?JSON.stringify(e.darkTheme):void 0,mode:e.mode})})},e.useCourier=()=>{const e=e=>B.shared.signIn(e),n=()=>B.shared.signOut(),i=e=>le.shared.load(e),o=e=>le.shared.fetchNextPageOfMessages(e),s=e=>B.shared.paginationLimit=e,r=e=>le.shared.readMessage({message:e}),a=e=>le.shared.unreadMessage({message:e}),l=e=>le.shared.clickMessage({message:e}),d=e=>le.shared.archiveMessage({message:e}),h=e=>le.shared.openMessage({message:e}),u=e=>le.shared.unarchiveMessage({message:e}),c=()=>le.shared.readAllMessages(),[p,v]=t.useState({userId:void 0,signIn:e,signOut:n}),[g,m]=t.useState({load:i,fetchNextPageOfMessages:o,setPaginationLimit:s,readMessage:r,unreadMessage:a,clickMessage:l,archiveMessage:d,openMessage:h,unarchiveMessage:u,readAllMessages:c});t.useEffect((()=>{const e=B.shared.addAuthenticationListener((()=>b())),t=new fe({onError:e=>_(e),onDataSetChange:()=>_(),onPageAdded:()=>_(),onMessageAdd:()=>_(),onMessageRemove:()=>_(),onMessageUpdate:()=>_(),onUnreadCountChange:()=>_()});return le.shared.addDataStoreListener(t),b(),_(),()=>{e.remove(),t.remove()}}),[]);const b=()=>{var t;const i=null==(t=B.shared.client)?void 0:t.options;v({userId:null==i?void 0:i.userId,signIn:e,signOut:n})},_=e=>{const t=le.shared;m({load:i,fetchNextPageOfMessages:o,setPaginationLimit:s,readMessage:r,unreadMessage:a,clickMessage:l,archiveMessage:d,openMessage:h,unarchiveMessage:u,readAllMessages:c,inbox:t.inboxDataSet,archive:t.archiveDataSet,unreadCount:t.unreadCount,error:e})};return{shared:B.shared,auth:p,inbox:g}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
|
2
|
-
//# sourceMappingURL=index.js.map
|