@trycourier/courier-react 8.0.11-beta → 8.0.12-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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-dom"),require("react-dom/client")):"function"==typeof define&&define.amd?define(["exports","react","react-dom","react-dom/client"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CourierReact={},e.React,e.ReactDOM,e.ReactDOMClient)}(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=class e{constructor(e,t){s(this,"webSocket",null),s(this,"pingInterval",null),s(this,"onOpen"),s(this,"onMessageReceived"),s(this,"onClose"),s(this,"onError"),s(this,"url"),s(this,"options"),this.url=e,this.options=t}get isConnected(){return null!==this.webSocket}async connect(){return this.disconnect(),new Promise(((e,t)=>{try{this.webSocket=new WebSocket(this.url),this.webSocket.onopen=()=>{var t;null==(t=this.onOpen)||t.call(this),e()},this.webSocket.onmessage=e=>{var t;null==(t=this.onMessageReceived)||t.call(this,e.data)},this.webSocket.onclose=e=>{var t;this.webSocket=null,null==(t=this.onClose)||t.call(this,e.code,e.reason)},this.webSocket.onerror=e=>{var n;this.webSocket=null;const i=new Error("Courier Socket connection failed");i.originalEvent=e,null==(n=this.onError)||n.call(this,i),t(i)}}catch(n){this.webSocket=null,t(n)}}))}disconnect(){this.stopPing(),this.webSocket&&(this.webSocket.close(e.NORMAL_CLOSURE_STATUS),this.webSocket=null)}async send(e){if(!this.webSocket)return!1;const t=JSON.stringify(e);return void 0!==this.webSocket.send(t)}keepAlive(e){this.stopPing(),this.pingInterval=setInterval((async()=>{var e;try{await this.send({action:"keepAlive"})}catch(t){null==(e=this.options.logger)||e.error("Error occurred on Keep Alive:",t)}}),(null==e?void 0:e.intervalInMillis)??3e5)}stopPing(){this.pingInterval&&(clearInterval(this.pingInterval),this.pingInterval=null)}};s(r,"NORMAL_CLOSURE_STATUS",1e3);let a=r;const l=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 d{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)}}class u{static generate(e){const t=Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15);return e?e+t:t}}class h extends Error{constructor(e,t,n){super(t),this.code=e,this.type=n,this.name="CourierRequestError"}}function c(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 p(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 v(e){const t=e.validCodes??[200],n=e.options.showLogs?u.generate():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&&c(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 h(o.status,"Failed to parse response as JSON","PARSE_ERROR")}if(n&&p(e.options.logger,n,"HTTP",{status:o.status,response:s}),!t.includes(o.status))throw new h(o.status,(null==s?void 0:s.message)||"Unknown Error",null==s?void 0:s.type);return s}async function g(e){const t=e.options.showLogs?u.generate():void 0;t&&c(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 h(n.status,"Failed to parse response as JSON","PARSE_ERROR")}if(t&&p(e.options.logger,t,"GraphQL",{status:n.status,response:i}),!n.ok)throw new h(n.status,(null==i?void 0:i.message)||"Unknown Error",null==i?void 0:i.type);return i}class m{constructor(e){this.options=e}}class b extends m{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 g({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}}class _ extends a{constructor(e){super(_.buildUrl(e),e),s(this,"receivedMessage"),s(this,"receivedMessageEvent"),this.onMessageReceived=e=>this.convertToType(e)}convertToType(e){var t,n,i,o;try{switch(JSON.parse(e).type){case"event":const i=JSON.parse(e);null==(t=this.receivedMessageEvent)||t.call(this,i);break;case"message":const o=JSON.parse(e);null==(n=this.receivedMessage)||n.call(this,o)}}catch(s){null==(i=this.options.logger)||i.error("Error parsing socket message",s),s instanceof Error&&(null==(o=this.onError)||o.call(this,s))}}async sendSubscribe(e){var t;const n={action:"subscribe",data:{userAgent:"courier-js",channel:this.options.userId,event:"*",version:(null==e?void 0:e.version)??5}};this.options.connectionId&&(n.data.clientSourceId=this.options.connectionId),this.options.tenantId&&(n.data.accountId=this.options.tenantId),null==(t=this.options.logger)||t.debug("Sending subscribe request",n),await this.send(n)}static buildUrl(e){var t;let n=(null==(t=e.apiUrls)?void 0:t.inbox.webSocket)??"";return e.accessToken&&(n+=`/?auth=${e.accessToken}`),n}}class f extends m{constructor(e){super(e),s(this,"socket"),this.socket=new _(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 g({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 g({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 g({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 g({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 g({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 g({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 g({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 g({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 g({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 g({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 g({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 g({options:this.options,query:"\n mutation TrackEvent {\n archiveAll\n }\n ",headers:e,url:this.options.apiUrls.inbox.graphql})}}class x{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 y extends m{constructor(){super(...arguments),s(this,"transformer",new x)}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 v({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 v({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 v({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 C extends m{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 v({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 v({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 k extends m{async putSubscription(e){return await v({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 v({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 S extends m{async postInboundCourier(e){return await v({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 v({url:e.url,options:this.options,method:"POST",body:{event:e.event}})}}class w extends m{constructor(e){var t,n;const i=void 0!==e.showLogs?e.showLogs:"development"===process.env.NODE_ENV,o={...e,showLogs:i,apiUrls:e.apiUrls||l(),accessToken:e.jwt??e.publicApiKey};super({...o,logger:new d(o.showLogs),apiUrls:l(o.apiUrls)}),s(this,"tokens"),s(this,"brands"),s(this,"preferences"),s(this,"inbox"),s(this,"lists"),s(this,"tracking"),this.tokens=new C(this.options),this.brands=new b(this.options),this.preferences=new y(this.options),this.inbox=new f(this.options),this.lists=new k(this.options),this.tracking=new S(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 M{constructor(e){s(this,"callback"),this.callback=e}remove(){E.shared.removeAuthenticationListener(this)}}const I=class e{constructor(){s(this,"id",u.generate()),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??u.generate();this.instanceClient=new w({...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 M(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(I,"instance");let E=I;var T=Object.defineProperty,$=(e,t,n)=>((e,t,n)=>t in e?T(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n),L=Object.defineProperty,P=(e,t,n)=>((e,t,n)=>t in e?L(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);const A={500:"#171717",50010:"#1717171A",50020:"#17171733"},B={200:"#F5F5F5",400:"#3A3A3A",500:"#E5E5E5",600:"#737373"},D={500:"#FFFFFF",50010:"#FFFFFF1A",50020:"#FFFFFF33"},R={400:"#60A5FA",500:"#2563EB"},O={light:{colors:{primary:A[500],secondary:D[500],border:B[500],link:R[500],icon:A[500]},button:{cornerRadius:"4px"}},dark:{colors:{primary:D[500],secondary:A[500],border:B[400],link:R[400],icon:D[500]},button:{cornerRadius:"4px"}}},F=()=>"undefined"==typeof window?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",H=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)}};class z extends HTMLElement{constructor(){super(),P(this,"_currentSystemTheme"),P(this,"_systemThemeCleanup"),this._currentSystemTheme=F(),this._systemThemeCleanup=H((e=>{this._currentSystemTheme=e,this.onSystemThemeChange(e)}))}get currentSystemTheme(){return this._currentSystemTheme}disconnectedCallback(){this._systemThemeCleanup&&this._systemThemeCleanup()}onSystemThemeChange(e){}}const N={borderRadius:"4px",fontSize:"14px"},U=e=>({...N,backgroundColor:O[e].colors.secondary,textColor:O[e].colors.primary,fontWeight:"500",border:`1px solid ${O[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 q extends z{constructor(e){super(),P(this,"_button"),P(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??(()=>U(this.currentSystemTheme).borderRadius)()};\n font-weight: ${e.fontWeight??(()=>U(this.currentSystemTheme).fontWeight)()};\n font-family: ${e.fontFamily??"inherit"};\n font-size: ${e.fontSize??(()=>U(this.currentSystemTheme).fontSize)()};\n padding: 6px 10px;\n cursor: pointer;\n width: 100%;\n height: 100%;\n background-color: ${e.backgroundColor??(()=>U(this.currentSystemTheme).backgroundColor)()};\n color: ${e.textColor??(()=>U(this.currentSystemTheme).textColor)()};\n border: ${e.border??(()=>U(this.currentSystemTheme).border)()};\n box-shadow: ${e.shadow??(()=>U(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)}}customElements.get("courier-button")||customElements.define("courier-button",q);const j={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 V extends HTMLElement{constructor(e,t){super(),P(this,"_color"),P(this,"_svg"),P(this,"_iconContainer"),P(this,"_style"),this._color=e??A[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()}}customElements.get("courier-icon")||customElements.define("courier-icon",V);class J extends HTMLElement{constructor(){super(),P(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, ${O.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, ${O.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")}}P(J,"observedAttributes",["href","variant","disabled","color","underline","mode","target","font-family","font-size"]),customElements.get("courier-link")||customElements.define("courier-link",J);class Z extends z{constructor(){super(),P(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 G extends Z{constructor(e){super(),P(this,"_props"),P(this,"_title"),P(this,"_button"),P(this,"_style"),P(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 q(this._props.button??U(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}}customElements.get("courier-info-state")||customElements.define("courier-info-state",G);class W extends HTMLElement{constructor(e,t,n,i,o,s,r,a){super(),P(this,"_backgroundColor"),P(this,"_hoverBackgroundColor"),P(this,"_activeBackgroundColor"),P(this,"_borderRadius"),P(this,"_height"),P(this,"_width"),P(this,"_style"),P(this,"_button"),P(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 V(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()}}customElements.get("courier-icon-button")||customElements.define("courier-icon-button",W);function K(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 X(e){return{...e,messages:e.messages.map((e=>K(e)))}}[{name:"courier-button",class:q},{name:"courier-icon",class:V},{name:"courier-link",class:J},{name:"courier-info-state",class:G},{name:"courier-icon-button",class:W}].forEach((({name:e,class:t})=>{customElements.get(e)||customElements.define(e,t)}));class Y extends HTMLElement{constructor(e){super(),$(this,"_theme"),$(this,"_options",[]),$(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 W(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")}}customElements.get("courier-list-item-menu")||customElements.define("courier-list-item-menu",Y);const Q=class e{constructor(){$(this,"_inboxDataSet"),$(this,"_archiveDataSet"),$(this,"_dataStoreListeners",[]),$(this,"_unreadCount"),$(this,"isPaginatingInbox",!1),$(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,u;if(e.canUseCache)switch(e.feedType){case"inbox":if(this._inboxDataSet)return this._inboxDataSet;break;case"archive":if(this._archiveDataSet)return this._archiveDataSet}const h="inbox"===e.feedType?await(null==(t=E.shared.client)?void 0:t.inbox.getMessages()):await(null==(n=E.shared.client)?void 0:n.inbox.getArchivedMessages());return{feedType:e.feedType,messages:(null==(o=null==(i=null==h?void 0:h.data)?void 0:i.messages)?void 0:o.nodes)??[],canPaginate:(null==(a=null==(r=null==(s=null==h?void 0:h.data)?void 0:s.messages)?void 0:r.pageInfo)?void 0:a.hasNextPage)??!1,paginationCursor:(null==(u=null==(d=null==(l=null==h?void 0:h.data)?void 0:l.messages)?void 0:d.pageInfo)?void 0:u.startCursor)??null}}async fetchUnreadCount(e){var t;if(e.canUseCache&&void 0!==this._unreadCount)return this._unreadCount;return await(null==(t=E.shared.client)?void 0:t.inbox.getUnreadMessageCount())??0}async load(e){var t,n,i;try{if(!(null==(t=E.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=E.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=E.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,u,h;const c=null==(e=E.shared.client)?void 0:e.inbox.socket;try{if(!c)return void(null==(n=null==(t=E.shared.client)?void 0:t.options.logger)||n.info("CourierInbox socket not available"));if(null==(s=null==(i=E.shared.client)?void 0:i.options.logger)||s.info("CourierInbox socket connectionId:",null==(o=E.shared.client)?void 0:o.options.connectionId),c.isConnected)return void(null==(a=null==(r=E.shared.client)?void 0:r.options.logger)||a.info("CourierInbox socket already connected. Socket will not attempt reconnection."));c.receivedMessage=e=>{this.addMessage(e,0,"inbox")},c.receivedMessageEvent=e=>{let t;switch(e.messageId&&(t=this.getMessage({messageId:e.messageId})),e.event){case"mark-all-read":this.readAllMessages({canCallApi:!1});break;case"read":t&&this.readMessage({message:t,canCallApi:!1});break;case"unread":t&&this.unreadMessage({message:t,canCallApi:!1});break;case"opened":t&&this.openMessage({message:t,canCallApi:!1});break;case"archive":t&&this.archiveMessage({message:t,canCallApi:!1});break;case"archive-read":this.archiveReadMessages({canCallApi:!1});break;case"click":t&&this.clickMessage({message:t,canCallApi:!1});break;case"unarchive":t&&this.unarchiveMessage({message:t,canCallApi:!1})}},await c.connect(),await c.sendSubscribe(),c.keepAlive(),null==(d=null==(l=E.shared.client)?void 0:l.options.logger)||d.info("CourierInbox socket connected")}catch(p){null==(h=null==(u=E.shared.client)?void 0:u.options.logger)||h.error("Failed to connect socket:",p)}}getMessage(e){var t,n;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,u,h,c,p,v,g,m,b,_,f,x,y,C,k,S;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=E.shared.client)?void 0:n.inbox.getMessages({paginationLimit:E.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==(u=null==(d=null==(l=null==e?void 0:e.data)?void 0:l.messages)?void 0:d.pageInfo)?void 0:u.startCursor)??null};return this.addPage(t),t}catch(w){return null==(c=null==(h=E.shared.client)?void 0:h.options.logger)||c.error("Error fetching next page of inbox messages:",w),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=E.shared.client)?void 0:v.inbox.getArchivedMessages({paginationLimit:E.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==(f=null==(_=null==(b=null==e?void 0:e.data)?void 0:b.messages)?void 0:_.pageInfo)?void 0:f.hasNextPage)??!1,paginationCursor:(null==(C=null==(y=null==(x=null==e?void 0:e.data)?void 0:x.messages)?void 0:y.pageInfo)?void 0:C.startCursor)??null};return this.addPage(t),t}catch(w){return null==(S=null==(k=E.shared.client)?void 0:k.options.logger)||S.error("Error fetching next page of archived messages:",w),null}finally{this.isPaginatingArchive=!1}}return null}canMutate(){return!!(E.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=E.shared.client)?void 0:n.inbox.read({messageId:e.messageId}))}catch(a){null==(o=null==(i=E.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=E.shared.client)?void 0:n.inbox.unread({messageId:e.messageId}))}catch(a){null==(o=null==(i=E.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=E.shared.client)?void 0:n.inbox.open({messageId:e.messageId}))}catch(r){this.applyMessageSnapshot(s),null==(o=null==(i=E.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=E.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=E.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=E.shared.client)?void 0:i.inbox.archive({messageId:e.messageId}))}catch(l){null==(s=null==(o=E.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=E.shared.client)?void 0:i.inbox.unarchive({messageId:e.messageId}))}catch(l){null==(s=null==(o=E.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=E.shared.client)?void 0:n.inbox.archiveRead())}catch(r){null==(o=null==(i=E.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=E.shared.client)?void 0:n.inbox.archiveAll())}catch(r){null==(o=null==(i=E.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=E.shared.client)?void 0:i.inbox.readAll())}catch(a){null==(s=null==(o=E.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:X(t),archive:X(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:K(e),archiveIndex:t,inboxIndex:n}}};$(Q,"instance");let ee=Q;class te extends HTMLElement{constructor(e){super(),$(this,"_theme"),$(this,"_message",null),$(this,"_feedType","inbox"),$(this,"_isMobile",!1),$(this,"_titleElement"),$(this,"_subtitleElement"),$(this,"_timeElement"),$(this,"_style"),$(this,"_menu"),$(this,"_unreadIndicator"),$(this,"_actionsContainer"),$(this,"_longPressTimeout",null),$(this,"_isLongPress",!1),$(this,"onItemClick",null),$(this,"onItemLongPress",null),$(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 Y(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 V||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,u,h,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==(u=null==g?void 0:g.read)?void 0:u.color)??"red"},onClick:()=>{this._message&&(this._message.read?ee.shared.unreadMessage({message:this._message}):ee.shared.readMessage({message:this._message}))}}),m.push({id:b?"unarchive":"archive",icon:{svg:b?null==(h=null==g?void 0:g.unarchive)?void 0:h.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?ee.shared.unarchiveMessage({message:this._message}):ee.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,u;const h=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==h?void 0:h.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==h?void 0:h.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==h?void 0:h.hoverBackgroundColor)??"red"};\n }\n }\n :host(:active) {\n background-color: ${(null==h?void 0:h.activeBackgroundColor)??"red"};\n }\n\n /* ───────────────────────── Menu hover / active ────────────────── */\n @media (hover: hover) {\n :host(:hover):has(courier-list-item-menu:hover, courier-list-item-menu *:hover, courier-button:hover, courier-button *:hover) {\n background-color: ${(null==h?void 0:h.backgroundColor)??"transparent"};\n }\n }\n :host(:active):has(courier-list-item-menu:active, courier-list-item-menu *:active, courier-button:active, courier-button *:active) {\n background-color: ${(null==h?void 0:h.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==h?void 0:h.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==h?void 0:h.title)?void 0:n.family)??"inherit"};\n font-size: ${(null==(i=null==h?void 0:h.title)?void 0:i.size)??"14px"};\n color: ${(null==(o=null==h?void 0:h.title)?void 0:o.color)??"red"};\n margin-bottom: 4px;\n }\n\n p[part='subtitle'] {\n font-family: ${(null==(s=null==h?void 0:h.subtitle)?void 0:s.family)??"inherit"};\n font-size: ${(null==(r=null==h?void 0:h.subtitle)?void 0:r.size)??"14px"};\n color: ${(null==(a=null==h?void 0:h.subtitle)?void 0:a.color)??"red"};\n }\n\n p[part='time'] {\n font-family: ${(null==(l=null==h?void 0:h.time)?void 0:l.family)??"inherit"};\n font-size: ${(null==(d=null==h?void 0:h.time)?void 0:d.size)??"14px"};\n color: ${(null==(u=null==h?void 0:h.time)?void 0:u.color)??"red"};\n text-align: right;\n white-space: nowrap;\n }\n\n courier-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=E.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 q({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)}))}}customElements.get("courier-list-item")||customElements.define("courier-list-item",te);class ne extends HTMLElement{constructor(e,t){super(),$(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 ie(e,35),o=new ie(e,100),s=new ie(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 `}}customElements.get("courier-inbox-skeleton-list-item")||customElements.define("courier-inbox-skeleton-list-item",ne);class ie extends HTMLElement{constructor(e,t){super(),$(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,u,h,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),f=`rgba(${m}, ${b}, ${_}, 0.8)`,x=`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 ${f} 25%,\n ${x} 50%,\n ${f} 75%\n );\n background-size: 200% 100%;\n animation: shimmer ${(null==(u=null==(d=null==(l=e.inbox)?void 0:l.loading)?void 0:d.animation)?void 0:u.duration)??"2s"} ease-in-out infinite;\n border-radius: ${(null==(p=null==(c=null==(h=e.inbox)?void 0:h.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 `}}customElements.get("courier-skeleton-animated-row")||customElements.define("courier-skeleton-animated-row",ie);class oe extends Z{constructor(e){super(),$(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 ne(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 `}}customElements.get("courier-inbox-skeleton-list")||customElements.define("courier-inbox-skeleton-list",oe);class se extends HTMLElement{constructor(e){super(),$(this,"skeletonLoadingList"),$(this,"observer"),$(this,"customItem"),$(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 oe(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()}}customElements.get("courier-inbox-pagination-list-item")||customElements.define("courier-inbox-pagination-list-item",se);class re extends HTMLElement{constructor(e){super(),$(this,"_themeSubscription"),$(this,"_messages",[]),$(this,"_feedType","inbox"),$(this,"_isLoading",!0),$(this,"_error",null),$(this,"_canPaginate",!1),$(this,"_onMessageClick",null),$(this,"_onMessageActionClick",null),$(this,"_onMessageLongPress",null),$(this,"_onRefresh"),$(this,"_onPaginationTrigger"),$(this,"_listItemFactory"),$(this,"_paginationItemFactory"),$(this,"_loadingStateFactory"),$(this,"_emptyStateFactory"),$(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)??D[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,u,h,c,p,v,g,m,b,_,f,x,y,C,k,S,w,M,I,E,T,$,L,P,A,B,D,R,O,F,H,z,N,U,q,j,V,J,Z,W,K,X,Y,Q,ee,ne,ie,re,ae;this.reset();const le=this._themeSubscription.manager.getTheme();if(this._error){const I=null==(e=le.inbox)?void 0:e.error,E=new G({title:{text:(null==(t=null==I?void 0:I.title)?void 0:t.text)??this._error.message,textColor:null==(i=null==(n=null==I?void 0:I.title)?void 0:n.font)?void 0:i.color,fontFamily:null==(s=null==(o=null==I?void 0:I.title)?void 0:o.font)?void 0:s.family,fontSize:null==(a=null==(r=null==I?void 0:I.title)?void 0:r.font)?void 0:a.size,fontWeight:null==(d=null==(l=null==I?void 0:I.title)?void 0:l.font)?void 0:d.weight},button:{text:null==(u=null==I?void 0:I.button)?void 0:u.text,backgroundColor:null==(h=null==I?void 0:I.button)?void 0:h.backgroundColor,hoverBackgroundColor:null==(c=null==I?void 0:I.button)?void 0:c.hoverBackgroundColor,activeBackgroundColor:null==(p=null==I?void 0:I.button)?void 0:p.activeBackgroundColor,textColor:null==(g=null==(v=null==I?void 0:I.button)?void 0:v.font)?void 0:g.color,fontFamily:null==(b=null==(m=null==I?void 0:I.button)?void 0:m.font)?void 0:b.family,fontSize:null==(f=null==(_=null==I?void 0:I.button)?void 0:_.font)?void 0:f.size,fontWeight:null==(y=null==(x=null==I?void 0:I.button)?void 0:x.font)?void 0:y.weight,shadow:null==(C=null==I?void 0:I.button)?void 0:C.shadow,border:null==(k=null==I?void 0:I.button)?void 0:k.border,borderRadius:null==(S=null==I?void 0:I.button)?void 0:S.borderRadius}});return E.build(null==(w=this._errorStateFactory)?void 0:w.call(this,{feedType:this._feedType,error:this._error})),E.setButtonClickCallback((()=>this.handleRetry())),void(null==(M=this.shadowRoot)||M.appendChild(E))}if(this._isLoading){const e=new oe(le);return e.build(null==(I=this._loadingStateFactory)?void 0:I.call(this,{feedType:this._feedType})),void(null==(E=this.shadowRoot)||E.appendChild(e))}if(0===this._messages.length){const e=null==(T=le.inbox)?void 0:T.empty,t=new G({title:{text:(null==($=null==e?void 0:e.title)?void 0:$.text)??`No ${this._feedType} messages yet`,textColor:null==(P=null==(L=null==e?void 0:e.title)?void 0:L.font)?void 0:P.color,fontFamily:null==(B=null==(A=null==e?void 0:e.title)?void 0:A.font)?void 0:B.family,fontSize:null==(R=null==(D=null==e?void 0:e.title)?void 0:D.font)?void 0:R.size,fontWeight:null==(F=null==(O=null==e?void 0:e.title)?void 0:O.font)?void 0:F.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==(N=null==e?void 0:e.button)?void 0:N.hoverBackgroundColor,activeBackgroundColor:null==(U=null==e?void 0:e.button)?void 0:U.activeBackgroundColor,textColor:null==(j=null==(q=null==e?void 0:e.button)?void 0:q.font)?void 0:j.color,fontFamily:null==(J=null==(V=null==e?void 0:e.button)?void 0:V.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==(X=null==(K=null==e?void 0:e.button)?void 0:K.font)?void 0:X.weight,shadow:null==(Y=null==e?void 0:e.button)?void 0:Y.shadow,border:null==(Q=null==e?void 0:e.button)?void 0:Q.border,borderRadius:null==(ee=null==e?void 0:e.button)?void 0:ee.borderRadius}});return t.build(null==(ne=this._emptyStateFactory)?void 0:ne.call(this,{feedType:this._feedType})),t.setButtonClickCallback((()=>this.handleRefresh())),void(null==(ie=this.shadowRoot)||ie.appendChild(t))}const de=document.createElement("ul");if(null==(re=this.shadowRoot)||re.appendChild(de),this._messages.forEach(((e,t)=>{if(this._listItemFactory)return void de.appendChild(this._listItemFactory({message:e,index:t}));const n=new te(le);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)})),de.appendChild(n)})),this._canPaginate){const e=new se({theme:le,customItem:null==(ae=this._paginationItemFactory)?void 0:ae.call(this,{feedType:this._feedType}),onPaginationTrigger:()=>{var e;return null==(e=this._onPaginationTrigger)?void 0:e.call(this,this._feedType)}});de.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()}}customElements.get("courier-inbox-list")||customElements.define("courier-inbox-list",re);class ae extends HTMLElement{constructor(e){super(),$(this,"_option"),$(this,"_isSelected"),$(this,"_content"),$(this,"_itemIcon"),$(this,"_title"),$(this,"_selectionIcon"),$(this,"_style"),$(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 V(this._option.icon.svg??j.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 V(j.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,u,h,c,p,v,g,m,b,_,f,x,y,C,k,S,w,M,I,E,T,$,L,P,A;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==(h=null==(u=B.inbox)?void 0:u.header)?void 0:h.menus)?void 0:c.popup)?void 0:p.list)?void 0:v.font)?void 0:g.family)??"inherit"};\n font-weight: ${(null==(y=null==(x=null==(f=null==(_=null==(b=null==(m=B.inbox)?void 0:m.header)?void 0:b.menus)?void 0:_.popup)?void 0:f.list)?void 0:x.font)?void 0:y.weight)??"inherit"};\n font-size: ${(null==(I=null==(M=null==(w=null==(S=null==(k=null==(C=B.inbox)?void 0:C.header)?void 0:k.menus)?void 0:S.popup)?void 0:w.list)?void 0:M.font)?void 0:I.size)??"14px"};\n color: ${(null==(A=null==(P=null==(L=null==($=null==(T=null==(E=B.inbox)?void 0:E.header)?void 0:T.menus)?void 0:$.popup)?void 0:L.list)?void 0:P.font)?void 0:A.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)??j.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)??j.inbox)}}customElements.get("courier-inbox-filter-menu-item")||customElements.define("courier-inbox-filter-menu-item",ae);class le extends HTMLElement{constructor(e,t,n,i,o){super(),$(this,"_themeSubscription"),$(this,"_type"),$(this,"_selectedIndex",0),$(this,"_options"),$(this,"_selectable"),$(this,"_onMenuOpen"),$(this,"_menuButton"),$(this,"_menu"),$(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 W("filters"===t?j.filter:j.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,u,h,c,p,v,g,m,b,_,f,x;const y=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=y.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=y.inbox)?void 0:o.header)?void 0:s.menus)?void 0:r.popup)?void 0:a.border)??"1px solid red"};\n background: ${(null==(h=null==(u=null==(d=null==(l=y.inbox)?void 0:l.header)?void 0:d.menus)?void 0:u.popup)?void 0:h.backgroundColor)??"red"};\n box-shadow: ${(null==(g=null==(v=null==(p=null==(c=y.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==(x=null==(f=null==(_=null==(b=null==(m=y.inbox)?void 0:m.header)?void 0:b.menus)?void 0:_.popup)?void 0:f.list)?void 0:x.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?j.filter:j.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 ae({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()}}customElements.get("courier-inbox-option-menu")||customElements.define("courier-inbox-option-menu",le);class de extends HTMLElement{constructor(e){super(),$(this,"_themeSubscription"),$(this,"_location"),$(this,"_count",0),$(this,"_badge"),$(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,u=null==d?void 0:d.backgroundColor,h=null==d?void 0:d.borderRadius;return`\n :host {\n display: inline-block;\n }\n\n .unread-badge {\n background-color: ${u};\n color: ${null==(r=null==d?void 0:d.font)?void 0:r.color};\n border-radius: ${h};\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()}}customElements.get("courier-unread-count-badge")||customElements.define("courier-unread-count-badge",de);class ue extends HTMLElement{constructor(e,t){super(),$(this,"_themeSubscription"),$(this,"_option"),$(this,"_feedType"),$(this,"_titleElement"),$(this,"_iconElement"),$(this,"_unreadBadge"),$(this,"_container"),$(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 V(void 0,this._option.icon.svg),this._titleElement=document.createElement("h2"),this._unreadBadge=new de({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,u,h,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==(h=null==(u=null==(d=null==(l=m.inbox)?void 0:l.header)?void 0:d.filters)?void 0:u.font)?void 0:h.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,u,h,c,p,v,g,m,b,_,f,x,y,C,k,S,w,M,I;const E=this._themeSubscription.manager.getTheme();switch(this._feedType){case"inbox":this._titleElement.textContent=(null==(i=null==(n=null==(t=null==(e=E.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=E.inbox)?void 0:o.header)?void 0:s.filters)?void 0:r.inbox)?void 0:a.icon)?void 0:l.svg)??j.inbox),this._iconElement.updateColor((null==(p=null==(c=null==(h=null==(u=null==(d=E.inbox)?void 0:d.header)?void 0:u.filters)?void 0:h.inbox)?void 0:c.icon)?void 0:p.color)??"red");break;case"archive":this._titleElement.textContent=(null==(b=null==(m=null==(g=null==(v=E.inbox)?void 0:v.header)?void 0:g.filters)?void 0:m.archive)?void 0:b.text)??"Archive",this._iconElement.updateSVG((null==(C=null==(y=null==(x=null==(f=null==(_=E.inbox)?void 0:_.header)?void 0:f.filters)?void 0:x.archive)?void 0:y.icon)?void 0:C.svg)??j.archive),this._iconElement.updateColor((null==(I=null==(M=null==(w=null==(S=null==(k=E.inbox)?void 0:k.header)?void 0:S.filters)?void 0:w.archive)?void 0:M.icon)?void 0:I.color)??"red")}}disconnectedCallback(){this._themeSubscription.unsubscribe()}}customElements.get("courier-inbox-header-title")||customElements.define("courier-inbox-header-title",ue);class he extends Z{constructor(e){super(),$(this,"_themeSubscription"),$(this,"_feedType","inbox"),$(this,"_unreadCount",0),$(this,"_titleSection"),$(this,"_filterMenu"),$(this,"_actionMenu"),$(this,"_style"),$(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,u,h,c,p,v,g,m,b,_,f,x,y,C,k,S,w,M,I,E,T,$,L,P,A,B,D,R;const O=this._themeSubscription.manager.getTheme(),F=null==(n=null==(t=null==(e=O.inbox)?void 0:e.header)?void 0:t.menus)?void 0:n.filters;return[{id:"inbox",text:(null==(i=null==F?void 0:F.inbox)?void 0:i.text)??"Inbox",icon:{color:(null==(s=null==(o=null==F?void 0:F.inbox)?void 0:o.icon)?void 0:s.color)??"red",svg:(null==(a=null==(r=null==F?void 0:F.inbox)?void 0:r.icon)?void 0:a.svg)??j.inbox},selectionIcon:{color:(null==(p=null==(c=null==(h=null==(u=null==(d=null==(l=O.inbox)?void 0:l.header)?void 0:d.menus)?void 0:u.popup)?void 0:h.list)?void 0:c.selectionIcon)?void 0:p.color)??"red",svg:(null==(f=null==(_=null==(b=null==(m=null==(g=null==(v=O.inbox)?void 0:v.header)?void 0:g.menus)?void 0:m.popup)?void 0:b.list)?void 0:_.selectionIcon)?void 0:f.svg)??j.check},onClick:e=>{this.handleOptionMenuItemClick("inbox",e)}},{id:"archive",text:(null==(x=null==F?void 0:F.archive)?void 0:x.text)??"Archive",icon:{color:(null==(C=null==(y=null==F?void 0:F.archive)?void 0:y.icon)?void 0:C.color)??"red",svg:(null==(S=null==(k=null==F?void 0:F.archive)?void 0:k.icon)?void 0:S.svg)??j.archive},selectionIcon:{color:(null==($=null==(T=null==(E=null==(I=null==(M=null==(w=O.inbox)?void 0:w.header)?void 0:M.menus)?void 0:I.popup)?void 0:E.list)?void 0:T.selectionIcon)?void 0:$.color)??"red",svg:(null==(R=null==(D=null==(B=null==(A=null==(P=null==(L=O.inbox)?void 0:L.header)?void 0:P.menus)?void 0:A.popup)?void 0:B.list)?void 0:D.selectionIcon)?void 0:R.svg)??j.check},onClick:e=>{this.handleOptionMenuItemClick("archive",e)}}]}getActionOptions(){var e,t,n,i,o,s,r,a,l,d,u,h,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)??j.inbox},selectionIcon:null,onClick:e=>{ee.shared.readAllMessages({canCallApi:!0})}},{id:"archiveAll",text:(null==(l=null==_?void 0:_.archiveAll)?void 0:l.text)??"Archive All",icon:{color:(null==(u=null==(d=null==_?void 0:_.archiveAll)?void 0:d.icon)?void 0:u.color)??"red",svg:(null==(c=null==(h=null==_?void 0:_.archiveAll)?void 0:h.icon)?void 0:c.svg)??j.archive},selectionIcon:null,onClick:e=>{ee.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)??j.archive},selectionIcon:null,onClick:e=>{ee.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)??D[500],l.style.boxShadow=(null==(o=null==(i=a.inbox)?void 0:i.header)?void 0:o.shadow)??`0px 1px 0px 0px ${B[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 ue(this._themeSubscription.manager,e[0]),this._filterMenu=new le(this._themeSubscription.manager,"filters",!0,e,(()=>{var e;null==(e=this._actionMenu)||e.closeMenu()})),this._actionMenu=new le(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: ${D[500]};\n box-shadow: 0px 1px 0px 0px ${B[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()}}customElements.get("courier-inbox-header")||customElements.define("courier-inbox-header",he);class ce{constructor(e){$(this,"events"),this.events=e}remove(){ee.shared.removeDataStoreListener(this)}}const pe={popup:{button:{icon:{color:A[500],svg:j.inbox},backgroundColor:"transparent",hoverBackgroundColor:A[50010],activeBackgroundColor:A[50020],unreadIndicator:{font:{color:D[500],size:"14px",family:void 0,weight:void 0},backgroundColor:R[500],borderRadius:"12px"}},window:{backgroundColor:D[500],borderRadius:"8px",border:`1px solid ${B[500]}`,shadow:`0px 8px 16px -4px ${B[500]}`}},inbox:{header:{backgroundColor:D[500],shadow:`0px 1px 0px 0px ${B[500]}`,filters:{font:{color:A[500],family:void 0,size:"18px"},inbox:{icon:{color:A[500],svg:j.inbox},text:"Inbox"},archive:{icon:{color:A[500],svg:j.archive},text:"Archive"},unreadIndicator:{font:{color:D[500],family:void 0,size:"14px"},backgroundColor:R[500],borderRadius:"12px"}},menus:{popup:{backgroundColor:D[500],border:`1px solid ${B[500]}`,borderRadius:"4px",shadow:`0px 4px 8px -2px ${B[500]}`,list:{hoverBackgroundColor:B[200],activeBackgroundColor:B[500],divider:"none",font:{color:A[500],family:void 0,size:"14px"},selectionIcon:{color:A[500],svg:j.check}}},filters:{button:{icon:{color:A[500],svg:j.filter},backgroundColor:"transparent",hoverBackgroundColor:A[50010],activeBackgroundColor:A[50020]},inbox:{icon:{color:A[500],svg:j.inbox},text:"Inbox"},archive:{icon:{color:A[500],svg:j.archive},text:"Archive"}},actions:{button:{icon:{color:A[500],svg:j.overflow},backgroundColor:"transparent",hoverBackgroundColor:A[50010],activeBackgroundColor:A[50020]},markAllRead:{icon:{color:A[500],svg:j.read},text:"Read All"},archiveAll:{icon:{color:A[500],svg:j.archive},text:"Archive All"},archiveRead:{icon:{color:A[500],svg:j.archiveRead},text:"Archive Read"}}}},list:{backgroundColor:D[500],item:{backgroundColor:"transparent",unreadIndicatorColor:R[500],hoverBackgroundColor:B[200],activeBackgroundColor:B[500],actions:{backgroundColor:"transparent",hoverBackgroundColor:B[200],activeBackgroundColor:B[500],border:`1px solid ${B[500]}`,borderRadius:"4px",shadow:"0px 1px 2px 0px rgba(0, 0, 0, 0.06)",font:{color:A[500],family:void 0,size:"14px"}},title:{color:A[500],family:void 0,size:"14px"},subtitle:{color:B[600],family:void 0,size:"14px"},time:{color:B[600],family:void 0,size:"14px"},divider:`1px solid ${B[200]}`,menu:{enabled:!0,backgroundColor:D[500],border:`1px solid ${B[500]}`,borderRadius:"4px",shadow:`0px 2px 4px -2px ${B[500]}`,longPress:{displayDuration:4e3,vibrationDuration:50},item:{hoverBackgroundColor:B[200],activeBackgroundColor:B[500],borderRadius:"0px",read:{color:A[500],svg:j.read},unread:{color:A[500],svg:j.unread},archive:{color:A[500],svg:j.archive},unarchive:{color:A[500],svg:j.unarchive}}}}},loading:{animation:{barColor:B[500],barHeight:"14px",barBorderRadius:"14px",duration:"2s"},divider:`1px solid ${B[200]}`},empty:{title:{font:{size:"16px",weight:"500",color:A[500]}},button:{text:"Refresh"}},error:{title:{font:{size:"16px",weight:"500",color:A[500]}},button:{text:"Retry"}}}},ve={popup:{button:{icon:{color:D[500],svg:j.inbox},backgroundColor:"transparent",hoverBackgroundColor:D[50010],activeBackgroundColor:D[50020],unreadIndicator:{font:{color:D[500],size:"14px",family:void 0,weight:void 0},backgroundColor:R[500],borderRadius:"12px"}},window:{backgroundColor:A[500],borderRadius:"8px",border:`1px solid ${B[400]}`,shadow:`0px 4px 8px -2px ${D[50020]}`}},inbox:{header:{backgroundColor:A[500],shadow:`0px 1px 0px 0px ${B[400]}`,filters:{font:{color:D[500],family:void 0,size:"18px"},inbox:{icon:{color:D[500],svg:j.inbox},text:"Inbox"},archive:{icon:{color:D[500],svg:j.archive},text:"Archive"},unreadIndicator:{font:{color:D[500],family:void 0,size:"14px"},backgroundColor:R[500],borderRadius:"12px"}},menus:{popup:{backgroundColor:A[500],border:`1px solid ${B[400]}`,borderRadius:"4px",shadow:`0px 4px 8px -2px ${D[50020]}`,list:{hoverBackgroundColor:D[50010],activeBackgroundColor:D[50020],divider:"none",font:{color:D[500],family:void 0,size:"14px"},selectionIcon:{color:D[500],svg:j.check}}},filters:{button:{icon:{color:D[500],svg:j.filter},backgroundColor:"transparent",hoverBackgroundColor:D[50010],activeBackgroundColor:D[50020]},inbox:{icon:{color:D[500],svg:j.inbox},text:"Inbox"},archive:{icon:{color:D[500],svg:j.archive},text:"Archive"}},actions:{button:{icon:{color:D[500],svg:j.overflow},backgroundColor:"transparent",hoverBackgroundColor:D[50010],activeBackgroundColor:D[50020]},markAllRead:{icon:{color:D[500],svg:j.read},text:"Read All"},archiveAll:{icon:{color:D[500],svg:j.archive},text:"Archive All"},archiveRead:{icon:{color:D[500],svg:j.archiveRead},text:"Archive Read"}}}},list:{backgroundColor:A[500],item:{backgroundColor:"transparent",unreadIndicatorColor:R[500],hoverBackgroundColor:D[50010],activeBackgroundColor:D[50020],actions:{backgroundColor:"transparent",hoverBackgroundColor:D[50010],activeBackgroundColor:D[50020],border:`1px solid ${B[400]}`,borderRadius:"4px",shadow:`0px 1px 2px 0px ${D[50010]}`,font:{color:D[500],family:void 0,size:"14px"}},title:{color:D[500],family:void 0,size:"14px"},subtitle:{color:B[500],family:void 0,size:"14px"},time:{color:B[500],family:void 0,size:"12px"},divider:`1px solid ${B[400]}`,menu:{enabled:!0,backgroundColor:A[500],border:`1px solid ${B[400]}`,borderRadius:"4px",shadow:`0px 2px 4px -2px ${D[50020]}`,longPress:{displayDuration:4e3,vibrationDuration:50},item:{hoverBackgroundColor:D[50010],activeBackgroundColor:D[50020],borderRadius:"0px",read:{color:D[500],svg:j.read},unread:{color:D[500],svg:j.unread},archive:{color:D[500],svg:j.archive},unarchive:{color:D[500],svg:j.unarchive}}}}},loading:{animation:{barColor:D[500],barHeight:"14px",barBorderRadius:"14px",duration:"2s"},divider:`1px solid ${B[400]}`},empty:{title:{font:{size:"16px",weight:"500",color:D[500]}},button:{text:"Refresh"}},error:{title:{font:{size:"16px",weight:"500",color:D[500]}},button:{text:"Retry"}}}};class ge{constructor(e){$(this,"THEME_CHANGE_EVENT","courier_inbox_theme_change"),$(this,"_theme"),$(this,"_lightTheme",pe),$(this,"_darkTheme",ve),$(this,"_target"),$(this,"_subscriptions",[]),$(this,"_userMode"),$(this,"_systemMode"),$(this,"_systemThemeCleanup"),this._theme=e,this._target=new EventTarget,this._userMode="system",this._systemMode=F(),this.setLightTheme(pe),this.setDarkTheme(ve),this._systemThemeCleanup=H((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,u,h,c,p,v,g,m,b,_,f,x,y,C,k,S,w,M,I,E,T,$,L,P,A,B,D,R,O,F,H,z,N,U,q,j,V,J,Z,G,W,K,X,Y,Q,ee,te,ne,ie,oe,se,re,ae,le,de,ue,he,ce,ge,me,be,_e,fe,xe,ye,Ce,ke,Se,we,Me,Ie,Ee,Te,$e,Le,Pe,Ae,Be,De,Re,Oe,Fe,He,ze,Ne,Ue,qe,je,Ve,Je,Ze,Ge,We,Ke,Xe,Ye,Qe,et,tt,nt,it,ot,st,rt,at,lt,dt,ut,ht,ct,pt,vt,gt,mt,bt,_t,ft,xt,yt,Ct,kt,St,wt,Mt,It,Et,Tt,$t,Lt,Pt,At,Bt,Dt,Rt,Ot,Ft,Ht,zt,Nt,Ut,qt,jt,Vt,Jt,Zt,Gt,Wt,Kt,Xt,Yt,Qt,en,tn,nn,on,sn,rn,an,ln,dn,un,hn,cn,pn,vn,gn,mn,bn,_n,fn,xn,yn,Cn,kn,Sn,wn,Mn,In,En,Tn,$n,Ln,Pn,An,Bn,Dn,Rn,On,Fn,Hn,zn,Nn,Un,qn,jn,Vn,Jn,Zn,Gn,Wn,Kn,Xn,Yn,Qn,ei,ti,ni,ii,oi,si,ri,ai,li,di,ui,hi,ci,pi,vi,gi,mi,bi,_i,fi,xi,yi,Ci,ki,Si,wi,Mi,Ii,Ei,Ti,$i,Li,Pi,Ai,Bi,Di,Ri,Oi,Fi,Hi,zi,Ni,Ui,qi,ji,Vi,Ji;const Zi="light"===e?pe:ve;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==(h=null==(u=t.popup)?void 0:u.button)?void 0:h.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==(f=null==(_=t.inbox)?void 0:_.header)?void 0:f.filters,inbox:{...null==(C=null==(y=null==(x=Zi.inbox)?void 0:x.header)?void 0:y.filters)?void 0:C.inbox,...null==(w=null==(S=null==(k=t.inbox)?void 0:k.header)?void 0:S.filters)?void 0:w.inbox,icon:{...null==(T=null==(E=null==(I=null==(M=Zi.inbox)?void 0:M.header)?void 0:I.filters)?void 0:E.inbox)?void 0:T.icon,...null==(A=null==(P=null==(L=null==($=t.inbox)?void 0:$.header)?void 0:L.filters)?void 0:P.inbox)?void 0:A.icon}},archive:{...null==(R=null==(D=null==(B=Zi.inbox)?void 0:B.header)?void 0:D.filters)?void 0:R.archive,...null==(H=null==(F=null==(O=t.inbox)?void 0:O.header)?void 0:F.filters)?void 0:H.archive,icon:{...null==(q=null==(U=null==(N=null==(z=Zi.inbox)?void 0:z.header)?void 0:N.filters)?void 0:U.archive)?void 0:q.icon,...null==(Z=null==(J=null==(V=null==(j=t.inbox)?void 0:j.header)?void 0:V.filters)?void 0:J.archive)?void 0:Z.icon}},unreadIndicator:{...null==(K=null==(W=null==(G=Zi.inbox)?void 0:G.header)?void 0:W.filters)?void 0:K.unreadIndicator,...null==(Q=null==(Y=null==(X=t.inbox)?void 0:X.header)?void 0:Y.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==(ge=null==(ce=null==(he=null==(ue=Zi.inbox)?void 0:ue.header)?void 0:he.menus)?void 0:ce.popup)?void 0:ge.list,...null==(fe=null==(_e=null==(be=null==(me=t.inbox)?void 0:me.header)?void 0:be.menus)?void 0:_e.popup)?void 0:fe.list,font:{...null==(Se=null==(ke=null==(Ce=null==(ye=null==(xe=Zi.inbox)?void 0:xe.header)?void 0:ye.menus)?void 0:Ce.popup)?void 0:ke.list)?void 0:Se.font,...null==(Te=null==(Ee=null==(Ie=null==(Me=null==(we=t.inbox)?void 0:we.header)?void 0:Me.menus)?void 0:Ie.popup)?void 0:Ee.list)?void 0:Te.font},selectionIcon:{...null==(Be=null==(Ae=null==(Pe=null==(Le=null==($e=Zi.inbox)?void 0:$e.header)?void 0:Le.menus)?void 0:Pe.popup)?void 0:Ae.list)?void 0:Be.selectionIcon,...null==(He=null==(Fe=null==(Oe=null==(Re=null==(De=t.inbox)?void 0:De.header)?void 0:Re.menus)?void 0:Oe.popup)?void 0:Fe.list)?void 0:He.selectionIcon}}},filters:{...null==(Ue=null==(Ne=null==(ze=Zi.inbox)?void 0:ze.header)?void 0:Ne.menus)?void 0:Ue.filters,...null==(Ve=null==(je=null==(qe=t.inbox)?void 0:qe.header)?void 0:je.menus)?void 0:Ve.filters,inbox:{...null==(We=null==(Ge=null==(Ze=null==(Je=Zi.inbox)?void 0:Je.header)?void 0:Ze.menus)?void 0:Ge.filters)?void 0:We.inbox,...null==(Qe=null==(Ye=null==(Xe=null==(Ke=t.inbox)?void 0:Ke.header)?void 0:Xe.menus)?void 0:Ye.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==(ht=null==(ut=Zi.inbox)?void 0:ut.header)?void 0:ht.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==(Ct=null==(yt=null==(xt=null==(ft=null==(_t=Zi.inbox)?void 0:_t.header)?void 0:ft.menus)?void 0:xt.filters)?void 0:yt.archive)?void 0:Ct.icon,...null==(It=null==(Mt=null==(wt=null==(St=null==(kt=t.inbox)?void 0:kt.header)?void 0:St.menus)?void 0:wt.filters)?void 0:Mt.archive)?void 0:It.icon}}},actions:{...null==($t=null==(Tt=null==(Et=Zi.inbox)?void 0:Et.header)?void 0:Tt.menus)?void 0:$t.actions,...null==(At=null==(Pt=null==(Lt=t.inbox)?void 0:Lt.header)?void 0:Pt.menus)?void 0:At.actions,markAllRead:{...null==(Ot=null==(Rt=null==(Dt=null==(Bt=Zi.inbox)?void 0:Bt.header)?void 0:Dt.menus)?void 0:Rt.actions)?void 0:Ot.markAllRead,...null==(Nt=null==(zt=null==(Ht=null==(Ft=t.inbox)?void 0:Ft.header)?void 0:Ht.menus)?void 0:zt.actions)?void 0:Nt.markAllRead,icon:{...null==(Jt=null==(Vt=null==(jt=null==(qt=null==(Ut=Zi.inbox)?void 0:Ut.header)?void 0:qt.menus)?void 0:jt.actions)?void 0:Vt.markAllRead)?void 0:Jt.icon,...null==(Xt=null==(Kt=null==(Wt=null==(Gt=null==(Zt=t.inbox)?void 0:Zt.header)?void 0:Gt.menus)?void 0:Wt.actions)?void 0:Kt.markAllRead)?void 0:Xt.icon}},archiveAll:{...null==(tn=null==(en=null==(Qt=null==(Yt=Zi.inbox)?void 0:Yt.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==(hn=null==(un=null==(dn=null==(ln=null==(an=Zi.inbox)?void 0:an.header)?void 0:ln.menus)?void 0:dn.actions)?void 0:un.archiveAll)?void 0:hn.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==(xn=null==(fn=null==(_n=null==(bn=Zi.inbox)?void 0:bn.header)?void 0:_n.menus)?void 0:fn.actions)?void 0:xn.archiveRead,...null==(Sn=null==(kn=null==(Cn=null==(yn=t.inbox)?void 0:yn.header)?void 0:Cn.menus)?void 0:kn.actions)?void 0:Sn.archiveRead,icon:{...null==(Tn=null==(En=null==(In=null==(Mn=null==(wn=Zi.inbox)?void 0:wn.header)?void 0:Mn.menus)?void 0:In.actions)?void 0:En.archiveRead)?void 0:Tn.icon,...null==(Bn=null==(An=null==(Pn=null==(Ln=null==($n=t.inbox)?void 0:$n.header)?void 0:Ln.menus)?void 0:Pn.actions)?void 0:An.archiveRead)?void 0:Bn.icon}}}}},list:{...null==(Dn=Zi.inbox)?void 0:Dn.list,...null==(Rn=t.inbox)?void 0:Rn.list,item:{...null==(Fn=null==(On=Zi.inbox)?void 0:On.list)?void 0:Fn.item,...null==(zn=null==(Hn=t.inbox)?void 0:Hn.list)?void 0:zn.item,menu:{...null==(qn=null==(Un=null==(Nn=Zi.inbox)?void 0:Nn.list)?void 0:Un.item)?void 0:qn.menu,...null==(Jn=null==(Vn=null==(jn=t.inbox)?void 0:jn.list)?void 0:Vn.item)?void 0:Jn.menu,item:{...null==(Kn=null==(Wn=null==(Gn=null==(Zn=Zi.inbox)?void 0:Zn.list)?void 0:Gn.item)?void 0:Wn.menu)?void 0:Kn.item,...null==(ei=null==(Qn=null==(Yn=null==(Xn=t.inbox)?void 0:Xn.list)?void 0:Yn.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==(ui=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:ui.read},unread:{...null==(gi=null==(vi=null==(pi=null==(ci=null==(hi=Zi.inbox)?void 0:hi.list)?void 0:ci.item)?void 0:pi.menu)?void 0:vi.item)?void 0:gi.unread,...null==(xi=null==(fi=null==(_i=null==(bi=null==(mi=t.inbox)?void 0:mi.list)?void 0:bi.item)?void 0:_i.menu)?void 0:fi.item)?void 0:xi.unread},archive:{...null==(wi=null==(Si=null==(ki=null==(Ci=null==(yi=Zi.inbox)?void 0:yi.list)?void 0:Ci.item)?void 0:ki.menu)?void 0:Si.item)?void 0:wi.archive,...null==($i=null==(Ti=null==(Ei=null==(Ii=null==(Mi=t.inbox)?void 0:Mi.list)?void 0:Ii.item)?void 0:Ei.menu)?void 0:Ti.item)?void 0:$i.archive},unarchive:{...null==(Di=null==(Bi=null==(Ai=null==(Pi=null==(Li=Zi.inbox)?void 0:Li.list)?void 0:Pi.item)?void 0:Ai.menu)?void 0:Bi.item)?void 0:Di.unarchive,...null==(zi=null==(Hi=null==(Fi=null==(Oi=null==(Ri=t.inbox)?void 0:Ri.list)?void 0:Oi.item)?void 0:Fi.menu)?void 0:Hi.item)?void 0:zi.unarchive}}}}},loading:{...null==(Ni=Zi.inbox)?void 0:Ni.loading,...null==(Ui=t.inbox)?void 0:Ui.loading},empty:{...null==(qi=Zi.inbox)?void 0:qi.empty,...null==(ji=t.inbox)?void 0:ji.empty},error:{...null==(Vi=Zi.inbox)?void 0:Vi.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 me=class extends HTMLElement{constructor(e){var t;super(),$(this,"_currentFeed","inbox"),$(this,"_themeManager"),$(this,"_shadow"),$(this,"_list"),$(this,"_datastoreListener"),$(this,"_authListener"),$(this,"_style"),$(this,"_header"),$(this,"_headerFactory"),$(this,"_onMessageClick"),$(this,"_onMessageActionClick"),$(this,"_onMessageLongPress"),$(this,"_defaultProps",{title:"Inbox",icon:j.inbox,feedType:this._currentFeed,height:"768px"}),this._shadow=this.attachShadow({mode:"open"}),this._themeManager=e??new ge(pe),this._header=new he({themeManager:this._themeManager,onFeedTypeChange:e=>{this.setFeedType(e)}}),this._header.build(void 0),this._shadow.appendChild(this._header),this._list=new re({themeManager:this._themeManager,onRefresh:()=>{this.refresh()},onPaginationTrigger:async e=>{var t,n;try{await ee.shared.fetchNextPageOfMessages({feedType:e})}catch(i){null==(n=null==(t=E.shared.client)?void 0:t.options.logger)||n.error("Failed to fetch next page of messages:",i)}},onMessageClick:(e,t)=>{var n;ee.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 ce({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()}}),ee.shared.addDataStoreListener(this._datastoreListener),this._themeManager.subscribe((e=>{this.refreshTheme()})),this._authListener=E.shared.addAuthenticationListener((e=>{this.refresh()})),(null==(t=E.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:ee.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 ee.shared.load(e),await ee.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=E.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=E.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=E.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)}}};customElements.get("courier-inbox")||customElements.define("courier-inbox",me);class be extends Z{constructor(e){super(),$(this,"_themeSubscription"),$(this,"_container"),$(this,"_triggerButton"),$(this,"_unreadCountBadge"),this._themeSubscription=e.subscribe((e=>{this.updateTheme()}))}defaultElement(){this._container=document.createElement("div"),this._container.className="menu-button-container",this._triggerButton=new W(j.inbox),this._unreadCountBadge=new de({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,u,h,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)??A[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)??j.inbox),null==(u=this._triggerButton)||u.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==(h=null==_?void 0:_.popup)?void 0:h.button)?void 0:c.hoverBackgroundColor)??A[50010]),null==(m=this._triggerButton)||m.updateActiveBackgroundColor((null==(g=null==(v=null==_?void 0:_.popup)?void 0:v.button)?void 0:g.activeBackgroundColor)??A[50020]),null==(b=this._unreadCountBadge)||b.refreshTheme("button")}disconnectedCallback(){this._themeSubscription.unsubscribe()}}customElements.get("courier-inbox-menu-button")||customElements.define("courier-inbox-menu-button",be);let _e=class extends HTMLElement{constructor(){super(),$(this,"_width","440px"),$(this,"_height","440px"),$(this,"_popupAlignment","top-right"),$(this,"_top","40px"),$(this,"_right","0"),$(this,"_bottom","40px"),$(this,"_left","0"),$(this,"_themeManager",new ge(pe)),$(this,"_triggerButton"),$(this,"_popup"),$(this,"_inbox"),$(this,"_style"),$(this,"_datastoreListener"),$(this,"_popupMenuButtonFactory");const e=this.attachShadow({mode:"open"});this._triggerButton=new be(this._themeManager),this._triggerButton.build(void 0),this._popup=document.createElement("div"),this._popup.className="popup",this._inbox=new me(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 ce(this),ee.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=E.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=ee.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()}};customElements.get("courier-inbox-menu")||customElements.define("courier-inbox-menu",_e);var fe,xe={exports:{}},ye={};var Ce,ke,Se={};
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=class e{constructor(e,t){s(this,"webSocket",null),s(this,"pingInterval",null),s(this,"onOpen"),s(this,"onMessageReceived"),s(this,"onClose"),s(this,"onError"),s(this,"url"),s(this,"options"),this.url=e,this.options=t}get isConnected(){return null!==this.webSocket}async connect(){return this.disconnect(),new Promise(((e,t)=>{try{this.webSocket=new WebSocket(this.url),this.webSocket.onopen=()=>{var t;null==(t=this.onOpen)||t.call(this),e()},this.webSocket.onmessage=e=>{var t;null==(t=this.onMessageReceived)||t.call(this,e.data)},this.webSocket.onclose=e=>{var t;this.webSocket=null,null==(t=this.onClose)||t.call(this,e.code,e.reason)},this.webSocket.onerror=e=>{var n;this.webSocket=null;const i=new Error("Courier Socket connection failed");i.originalEvent=e,null==(n=this.onError)||n.call(this,i),t(i)}}catch(n){this.webSocket=null,t(n)}}))}disconnect(){this.stopPing(),this.webSocket&&(this.webSocket.close(e.NORMAL_CLOSURE_STATUS),this.webSocket=null)}async send(e){if(!this.webSocket)return!1;const t=JSON.stringify(e);return void 0!==this.webSocket.send(t)}keepAlive(e){this.stopPing(),this.pingInterval=setInterval((async()=>{var e;try{await this.send({action:"keepAlive"})}catch(t){null==(e=this.options.logger)||e.error("Error occurred on Keep Alive:",t)}}),(null==e?void 0:e.intervalInMillis)??3e5)}stopPing(){this.pingInterval&&(clearInterval(this.pingInterval),this.pingInterval=null)}};s(r,"NORMAL_CLOSURE_STATUS",1e3);let a=r;const l=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 d{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)}}class u{static generate(e){const t=Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15);return e?e+t:t}}class h extends Error{constructor(e,t,n){super(t),this.code=e,this.type=n,this.name="CourierRequestError"}}function c(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 p(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 v(e){const t=e.validCodes??[200],n=e.options.showLogs?u.generate():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&&c(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 h(o.status,"Failed to parse response as JSON","PARSE_ERROR")}if(n&&p(e.options.logger,n,"HTTP",{status:o.status,response:s}),!t.includes(o.status))throw new h(o.status,(null==s?void 0:s.message)||"Unknown Error",null==s?void 0:s.type);return s}async function g(e){const t=e.options.showLogs?u.generate():void 0;t&&c(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 h(n.status,"Failed to parse response as JSON","PARSE_ERROR")}if(t&&p(e.options.logger,t,"GraphQL",{status:n.status,response:i}),!n.ok)throw new h(n.status,(null==i?void 0:i.message)||"Unknown Error",null==i?void 0:i.type);return i}class m{constructor(e){this.options=e}}class b extends m{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 g({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}}class _ extends a{constructor(e){super(_.buildUrl(e),e),s(this,"receivedMessage"),s(this,"receivedMessageEvent"),this.onMessageReceived=e=>this.convertToType(e)}convertToType(e){var t,n,i,o;try{switch(JSON.parse(e).type){case"event":const i=JSON.parse(e);null==(t=this.receivedMessageEvent)||t.call(this,i);break;case"message":const o=JSON.parse(e);null==(n=this.receivedMessage)||n.call(this,o)}}catch(s){null==(i=this.options.logger)||i.error("Error parsing socket message",s),s instanceof Error&&(null==(o=this.onError)||o.call(this,s))}}async sendSubscribe(e){var t;const n={action:"subscribe",data:{userAgent:"courier-js",channel:this.options.userId,event:"*",version:(null==e?void 0:e.version)??5}};this.options.connectionId&&(n.data.clientSourceId=this.options.connectionId),this.options.tenantId&&(n.data.accountId=this.options.tenantId),null==(t=this.options.logger)||t.debug("Sending subscribe request",n),await this.send(n)}static buildUrl(e){var t;let n=(null==(t=e.apiUrls)?void 0:t.inbox.webSocket)??"";return e.accessToken&&(n+=`/?auth=${e.accessToken}`),n}}class f extends m{constructor(e){super(e),s(this,"socket"),this.socket=new _(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 g({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 g({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 g({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 g({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 g({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 g({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 g({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 g({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 g({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 g({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 g({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 g({options:this.options,query:"\n mutation TrackEvent {\n archiveAll\n }\n ",headers:e,url:this.options.apiUrls.inbox.graphql})}}class x{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 y extends m{constructor(){super(...arguments),s(this,"transformer",new x)}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 v({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 v({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 v({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 C extends m{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 v({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 v({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 k extends m{async putSubscription(e){return await v({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 v({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 S extends m{async postInboundCourier(e){return await v({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 v({url:e.url,options:this.options,method:"POST",body:{event:e.event}})}}class w extends m{constructor(e){var t,n;const i=void 0!==e.showLogs?e.showLogs:"development"===process.env.NODE_ENV,o={...e,showLogs:i,apiUrls:e.apiUrls||l(),accessToken:e.jwt??e.publicApiKey};super({...o,logger:new d(o.showLogs),apiUrls:l(o.apiUrls)}),s(this,"tokens"),s(this,"brands"),s(this,"preferences"),s(this,"inbox"),s(this,"lists"),s(this,"tracking"),this.tokens=new C(this.options),this.brands=new b(this.options),this.preferences=new y(this.options),this.inbox=new f(this.options),this.lists=new k(this.options),this.tracking=new S(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 M{constructor(e){s(this,"callback"),this.callback=e}remove(){E.shared.removeAuthenticationListener(this)}}const I=class e{constructor(){s(this,"id",u.generate()),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??u.generate();this.instanceClient=new w({...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 M(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(I,"instance");let E=I;var T=Object.defineProperty,$=(e,t,n)=>((e,t,n)=>t in e?T(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n),L=Object.defineProperty,P=(e,t,n)=>((e,t,n)=>t in e?L(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);const A={500:"#171717",50010:"#1717171A",50020:"#17171733"},B={200:"#F5F5F5",400:"#3A3A3A",500:"#E5E5E5",600:"#737373"},D={500:"#FFFFFF",50010:"#FFFFFF1A",50020:"#FFFFFF33"},R={400:"#60A5FA",500:"#2563EB"},O={light:{colors:{primary:A[500],secondary:D[500],border:B[500],link:R[500],icon:A[500]},button:{cornerRadius:"4px"}},dark:{colors:{primary:D[500],secondary:A[500],border:B[400],link:R[400],icon:D[500]},button:{cornerRadius:"4px"}}},F=()=>"undefined"==typeof window?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",H=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)}};class z extends HTMLElement{constructor(){super(),P(this,"_currentSystemTheme"),P(this,"_systemThemeCleanup"),this._currentSystemTheme=F(),this._systemThemeCleanup=H((e=>{this._currentSystemTheme=e,this.onSystemThemeChange(e)}))}get currentSystemTheme(){return this._currentSystemTheme}disconnectedCallback(){this._systemThemeCleanup&&this._systemThemeCleanup()}onSystemThemeChange(e){}}const N={borderRadius:"4px",fontSize:"14px"},U=e=>({...N,backgroundColor:O[e].colors.secondary,textColor:O[e].colors.primary,fontWeight:"500",border:`1px solid ${O[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 q extends z{constructor(e){super(),P(this,"_button"),P(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??(()=>U(this.currentSystemTheme).borderRadius)()};\n font-weight: ${e.fontWeight??(()=>U(this.currentSystemTheme).fontWeight)()};\n font-family: ${e.fontFamily??"inherit"};\n font-size: ${e.fontSize??(()=>U(this.currentSystemTheme).fontSize)()};\n padding: 6px 10px;\n cursor: pointer;\n width: 100%;\n height: 100%;\n background-color: ${e.backgroundColor??(()=>U(this.currentSystemTheme).backgroundColor)()};\n color: ${e.textColor??(()=>U(this.currentSystemTheme).textColor)()};\n border: ${e.border??(()=>U(this.currentSystemTheme).border)()};\n box-shadow: ${e.shadow??(()=>U(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)}}customElements.get("courier-button")||customElements.define("courier-button",q);const j={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 V extends HTMLElement{constructor(e,t){super(),P(this,"_color"),P(this,"_svg"),P(this,"_iconContainer"),P(this,"_style"),this._color=e??A[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()}}customElements.get("courier-icon")||customElements.define("courier-icon",V);class J extends HTMLElement{constructor(){super(),P(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, ${O.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, ${O.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")}}P(J,"observedAttributes",["href","variant","disabled","color","underline","mode","target","font-family","font-size"]),customElements.get("courier-link")||customElements.define("courier-link",J);class Z extends z{constructor(){super(),P(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 G extends Z{constructor(e){super(),P(this,"_props"),P(this,"_title"),P(this,"_button"),P(this,"_style"),P(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 q(this._props.button??U(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}}customElements.get("courier-info-state")||customElements.define("courier-info-state",G);class W extends HTMLElement{constructor(e,t,n,i,o,s,r,a){super(),P(this,"_backgroundColor"),P(this,"_hoverBackgroundColor"),P(this,"_activeBackgroundColor"),P(this,"_borderRadius"),P(this,"_height"),P(this,"_width"),P(this,"_style"),P(this,"_button"),P(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 V(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()}}customElements.get("courier-icon-button")||customElements.define("courier-icon-button",W);function K(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 X(e){return{...e,messages:e.messages.map((e=>K(e)))}}[{name:"courier-button",class:q},{name:"courier-icon",class:V},{name:"courier-link",class:J},{name:"courier-info-state",class:G},{name:"courier-icon-button",class:W}].forEach((({name:e,class:t})=>{customElements.get(e)||customElements.define(e,t)}));class Y extends HTMLElement{constructor(e){super(),$(this,"_theme"),$(this,"_options",[]),$(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 W(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")}}customElements.get("courier-list-item-menu")||customElements.define("courier-list-item-menu",Y);const Q=class e{constructor(){$(this,"_inboxDataSet"),$(this,"_archiveDataSet"),$(this,"_dataStoreListeners",[]),$(this,"_unreadCount"),$(this,"isPaginatingInbox",!1),$(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,u;if(e.canUseCache)switch(e.feedType){case"inbox":if(this._inboxDataSet)return this._inboxDataSet;break;case"archive":if(this._archiveDataSet)return this._archiveDataSet}const h="inbox"===e.feedType?await(null==(t=E.shared.client)?void 0:t.inbox.getMessages()):await(null==(n=E.shared.client)?void 0:n.inbox.getArchivedMessages());return{feedType:e.feedType,messages:(null==(o=null==(i=null==h?void 0:h.data)?void 0:i.messages)?void 0:o.nodes)??[],canPaginate:(null==(a=null==(r=null==(s=null==h?void 0:h.data)?void 0:s.messages)?void 0:r.pageInfo)?void 0:a.hasNextPage)??!1,paginationCursor:(null==(u=null==(d=null==(l=null==h?void 0:h.data)?void 0:l.messages)?void 0:d.pageInfo)?void 0:u.startCursor)??null}}async fetchUnreadCount(e){var t;if(e.canUseCache&&void 0!==this._unreadCount)return this._unreadCount;return await(null==(t=E.shared.client)?void 0:t.inbox.getUnreadMessageCount())??0}async load(e){var t,n,i;try{if(!(null==(t=E.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=E.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=E.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,u,h;const c=null==(e=E.shared.client)?void 0:e.inbox.socket;try{if(!c)return void(null==(n=null==(t=E.shared.client)?void 0:t.options.logger)||n.info("CourierInbox socket not available"));if(null==(s=null==(i=E.shared.client)?void 0:i.options.logger)||s.info("CourierInbox socket connectionId:",null==(o=E.shared.client)?void 0:o.options.connectionId),c.isConnected)return void(null==(a=null==(r=E.shared.client)?void 0:r.options.logger)||a.info("CourierInbox socket already connected. Socket will not attempt reconnection."));c.receivedMessage=e=>{this.addMessage(e,0,"inbox")},c.receivedMessageEvent=e=>{let t;switch(e.messageId&&(t=this.getMessage({messageId:e.messageId})),e.event){case"mark-all-read":this.readAllMessages({canCallApi:!1});break;case"read":t&&this.readMessage({message:t,canCallApi:!1});break;case"unread":t&&this.unreadMessage({message:t,canCallApi:!1});break;case"opened":t&&this.openMessage({message:t,canCallApi:!1});break;case"archive":t&&this.archiveMessage({message:t,canCallApi:!1});break;case"archive-read":this.archiveReadMessages({canCallApi:!1});break;case"click":t&&this.clickMessage({message:t,canCallApi:!1});break;case"unarchive":t&&this.unarchiveMessage({message:t,canCallApi:!1})}},await c.connect(),await c.sendSubscribe(),c.keepAlive(),null==(d=null==(l=E.shared.client)?void 0:l.options.logger)||d.info("CourierInbox socket connected")}catch(p){null==(h=null==(u=E.shared.client)?void 0:u.options.logger)||h.error("Failed to connect socket:",p)}}getMessage(e){var t,n;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,u,h,c,p,v,g,m,b,_,f,x,y,C,k,S;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=E.shared.client)?void 0:n.inbox.getMessages({paginationLimit:E.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==(u=null==(d=null==(l=null==e?void 0:e.data)?void 0:l.messages)?void 0:d.pageInfo)?void 0:u.startCursor)??null};return this.addPage(t),t}catch(w){return null==(c=null==(h=E.shared.client)?void 0:h.options.logger)||c.error("Error fetching next page of inbox messages:",w),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=E.shared.client)?void 0:v.inbox.getArchivedMessages({paginationLimit:E.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==(f=null==(_=null==(b=null==e?void 0:e.data)?void 0:b.messages)?void 0:_.pageInfo)?void 0:f.hasNextPage)??!1,paginationCursor:(null==(C=null==(y=null==(x=null==e?void 0:e.data)?void 0:x.messages)?void 0:y.pageInfo)?void 0:C.startCursor)??null};return this.addPage(t),t}catch(w){return null==(S=null==(k=E.shared.client)?void 0:k.options.logger)||S.error("Error fetching next page of archived messages:",w),null}finally{this.isPaginatingArchive=!1}}return null}canMutate(){return!!(E.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=E.shared.client)?void 0:n.inbox.read({messageId:e.messageId}))}catch(a){null==(o=null==(i=E.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=E.shared.client)?void 0:n.inbox.unread({messageId:e.messageId}))}catch(a){null==(o=null==(i=E.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=E.shared.client)?void 0:n.inbox.open({messageId:e.messageId}))}catch(r){this.applyMessageSnapshot(s),null==(o=null==(i=E.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=E.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=E.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=E.shared.client)?void 0:i.inbox.archive({messageId:e.messageId}))}catch(l){null==(s=null==(o=E.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=E.shared.client)?void 0:i.inbox.unarchive({messageId:e.messageId}))}catch(l){null==(s=null==(o=E.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=E.shared.client)?void 0:n.inbox.archiveRead())}catch(r){null==(o=null==(i=E.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=E.shared.client)?void 0:n.inbox.archiveAll())}catch(r){null==(o=null==(i=E.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=E.shared.client)?void 0:i.inbox.readAll())}catch(a){null==(s=null==(o=E.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:X(t),archive:X(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:K(e),archiveIndex:t,inboxIndex:n}}};$(Q,"instance");let ee=Q;class te extends HTMLElement{constructor(e){super(),$(this,"_theme"),$(this,"_message",null),$(this,"_feedType","inbox"),$(this,"_isMobile",!1),$(this,"_titleElement"),$(this,"_subtitleElement"),$(this,"_timeElement"),$(this,"_style"),$(this,"_menu"),$(this,"_unreadIndicator"),$(this,"_actionsContainer"),$(this,"_longPressTimeout",null),$(this,"_isLongPress",!1),$(this,"onItemClick",null),$(this,"onItemLongPress",null),$(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 Y(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 V||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,u,h,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==(u=null==g?void 0:g.read)?void 0:u.color)??"red"},onClick:()=>{this._message&&(this._message.read?ee.shared.unreadMessage({message:this._message}):ee.shared.readMessage({message:this._message}))}}),m.push({id:b?"unarchive":"archive",icon:{svg:b?null==(h=null==g?void 0:g.unarchive)?void 0:h.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?ee.shared.unarchiveMessage({message:this._message}):ee.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,u;const h=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==h?void 0:h.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==h?void 0:h.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==h?void 0:h.hoverBackgroundColor)??"red"};\n }\n }\n :host(:active) {\n background-color: ${(null==h?void 0:h.activeBackgroundColor)??"red"};\n }\n\n /* ───────────────────────── Menu hover / active ────────────────── */\n @media (hover: hover) {\n :host(:hover):has(courier-list-item-menu:hover, courier-list-item-menu *:hover, courier-button:hover, courier-button *:hover) {\n background-color: ${(null==h?void 0:h.backgroundColor)??"transparent"};\n }\n }\n :host(:active):has(courier-list-item-menu:active, courier-list-item-menu *:active, courier-button:active, courier-button *:active) {\n background-color: ${(null==h?void 0:h.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==h?void 0:h.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==h?void 0:h.title)?void 0:n.family)??"inherit"};\n font-size: ${(null==(i=null==h?void 0:h.title)?void 0:i.size)??"14px"};\n color: ${(null==(o=null==h?void 0:h.title)?void 0:o.color)??"red"};\n margin-bottom: 4px;\n }\n\n p[part='subtitle'] {\n font-family: ${(null==(s=null==h?void 0:h.subtitle)?void 0:s.family)??"inherit"};\n font-size: ${(null==(r=null==h?void 0:h.subtitle)?void 0:r.size)??"14px"};\n color: ${(null==(a=null==h?void 0:h.subtitle)?void 0:a.color)??"red"};\n }\n\n p[part='time'] {\n font-family: ${(null==(l=null==h?void 0:h.time)?void 0:l.family)??"inherit"};\n font-size: ${(null==(d=null==h?void 0:h.time)?void 0:d.size)??"14px"};\n color: ${(null==(u=null==h?void 0:h.time)?void 0:u.color)??"red"};\n text-align: right;\n white-space: nowrap;\n }\n\n courier-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=E.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 q({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)}))}}customElements.get("courier-list-item")||customElements.define("courier-list-item",te);class ne extends HTMLElement{constructor(e,t){super(),$(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 ie(e,35),o=new ie(e,100),s=new ie(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 `}}customElements.get("courier-inbox-skeleton-list-item")||customElements.define("courier-inbox-skeleton-list-item",ne);class ie extends HTMLElement{constructor(e,t){super(),$(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,u,h,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),f=`rgba(${m}, ${b}, ${_}, 0.8)`,x=`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 ${f} 25%,\n ${x} 50%,\n ${f} 75%\n );\n background-size: 200% 100%;\n animation: shimmer ${(null==(u=null==(d=null==(l=e.inbox)?void 0:l.loading)?void 0:d.animation)?void 0:u.duration)??"2s"} ease-in-out infinite;\n border-radius: ${(null==(p=null==(c=null==(h=e.inbox)?void 0:h.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 `}}customElements.get("courier-skeleton-animated-row")||customElements.define("courier-skeleton-animated-row",ie);class oe extends Z{constructor(e){super(),$(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 ne(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 `}}customElements.get("courier-inbox-skeleton-list")||customElements.define("courier-inbox-skeleton-list",oe);class se extends HTMLElement{constructor(e){super(),$(this,"skeletonLoadingList"),$(this,"observer"),$(this,"customItem"),$(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 oe(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()}}customElements.get("courier-inbox-pagination-list-item")||customElements.define("courier-inbox-pagination-list-item",se);class re extends HTMLElement{constructor(e){super(),$(this,"_themeSubscription"),$(this,"_messages",[]),$(this,"_feedType","inbox"),$(this,"_isLoading",!0),$(this,"_error",null),$(this,"_canPaginate",!1),$(this,"_onMessageClick",null),$(this,"_onMessageActionClick",null),$(this,"_onMessageLongPress",null),$(this,"_onRefresh"),$(this,"_onPaginationTrigger"),$(this,"_listItemFactory"),$(this,"_paginationItemFactory"),$(this,"_loadingStateFactory"),$(this,"_emptyStateFactory"),$(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)??D[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,u,h,c,p,v,g,m,b,_,f,x,y,C,k,S,w,M,I,E,T,$,L,P,A,B,D,R,O,F,H,z,N,U,q,j,V,J,Z,W,K,X,Y,Q,ee,ne,ie,re,ae;this.reset();const le=this._themeSubscription.manager.getTheme();if(this._error){const I=null==(e=le.inbox)?void 0:e.error,E=new G({title:{text:(null==(t=null==I?void 0:I.title)?void 0:t.text)??this._error.message,textColor:null==(i=null==(n=null==I?void 0:I.title)?void 0:n.font)?void 0:i.color,fontFamily:null==(s=null==(o=null==I?void 0:I.title)?void 0:o.font)?void 0:s.family,fontSize:null==(a=null==(r=null==I?void 0:I.title)?void 0:r.font)?void 0:a.size,fontWeight:null==(d=null==(l=null==I?void 0:I.title)?void 0:l.font)?void 0:d.weight},button:{text:null==(u=null==I?void 0:I.button)?void 0:u.text,backgroundColor:null==(h=null==I?void 0:I.button)?void 0:h.backgroundColor,hoverBackgroundColor:null==(c=null==I?void 0:I.button)?void 0:c.hoverBackgroundColor,activeBackgroundColor:null==(p=null==I?void 0:I.button)?void 0:p.activeBackgroundColor,textColor:null==(g=null==(v=null==I?void 0:I.button)?void 0:v.font)?void 0:g.color,fontFamily:null==(b=null==(m=null==I?void 0:I.button)?void 0:m.font)?void 0:b.family,fontSize:null==(f=null==(_=null==I?void 0:I.button)?void 0:_.font)?void 0:f.size,fontWeight:null==(y=null==(x=null==I?void 0:I.button)?void 0:x.font)?void 0:y.weight,shadow:null==(C=null==I?void 0:I.button)?void 0:C.shadow,border:null==(k=null==I?void 0:I.button)?void 0:k.border,borderRadius:null==(S=null==I?void 0:I.button)?void 0:S.borderRadius}});return E.build(null==(w=this._errorStateFactory)?void 0:w.call(this,{feedType:this._feedType,error:this._error})),E.setButtonClickCallback((()=>this.handleRetry())),void(null==(M=this.shadowRoot)||M.appendChild(E))}if(this._isLoading){const e=new oe(le);return e.build(null==(I=this._loadingStateFactory)?void 0:I.call(this,{feedType:this._feedType})),void(null==(E=this.shadowRoot)||E.appendChild(e))}if(0===this._messages.length){const e=null==(T=le.inbox)?void 0:T.empty,t=new G({title:{text:(null==($=null==e?void 0:e.title)?void 0:$.text)??`No ${this._feedType} messages yet`,textColor:null==(P=null==(L=null==e?void 0:e.title)?void 0:L.font)?void 0:P.color,fontFamily:null==(B=null==(A=null==e?void 0:e.title)?void 0:A.font)?void 0:B.family,fontSize:null==(R=null==(D=null==e?void 0:e.title)?void 0:D.font)?void 0:R.size,fontWeight:null==(F=null==(O=null==e?void 0:e.title)?void 0:O.font)?void 0:F.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==(N=null==e?void 0:e.button)?void 0:N.hoverBackgroundColor,activeBackgroundColor:null==(U=null==e?void 0:e.button)?void 0:U.activeBackgroundColor,textColor:null==(j=null==(q=null==e?void 0:e.button)?void 0:q.font)?void 0:j.color,fontFamily:null==(J=null==(V=null==e?void 0:e.button)?void 0:V.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==(X=null==(K=null==e?void 0:e.button)?void 0:K.font)?void 0:X.weight,shadow:null==(Y=null==e?void 0:e.button)?void 0:Y.shadow,border:null==(Q=null==e?void 0:e.button)?void 0:Q.border,borderRadius:null==(ee=null==e?void 0:e.button)?void 0:ee.borderRadius}});return t.build(null==(ne=this._emptyStateFactory)?void 0:ne.call(this,{feedType:this._feedType})),t.setButtonClickCallback((()=>this.handleRefresh())),void(null==(ie=this.shadowRoot)||ie.appendChild(t))}const de=document.createElement("ul");if(null==(re=this.shadowRoot)||re.appendChild(de),this._messages.forEach(((e,t)=>{if(this._listItemFactory)return void de.appendChild(this._listItemFactory({message:e,index:t}));const n=new te(le);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)})),de.appendChild(n)})),this._canPaginate){const e=new se({theme:le,customItem:null==(ae=this._paginationItemFactory)?void 0:ae.call(this,{feedType:this._feedType}),onPaginationTrigger:()=>{var e;return null==(e=this._onPaginationTrigger)?void 0:e.call(this,this._feedType)}});de.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()}}customElements.get("courier-inbox-list")||customElements.define("courier-inbox-list",re);class ae extends HTMLElement{constructor(e){super(),$(this,"_option"),$(this,"_isSelected"),$(this,"_content"),$(this,"_itemIcon"),$(this,"_title"),$(this,"_selectionIcon"),$(this,"_style"),$(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 V(this._option.icon.svg??j.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 V(j.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,u,h,c,p,v,g,m,b,_,f,x,y,C,k,S,w,M,I,E,T,$,L,P,A;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==(h=null==(u=B.inbox)?void 0:u.header)?void 0:h.menus)?void 0:c.popup)?void 0:p.list)?void 0:v.font)?void 0:g.family)??"inherit"};\n font-weight: ${(null==(y=null==(x=null==(f=null==(_=null==(b=null==(m=B.inbox)?void 0:m.header)?void 0:b.menus)?void 0:_.popup)?void 0:f.list)?void 0:x.font)?void 0:y.weight)??"inherit"};\n font-size: ${(null==(I=null==(M=null==(w=null==(S=null==(k=null==(C=B.inbox)?void 0:C.header)?void 0:k.menus)?void 0:S.popup)?void 0:w.list)?void 0:M.font)?void 0:I.size)??"14px"};\n color: ${(null==(A=null==(P=null==(L=null==($=null==(T=null==(E=B.inbox)?void 0:E.header)?void 0:T.menus)?void 0:$.popup)?void 0:L.list)?void 0:P.font)?void 0:A.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)??j.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)??j.inbox)}}customElements.get("courier-inbox-filter-menu-item")||customElements.define("courier-inbox-filter-menu-item",ae);class le extends HTMLElement{constructor(e,t,n,i,o){super(),$(this,"_themeSubscription"),$(this,"_type"),$(this,"_selectedIndex",0),$(this,"_options"),$(this,"_selectable"),$(this,"_onMenuOpen"),$(this,"_menuButton"),$(this,"_menu"),$(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 W("filters"===t?j.filter:j.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,u,h,c,p,v,g,m,b,_,f,x;const y=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=y.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=y.inbox)?void 0:o.header)?void 0:s.menus)?void 0:r.popup)?void 0:a.border)??"1px solid red"};\n background: ${(null==(h=null==(u=null==(d=null==(l=y.inbox)?void 0:l.header)?void 0:d.menus)?void 0:u.popup)?void 0:h.backgroundColor)??"red"};\n box-shadow: ${(null==(g=null==(v=null==(p=null==(c=y.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==(x=null==(f=null==(_=null==(b=null==(m=y.inbox)?void 0:m.header)?void 0:b.menus)?void 0:_.popup)?void 0:f.list)?void 0:x.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?j.filter:j.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 ae({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()}}customElements.get("courier-inbox-option-menu")||customElements.define("courier-inbox-option-menu",le);class de extends HTMLElement{constructor(e){super(),$(this,"_themeSubscription"),$(this,"_location"),$(this,"_count",0),$(this,"_badge"),$(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,u=null==d?void 0:d.backgroundColor,h=null==d?void 0:d.borderRadius;return`\n :host {\n display: inline-block;\n }\n\n .unread-badge {\n background-color: ${u};\n color: ${null==(r=null==d?void 0:d.font)?void 0:r.color};\n border-radius: ${h};\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()}}customElements.get("courier-unread-count-badge")||customElements.define("courier-unread-count-badge",de);class ue extends HTMLElement{constructor(e,t){super(),$(this,"_themeSubscription"),$(this,"_option"),$(this,"_feedType"),$(this,"_titleElement"),$(this,"_iconElement"),$(this,"_unreadBadge"),$(this,"_container"),$(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 V(void 0,this._option.icon.svg),this._titleElement=document.createElement("h2"),this._unreadBadge=new de({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,u,h,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==(h=null==(u=null==(d=null==(l=m.inbox)?void 0:l.header)?void 0:d.filters)?void 0:u.font)?void 0:h.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,u,h,c,p,v,g,m,b,_,f,x,y,C,k,S,w,M,I;const E=this._themeSubscription.manager.getTheme();switch(this._feedType){case"inbox":this._titleElement.textContent=(null==(i=null==(n=null==(t=null==(e=E.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=E.inbox)?void 0:o.header)?void 0:s.filters)?void 0:r.inbox)?void 0:a.icon)?void 0:l.svg)??j.inbox),this._iconElement.updateColor((null==(p=null==(c=null==(h=null==(u=null==(d=E.inbox)?void 0:d.header)?void 0:u.filters)?void 0:h.inbox)?void 0:c.icon)?void 0:p.color)??"red");break;case"archive":this._titleElement.textContent=(null==(b=null==(m=null==(g=null==(v=E.inbox)?void 0:v.header)?void 0:g.filters)?void 0:m.archive)?void 0:b.text)??"Archive",this._iconElement.updateSVG((null==(C=null==(y=null==(x=null==(f=null==(_=E.inbox)?void 0:_.header)?void 0:f.filters)?void 0:x.archive)?void 0:y.icon)?void 0:C.svg)??j.archive),this._iconElement.updateColor((null==(I=null==(M=null==(w=null==(S=null==(k=E.inbox)?void 0:k.header)?void 0:S.filters)?void 0:w.archive)?void 0:M.icon)?void 0:I.color)??"red")}}disconnectedCallback(){this._themeSubscription.unsubscribe()}}customElements.get("courier-inbox-header-title")||customElements.define("courier-inbox-header-title",ue);class he extends Z{constructor(e){super(),$(this,"_themeSubscription"),$(this,"_feedType","inbox"),$(this,"_unreadCount",0),$(this,"_titleSection"),$(this,"_filterMenu"),$(this,"_actionMenu"),$(this,"_style"),$(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,u,h,c,p,v,g,m,b,_,f,x,y,C,k,S,w,M,I,E,T,$,L,P,A,B,D,R;const O=this._themeSubscription.manager.getTheme(),F=null==(n=null==(t=null==(e=O.inbox)?void 0:e.header)?void 0:t.menus)?void 0:n.filters;return[{id:"inbox",text:(null==(i=null==F?void 0:F.inbox)?void 0:i.text)??"Inbox",icon:{color:(null==(s=null==(o=null==F?void 0:F.inbox)?void 0:o.icon)?void 0:s.color)??"red",svg:(null==(a=null==(r=null==F?void 0:F.inbox)?void 0:r.icon)?void 0:a.svg)??j.inbox},selectionIcon:{color:(null==(p=null==(c=null==(h=null==(u=null==(d=null==(l=O.inbox)?void 0:l.header)?void 0:d.menus)?void 0:u.popup)?void 0:h.list)?void 0:c.selectionIcon)?void 0:p.color)??"red",svg:(null==(f=null==(_=null==(b=null==(m=null==(g=null==(v=O.inbox)?void 0:v.header)?void 0:g.menus)?void 0:m.popup)?void 0:b.list)?void 0:_.selectionIcon)?void 0:f.svg)??j.check},onClick:e=>{this.handleOptionMenuItemClick("inbox",e)}},{id:"archive",text:(null==(x=null==F?void 0:F.archive)?void 0:x.text)??"Archive",icon:{color:(null==(C=null==(y=null==F?void 0:F.archive)?void 0:y.icon)?void 0:C.color)??"red",svg:(null==(S=null==(k=null==F?void 0:F.archive)?void 0:k.icon)?void 0:S.svg)??j.archive},selectionIcon:{color:(null==($=null==(T=null==(E=null==(I=null==(M=null==(w=O.inbox)?void 0:w.header)?void 0:M.menus)?void 0:I.popup)?void 0:E.list)?void 0:T.selectionIcon)?void 0:$.color)??"red",svg:(null==(R=null==(D=null==(B=null==(A=null==(P=null==(L=O.inbox)?void 0:L.header)?void 0:P.menus)?void 0:A.popup)?void 0:B.list)?void 0:D.selectionIcon)?void 0:R.svg)??j.check},onClick:e=>{this.handleOptionMenuItemClick("archive",e)}}]}getActionOptions(){var e,t,n,i,o,s,r,a,l,d,u,h,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)??j.inbox},selectionIcon:null,onClick:e=>{ee.shared.readAllMessages({canCallApi:!0})}},{id:"archiveAll",text:(null==(l=null==_?void 0:_.archiveAll)?void 0:l.text)??"Archive All",icon:{color:(null==(u=null==(d=null==_?void 0:_.archiveAll)?void 0:d.icon)?void 0:u.color)??"red",svg:(null==(c=null==(h=null==_?void 0:_.archiveAll)?void 0:h.icon)?void 0:c.svg)??j.archive},selectionIcon:null,onClick:e=>{ee.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)??j.archive},selectionIcon:null,onClick:e=>{ee.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)??D[500],l.style.boxShadow=(null==(o=null==(i=a.inbox)?void 0:i.header)?void 0:o.shadow)??`0px 1px 0px 0px ${B[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 ue(this._themeSubscription.manager,e[0]),this._filterMenu=new le(this._themeSubscription.manager,"filters",!0,e,(()=>{var e;null==(e=this._actionMenu)||e.closeMenu()})),this._actionMenu=new le(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: ${D[500]};\n box-shadow: 0px 1px 0px 0px ${B[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()}}customElements.get("courier-inbox-header")||customElements.define("courier-inbox-header",he);class ce{constructor(e){$(this,"events"),this.events=e}remove(){ee.shared.removeDataStoreListener(this)}}const pe={popup:{button:{icon:{color:A[500],svg:j.inbox},backgroundColor:"transparent",hoverBackgroundColor:A[50010],activeBackgroundColor:A[50020],unreadIndicator:{font:{color:D[500],size:"14px",family:void 0,weight:void 0},backgroundColor:R[500],borderRadius:"12px"}},window:{backgroundColor:D[500],borderRadius:"8px",border:`1px solid ${B[500]}`,shadow:`0px 8px 16px -4px ${B[500]}`}},inbox:{header:{backgroundColor:D[500],shadow:`0px 1px 0px 0px ${B[500]}`,filters:{font:{color:A[500],family:void 0,size:"18px"},inbox:{icon:{color:A[500],svg:j.inbox},text:"Inbox"},archive:{icon:{color:A[500],svg:j.archive},text:"Archive"},unreadIndicator:{font:{color:D[500],family:void 0,size:"14px"},backgroundColor:R[500],borderRadius:"12px"}},menus:{popup:{backgroundColor:D[500],border:`1px solid ${B[500]}`,borderRadius:"4px",shadow:`0px 4px 8px -2px ${B[500]}`,list:{hoverBackgroundColor:B[200],activeBackgroundColor:B[500],divider:"none",font:{color:A[500],family:void 0,size:"14px"},selectionIcon:{color:A[500],svg:j.check}}},filters:{button:{icon:{color:A[500],svg:j.filter},backgroundColor:"transparent",hoverBackgroundColor:A[50010],activeBackgroundColor:A[50020]},inbox:{icon:{color:A[500],svg:j.inbox},text:"Inbox"},archive:{icon:{color:A[500],svg:j.archive},text:"Archive"}},actions:{button:{icon:{color:A[500],svg:j.overflow},backgroundColor:"transparent",hoverBackgroundColor:A[50010],activeBackgroundColor:A[50020]},markAllRead:{icon:{color:A[500],svg:j.read},text:"Read All"},archiveAll:{icon:{color:A[500],svg:j.archive},text:"Archive All"},archiveRead:{icon:{color:A[500],svg:j.archiveRead},text:"Archive Read"}}}},list:{backgroundColor:D[500],item:{backgroundColor:"transparent",unreadIndicatorColor:R[500],hoverBackgroundColor:B[200],activeBackgroundColor:B[500],actions:{backgroundColor:"transparent",hoverBackgroundColor:B[200],activeBackgroundColor:B[500],border:`1px solid ${B[500]}`,borderRadius:"4px",shadow:"0px 1px 2px 0px rgba(0, 0, 0, 0.06)",font:{color:A[500],family:void 0,size:"14px"}},title:{color:A[500],family:void 0,size:"14px"},subtitle:{color:B[600],family:void 0,size:"14px"},time:{color:B[600],family:void 0,size:"14px"},divider:`1px solid ${B[200]}`,menu:{enabled:!0,backgroundColor:D[500],border:`1px solid ${B[500]}`,borderRadius:"4px",shadow:`0px 2px 4px -2px ${B[500]}`,longPress:{displayDuration:4e3,vibrationDuration:50},item:{hoverBackgroundColor:B[200],activeBackgroundColor:B[500],borderRadius:"0px",read:{color:A[500],svg:j.read},unread:{color:A[500],svg:j.unread},archive:{color:A[500],svg:j.archive},unarchive:{color:A[500],svg:j.unarchive}}}}},loading:{animation:{barColor:B[500],barHeight:"14px",barBorderRadius:"14px",duration:"2s"},divider:`1px solid ${B[200]}`},empty:{title:{font:{size:"16px",weight:"500",color:A[500]}},button:{text:"Refresh"}},error:{title:{font:{size:"16px",weight:"500",color:A[500]}},button:{text:"Retry"}}}},ve={popup:{button:{icon:{color:D[500],svg:j.inbox},backgroundColor:"transparent",hoverBackgroundColor:D[50010],activeBackgroundColor:D[50020],unreadIndicator:{font:{color:D[500],size:"14px",family:void 0,weight:void 0},backgroundColor:R[500],borderRadius:"12px"}},window:{backgroundColor:A[500],borderRadius:"8px",border:`1px solid ${B[400]}`,shadow:`0px 4px 8px -2px ${D[50020]}`}},inbox:{header:{backgroundColor:A[500],shadow:`0px 1px 0px 0px ${B[400]}`,filters:{font:{color:D[500],family:void 0,size:"18px"},inbox:{icon:{color:D[500],svg:j.inbox},text:"Inbox"},archive:{icon:{color:D[500],svg:j.archive},text:"Archive"},unreadIndicator:{font:{color:D[500],family:void 0,size:"14px"},backgroundColor:R[500],borderRadius:"12px"}},menus:{popup:{backgroundColor:A[500],border:`1px solid ${B[400]}`,borderRadius:"4px",shadow:`0px 4px 8px -2px ${D[50020]}`,list:{hoverBackgroundColor:D[50010],activeBackgroundColor:D[50020],divider:"none",font:{color:D[500],family:void 0,size:"14px"},selectionIcon:{color:D[500],svg:j.check}}},filters:{button:{icon:{color:D[500],svg:j.filter},backgroundColor:"transparent",hoverBackgroundColor:D[50010],activeBackgroundColor:D[50020]},inbox:{icon:{color:D[500],svg:j.inbox},text:"Inbox"},archive:{icon:{color:D[500],svg:j.archive},text:"Archive"}},actions:{button:{icon:{color:D[500],svg:j.overflow},backgroundColor:"transparent",hoverBackgroundColor:D[50010],activeBackgroundColor:D[50020]},markAllRead:{icon:{color:D[500],svg:j.read},text:"Read All"},archiveAll:{icon:{color:D[500],svg:j.archive},text:"Archive All"},archiveRead:{icon:{color:D[500],svg:j.archiveRead},text:"Archive Read"}}}},list:{backgroundColor:A[500],item:{backgroundColor:"transparent",unreadIndicatorColor:R[500],hoverBackgroundColor:D[50010],activeBackgroundColor:D[50020],actions:{backgroundColor:"transparent",hoverBackgroundColor:D[50010],activeBackgroundColor:D[50020],border:`1px solid ${B[400]}`,borderRadius:"4px",shadow:`0px 1px 2px 0px ${D[50010]}`,font:{color:D[500],family:void 0,size:"14px"}},title:{color:D[500],family:void 0,size:"14px"},subtitle:{color:B[500],family:void 0,size:"14px"},time:{color:B[500],family:void 0,size:"12px"},divider:`1px solid ${B[400]}`,menu:{enabled:!0,backgroundColor:A[500],border:`1px solid ${B[400]}`,borderRadius:"4px",shadow:`0px 2px 4px -2px ${D[50020]}`,longPress:{displayDuration:4e3,vibrationDuration:50},item:{hoverBackgroundColor:D[50010],activeBackgroundColor:D[50020],borderRadius:"0px",read:{color:D[500],svg:j.read},unread:{color:D[500],svg:j.unread},archive:{color:D[500],svg:j.archive},unarchive:{color:D[500],svg:j.unarchive}}}}},loading:{animation:{barColor:D[500],barHeight:"14px",barBorderRadius:"14px",duration:"2s"},divider:`1px solid ${B[400]}`},empty:{title:{font:{size:"16px",weight:"500",color:D[500]}},button:{text:"Refresh"}},error:{title:{font:{size:"16px",weight:"500",color:D[500]}},button:{text:"Retry"}}}};class ge{constructor(e){$(this,"THEME_CHANGE_EVENT","courier_inbox_theme_change"),$(this,"_theme"),$(this,"_lightTheme",pe),$(this,"_darkTheme",ve),$(this,"_target"),$(this,"_subscriptions",[]),$(this,"_userMode"),$(this,"_systemMode"),$(this,"_systemThemeCleanup"),this._theme=e,this._target=new EventTarget,this._userMode="system",this._systemMode=F(),this.setLightTheme(pe),this.setDarkTheme(ve),this._systemThemeCleanup=H((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,u,h,c,p,v,g,m,b,_,f,x,y,C,k,S,w,M,I,E,T,$,L,P,A,B,D,R,O,F,H,z,N,U,q,j,V,J,Z,G,W,K,X,Y,Q,ee,te,ne,ie,oe,se,re,ae,le,de,ue,he,ce,ge,me,be,_e,fe,xe,ye,Ce,ke,Se,we,Me,Ie,Ee,Te,$e,Le,Pe,Ae,Be,De,Re,Oe,Fe,He,ze,Ne,Ue,qe,je,Ve,Je,Ze,Ge,We,Ke,Xe,Ye,Qe,et,tt,nt,it,ot,st,rt,at,lt,dt,ut,ht,ct,pt,vt,gt,mt,bt,_t,ft,xt,yt,Ct,kt,St,wt,Mt,It,Et,Tt,$t,Lt,Pt,At,Bt,Dt,Rt,Ot,Ft,Ht,zt,Nt,Ut,qt,jt,Vt,Jt,Zt,Gt,Wt,Kt,Xt,Yt,Qt,en,tn,nn,on,sn,rn,an,ln,dn,un,hn,cn,pn,vn,gn,mn,bn,_n,fn,xn,yn,Cn,kn,Sn,wn,Mn,In,En,Tn,$n,Ln,Pn,An,Bn,Dn,Rn,On,Fn,Hn,zn,Nn,Un,qn,jn,Vn,Jn,Zn,Gn,Wn,Kn,Xn,Yn,Qn,ei,ti,ni,ii,oi,si,ri,ai,li,di,ui,hi,ci,pi,vi,gi,mi,bi,_i,fi,xi,yi,Ci,ki,Si,wi,Mi,Ii,Ei,Ti,$i,Li,Pi,Ai,Bi,Di,Ri,Oi,Fi,Hi,zi,Ni,Ui,qi,ji,Vi,Ji;const Zi="light"===e?pe:ve;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==(h=null==(u=t.popup)?void 0:u.button)?void 0:h.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==(f=null==(_=t.inbox)?void 0:_.header)?void 0:f.filters,inbox:{...null==(C=null==(y=null==(x=Zi.inbox)?void 0:x.header)?void 0:y.filters)?void 0:C.inbox,...null==(w=null==(S=null==(k=t.inbox)?void 0:k.header)?void 0:S.filters)?void 0:w.inbox,icon:{...null==(T=null==(E=null==(I=null==(M=Zi.inbox)?void 0:M.header)?void 0:I.filters)?void 0:E.inbox)?void 0:T.icon,...null==(A=null==(P=null==(L=null==($=t.inbox)?void 0:$.header)?void 0:L.filters)?void 0:P.inbox)?void 0:A.icon}},archive:{...null==(R=null==(D=null==(B=Zi.inbox)?void 0:B.header)?void 0:D.filters)?void 0:R.archive,...null==(H=null==(F=null==(O=t.inbox)?void 0:O.header)?void 0:F.filters)?void 0:H.archive,icon:{...null==(q=null==(U=null==(N=null==(z=Zi.inbox)?void 0:z.header)?void 0:N.filters)?void 0:U.archive)?void 0:q.icon,...null==(Z=null==(J=null==(V=null==(j=t.inbox)?void 0:j.header)?void 0:V.filters)?void 0:J.archive)?void 0:Z.icon}},unreadIndicator:{...null==(K=null==(W=null==(G=Zi.inbox)?void 0:G.header)?void 0:W.filters)?void 0:K.unreadIndicator,...null==(Q=null==(Y=null==(X=t.inbox)?void 0:X.header)?void 0:Y.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==(ge=null==(ce=null==(he=null==(ue=Zi.inbox)?void 0:ue.header)?void 0:he.menus)?void 0:ce.popup)?void 0:ge.list,...null==(fe=null==(_e=null==(be=null==(me=t.inbox)?void 0:me.header)?void 0:be.menus)?void 0:_e.popup)?void 0:fe.list,font:{...null==(Se=null==(ke=null==(Ce=null==(ye=null==(xe=Zi.inbox)?void 0:xe.header)?void 0:ye.menus)?void 0:Ce.popup)?void 0:ke.list)?void 0:Se.font,...null==(Te=null==(Ee=null==(Ie=null==(Me=null==(we=t.inbox)?void 0:we.header)?void 0:Me.menus)?void 0:Ie.popup)?void 0:Ee.list)?void 0:Te.font},selectionIcon:{...null==(Be=null==(Ae=null==(Pe=null==(Le=null==($e=Zi.inbox)?void 0:$e.header)?void 0:Le.menus)?void 0:Pe.popup)?void 0:Ae.list)?void 0:Be.selectionIcon,...null==(He=null==(Fe=null==(Oe=null==(Re=null==(De=t.inbox)?void 0:De.header)?void 0:Re.menus)?void 0:Oe.popup)?void 0:Fe.list)?void 0:He.selectionIcon}}},filters:{...null==(Ue=null==(Ne=null==(ze=Zi.inbox)?void 0:ze.header)?void 0:Ne.menus)?void 0:Ue.filters,...null==(Ve=null==(je=null==(qe=t.inbox)?void 0:qe.header)?void 0:je.menus)?void 0:Ve.filters,inbox:{...null==(We=null==(Ge=null==(Ze=null==(Je=Zi.inbox)?void 0:Je.header)?void 0:Ze.menus)?void 0:Ge.filters)?void 0:We.inbox,...null==(Qe=null==(Ye=null==(Xe=null==(Ke=t.inbox)?void 0:Ke.header)?void 0:Xe.menus)?void 0:Ye.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==(ht=null==(ut=Zi.inbox)?void 0:ut.header)?void 0:ht.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==(Ct=null==(yt=null==(xt=null==(ft=null==(_t=Zi.inbox)?void 0:_t.header)?void 0:ft.menus)?void 0:xt.filters)?void 0:yt.archive)?void 0:Ct.icon,...null==(It=null==(Mt=null==(wt=null==(St=null==(kt=t.inbox)?void 0:kt.header)?void 0:St.menus)?void 0:wt.filters)?void 0:Mt.archive)?void 0:It.icon}}},actions:{...null==($t=null==(Tt=null==(Et=Zi.inbox)?void 0:Et.header)?void 0:Tt.menus)?void 0:$t.actions,...null==(At=null==(Pt=null==(Lt=t.inbox)?void 0:Lt.header)?void 0:Pt.menus)?void 0:At.actions,markAllRead:{...null==(Ot=null==(Rt=null==(Dt=null==(Bt=Zi.inbox)?void 0:Bt.header)?void 0:Dt.menus)?void 0:Rt.actions)?void 0:Ot.markAllRead,...null==(Nt=null==(zt=null==(Ht=null==(Ft=t.inbox)?void 0:Ft.header)?void 0:Ht.menus)?void 0:zt.actions)?void 0:Nt.markAllRead,icon:{...null==(Jt=null==(Vt=null==(jt=null==(qt=null==(Ut=Zi.inbox)?void 0:Ut.header)?void 0:qt.menus)?void 0:jt.actions)?void 0:Vt.markAllRead)?void 0:Jt.icon,...null==(Xt=null==(Kt=null==(Wt=null==(Gt=null==(Zt=t.inbox)?void 0:Zt.header)?void 0:Gt.menus)?void 0:Wt.actions)?void 0:Kt.markAllRead)?void 0:Xt.icon}},archiveAll:{...null==(tn=null==(en=null==(Qt=null==(Yt=Zi.inbox)?void 0:Yt.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==(hn=null==(un=null==(dn=null==(ln=null==(an=Zi.inbox)?void 0:an.header)?void 0:ln.menus)?void 0:dn.actions)?void 0:un.archiveAll)?void 0:hn.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==(xn=null==(fn=null==(_n=null==(bn=Zi.inbox)?void 0:bn.header)?void 0:_n.menus)?void 0:fn.actions)?void 0:xn.archiveRead,...null==(Sn=null==(kn=null==(Cn=null==(yn=t.inbox)?void 0:yn.header)?void 0:Cn.menus)?void 0:kn.actions)?void 0:Sn.archiveRead,icon:{...null==(Tn=null==(En=null==(In=null==(Mn=null==(wn=Zi.inbox)?void 0:wn.header)?void 0:Mn.menus)?void 0:In.actions)?void 0:En.archiveRead)?void 0:Tn.icon,...null==(Bn=null==(An=null==(Pn=null==(Ln=null==($n=t.inbox)?void 0:$n.header)?void 0:Ln.menus)?void 0:Pn.actions)?void 0:An.archiveRead)?void 0:Bn.icon}}}}},list:{...null==(Dn=Zi.inbox)?void 0:Dn.list,...null==(Rn=t.inbox)?void 0:Rn.list,item:{...null==(Fn=null==(On=Zi.inbox)?void 0:On.list)?void 0:Fn.item,...null==(zn=null==(Hn=t.inbox)?void 0:Hn.list)?void 0:zn.item,menu:{...null==(qn=null==(Un=null==(Nn=Zi.inbox)?void 0:Nn.list)?void 0:Un.item)?void 0:qn.menu,...null==(Jn=null==(Vn=null==(jn=t.inbox)?void 0:jn.list)?void 0:Vn.item)?void 0:Jn.menu,item:{...null==(Kn=null==(Wn=null==(Gn=null==(Zn=Zi.inbox)?void 0:Zn.list)?void 0:Gn.item)?void 0:Wn.menu)?void 0:Kn.item,...null==(ei=null==(Qn=null==(Yn=null==(Xn=t.inbox)?void 0:Xn.list)?void 0:Yn.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==(ui=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:ui.read},unread:{...null==(gi=null==(vi=null==(pi=null==(ci=null==(hi=Zi.inbox)?void 0:hi.list)?void 0:ci.item)?void 0:pi.menu)?void 0:vi.item)?void 0:gi.unread,...null==(xi=null==(fi=null==(_i=null==(bi=null==(mi=t.inbox)?void 0:mi.list)?void 0:bi.item)?void 0:_i.menu)?void 0:fi.item)?void 0:xi.unread},archive:{...null==(wi=null==(Si=null==(ki=null==(Ci=null==(yi=Zi.inbox)?void 0:yi.list)?void 0:Ci.item)?void 0:ki.menu)?void 0:Si.item)?void 0:wi.archive,...null==($i=null==(Ti=null==(Ei=null==(Ii=null==(Mi=t.inbox)?void 0:Mi.list)?void 0:Ii.item)?void 0:Ei.menu)?void 0:Ti.item)?void 0:$i.archive},unarchive:{...null==(Di=null==(Bi=null==(Ai=null==(Pi=null==(Li=Zi.inbox)?void 0:Li.list)?void 0:Pi.item)?void 0:Ai.menu)?void 0:Bi.item)?void 0:Di.unarchive,...null==(zi=null==(Hi=null==(Fi=null==(Oi=null==(Ri=t.inbox)?void 0:Ri.list)?void 0:Oi.item)?void 0:Fi.menu)?void 0:Hi.item)?void 0:zi.unarchive}}}}},loading:{...null==(Ni=Zi.inbox)?void 0:Ni.loading,...null==(Ui=t.inbox)?void 0:Ui.loading},empty:{...null==(qi=Zi.inbox)?void 0:qi.empty,...null==(ji=t.inbox)?void 0:ji.empty},error:{...null==(Vi=Zi.inbox)?void 0:Vi.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 me=class extends HTMLElement{constructor(e){var t;super(),$(this,"_currentFeed","inbox"),$(this,"_themeManager"),$(this,"_shadow"),$(this,"_list"),$(this,"_datastoreListener"),$(this,"_authListener"),$(this,"_style"),$(this,"_header"),$(this,"_headerFactory"),$(this,"_onMessageClick"),$(this,"_onMessageActionClick"),$(this,"_onMessageLongPress"),$(this,"_defaultProps",{title:"Inbox",icon:j.inbox,feedType:this._currentFeed,height:"768px"}),this._shadow=this.attachShadow({mode:"open"}),this._themeManager=e??new ge(pe),this._header=new he({themeManager:this._themeManager,onFeedTypeChange:e=>{this.setFeedType(e)}}),this._header.build(void 0),this._shadow.appendChild(this._header),this._list=new re({themeManager:this._themeManager,onRefresh:()=>{this.refresh()},onPaginationTrigger:async e=>{var t,n;try{await ee.shared.fetchNextPageOfMessages({feedType:e})}catch(i){null==(n=null==(t=E.shared.client)?void 0:t.options.logger)||n.error("Failed to fetch next page of messages:",i)}},onMessageClick:(e,t)=>{var n;ee.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 ce({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()}}),ee.shared.addDataStoreListener(this._datastoreListener),this._themeManager.subscribe((e=>{this.refreshTheme()})),this._authListener=E.shared.addAuthenticationListener((e=>{this.refresh()})),(null==(t=E.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:ee.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 ee.shared.load(e),await ee.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=E.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=E.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=E.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)}}};customElements.get("courier-inbox")||customElements.define("courier-inbox",me);class be extends Z{constructor(e){super(),$(this,"_themeSubscription"),$(this,"_container"),$(this,"_triggerButton"),$(this,"_unreadCountBadge"),this._themeSubscription=e.subscribe((e=>{this.updateTheme()}))}defaultElement(){this._container=document.createElement("div"),this._container.className="menu-button-container",this._triggerButton=new W(j.inbox),this._unreadCountBadge=new de({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,u,h,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)??A[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)??j.inbox),null==(u=this._triggerButton)||u.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==(h=null==_?void 0:_.popup)?void 0:h.button)?void 0:c.hoverBackgroundColor)??A[50010]),null==(m=this._triggerButton)||m.updateActiveBackgroundColor((null==(g=null==(v=null==_?void 0:_.popup)?void 0:v.button)?void 0:g.activeBackgroundColor)??A[50020]),null==(b=this._unreadCountBadge)||b.refreshTheme("button")}disconnectedCallback(){this._themeSubscription.unsubscribe()}}customElements.get("courier-inbox-menu-button")||customElements.define("courier-inbox-menu-button",be);let _e=class extends HTMLElement{constructor(){super(),$(this,"_width","440px"),$(this,"_height","440px"),$(this,"_popupAlignment","top-right"),$(this,"_top","40px"),$(this,"_right","0"),$(this,"_bottom","40px"),$(this,"_left","0"),$(this,"_themeManager",new ge(pe)),$(this,"_triggerButton"),$(this,"_popup"),$(this,"_inbox"),$(this,"_style"),$(this,"_datastoreListener"),$(this,"_popupMenuButtonFactory");const e=this.attachShadow({mode:"open"});this._triggerButton=new be(this._themeManager),this._triggerButton.build(void 0),this._popup=document.createElement("div"),this._popup.className="popup",this._inbox=new me(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 ce(this),ee.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=E.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=ee.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()}};customElements.get("courier-inbox-menu")||customElements.define("courier-inbox-menu",_e);var fe,xe={exports:{}},ye={};var Ce,ke,Se={};
2
2
  /**
3
3
  * @license React
4
4
  * react-jsx-runtime.development.js
@@ -7,5 +7,5 @@
7
7
  *
8
8
  * This source code is licensed under the MIT license found in the
9
9
  * LICENSE file in the root directory of this source tree.
10
- */function we(){return Ce||(Ce=1,"production"!==process.env.NODE_ENV&&function(){function e(t){if(null==t)return null;if("function"==typeof t)return t.$$typeof===S?null:t.displayName||t.name||null;if("string"==typeof t)return t;switch(t){case p:return"Fragment";case g:return"Profiler";case v:return"StrictMode";case f:return"Suspense";case x:return"SuspenseList";case k:return"Activity"}if("object"==typeof t)switch("number"==typeof t.tag&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case c:return"Portal";case b:return(t.displayName||"Context")+".Provider";case m:return(t._context.displayName||"Context")+".Consumer";case _:var n=t.render;return(t=t.displayName)||(t=""!==(t=n.displayName||n.name||"")?"ForwardRef("+t+")":"ForwardRef"),t;case y:return null!==(n=t.displayName||null)?n:e(t.type)||"Memo";case C:n=t._payload,t=t._init;try{return e(t(n))}catch(i){}}return null}function n(e){return""+e}function i(e){try{n(e);var t=!1}catch(s){t=!0}if(t){var i=(t=console).error,o="function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return i.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",o),n(e)}}function o(t){if(t===p)return"<>";if("object"==typeof t&&null!==t&&t.$$typeof===C)return"<...>";try{var n=e(t);return n?"<"+n+">":"<...>"}catch(i){return"<...>"}}function s(){return Error("react-stack-top-frame")}function r(){var t=e(this.type);return T[t]||(T[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),void 0!==(t=this.props.ref)?t:null}function a(t,n,o,s,a,u,c,p){var v,g=n.children;if(void 0!==g)if(s)if(I(g)){for(s=0;s<g.length;s++)l(g[s]);Object.freeze&&Object.freeze(g)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else l(g);if(M.call(n,"key")){g=e(t);var m=Object.keys(n).filter((function(e){return"key"!==e}));s=0<m.length?"{key: someKey, "+m.join(": ..., ")+": ...}":"{key: someKey}",P[g+s]||(m=0<m.length?"{"+m.join(": ..., ")+": ...}":"{}",console.error('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',s,g,m,g),P[g+s]=!0)}if(g=null,void 0!==o&&(i(o),g=""+o),function(e){if(M.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(n)&&(i(n.key),g=""+n.key),"key"in n)for(var b in o={},n)"key"!==b&&(o[b]=n[b]);else o=n;return g&&function(e,t){function n(){d||(d=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}(o,"function"==typeof t?t.displayName||t.name||"Unknown":t),function(e,t,n,i,o,s,a,l){return n=s.ref,e={$$typeof:h,type:e,key:t,props:s,_owner:o},null!==(void 0!==n?n:null)?Object.defineProperty(e,"ref",{enumerable:!1,get:r}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:l}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(t,g,u,0,null===(v=w.A)?null:v.getOwner(),o,c,p)}function l(e){"object"==typeof e&&null!==e&&e.$$typeof===h&&e._store&&(e._store.validated=1)}var d,u=t,h=Symbol.for("react.transitional.element"),c=Symbol.for("react.portal"),p=Symbol.for("react.fragment"),v=Symbol.for("react.strict_mode"),g=Symbol.for("react.profiler"),m=Symbol.for("react.consumer"),b=Symbol.for("react.context"),_=Symbol.for("react.forward_ref"),f=Symbol.for("react.suspense"),x=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),C=Symbol.for("react.lazy"),k=Symbol.for("react.activity"),S=Symbol.for("react.client.reference"),w=u.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,M=Object.prototype.hasOwnProperty,I=Array.isArray,E=console.createTask?console.createTask:function(){return null},T={},$=(u={"react-stack-bottom-frame":function(e){return e()}})["react-stack-bottom-frame"].bind(u,s)(),L=E(o(s)),P={};Se.Fragment=p,Se.jsx=function(e,t,n,i,s){var r=1e4>w.recentlyCreatedOwnerStacks++;return a(e,t,n,!1,0,s,r?Error("react-stack-top-frame"):$,r?E(o(e)):L)},Se.jsxs=function(e,t,n,i,s){var r=1e4>w.recentlyCreatedOwnerStacks++;return a(e,t,n,!0,0,s,r?Error("react-stack-top-frame"):$,r?E(o(e)):L)}}()),Se}var Me=(ke||(ke=1,"production"===process.env.NODE_ENV?xe.exports=function(){if(fe)return ye;fe=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 ye.Fragment=t,ye.jsx=n,ye.jsxs=n,ye}():xe.exports=we()),xe.exports);const Ie=parseInt(t.version.split(".")[0]);function Ee(e){const t=document.createElement("div");return n.flushSync((()=>{!function(e,t){if(Ie>=18){return i.createRoot(t).render(e)}(0,n.render)(e,t)}(e,t)})),t}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=>Ee(e.renderHeader(t))))}))}),[e.renderHeader,n]),t.useEffect((()=>{const t=n.current;t&&e.renderListItem&&queueMicrotask((()=>{t.setListItem((t=>Ee(e.renderListItem(t))))}))}),[e.renderListItem,n]),t.useEffect((()=>{const t=n.current;t&&e.renderEmptyState&&queueMicrotask((()=>{t.setEmptyState((t=>Ee(e.renderEmptyState(t))))}))}),[e.renderEmptyState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderLoadingState&&queueMicrotask((()=>{t.setLoadingState((t=>Ee(e.renderLoadingState(t))))}))}),[e.renderLoadingState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderErrorState&&queueMicrotask((()=>{t.setErrorState((t=>Ee(e.renderErrorState(t))))}))}),[e.renderErrorState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPaginationItem&&queueMicrotask((()=>{t.setPaginationItem((t=>Ee(e.renderPaginationItem(t))))}))}),[e.renderPaginationItem,n]),t.useEffect((()=>{const t=n.current;t&&queueMicrotask((()=>{t.setFeedType(e.feedType||"inbox")}))}),[e.feedType,n]),Me.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.CourierInboxMenu=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=>Ee(e.renderPopupHeader(t))))}))}),[e.renderPopupHeader,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupListItem&&queueMicrotask((()=>{t.setPopupListItem((t=>Ee(e.renderPopupListItem(t))))}))}),[e.renderPopupListItem,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupEmptyState&&queueMicrotask((()=>{t.setPopupEmptyState((t=>Ee(e.renderPopupEmptyState(t))))}))}),[e.renderPopupEmptyState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupLoadingState&&queueMicrotask((()=>{t.setPopupLoadingState((t=>Ee(e.renderPopupLoadingState(t))))}))}),[e.renderPopupLoadingState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupErrorState&&queueMicrotask((()=>{t.setPopupErrorState((t=>Ee(e.renderPopupErrorState(t))))}))}),[e.renderPopupErrorState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupPaginationItem&&queueMicrotask((()=>{t.setPopupPaginationItem((t=>Ee(e.renderPopupPaginationItem(t))))}))}),[e.renderPopupPaginationItem,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupMenuButton&&queueMicrotask((()=>{t.setPopupMenuButton((t=>Ee(e.renderPopupMenuButton(t))))}))}),[e.renderPopupMenuButton,n]),t.useEffect((()=>{const t=n.current;t&&queueMicrotask((()=>{t.setFeedType(e.feedType||"inbox")}))}),[e.feedType,n]),Me.jsx("courier-inbox-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=>E.shared.signIn(e),n=()=>E.shared.signOut(),i=e=>ee.shared.load(e),o=e=>ee.shared.fetchNextPageOfMessages(e),s=e=>E.shared.paginationLimit=e,r=e=>ee.shared.readMessage({message:e}),a=e=>ee.shared.unreadMessage({message:e}),l=e=>ee.shared.clickMessage({message:e}),d=e=>ee.shared.archiveMessage({message:e}),u=e=>ee.shared.openMessage({message:e}),h=e=>ee.shared.unarchiveMessage({message:e}),c=()=>ee.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:u,unarchiveMessage:h,readAllMessages:c});t.useEffect((()=>{const e=E.shared.addAuthenticationListener((()=>b())),t=new ce({onError:e=>_(e),onDataSetChange:()=>_(),onPageAdded:()=>_(),onMessageAdd:()=>_(),onMessageRemove:()=>_(),onMessageUpdate:()=>_(),onUnreadCountChange:()=>_()});return ee.shared.addDataStoreListener(t),b(),_(),()=>{e.remove(),t.remove()}}),[]);const b=()=>{var t;const i=null==(t=E.shared.client)?void 0:t.options;v({userId:null==i?void 0:i.userId,signIn:e,signOut:n})},_=e=>{const t=ee.shared;m({load:i,fetchNextPageOfMessages:o,setPaginationLimit:s,readMessage:r,unreadMessage:a,clickMessage:l,archiveMessage:d,openMessage:u,unarchiveMessage:h,readAllMessages:c,inbox:t.inboxDataSet,archive:t.archiveDataSet,unreadCount:t.unreadCount,error:e})};return{shared:E.shared,auth:p,inbox:g}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
10
+ */function we(){return Ce||(Ce=1,"production"!==process.env.NODE_ENV&&function(){function e(t){if(null==t)return null;if("function"==typeof t)return t.$$typeof===S?null:t.displayName||t.name||null;if("string"==typeof t)return t;switch(t){case p:return"Fragment";case g:return"Profiler";case v:return"StrictMode";case f:return"Suspense";case x:return"SuspenseList";case k:return"Activity"}if("object"==typeof t)switch("number"==typeof t.tag&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case c:return"Portal";case b:return(t.displayName||"Context")+".Provider";case m:return(t._context.displayName||"Context")+".Consumer";case _:var n=t.render;return(t=t.displayName)||(t=""!==(t=n.displayName||n.name||"")?"ForwardRef("+t+")":"ForwardRef"),t;case y:return null!==(n=t.displayName||null)?n:e(t.type)||"Memo";case C:n=t._payload,t=t._init;try{return e(t(n))}catch(i){}}return null}function n(e){return""+e}function i(e){try{n(e);var t=!1}catch(s){t=!0}if(t){var i=(t=console).error,o="function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return i.call(t,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",o),n(e)}}function o(t){if(t===p)return"<>";if("object"==typeof t&&null!==t&&t.$$typeof===C)return"<...>";try{var n=e(t);return n?"<"+n+">":"<...>"}catch(i){return"<...>"}}function s(){return Error("react-stack-top-frame")}function r(){var t=e(this.type);return T[t]||(T[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),void 0!==(t=this.props.ref)?t:null}function a(t,n,o,s,a,u,c,p){var v,g=n.children;if(void 0!==g)if(s)if(I(g)){for(s=0;s<g.length;s++)l(g[s]);Object.freeze&&Object.freeze(g)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else l(g);if(M.call(n,"key")){g=e(t);var m=Object.keys(n).filter((function(e){return"key"!==e}));s=0<m.length?"{key: someKey, "+m.join(": ..., ")+": ...}":"{key: someKey}",P[g+s]||(m=0<m.length?"{"+m.join(": ..., ")+": ...}":"{}",console.error('A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',s,g,m,g),P[g+s]=!0)}if(g=null,void 0!==o&&(i(o),g=""+o),function(e){if(M.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(n)&&(i(n.key),g=""+n.key),"key"in n)for(var b in o={},n)"key"!==b&&(o[b]=n[b]);else o=n;return g&&function(e,t){function n(){d||(d=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",t))}n.isReactWarning=!0,Object.defineProperty(e,"key",{get:n,configurable:!0})}(o,"function"==typeof t?t.displayName||t.name||"Unknown":t),function(e,t,n,i,o,s,a,l){return n=s.ref,e={$$typeof:h,type:e,key:t,props:s,_owner:o},null!==(void 0!==n?n:null)?Object.defineProperty(e,"ref",{enumerable:!1,get:r}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:a}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:l}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}(t,g,u,0,null===(v=w.A)?null:v.getOwner(),o,c,p)}function l(e){"object"==typeof e&&null!==e&&e.$$typeof===h&&e._store&&(e._store.validated=1)}var d,u=t,h=Symbol.for("react.transitional.element"),c=Symbol.for("react.portal"),p=Symbol.for("react.fragment"),v=Symbol.for("react.strict_mode"),g=Symbol.for("react.profiler"),m=Symbol.for("react.consumer"),b=Symbol.for("react.context"),_=Symbol.for("react.forward_ref"),f=Symbol.for("react.suspense"),x=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),C=Symbol.for("react.lazy"),k=Symbol.for("react.activity"),S=Symbol.for("react.client.reference"),w=u.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,M=Object.prototype.hasOwnProperty,I=Array.isArray,E=console.createTask?console.createTask:function(){return null},T={},$=(u={"react-stack-bottom-frame":function(e){return e()}})["react-stack-bottom-frame"].bind(u,s)(),L=E(o(s)),P={};Se.Fragment=p,Se.jsx=function(e,t,n,i,s){var r=1e4>w.recentlyCreatedOwnerStacks++;return a(e,t,n,!1,0,s,r?Error("react-stack-top-frame"):$,r?E(o(e)):L)},Se.jsxs=function(e,t,n,i,s){var r=1e4>w.recentlyCreatedOwnerStacks++;return a(e,t,n,!0,0,s,r?Error("react-stack-top-frame"):$,r?E(o(e)):L)}}()),Se}var Me=(ke||(ke=1,"production"===process.env.NODE_ENV?xe.exports=function(){if(fe)return ye;fe=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 ye.Fragment=t,ye.jsx=n,ye.jsxs=n,ye}():xe.exports=we()),xe.exports);function Ie(e){const t=document.createElement("div");return i.flushSync((()=>{!function(e,t){const i=n.createRoot(t);i.render(e)}(e,t)})),t}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=>Ie(e.renderHeader(t))))}))}),[e.renderHeader,n]),t.useEffect((()=>{const t=n.current;t&&e.renderListItem&&queueMicrotask((()=>{t.setListItem((t=>Ie(e.renderListItem(t))))}))}),[e.renderListItem,n]),t.useEffect((()=>{const t=n.current;t&&e.renderEmptyState&&queueMicrotask((()=>{t.setEmptyState((t=>Ie(e.renderEmptyState(t))))}))}),[e.renderEmptyState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderLoadingState&&queueMicrotask((()=>{t.setLoadingState((t=>Ie(e.renderLoadingState(t))))}))}),[e.renderLoadingState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderErrorState&&queueMicrotask((()=>{t.setErrorState((t=>Ie(e.renderErrorState(t))))}))}),[e.renderErrorState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPaginationItem&&queueMicrotask((()=>{t.setPaginationItem((t=>Ie(e.renderPaginationItem(t))))}))}),[e.renderPaginationItem,n]),t.useEffect((()=>{const t=n.current;t&&queueMicrotask((()=>{t.setFeedType(e.feedType||"inbox")}))}),[e.feedType,n]),Me.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.CourierInboxMenu=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=>Ie(e.renderPopupHeader(t))))}))}),[e.renderPopupHeader,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupListItem&&queueMicrotask((()=>{t.setPopupListItem((t=>Ie(e.renderPopupListItem(t))))}))}),[e.renderPopupListItem,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupEmptyState&&queueMicrotask((()=>{t.setPopupEmptyState((t=>Ie(e.renderPopupEmptyState(t))))}))}),[e.renderPopupEmptyState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupLoadingState&&queueMicrotask((()=>{t.setPopupLoadingState((t=>Ie(e.renderPopupLoadingState(t))))}))}),[e.renderPopupLoadingState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupErrorState&&queueMicrotask((()=>{t.setPopupErrorState((t=>Ie(e.renderPopupErrorState(t))))}))}),[e.renderPopupErrorState,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupPaginationItem&&queueMicrotask((()=>{t.setPopupPaginationItem((t=>Ie(e.renderPopupPaginationItem(t))))}))}),[e.renderPopupPaginationItem,n]),t.useEffect((()=>{const t=n.current;t&&e.renderPopupMenuButton&&queueMicrotask((()=>{t.setPopupMenuButton((t=>Ie(e.renderPopupMenuButton(t))))}))}),[e.renderPopupMenuButton,n]),t.useEffect((()=>{const t=n.current;t&&queueMicrotask((()=>{t.setFeedType(e.feedType||"inbox")}))}),[e.feedType,n]),Me.jsx("courier-inbox-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=>E.shared.signIn(e),n=()=>E.shared.signOut(),i=e=>ee.shared.load(e),o=e=>ee.shared.fetchNextPageOfMessages(e),s=e=>E.shared.paginationLimit=e,r=e=>ee.shared.readMessage({message:e}),a=e=>ee.shared.unreadMessage({message:e}),l=e=>ee.shared.clickMessage({message:e}),d=e=>ee.shared.archiveMessage({message:e}),u=e=>ee.shared.openMessage({message:e}),h=e=>ee.shared.unarchiveMessage({message:e}),c=()=>ee.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:u,unarchiveMessage:h,readAllMessages:c});t.useEffect((()=>{const e=E.shared.addAuthenticationListener((()=>b())),t=new ce({onError:e=>_(e),onDataSetChange:()=>_(),onPageAdded:()=>_(),onMessageAdd:()=>_(),onMessageRemove:()=>_(),onMessageUpdate:()=>_(),onUnreadCountChange:()=>_()});return ee.shared.addDataStoreListener(t),b(),_(),()=>{e.remove(),t.remove()}}),[]);const b=()=>{var t;const i=null==(t=E.shared.client)?void 0:t.options;v({userId:null==i?void 0:i.userId,signIn:e,signOut:n})},_=e=>{const t=ee.shared;m({load:i,fetchNextPageOfMessages:o,setPaginationLimit:s,readMessage:r,unreadMessage:a,clickMessage:l,archiveMessage:d,openMessage:u,unarchiveMessage:h,readAllMessages:c,inbox:t.inboxDataSet,archive:t.archiveDataSet,unreadCount:t.unreadCount,error:e})};return{shared:E.shared,auth:p,inbox:g}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
11
11
  //# sourceMappingURL=index.js.map