@trycourier/courier-ui-inbox 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +148 -969
- package/dist/index.mjs.map +1 -1
- package/dist/types/courier-inbox-theme-manager.d.ts +17 -37
- package/dist/types/courier-inbox-theme.d.ts +5 -27
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@trycourier/courier-js")):"function"==typeof define&&define.amd?define(["exports","@trycourier/courier-js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CourierUIInbox={},e.CourierJS)}(this,(function(e,t){"use strict";var n,i=Object.defineProperty,o=(e,t,n)=>((e,t,n)=>t in e?i(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n),s=Object.defineProperty,l=e=>{throw TypeError(e)},r=(e,t,n)=>((e,t,n)=>t in e?s(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n),a=(e,t,n)=>t.has(e)||l("Cannot "+n),d=(e,t,n,i)=>(a(e,t,"write to private field"),t.set(e,n),n);const h={500:"#171717",50010:"#1717171A",50020:"#17171733"},u={200:"#F5F5F5",400:"#3A3A3A",500:"#E5E5E5",600:"#737373"},c={500:"#FFFFFF",50010:"#FFFFFF1A",50020:"#FFFFFF33"},v={400:"#60A5FA",500:"#2563EB"},p={light:{colors:{primary:h[500],secondary:c[500],border:u[500],link:v[500],icon:h[500]},button:{cornerRadius:"4px"}},dark:{colors:{primary:c[500],secondary:h[500],border:u[400],link:v[400],icon:c[500]},button:{cornerRadius:"4px"}}},g=()=>"undefined"==typeof window?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",m=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)}},_=(()=>{try{return"undefined"==typeof HTMLElement?class{}:HTMLElement}catch{return class{}}})();class b extends _{constructor(){var e,t,i;super(...arguments),e=this,i=!1,(t=n).has(e)?l("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i)}static get id(){return"courier-base-element"}connectedCallback(){var e,t,i;(a(t=this,i=n,"read from private field"),i.get(t))||(d(this,n,!0),null==(e=this.onComponentMounted)||e.call(this))}disconnectedCallback(){var e;d(this,n,!1),null==(e=this.onComponentUnmounted)||e.call(this)}onComponentMounted(){}onComponentUnmounted(){}}n=new WeakMap;class x extends b{constructor(){super(),r(this,"_currentSystemTheme"),r(this,"_systemThemeCleanup"),this._currentSystemTheme=g(),this._systemThemeCleanup=m((e=>{this._currentSystemTheme=e,this.onSystemThemeChange(e)}))}static get id(){return"courier-system-theme-element"}get currentSystemTheme(){return this._currentSystemTheme}onComponentUnmounted(){var e;null==(e=this._systemThemeCleanup)||e.call(this),super.onComponentUnmounted()}onSystemThemeChange(e){}}const C={borderRadius:"4px",fontSize:"14px"},f=e=>({...C,backgroundColor:p[e].colors.secondary,textColor:p[e].colors.primary,fontWeight:"500",border:`1px solid ${p[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 y extends x{constructor(e){super(),r(this,"_button"),r(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()}))}static get id(){return"courier-button"}getStyles(e){const t="system"===e.mode?this.currentSystemTheme:e.mode;return`\n :host {\n display: inline-block;\n }\n\n button {\n border: none;\n border-radius: ${e.borderRadius??f(t).borderRadius};\n font-weight: ${e.fontWeight??f(t).fontWeight};\n font-family: ${e.fontFamily??"inherit"};\n font-size: ${e.fontSize??f(t).fontSize};\n padding: 6px 10px;\n cursor: pointer;\n width: 100%;\n height: 100%;\n background-color: ${e.backgroundColor??f(t).backgroundColor};\n color: ${e.textColor??f(t).textColor};\n border: ${e.border??f(t).border};\n box-shadow: ${e.shadow??f(t).shadow};\n touch-action: manipulation;\n }\n\n button:hover {\n ${e.hoverBackgroundColor?`background-color: ${e.hoverBackgroundColor};`:"filter: brightness(0.9);"}\n }\n\n button:active {\n ${e.activeBackgroundColor?`background-color: ${e.activeBackgroundColor};`:"filter: brightness(0.8);"}\n }\n\n button:disabled {\n opacity: 0.5;\n cursor: not-allowed;\n }\n `}updateButton(e){e.text&&(this._button.textContent=e.text),this._style.textContent=this.getStyles(e)}}const k={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 S extends b{constructor(e,t){super(),r(this,"_color"),r(this,"_svg"),r(this,"_iconContainer"),r(this,"_style"),this._color=e??h[500],this._svg=t;const n=this.attachShadow({mode:"open"});this._iconContainer=document.createElement("div"),n.appendChild(this._iconContainer),this._style=document.createElement("style"),this._style.textContent=this.getStyles(this._color),n.appendChild(this._style),this.refresh()}static get id(){return"courier-icon"}getStyles(e){return`\n :host {\n display: inline-block;\n line-height: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n }\n\n svg {\n width: 24px;\n height: 24px;\n color: ${e};\n }\n `}refresh(){this._svg&&(this._iconContainer.innerHTML=this._svg),this._color&&(this._style.textContent=this.getStyles(this._color))}updateColor(e){this._color=e,this.refresh()}updateSVG(e){this._svg=e,this.refresh()}}class M extends b{constructor(){super(),r(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, ${p.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, ${p.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()}static get id(){return"courier-link"}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")}}r(M,"observedAttributes",["href","variant","disabled","color","underline","mode","target","font-family","font-size"]);class w extends x{constructor(){super()}build(e){if(null===e)return void this.replaceChildren();const t=e??this.defaultElement();this.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 I extends w{constructor(e){super(),r(this,"_props"),r(this,"_title"),r(this,"_button"),r(this,"_style"),this._props=e}static get id(){return"courier-info-state"}defaultElement(){var e;const t=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 y(this._props.button??f(this.currentSystemTheme)),this._style=document.createElement("style"),this._style.textContent=this.getStyles(this._props),t.className="container",t.appendChild(this._style),t.appendChild(this._title),t.appendChild(this._button),this.appendChild(t),t}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 box-sizing: border-box;\n height: 100%;\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)}}class E extends b{constructor(e,t,n,i,o,s,l,a){super(),r(this,"_backgroundColor"),r(this,"_hoverBackgroundColor"),r(this,"_activeBackgroundColor"),r(this,"_borderRadius"),r(this,"_height"),r(this,"_width"),r(this,"_style"),r(this,"_button"),r(this,"_icon"),this._borderRadius=s,this._backgroundColor=n,this._hoverBackgroundColor=i,this._activeBackgroundColor=o,this._height=l,this._width=a;const d=this.attachShadow({mode:"open"});this._button=document.createElement("button"),this._button.setAttribute("part","button"),this._icon=new S(t,e),this._style=document.createElement("style"),this.refresh(),d.appendChild(this._style),this._button.appendChild(this._icon),d.appendChild(this._button)}static get id(){return"courier-icon-button"}refresh(){this._style.textContent=this.getStyles()}getStyles(){return`\n :host {\n display: inline-block;\n border-radius: ${this._borderRadius??"50%"};\n }\n\n button {\n border: none;\n border-radius: ${this._borderRadius??"50%"};\n cursor: pointer;\n width: ${this._width??"36px"};\n height: ${this._height??"36px"};\n display: flex;\n align-items: center;\n justify-content: center;\n background: ${this._backgroundColor??"transparent"};\n transition: background-color 0.2s ease;\n touch-action: manipulation;\n }\n\n button:hover {\n background-color: ${this._hoverBackgroundColor??"red"};\n }\n\n button:active {\n background-color: ${this._activeBackgroundColor??"red"};\n }\n\n button:disabled {\n opacity: 0.6;\n cursor: not-allowed;\n }\n\n [part="icon"] {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 24px;\n height: 24px;\n }\n `}updateIconColor(e){this._icon.updateColor(e)}updateIconSVG(e){this._icon.updateSVG(e)}updateBackgroundColor(e){this._backgroundColor=e,this.refresh()}updateHoverBackgroundColor(e){this._hoverBackgroundColor=e,this.refresh()}updateActiveBackgroundColor(e){this._activeBackgroundColor=e,this.refresh()}}function $(e){"undefined"==typeof window||customElements.get(e.id)||customElements.define(e.id,e)}function T(e,t){const n=`style[data-${e}]`,i=document.querySelector(n);if(!i){const n=document.createElement("style");return n.setAttribute(`data-${e}`,""),n.textContent=t,document.head.appendChild(n),n}return i}function D(e){const t={...e};return e.actions&&(t.actions=e.actions.map((e=>function(e){const t={...e};e.data&&(t.data=JSON.parse(JSON.stringify(e.data)));return t}(e)))),e.data&&(t.data=JSON.parse(JSON.stringify(e.data))),e.tags&&(t.tags=[...e.tags]),e.trackingIds&&(t.trackingIds={...e.trackingIds}),t}function L(e){if(e)return{...e,messages:e.messages.map((e=>D(e)))}}$(y),$(S),$(M),$(I),$(E),$(x);class A extends b{constructor(e){super(),o(this,"_theme"),o(this,"_options",[]),this._theme=e}static get id(){return"courier-inbox-list-item-menu"}onComponentMounted(){const e=document.createElement("ul");e.className="menu",this.appendChild(e)}static getStyles(e){var t,n,i;const o=null==(i=null==(n=null==(t=e.inbox)?void 0:t.list)?void 0:n.item)?void 0:i.menu;return`\n ${A.id} {\n display: none;\n position: absolute;\n background: ${(null==o?void 0:o.backgroundColor)??"red"};\n border: ${(null==o?void 0:o.border)??"1px solid red"};\n border-radius: ${(null==o?void 0:o.borderRadius)??"0px"};\n box-shadow: ${(null==o?void 0:o.shadow)??"0 2px 8px red"};\n user-select: none;\n opacity: 0;\n pointer-events: none;\n transition: opacity 0.15s;\n overflow: hidden;\n }\n\n ${A.id}.visible {\n display: block;\n opacity: 1;\n pointer-events: auto;\n }\n\n ${A.id} ul.menu {\n list-style: none;\n margin: 0;\n padding: 0;\n display: flex;\n flex-direction: row;\n }\n\n ${A.id} li.menu-item {\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n border-bottom: none;\n background: transparent;\n }\n `}setOptions(e){this._options=e,this.renderMenu()}renderMenu(){var e,t,n;const i=this.querySelector("ul.menu");if(!i)return;i.innerHTML="";const o=null==(n=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:n.menu,s=e=>{e.stopPropagation(),e.preventDefault()};this._options.forEach((e=>{var t,n,l;const r=new E(e.icon.svg,e.icon.color,null==o?void 0:o.backgroundColor,null==(t=null==o?void 0:o.item)?void 0:t.hoverBackgroundColor,null==(n=null==o?void 0:o.item)?void 0:n.activeBackgroundColor,null==(l=null==o?void 0:o.item)?void 0:l.borderRadius),a=t=>{s(t),e.onClick()};r.addEventListener("click",a),r.addEventListener("touchstart",s),r.addEventListener("touchend",a),r.addEventListener("touchmove",s),r.addEventListener("mousedown",s),r.addEventListener("mouseup",s),i.appendChild(r)}))}show(){this.style.display="block",this.classList.add("visible")}hide(){this.style.display="none",this.classList.remove("visible")}}$(A);const P=class e{constructor(){o(this,"_inboxDataSet"),o(this,"_archiveDataSet"),o(this,"_dataStoreListeners",[]),o(this,"_unreadCount"),o(this,"isPaginatingInbox",!1),o(this,"isPaginatingArchive",!1)}static get shared(){return e.instance||(e.instance=new e),e.instance}get unreadCount(){return this._unreadCount??0}get inboxDataSet(){return this._inboxDataSet??{feedType:"inbox",messages:[],canPaginate:!1,paginationCursor:null}}get archiveDataSet(){return this._archiveDataSet??{feedType:"archive",messages:[],canPaginate:!1,paginationCursor:null}}addDataStoreListener(e){this._dataStoreListeners.push(e)}removeDataStoreListener(e){this._dataStoreListeners=this._dataStoreListeners.filter((t=>t!==e))}async fetchCachableDataSet(e){var t,n,i,o,s,l,r,a;if(e.canUseCache){if("inbox"===e.feedType&&this._inboxDataSet)return this._inboxDataSet;if("archive"===e.feedType&&this._archiveDataSet)return this._archiveDataSet}const d=await e.fetch;return{feedType:e.feedType,messages:(null==(n=null==(t=d.data)?void 0:t.messages)?void 0:n.nodes)??[],canPaginate:(null==(s=null==(o=null==(i=d.data)?void 0:i.messages)?void 0:o.pageInfo)?void 0:s.hasNextPage)??!1,paginationCursor:(null==(a=null==(r=null==(l=d.data)?void 0:l.messages)?void 0:r.pageInfo)?void 0:a.startCursor)??null}}async fetchUnreadCount(e){var n;if(e.canUseCache&&void 0!==this._unreadCount)return this._unreadCount;return await(null==(n=t.Courier.shared.client)?void 0:n.inbox.getUnreadMessageCount())??0}async load(e){var n,i;try{const n=t.Courier.shared.client;if(!(null==n?void 0:n.options.userId))throw new Error("User is not signed in");const i=e??{canUseCache:!0},[o,s,l]=await Promise.all([this.fetchCachableDataSet({fetch:n.inbox.getMessages(),feedType:"inbox",canUseCache:i.canUseCache}),this.fetchCachableDataSet({fetch:n.inbox.getArchivedMessages(),feedType:"archive",canUseCache:i.canUseCache}),this.fetchUnreadCount(i)]);this._inboxDataSet=o,this._archiveDataSet=s,this._unreadCount=l,this._dataStoreListeners.forEach((e=>{var t,n,i,o,s,l;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==(l=(s=e.events).onUnreadCountChange)||l.call(s,this._unreadCount??0)}))}catch(o){null==(i=null==(n=t.Courier.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,n;try{await this.connectSocket()}catch(i){null==(n=null==(e=t.Courier.shared.client)?void 0:e.options.logger)||n.error("Error listening for updates:",i),this._dataStoreListeners.forEach((e=>{var t,n;null==(n=(t=e.events).onError)||n.call(t,i)}))}}async connectSocket(){var e,n,i,o,s,l,r,a,d,h,u;const c=null==(e=t.Courier.shared.client)?void 0:e.inbox.socket;try{if(!c)return void(null==(i=null==(n=t.Courier.shared.client)?void 0:n.options.logger)||i.info("CourierInbox socket not available"));if(c.isConnecting||c.isOpen)return void(null==(l=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||l.info(`Inbox socket already connecting or open for client ID: [${null==(s=t.Courier.shared.client)?void 0:s.options.connectionId}]`));c.addMessageEventListener((e=>{if(e.event===t.InboxMessageEvent.NewMessage){const t=e.data;return void this.addMessage(t,0,"inbox")}const n=this.getMessage({messageId:e.messageId});switch(e.event){case t.InboxMessageEvent.MarkAllRead:this.readAllMessages({canCallApi:!1});break;case t.InboxMessageEvent.Read:n&&this.readMessage({message:n,canCallApi:!1});break;case t.InboxMessageEvent.Unread:n&&this.unreadMessage({message:n,canCallApi:!1});break;case t.InboxMessageEvent.Opened:n&&this.openMessage({message:n,canCallApi:!1});break;case t.InboxMessageEvent.Archive:n&&this.archiveMessage({message:n,canCallApi:!1});break;case t.InboxMessageEvent.ArchiveRead:this.archiveReadMessages({canCallApi:!1});break;case t.InboxMessageEvent.ArchiveAll:this.archiveAllMessages({canCallApi:!1});break;case t.InboxMessageEvent.Clicked:n&&this.clickMessage({message:n,canCallApi:!1});break;case t.InboxMessageEvent.Unarchive:n&&this.unarchiveMessage({message:n,canCallApi:!1});case t.InboxMessageEvent.Unopened:}})),await c.connect(),null==(d=null==(r=t.Courier.shared.client)?void 0:r.options.logger)||d.info(`Inbox socket connected for client ID: [${null==(a=t.Courier.shared.client)?void 0:a.options.connectionId}]`)}catch(v){null==(u=null==(h=t.Courier.shared.client)?void 0:h.options.logger)||u.error("Failed to connect socket:",v)}}getMessage(e){var t,n;if(e.messageId)return(null==(t=this._inboxDataSet)?void 0:t.messages.find((t=>t.messageId===e.messageId)))??(null==(n=this._archiveDataSet)?void 0:n.messages.find((t=>t.messageId===e.messageId)))}async fetchNextPageOfMessages(e){var n,i,o,s,l,r,a,d,h,u,c,v,p,g,m,_,b,x,C,f,y,k,S,M;switch(e.feedType){case"inbox":if(this.isPaginatingInbox)return null;if((null==(n=this._inboxDataSet)?void 0:n.canPaginate)&&this._inboxDataSet.paginationCursor)try{this.isPaginatingInbox=!0;const e=await(null==(i=t.Courier.shared.client)?void 0:i.inbox.getMessages({paginationLimit:t.Courier.shared.paginationLimit,startCursor:this._inboxDataSet.paginationCursor})),n={feedType:"inbox",messages:(null==(s=null==(o=null==e?void 0:e.data)?void 0:o.messages)?void 0:s.nodes)??[],canPaginate:(null==(a=null==(r=null==(l=null==e?void 0:e.data)?void 0:l.messages)?void 0:r.pageInfo)?void 0:a.hasNextPage)??!1,paginationCursor:(null==(u=null==(h=null==(d=null==e?void 0:e.data)?void 0:d.messages)?void 0:h.pageInfo)?void 0:u.startCursor)??null};return this.addPage(n),n}catch(w){return null==(v=null==(c=t.Courier.shared.client)?void 0:c.options.logger)||v.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==(g=t.Courier.shared.client)?void 0:g.inbox.getArchivedMessages({paginationLimit:t.Courier.shared.paginationLimit,startCursor:this._archiveDataSet.paginationCursor})),n={feedType:"archive",messages:(null==(_=null==(m=null==e?void 0:e.data)?void 0:m.messages)?void 0:_.nodes)??[],canPaginate:(null==(C=null==(x=null==(b=null==e?void 0:e.data)?void 0:b.messages)?void 0:x.pageInfo)?void 0:C.hasNextPage)??!1,paginationCursor:(null==(k=null==(y=null==(f=null==e?void 0:e.data)?void 0:f.messages)?void 0:y.pageInfo)?void 0:k.startCursor)??null};return this.addPage(n),n}catch(w){return null==(M=null==(S=t.Courier.shared.client)?void 0:S.options.logger)||M.error("Error fetching next page of archived messages:",w),null}finally{this.isPaginatingArchive=!1}}return null}canMutate(){return!!(t.Courier.shared.client&&this._inboxDataSet&&this._archiveDataSet)}async readMessage({message:e,canCallApi:n=!0}){var i,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet),r=this.getMessageSnapshot(e);if(!r.message.read)try{r.message.read=(new Date).toISOString(),this.applyMessageSnapshot(r),this._unreadCount=l.unreadCount-1,this._dataStoreListeners.forEach((e=>{var t,n;null==(n=(t=e.events).onUnreadCountChange)||n.call(t,this._unreadCount)})),n&&await(null==(i=t.Courier.shared.client)?void 0:i.inbox.read({messageId:e.messageId}))}catch(a){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error reading message:",a),this.applyDatastoreSnapshot(l)}}async unreadMessage({message:e,canCallApi:n=!0}){var i,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet),r=this.getMessageSnapshot(e);if(r.message.read)try{r.message.read=void 0,this.applyMessageSnapshot(r),this._unreadCount=l.unreadCount+1,this._dataStoreListeners.forEach((e=>{var t,n;null==(n=(t=e.events).onUnreadCountChange)||n.call(t,this._unreadCount)})),n&&await(null==(i=t.Courier.shared.client)?void 0:i.inbox.unread({messageId:e.messageId}))}catch(a){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error unreading message:",a),this.applyDatastoreSnapshot(l)}}async openMessage({message:e,canCallApi:n=!0}){var i,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet),r=this.getMessageSnapshot(e);if((void 0!==r.inboxIndex||void 0!==r.archiveIndex)&&!r.message.opened)try{r.message.opened=(new Date).toISOString(),this.applyMessageSnapshot(r),n&&await(null==(i=t.Courier.shared.client)?void 0:i.inbox.open({messageId:e.messageId}))}catch(a){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error opening message:",a),this.applyDatastoreSnapshot(l)}}async clickMessage({message:e,canCallApi:n=!0}){var i,o,s,l,r;if(this.canMutate())try{(null==(i=e.trackingIds)?void 0:i.clickTrackingId)&&n&&await(null==(s=t.Courier.shared.client)?void 0:s.inbox.click({messageId:e.messageId,trackingId:null==(o=e.trackingIds)?void 0:o.clickTrackingId}))}catch(a){null==(r=null==(l=t.Courier.shared.client)?void 0:l.options.logger)||r.error("Error clicking message:",a)}}async archiveMessage({message:e,canCallApi:n=!0}){var i,o,s,l;if(!this.canMutate())return;const r=this.getMessageSnapshot(e);if(void 0===r.inboxIndex)return;const a=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{if(e.archived=(new Date).toISOString(),this.removeMessage(e,r.inboxIndex,"inbox"),null==(i=this._archiveDataSet)?void 0:i.messages){const t=this.findInsertIndex(e,this._archiveDataSet);this.addMessage(e,t,"archive")}n&&await(null==(o=t.Courier.shared.client)?void 0:o.inbox.archive({messageId:e.messageId}))}catch(d){null==(l=null==(s=t.Courier.shared.client)?void 0:s.options.logger)||l.error("Error archiving message:",d),this.applyDatastoreSnapshot(a)}}async unarchiveMessage({message:e,canCallApi:n=!0}){var i,o,s,l;if(!this.canMutate())return;const r=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet),a=this.getMessageSnapshot(e);if(void 0!==a.archiveIndex)try{if(a.message.archived=void 0,this.removeMessage(e,a.archiveIndex,"archive"),null==(i=this._inboxDataSet)?void 0:i.messages){const t=this.findInsertIndex(e,this._inboxDataSet);this.addMessage(e,t,"inbox")}n&&await(null==(o=t.Courier.shared.client)?void 0:o.inbox.unarchive({messageId:e.messageId}))}catch(d){null==(l=null==(s=t.Courier.shared.client)?void 0:s.options.logger)||l.error("Error unarchiving message:",d),this.applyDatastoreSnapshot(r)}}async archiveReadMessages({canCallApi:e=!0}={}){var n,i,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{const o=(new Date).toISOString();((null==(n=this._inboxDataSet)?void 0:n.messages.filter((e=>e.read)))??[]).forEach((e=>{var t,n,i;e.archived=o;const s=null==(t=this._inboxDataSet)?void 0:t.messages.findIndex((t=>t.messageId===e.messageId));if(void 0!==s&&-1!==s&&(null==(n=this._inboxDataSet)||n.messages.splice(s,1)),null==(i=this._archiveDataSet)?void 0:i.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==(i=t.Courier.shared.client)?void 0:i.inbox.archiveRead())}catch(r){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error archiving read messages:",r),this.applyDatastoreSnapshot(l)}}async archiveAllMessages({canCallApi:e=!0}={}){var n,i,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{const o=(new Date).toISOString();null==(n=this._inboxDataSet)||n.messages.forEach((e=>{var t;if(e.archived=o,null==(t=this._archiveDataSet)?void 0:t.messages){const t=this.findInsertIndex(e,this._archiveDataSet);this._archiveDataSet.messages.splice(t,0,e)}})),this._inboxDataSet={messages:[],canPaginate:!1,paginationCursor:null,feedType:"inbox"},this._unreadCount=0,this._dataStoreListeners.forEach((e=>{var t,n,i,o,s,l;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==(l=(s=e.events).onUnreadCountChange)||l.call(s,this._unreadCount)})),e&&await(null==(i=t.Courier.shared.client)?void 0:i.inbox.archiveAll())}catch(r){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error archiving all messages:",r),this.applyDatastoreSnapshot(l)}}async readAllMessages({canCallApi:e=!0}={}){var n,i,o,s,l;if(!this.canMutate())return;const r=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{const s=(new Date).toISOString();null==(n=this._inboxDataSet)||n.messages.forEach((e=>{e.read||(e.read=s)})),null==(i=this._archiveDataSet)||i.messages.forEach((e=>{e.read||(e.read=s)})),this._unreadCount=0,this._dataStoreListeners.forEach((e=>{var t,n,i,o,s,l;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==(l=(s=e.events).onUnreadCountChange)||l.call(s,this._unreadCount)})),e&&await(null==(o=t.Courier.shared.client)?void 0:o.inbox.readAll())}catch(a){null==(l=null==(s=t.Courier.shared.client)?void 0:s.options.logger)||l.error("Error reading all messages:",a),this.applyDatastoreSnapshot(r)}}findInsertIndex(e,t){const 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,l,r;null==(s=(o=i.events).onMessageAdd)||s.call(o,e,t,n),null==(r=(l=i.events).onUnreadCountChange)||r.call(l,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,l,r;null==(s=(o=i.events).onMessageRemove)||s.call(o,e,t,n),null==(r=(l=i.events).onUnreadCountChange)||r.call(l,this._unreadCount??0)}))}applyMessageSnapshot(e){void 0!==e.archiveIndex&&this.updateMessage(e.message,e.archiveIndex,"archive"),void 0!==e.inboxIndex&&this.updateMessage(e.message,e.inboxIndex,"inbox")}applyDatastoreSnapshot(e){const{unreadCount:t,inbox:n,archive:i}=e;this._inboxDataSet=n,this._archiveDataSet=i,this._dataStoreListeners.forEach((e=>{var n,i,o,s,l,r;this._inboxDataSet&&(null==(i=(n=e.events).onDataSetChange)||i.call(n,this._inboxDataSet,"inbox")),this._archiveDataSet&&(null==(s=(o=e.events).onDataSetChange)||s.call(o,this._archiveDataSet,"archive")),null==(r=(l=e.events).onUnreadCountChange)||r.call(l,t)}))}updateMessage(e,t,n){switch(n){case"inbox":this._inboxDataSet&&(this._inboxDataSet.messages[t]=e);break;case"archive":this._archiveDataSet&&(this._archiveDataSet.messages[t]=e)}this._dataStoreListeners.forEach((i=>{var o,s,l,r;null==(s=(o=i.events).onMessageUpdate)||s.call(o,e,t,n),null==(r=(l=i.events).onUnreadCountChange)||r.call(l,this._unreadCount??0)}))}getDatastoreSnapshot(e,t,n){return{unreadCount:e,inbox:L(t),archive:L(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:D(e),archiveIndex:t,inboxIndex:n}}};o(P,"instance");let B=P;class F extends b{constructor(e,t,n){super(),o(this,"_themeManager"),o(this,"_theme"),o(this,"_message",null),o(this,"_feedType","inbox"),o(this,"_isMobile",!1),o(this,"_canClick",!1),o(this,"_titleElement"),o(this,"_subtitleElement"),o(this,"_timeElement"),o(this,"_menu"),o(this,"_unreadIndicator"),o(this,"_actionsContainer"),o(this,"_longPressTimeout",null),o(this,"_isLongPress",!1),o(this,"_observer"),o(this,"onItemClick",null),o(this,"onItemLongPress",null),o(this,"onItemActionClick",null),o(this,"onItemVisible",null),this._canClick=t,this._themeManager=e,this._theme=e.getTheme(),this._isMobile="ontouchstart"in window,this.render(),this._setupIntersectionObserver()}static get id(){return"courier-inbox-list-item"}render(){const e=document.createElement("div");e.className="content-container",this._titleElement=document.createElement("p"),this._titleElement.className="title",this._subtitleElement=document.createElement("p"),this._subtitleElement.className="subtitle",this._actionsContainer=document.createElement("div"),this._actionsContainer.className="actions-container",e.appendChild(this._titleElement),e.appendChild(this._subtitleElement),e.appendChild(this._actionsContainer),this._timeElement=document.createElement("p"),this._timeElement.className="time",this._unreadIndicator=document.createElement("div"),this._unreadIndicator.className="unread-indicator",this._menu=new A(this._theme),this._menu.setOptions(this._getMenuOptions()),this.append(this._unreadIndicator,e,this._timeElement,this._menu);const t=e=>{e.stopPropagation(),e.preventDefault()};this._menu.addEventListener("mousedown",t),this._menu.addEventListener("pointerdown",t),this._menu.addEventListener("click",t),this.addEventListener("click",(e=>{this._canClick&&(this._menu&&(this._menu.contains(e.target)||e.composedPath().includes(this._menu))||!this._message||!this.onItemClick||e.target instanceof S||this._isLongPress||this.onItemClick(this._message))})),this._setupHoverBehavior(),this._setupLongPressBehavior(),this._canClick&&this.classList.add("clickable")}_setupIntersectionObserver(){"undefined"!=typeof window&&"undefined"!=typeof IntersectionObserver&&(this._observer&&this._observer.disconnect(),this._observer=new IntersectionObserver((e=>{e.forEach((e=>{1===e.intersectionRatio&&this.onItemVisible&&this._message&&this.onItemVisible(this._message)}))}),{threshold:1}),this._observer.observe(this))}onComponentUnmounted(){var e;null==(e=this._observer)||e.disconnect()}static getStyles(e){var t,n,i,o,s,l,r,a,d,h,u,c,v,p,g,m,_,b,x,C,f,y,k,S,M,w;const I=null==(t=e.inbox)?void 0:t.list;return`\n ${F.id} {\n display: flex;\n flex-direction: row;\n align-items: flex-start;\n justify-content: space-between;\n border-bottom: ${(null==(n=null==I?void 0:I.item)?void 0:n.divider)??"1px solid red"};\n font-family: inherit;\n cursor: default;\n transition: background-color 0.2s ease;\n margin: 0;\n width: 100%;\n box-sizing: border-box;\n padding: 12px 20px;\n position: relative;\n background-color: ${(null==(i=null==I?void 0:I.item)?void 0:i.backgroundColor)??"transparent"};\n user-select: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n touch-action: manipulation;\n }\n\n /* Only apply hover/active background if clickable */\n @media (hover: hover) {\n ${F.id}.clickable:hover {\n cursor: pointer;\n background-color: ${(null==(o=null==I?void 0:I.item)?void 0:o.hoverBackgroundColor)??"red"};\n }\n }\n\n ${F.id}.clickable:active {\n cursor: pointer;\n background-color: ${(null==(s=null==I?void 0:I.item)?void 0:s.activeBackgroundColor)??"red"};\n }\n\n /* Menu hover / active */\n @media (hover: hover) {\n ${F.id}.clickable:hover:has(courier-inbox-list-item-menu:hover, courier-inbox-list-item-menu *:hover, courier-button:hover, courier-button *:hover) {\n background-color: ${(null==(l=null==I?void 0:I.item)?void 0:l.backgroundColor)??"transparent"};\n }\n }\n\n ${F.id}.clickable:active:has(courier-inbox-list-item-menu:active, courier-inbox-list-item-menu *:active, courier-button:active, courier-button *:active) {\n background-color: ${(null==(r=null==I?void 0:I.item)?void 0:r.backgroundColor)??"transparent"};\n }\n\n ${F.id}:last-child {\n border-bottom: none;\n }\n\n ${F.id} .unread-indicator {\n position: absolute;\n top: 28px;\n left: 6px;\n width: 8px;\n height: 8px;\n border-radius: 50%;\n background-color: ${(null==(a=null==I?void 0:I.item)?void 0:a.unreadIndicatorColor)??"red"};\n display: none;\n }\n\n ${F.id}.unread .unread-indicator {\n display: block;\n }\n\n ${F.id} .content-container {\n flex: 1;\n display: flex;\n flex-direction: column;\n margin-right: 12px;\n }\n\n ${F.id} p {\n margin: 0;\n overflow-wrap: break-word;\n word-break: break-word;\n hyphens: auto;\n line-height: 1.4;\n user-select: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n text-align: left;\n }\n\n ${F.id} .title {\n font-family: ${(null==(h=null==(d=null==I?void 0:I.item)?void 0:d.title)?void 0:h.family)??"inherit"};\n font-size: ${(null==(c=null==(u=null==I?void 0:I.item)?void 0:u.title)?void 0:c.size)??"14px"};\n color: ${(null==(p=null==(v=null==I?void 0:I.item)?void 0:v.title)?void 0:p.color)??"red"};\n margin-bottom: 4px;\n }\n\n ${F.id} .subtitle {\n font-family: ${(null==(m=null==(g=null==I?void 0:I.item)?void 0:g.subtitle)?void 0:m.family)??"inherit"};\n font-size: ${(null==(b=null==(_=null==I?void 0:I.item)?void 0:_.subtitle)?void 0:b.size)??"14px"};\n color: ${(null==(C=null==(x=null==I?void 0:I.item)?void 0:x.subtitle)?void 0:C.color)??"red"};\n }\n\n ${F.id} .time {\n font-family: ${(null==(y=null==(f=null==I?void 0:I.item)?void 0:f.time)?void 0:y.family)??"inherit"};\n font-size: ${(null==(S=null==(k=null==I?void 0:I.item)?void 0:k.time)?void 0:S.size)??"14px"};\n color: ${(null==(w=null==(M=null==I?void 0:I.item)?void 0:M.time)?void 0:w.color)??"red"};\n text-align: right;\n white-space: nowrap;\n }\n\n ${F.id} courier-inbox-list-item-menu {\n z-index: 1;\n position: absolute;\n top: 8px;\n right: 8px;\n display: none;\n }\n\n ${F.id} .actions-container {\n display: flex;\n margin-top: 10px;\n flex-wrap: wrap;\n flex-direction: row;\n align-items: center;\n gap: 8px;\n display: none;\n }\n `}_setupHoverBehavior(){this._isMobile||(this.addEventListener("mouseenter",(()=>{this._isLongPress=!1,this._showMenu()})),this.addEventListener("mouseleave",(()=>this._hideMenu())))}_setupLongPressBehavior(){var e,t,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)}))}_getMenuOptions(){var e,t,n,i,o,s,l,r,a,d,h,u,c,v,p;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 _="archive"===this._feedType;return _||m.push({id:(null==(o=this._message)?void 0:o.read)?"unread":"read",icon:{svg:(null==(s=this._message)?void 0:s.read)?null==(l=null==g?void 0:g.unread)?void 0:l.svg:null==(r=null==g?void 0:g.read)?void 0:r.svg,color:(null==(a=this._message)?void 0:a.read)?null==(d=null==g?void 0:g.unread)?void 0:d.color:(null==(h=null==g?void 0:g.read)?void 0:h.color)??"red"},onClick:()=>{this._message&&(this._message.read?B.shared.unreadMessage({message:this._message}):B.shared.readMessage({message:this._message}))}}),m.push({id:_?"unarchive":"archive",icon:{svg:_?null==(u=null==g?void 0:g.unarchive)?void 0:u.svg:null==(c=null==g?void 0:g.archive)?void 0:c.svg,color:_?null==(v=null==g?void 0:g.unarchive)?void 0:v.color:(null==(p=null==g?void 0:g.archive)?void 0:p.color)??"red"},onClick:()=>{this._message&&(_?B.shared.unarchiveMessage({message:this._message}):B.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&&this._timeElement&&(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&&this._timeElement&&(this._menu.hide(),this._menu.style.display="none",this._timeElement.style.opacity="1")}setMessage(e,t){this._message=e,this._feedType=t,this._updateContent()}setOnItemClick(e){this.onItemClick=e}setOnItemActionClick(e){this.onItemActionClick=e}setOnItemLongPress(e){this.onItemLongPress=e}setOnItemVisible(e){this.onItemVisible=e}_updateContent(){var e,t,n;if(!this._message)return this._titleElement&&(this._titleElement.textContent=""),void(this._subtitleElement&&(this._subtitleElement.textContent=""));this.classList.toggle("unread",!this._message.read&&"archive"!==this._feedType),this._titleElement&&(this._titleElement.textContent=this._message.title||"Untitled Message"),this._subtitleElement&&(this._subtitleElement.textContent=this._message.preview||this._message.body||""),this._timeElement&&(this._timeElement.textContent=function(e){if(!e.created)return"Now";const t=new Date,n=new Date(e.created),i=Math.floor((t.getTime()-n.getTime())/1e3);return i<5?"Now":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&&this._menu.setOptions(this._getMenuOptions());const i=this._message.actions&&this._message.actions.length>0;this._actionsContainer&&(this._actionsContainer.style.display=i?"flex":"none");const o=null==(n=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:n.actions;this._actionsContainer&&this._message.actions&&(this._actionsContainer.innerHTML="",this._message.actions.forEach((e=>{var t,n,i,s,l;const r=new y({mode:this._themeManager.mode,text:e.content,variant:"secondary",backgroundColor:null==o?void 0:o.backgroundColor,hoverBackgroundColor:null==o?void 0:o.hoverBackgroundColor,activeBackgroundColor:null==o?void 0:o.activeBackgroundColor,border:null==o?void 0:o.border,borderRadius:null==o?void 0:o.borderRadius,shadow:null==o?void 0:o.shadow,fontFamily:null==(t=null==o?void 0:o.font)?void 0:t.family,fontSize:null==(n=null==o?void 0:o.font)?void 0:n.size,fontWeight:null==(i=null==o?void 0:o.font)?void 0:i.weight,textColor:null==(s=null==o?void 0:o.font)?void 0:s.color,onClick:()=>{this._message&&this.onItemActionClick&&this.onItemActionClick(this._message,e)}});null==(l=this._actionsContainer)||l.appendChild(r)})))}}$(F);class R extends b{constructor(e){super(),o(this,"_theme"),o(this,"_style"),this._theme=e}static get id(){return"courier-inbox-skeleton-list-item"}onComponentMounted(){this._style=T(R.id,R.getStyles(this._theme)),this.render()}onComponentUnmounted(){var e;null==(e=this._style)||e.remove()}render(){const e=new H(this._theme),t=new H(this._theme),n=new H(this._theme);this.appendChild(e),this.appendChild(t),this.appendChild(n)}static getStyles(e){return`\n ${R.id} {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n width: 100%;\n box-sizing: border-box;\n }\n\n ${R.id} > *:first-child {\n width: 35%;\n }\n\n ${R.id} > *:nth-child(2) {\n width: 100%;\n }\n\n ${R.id} > *:nth-child(3) {\n width: 82%;\n }\n `}}$(R);class H extends b{constructor(e){super(),o(this,"_theme"),o(this,"_style"),this._theme=e}static get id(){return"courier-skeleton-animated-row"}onComponentMounted(){this._style=T(H.id,H.getStyles(this._theme)),this.render()}onComponentUnmounted(){var e;null==(e=this._style)||e.remove()}render(){const e=document.createElement("div");e.className="skeleton-item",this.appendChild(e)}static getStyles(e){var t,n,i,o,s,l,r,a,d,h,u,c;const v=(null==(i=null==(n=null==(t=e.inbox)?void 0:t.loading)?void 0:n.animation)?void 0:i.barColor)??"#000",p=4===v.length?`#${v[1]}${v[1]}${v[2]}${v[2]}${v[3]}${v[3]}`:v,g=parseInt(p.slice(1,3),16),m=parseInt(p.slice(3,5),16),_=parseInt(p.slice(5,7),16),b=`rgba(${g}, ${m}, ${_}, 0.8)`,x=`rgba(${g}, ${m}, ${_}, 0.4)`;return`\n ${H.id} {\n display: flex;\n height: 100%;\n width: 100%;\n align-items: flex-start;\n justify-content: flex-start;\n }\n\n ${H.id} .skeleton-item {\n height: ${(null==(l=null==(s=null==(o=e.inbox)?void 0:o.loading)?void 0:s.animation)?void 0:l.barHeight)??"14px"};\n width: 100%;\n background: linear-gradient(\n 90deg,\n ${b} 25%,\n ${x} 50%,\n ${b} 75%\n );\n background-size: 200% 100%;\n animation: ${H.id}-shimmer ${(null==(d=null==(a=null==(r=e.inbox)?void 0:r.loading)?void 0:a.animation)?void 0:d.duration)??"2s"} ease-in-out infinite;\n border-radius: ${(null==(c=null==(u=null==(h=e.inbox)?void 0:h.loading)?void 0:u.animation)?void 0:c.barBorderRadius)??"14px"};\n }\n\n @keyframes ${H.id}-shimmer {\n 0% {\n background-position: 200% 0;\n }\n 100% {\n background-position: -200% 0;\n }\n }\n `}}$(H);class z extends w{constructor(e){super(),o(this,"_theme"),o(this,"_style"),this._theme=e}static get id(){return"courier-inbox-skeleton-list"}onComponentMounted(){this._style=T(z.id,z.getStyles(this._theme))}onComponentUnmounted(){var e;null==(e=this._style)||e.remove()}defaultElement(){const e=document.createElement("div");e.className="list";for(let t=0;t<3;t++){const t=new R(this._theme);e.appendChild(t)}return this.appendChild(e),e}static getStyles(e){var t,n,i,o;return`\n ${z.id} {\n display: flex;\n height: 100%;\n width: 100%;\n align-items: flex-start;\n justify-content: flex-start;\n overflow: hidden;\n }\n\n ${z.id} .list {\n display: flex;\n flex-direction: column;\n width: 100%;\n overflow: hidden;\n }\n\n ${z.id} .list > * {\n border-bottom: ${(null==(n=null==(t=e.inbox)?void 0:t.loading)?void 0:n.divider)??"1px solid red"};\n opacity: 100%;\n }\n\n ${z.id} .list > *:nth-child(2) {\n border-bottom: ${(null==(o=null==(i=e.inbox)?void 0:i.loading)?void 0:o.divider)??"1px solid red"};\n opacity: 88%;\n }\n\n ${z.id} .list > *:nth-child(3) {\n border-bottom: none;\n opacity: 50%;\n }\n `}}$(z);class O extends b{constructor(e){super(),o(this,"_theme"),o(this,"_style"),o(this,"_skeletonLoadingList"),o(this,"_observer"),o(this,"_customItem"),o(this,"_onPaginationTrigger"),this._theme=e.theme,this._customItem=e.customItem,this._onPaginationTrigger=e.onPaginationTrigger}static get id(){return"courier-inbox-pagination-list-item"}onComponentMounted(){if(this._style=T(O.id,O.getStyles(this._theme)),this._customItem)this.appendChild(this._customItem);else{const e=document.createElement("div");e.className="skeleton-container",this._skeletonLoadingList=new z(this._theme),this._skeletonLoadingList.build(void 0),e.appendChild(this._skeletonLoadingList),this.appendChild(e)}this._observer=new IntersectionObserver((e=>{e.forEach((e=>{e.isIntersecting&&this._onPaginationTrigger()}))})),this._observer.observe(this)}onComponentUnmounted(){var e,t;null==(e=this._observer)||e.disconnect(),null==(t=this._style)||t.remove()}static getStyles(e){return`\n ${O.id} {\n padding: 0;\n margin: 0;\n box-sizing: border-box;\n }\n\n ${O.id} .skeleton-container {\n height: 150%;\n }\n `}}function U(e){return B.shared.openMessage({message:e})}$(O);class V extends b{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_messages",[]),o(this,"_feedType","inbox"),o(this,"_isLoading",!0),o(this,"_error",null),o(this,"_canPaginate",!1),o(this,"_canClickListItems",!1),o(this,"_canLongPressListItems",!1),o(this,"_onMessageClick",null),o(this,"_onMessageActionClick",null),o(this,"_onMessageLongPress",null),o(this,"_onRefresh"),o(this,"_onPaginationTrigger"),o(this,"_listItemFactory"),o(this,"_paginationItemFactory"),o(this,"_loadingStateFactory"),o(this,"_emptyStateFactory"),o(this,"_errorStateFactory"),o(this,"_listStyles"),o(this,"_listItemStyles"),o(this,"_listItemMenuStyles"),o(this,"_errorContainer"),o(this,"_emptyContainer"),this._onRefresh=e.onRefresh,this._onPaginationTrigger=e.onPaginationTrigger,this._onMessageClick=e.onMessageClick,this._onMessageActionClick=e.onMessageActionClick,this._onMessageLongPress=e.onMessageLongPress,this._themeSubscription=e.themeManager.subscribe((e=>{this.render()}))}static get id(){return"courier-inbox-list"}get messages(){return this._messages}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this._listStyles=T(V.id,V.getStyles(this.theme)),this._listItemStyles=T(F.id,F.getStyles(this.theme)),this._listItemMenuStyles=T(A.id,A.getStyles(this.theme)),this.render()}onComponentUnmounted(){var e,t,n;this._themeSubscription.unsubscribe(),null==(e=this._listStyles)||e.remove(),null==(t=this._listItemStyles)||t.remove(),null==(n=this._listItemMenuStyles)||n.remove()}setCanClickListItems(e){this._canClickListItems=e}setCanLongPressListItems(e){this._canLongPressListItems=e}static getStyles(e){var t;const n=null==(t=e.inbox)?void 0:t.list;return`\n ${V.id} {\n flex: 1;\n width: 100%;\n background-color: ${(null==n?void 0:n.backgroundColor)??"red"};\n }\n\n ${V.id} ul {\n list-style: none;\n padding: 0;\n margin: 0;\n height: 100%;\n }\n `}setDataSet(e){this._messages=[...e.messages],this._canPaginate=Boolean(e.canPaginate),this._error=null,this._isLoading=!1,this.render()}addPage(e){this._messages=[...this._messages,...e.messages],this._canPaginate=Boolean(e.canPaginate),this._error=null,this._isLoading=!1,this.render()}addMessage(e,t=0){this._messages.splice(t,0,e),this.render()}removeMessage(e=0){this._messages.splice(e,1),this.render()}updateMessage(e,t=0){this._messages[t]=e,this.render()}setFeedType(e){this._feedType=e,this._error=null,this._isLoading=!0,this.render()}setLoading(e){this._error=null,this._isLoading=e,this.render()}setError(e){this._error=e,this._isLoading=!1,this._messages=[],this.render()}setErrorNoClient(){this.setError(new Error("No user signed in"))}handleRetry(){this._onRefresh()}handleRefresh(){this._onRefresh()}refreshInfoStateThemes(){var e,t;null==(e=this._emptyContainer)||e.updateStyles(this.errorProps),null==(t=this._emptyContainer)||t.updateStyles(this.emptyProps)}get errorProps(){var e,t,n,i,o,s,l,r,a,d,h,u,c,v,p,g,m,_,b,x,C,f,y,k,S,M;const w=null==(e=this.theme.inbox)?void 0:e.error,I=this._themeSubscription.manager.mode;return{title:{text:(null==(t=null==w?void 0:w.title)?void 0:t.text)??(null==(n=this._error)?void 0:n.message),textColor:null==(o=null==(i=null==w?void 0:w.title)?void 0:i.font)?void 0:o.color,fontFamily:null==(l=null==(s=null==w?void 0:w.title)?void 0:s.font)?void 0:l.family,fontSize:null==(a=null==(r=null==w?void 0:w.title)?void 0:r.font)?void 0:a.size,fontWeight:null==(h=null==(d=null==w?void 0:w.title)?void 0:d.font)?void 0:h.weight},button:{mode:I,text:null==(u=null==w?void 0:w.button)?void 0:u.text,backgroundColor:null==(c=null==w?void 0:w.button)?void 0:c.backgroundColor,hoverBackgroundColor:null==(v=null==w?void 0:w.button)?void 0:v.hoverBackgroundColor,activeBackgroundColor:null==(p=null==w?void 0:w.button)?void 0:p.activeBackgroundColor,textColor:null==(m=null==(g=null==w?void 0:w.button)?void 0:g.font)?void 0:m.color,fontFamily:null==(b=null==(_=null==w?void 0:w.button)?void 0:_.font)?void 0:b.family,fontSize:null==(C=null==(x=null==w?void 0:w.button)?void 0:x.font)?void 0:C.size,fontWeight:null==(y=null==(f=null==w?void 0:w.button)?void 0:f.font)?void 0:y.weight,shadow:null==(k=null==w?void 0:w.button)?void 0:k.shadow,border:null==(S=null==w?void 0:w.button)?void 0:S.border,borderRadius:null==(M=null==w?void 0:w.button)?void 0:M.borderRadius,onClick:()=>this.handleRetry()}}}get emptyProps(){var e,t,n,i,o,s,l,r,a,d,h,u,c,v,p,g,m,_,b,x,C,f,y,k,S;const M=null==(e=this.theme.inbox)?void 0:e.empty,w=this._themeSubscription.manager.mode;return{title:{text:(null==(t=null==M?void 0:M.title)?void 0:t.text)??`No ${this._feedType} messages yet`,textColor:null==(i=null==(n=null==M?void 0:M.title)?void 0:n.font)?void 0:i.color,fontFamily:null==(s=null==(o=null==M?void 0:M.title)?void 0:o.font)?void 0:s.family,fontSize:null==(r=null==(l=null==M?void 0:M.title)?void 0:l.font)?void 0:r.size,fontWeight:null==(d=null==(a=null==M?void 0:M.title)?void 0:a.font)?void 0:d.weight},button:{mode:w,text:null==(h=null==M?void 0:M.button)?void 0:h.text,backgroundColor:null==(u=null==M?void 0:M.button)?void 0:u.backgroundColor,hoverBackgroundColor:null==(c=null==M?void 0:M.button)?void 0:c.hoverBackgroundColor,activeBackgroundColor:null==(v=null==M?void 0:M.button)?void 0:v.activeBackgroundColor,textColor:null==(g=null==(p=null==M?void 0:M.button)?void 0:p.font)?void 0:g.color,fontFamily:null==(_=null==(m=null==M?void 0:M.button)?void 0:m.font)?void 0:_.family,fontSize:null==(x=null==(b=null==M?void 0:M.button)?void 0:b.font)?void 0:x.size,fontWeight:null==(f=null==(C=null==M?void 0:M.button)?void 0:C.font)?void 0:f.weight,shadow:null==(y=null==M?void 0:M.button)?void 0:y.shadow,border:null==(k=null==M?void 0:M.button)?void 0:k.border,borderRadius:null==(S=null==M?void 0:M.button)?void 0:S.borderRadius,onClick:()=>this.handleRefresh()}}}render(){for(var e,t,n,i;this.firstChild;)this.removeChild(this.firstChild),this._errorContainer=void 0,this._emptyContainer=void 0;if(this._listStyles&&(this._listStyles.textContent=V.getStyles(this.theme)),this._listItemStyles&&(this._listItemStyles.textContent=F.getStyles(this.theme)),this._listItemMenuStyles&&(this._listItemMenuStyles.textContent=A.getStyles(this.theme)),this._error)return this._errorContainer=new I(this.errorProps),this._errorContainer.build(null==(e=this._errorStateFactory)?void 0:e.call(this,{feedType:this._feedType,error:this._error})),void this.appendChild(this._errorContainer);if(this._isLoading){const e=new z(this.theme);return e.build(null==(t=this._loadingStateFactory)?void 0:t.call(this,{feedType:this._feedType})),void this.appendChild(e)}if(0===this._messages.length)return this._emptyContainer=new I(this.emptyProps),this._emptyContainer.build(null==(n=this._emptyStateFactory)?void 0:n.call(this,{feedType:this._feedType})),void this.appendChild(this._emptyContainer);const o=document.createElement("ul");if(this.appendChild(o),this._messages.forEach(((e,t)=>{if(this._listItemFactory)return void o.appendChild(this._listItemFactory({message:e,index:t}));const n=new F(this._themeSubscription.manager,this._canClickListItems,this._canLongPressListItems);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)})),n.setOnItemVisible((e=>this.openVisibleMessage(e))),o.appendChild(n)})),this._canPaginate){const e=new O({theme:this.theme,customItem:null==(i=this._paginationItemFactory)?void 0:i.call(this,{feedType:this._feedType}),onPaginationTrigger:()=>{var e;return null==(e=this._onPaginationTrigger)?void 0:e.call(this,this._feedType)}});o.appendChild(e)}}async openVisibleMessage(e){try{await U(e)}catch(t){}}setLoadingStateFactory(e){this._loadingStateFactory=e,this.render()}setEmptyStateFactory(e){this._emptyStateFactory=e,this.render()}setErrorStateFactory(e){this._errorStateFactory=e,this.render()}setListItemFactory(e){this._listItemFactory=e,this.render()}setPaginationItemFactory(e){this._paginationItemFactory=e,this.render()}}$(V);class N extends b{constructor(e){super(),o(this,"_option"),o(this,"_isSelectedable"),o(this,"_isSelected"),o(this,"_content"),o(this,"_itemIcon"),o(this,"_title"),o(this,"_selectionIcon"),this._option=e.option,this._isSelected=e.isSelected,this._isSelectedable=e.selectable}static get id(){return"courier-inbox-option-menu-item"}onComponentMounted(){this._content=document.createElement("div"),this._content.className="menu-item",this._itemIcon=new S(this._option.icon.svg??k.inbox),this._itemIcon.setAttribute("size","16"),this._title=document.createElement("p"),this._title.textContent=this._option.text;const e=document.createElement("div");e.className="spacer",this._selectionIcon=new S(k.check),this._content.appendChild(this._itemIcon),this._content.appendChild(this._title),this._content.appendChild(e),this._isSelectedable&&this._content.appendChild(this._selectionIcon),this.appendChild(this._content),this._selectionIcon.style.display=this._isSelected?"block":"none",this.refreshTheme()}refreshTheme(){var e,t,n,i,o,s,l,r;null==(t=this._selectionIcon)||t.updateColor((null==(e=this._option.selectionIcon)?void 0:e.color)??"red"),null==(i=this._selectionIcon)||i.updateSVG((null==(n=this._option.selectionIcon)?void 0:n.svg)??k.check),this._title&&(this._title.textContent=this._option.text??"Missing Text"),null==(s=this._itemIcon)||s.updateColor((null==(o=this._option.icon)?void 0:o.color)??"red"),null==(r=this._itemIcon)||r.updateSVG((null==(l=this._option.icon)?void 0:l.svg)??k.inbox)}}$(N);class Z extends b{constructor(e,t,n,i,s){super(),o(this,"_themeSubscription"),o(this,"_type"),o(this,"_selectedIndex",0),o(this,"_options"),o(this,"_selectable"),o(this,"_onMenuOpen"),o(this,"_menuButton"),o(this,"_menu"),o(this,"_style"),this._type=t,this._selectable=n,this._options=i,this._selectedIndex=0,this._onMenuOpen=s,this._themeSubscription=e.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-option-menu"}onComponentMounted(){this._style=T(Z.id,this.getStyles()),this._menuButton=new E("filters"===this._type?k.filter:k.overflow),this._menu=document.createElement("div"),this._menu.className=`menu ${this._type}`,this.appendChild(this._menuButton),this.appendChild(this._menu),this._menuButton.addEventListener("click",this.toggleMenu.bind(this)),document.addEventListener("click",this.handleOutsideClick.bind(this)),this.refreshTheme()}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}getStyles(){var e,t,n,i,o,s,l,r,a,d,h,u,c,v,p,g,m,_,b,x,C,f,y,k,S,M,w,I,E,$,T,D,L,A,P,B,F,R,H,z,O,U,V,j,G,W,J,q,X,Y,K,Q,ee,te,ne;const ie=this._themeSubscription.manager.getTheme();return`\n ${Z.id} {\n position: relative;\n display: inline-block;\n }\n\n ${Z.id} .menu {\n display: none;\n position: absolute;\n top: 42px;\n right: -6px;\n border-radius: ${(null==(i=null==(n=null==(t=null==(e=ie.inbox)?void 0:e.header)?void 0:t.menus)?void 0:n.popup)?void 0:i.borderRadius)??"6px"};\n border: ${(null==(r=null==(l=null==(s=null==(o=ie.inbox)?void 0:o.header)?void 0:s.menus)?void 0:l.popup)?void 0:r.border)??"1px solid red"};\n background: ${(null==(u=null==(h=null==(d=null==(a=ie.inbox)?void 0:a.header)?void 0:d.menus)?void 0:h.popup)?void 0:u.backgroundColor)??"red"};\n box-shadow: ${(null==(g=null==(p=null==(v=null==(c=ie.inbox)?void 0:c.header)?void 0:v.menus)?void 0:p.popup)?void 0:g.shadow)??"0 4px 12px 0 red"};\n z-index: 1000;\n min-width: 200px;\n overflow: hidden;\n padding: 4px 0;\n }\n\n ${Z.id} courier-inbox-filter-menu-item {\n border-bottom: ${(null==(C=null==(x=null==(b=null==(_=null==(m=ie.inbox)?void 0:m.header)?void 0:_.menus)?void 0:b.popup)?void 0:x.list)?void 0:C.divider)??"none"};\n }\n\n ${Z.id} courier-inbox-filter-menu-item:last-child {\n border-bottom: none;\n }\n\n ${N.id} {\n display: flex;\n flex-direction: row;\n padding: 6px 12px;\n cursor: pointer;\n }\n\n ${N.id}:hover {\n background-color: ${(null==(M=null==(S=null==(k=null==(y=null==(f=ie.inbox)?void 0:f.header)?void 0:y.menus)?void 0:k.popup)?void 0:S.list)?void 0:M.hoverBackgroundColor)??"red"};\n }\n\n ${N.id}:active {\n background-color: ${(null==(T=null==($=null==(E=null==(I=null==(w=ie.inbox)?void 0:w.header)?void 0:I.menus)?void 0:E.popup)?void 0:$.list)?void 0:T.activeBackgroundColor)??"red"};\n }\n\n ${N.id} .menu-item {\n display: flex;\n align-items: center;\n width: 100%;\n gap: 12px;\n }\n\n ${N.id} .spacer {\n flex: 1;\n }\n\n ${N.id} p {\n margin: 0;\n font-family: ${(null==(F=null==(B=null==(P=null==(A=null==(L=null==(D=ie.inbox)?void 0:D.header)?void 0:L.menus)?void 0:A.popup)?void 0:P.list)?void 0:B.font)?void 0:F.family)??"inherit"};\n font-weight: ${(null==(V=null==(U=null==(O=null==(z=null==(H=null==(R=ie.inbox)?void 0:R.header)?void 0:H.menus)?void 0:z.popup)?void 0:O.list)?void 0:U.font)?void 0:V.weight)??"inherit"};\n font-size: ${(null==(X=null==(q=null==(J=null==(W=null==(G=null==(j=ie.inbox)?void 0:j.header)?void 0:G.menus)?void 0:W.popup)?void 0:J.list)?void 0:q.font)?void 0:X.size)??"14px"};\n color: ${(null==(ne=null==(te=null==(ee=null==(Q=null==(K=null==(Y=ie.inbox)?void 0:Y.header)?void 0:K.menus)?void 0:Q.popup)?void 0:ee.list)?void 0:te.font)?void 0:ne.color)??"red"};\n white-space: nowrap;\n }\n\n ${N.id} .check-icon {\n display: none;\n }\n `}refreshTheme(){var e,t,n,i,o,s,l,r,a,d,h;this._style&&(this._style.textContent=this.getStyles());const u=null==(t=null==(e=this._themeSubscription.manager.getTheme().inbox)?void 0:e.header)?void 0:t.menus,c="filters"===this._type,v=c?null==(n=null==u?void 0:u.filters)?void 0:n.button:null==(i=null==u?void 0:u.actions)?void 0:i.button,p=c?k.filter:k.overflow;null==(s=this._menuButton)||s.updateIconSVG((null==(o=null==v?void 0:v.icon)?void 0:o.svg)??p),null==(r=this._menuButton)||r.updateIconColor((null==(l=null==v?void 0:v.icon)?void 0:l.color)??"red"),null==(a=this._menuButton)||a.updateBackgroundColor((null==v?void 0:v.backgroundColor)??"transparent"),null==(d=this._menuButton)||d.updateHoverBackgroundColor((null==v?void 0:v.hoverBackgroundColor)??"red"),null==(h=this._menuButton)||h.updateActiveBackgroundColor((null==v?void 0:v.activeBackgroundColor)??"red"),this.refreshMenuItems()}setOptions(e){this._options=e,this.refreshMenuItems()}refreshMenuItems(){this._menu&&(this._menu.innerHTML=""),this._options.forEach(((e,t)=>{var n;const i=new N({option:e,selectable:this._selectable,isSelected:this._selectedIndex===t,themeManager:this._themeSubscription.manager});i.addEventListener("click",(()=>{this._selectedIndex=t,e.onClick(e),this.refreshMenuItems(),this.closeMenu()})),null==(n=this._menu)||n.appendChild(i)}))}toggleMenu(e){var t;e.stopPropagation();const n="block"!==(null==(t=this._menu)?void 0:t.style.display);this._menu&&(this._menu.style.display=n?"block":"none"),n&&this._onMenuOpen()}handleOutsideClick(e){this.contains(e.target)||this.closeMenu()}closeMenu(){this._menu&&(this._menu.style.display="none")}selectOption(e){this._selectedIndex=this._options.findIndex((t=>t.id===e.id)),this.refreshMenuItems()}}$(Z);class j extends b{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_location"),o(this,"_count",0),o(this,"_badge"),o(this,"_style"),this._location=e.location,this._themeSubscription=e.themeBus.subscribe((e=>{this.refreshTheme(this._location)}))}static get id(){return"courier-unread-count-badge"}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this._badge=document.createElement("span"),this._badge.className=`unread-badge ${this._location}`,this.appendChild(this._badge),this.updateBadge()}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}static getStyles(e){var t,n,i,o,s,l,r,a,d,h,u,c,v,p,g,m,_,b,x,C,f,y;return`\n ${j.id} {\n display: inline-block;\n }\n\n ${j.id} .unread-badge {\n padding: 3px 8px;\n font-size: 12px;\n text-align: center;\n display: none;\n pointer-events: none;\n }\n\n ${j.id} .header {\n background-color: ${null==(o=null==(i=null==(n=null==(t=e.inbox)?void 0:t.header)?void 0:n.filters)?void 0:i.unreadIndicator)?void 0:o.backgroundColor};\n color: ${null==(d=null==(a=null==(r=null==(l=null==(s=e.inbox)?void 0:s.header)?void 0:l.filters)?void 0:r.unreadIndicator)?void 0:a.font)?void 0:d.color};\n border-radius: ${null==(v=null==(c=null==(u=null==(h=e.inbox)?void 0:h.header)?void 0:u.filters)?void 0:c.unreadIndicator)?void 0:v.borderRadius};\n font-size: ${null==(b=null==(_=null==(m=null==(g=null==(p=e.inbox)?void 0:p.header)?void 0:g.filters)?void 0:m.unreadIndicator)?void 0:_.font)?void 0:b.size};\n padding: ${null==(y=null==(f=null==(C=null==(x=e.inbox)?void 0:x.header)?void 0:C.filters)?void 0:f.unreadIndicator)?void 0:y.padding};\n }\n `}setCount(e){this._count=e,this.updateBadge()}refreshTheme(e){this._location=e,this.updateBadge()}updateBadge(){this._badge&&(this._count>0?(this._badge.textContent=this._count>99?"99+":this._count.toString(),this._badge.style.display="block"):this._badge.style.display="none")}}$(j);class G extends b{constructor(e,t){super(),o(this,"_themeSubscription"),o(this,"_option"),o(this,"_feedType"),o(this,"_style"),o(this,"_titleElement"),o(this,"_iconElement"),o(this,"_unreadBadge"),this._option=t,this._themeSubscription=e.subscribe((e=>{this.refreshTheme(this._feedType??"inbox")}))}static get id(){return"courier-inbox-header-title"}get theme(){return this._themeSubscription.manager.getTheme()}static getStyles(e){var t,n,i,o,s,l,r,a,d,h,u,c,v,p,g,m;return`\n ${G.id} {\n display: flex;\n align-items: center;\n gap: 8px;\n position: relative;\n }\n\n ${G.id} courier-icon {\n display: flex;\n align-items: center;\n }\n\n ${G.id} h2 {\n margin: 0;\n font-family: ${(null==(o=null==(i=null==(n=null==(t=e.inbox)?void 0:t.header)?void 0:n.filters)?void 0:i.font)?void 0:o.family)??"inherit"};\n font-size: ${(null==(a=null==(r=null==(l=null==(s=e.inbox)?void 0:s.header)?void 0:l.filters)?void 0:r.font)?void 0:a.size)??"18px"};\n font-weight: ${(null==(c=null==(u=null==(h=null==(d=e.inbox)?void 0:d.header)?void 0:h.filters)?void 0:u.font)?void 0:c.weight)??"500"};\n color: ${(null==(m=null==(g=null==(p=null==(v=e.inbox)?void 0:v.header)?void 0:p.filters)?void 0:g.font)?void 0:m.color)??"red"};\n }\n\n ${G.id} courier-unread-count-badge {\n margin-left: 4px;\n }\n `}onComponentMounted(){this._style=T(G.id,G.getStyles(this.theme)),this._iconElement=new S(void 0,this._option.icon.svg),this._titleElement=document.createElement("h2"),this._unreadBadge=new j({themeBus:this._themeSubscription.manager,location:"header"}),this.appendChild(this._iconElement),this.appendChild(this._titleElement),this.appendChild(this._unreadBadge),this.refreshTheme(this._feedType??"inbox")}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}refreshTheme(e){var t;this._feedType=e,this._style&&(this._style.textContent=G.getStyles(this.theme)),null==(t=this._unreadBadge)||t.refreshTheme("header"),this.updateFilter()}updateSelectedOption(e,t,n){var i;this._option=e,this._feedType=t,null==(i=this._unreadBadge)||i.setCount(n),this.updateFilter()}updateFilter(){var e,t,n,i,o,s,l,r,a,d,h,u,c,v,p,g,m,_,b,x,C,f,y,S,M,w,I,E,$,T,D,L;const A=this._themeSubscription.manager.getTheme();switch(this._feedType){case"inbox":this._titleElement&&(this._titleElement.textContent=(null==(i=null==(n=null==(t=null==(e=A.inbox)?void 0:e.header)?void 0:t.filters)?void 0:n.inbox)?void 0:i.text)??"Inbox"),null==(d=this._iconElement)||d.updateSVG((null==(a=null==(r=null==(l=null==(s=null==(o=A.inbox)?void 0:o.header)?void 0:s.filters)?void 0:l.inbox)?void 0:r.icon)?void 0:a.svg)??k.inbox),null==(g=this._iconElement)||g.updateColor((null==(p=null==(v=null==(c=null==(u=null==(h=A.inbox)?void 0:h.header)?void 0:u.filters)?void 0:c.inbox)?void 0:v.icon)?void 0:p.color)??"red");break;case"archive":this._titleElement&&(this._titleElement.textContent=(null==(x=null==(b=null==(_=null==(m=A.inbox)?void 0:m.header)?void 0:_.filters)?void 0:b.archive)?void 0:x.text)??"Archive"),null==(w=this._iconElement)||w.updateSVG((null==(M=null==(S=null==(y=null==(f=null==(C=A.inbox)?void 0:C.header)?void 0:f.filters)?void 0:y.archive)?void 0:S.icon)?void 0:M.svg)??k.archive),null==(L=this._iconElement)||L.updateColor((null==(D=null==(T=null==($=null==(E=null==(I=A.inbox)?void 0:I.header)?void 0:E.filters)?void 0:$.archive)?void 0:T.icon)?void 0:D.color)??"red")}}}$(G);class W extends w{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_feedType","inbox"),o(this,"_unreadCount",0),o(this,"_titleSection"),o(this,"_filterMenu"),o(this,"_actionMenu"),o(this,"_style"),o(this,"_onFeedTypeChange"),this._themeSubscription=e.themeManager.subscribe((e=>{this.refreshTheme()})),this._onFeedTypeChange=e.onFeedTypeChange}static get id(){return"courier-inbox-header"}static get observedAttributes(){return["icon","title","feed-type"]}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this._style=T(W.id,W.getStyles(this.theme))}onComponentUmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}getFilterOptions(){var e,t,n,i,o,s,l,r,a,d,h,u,c,v,p,g,m,_,b,x,C,f,y,S,M,w,I,E,$,T,D,L,A,P,B,F,R;const H=this._themeSubscription.manager.getTheme(),z=null==(n=null==(t=null==(e=H.inbox)?void 0:e.header)?void 0:t.menus)?void 0:n.filters;return[{id:"inbox",text:(null==(i=null==z?void 0:z.inbox)?void 0:i.text)??"Inbox",icon:{color:(null==(s=null==(o=null==z?void 0:z.inbox)?void 0:o.icon)?void 0:s.color)??"red",svg:(null==(r=null==(l=null==z?void 0:z.inbox)?void 0:l.icon)?void 0:r.svg)??k.inbox},selectionIcon:{color:(null==(v=null==(c=null==(u=null==(h=null==(d=null==(a=H.inbox)?void 0:a.header)?void 0:d.menus)?void 0:h.popup)?void 0:u.list)?void 0:c.selectionIcon)?void 0:v.color)??"red",svg:(null==(x=null==(b=null==(_=null==(m=null==(g=null==(p=H.inbox)?void 0:p.header)?void 0:g.menus)?void 0:m.popup)?void 0:_.list)?void 0:b.selectionIcon)?void 0:x.svg)??k.check},onClick:e=>{this.handleOptionMenuItemClick("inbox",e)}},{id:"archive",text:(null==(C=null==z?void 0:z.archive)?void 0:C.text)??"Archive",icon:{color:(null==(y=null==(f=null==z?void 0:z.archive)?void 0:f.icon)?void 0:y.color)??"red",svg:(null==(M=null==(S=null==z?void 0:z.archive)?void 0:S.icon)?void 0:M.svg)??k.archive},selectionIcon:{color:(null==(D=null==(T=null==($=null==(E=null==(I=null==(w=H.inbox)?void 0:w.header)?void 0:I.menus)?void 0:E.popup)?void 0:$.list)?void 0:T.selectionIcon)?void 0:D.color)??"red",svg:(null==(R=null==(F=null==(B=null==(P=null==(A=null==(L=H.inbox)?void 0:L.header)?void 0:A.menus)?void 0:P.popup)?void 0:B.list)?void 0:F.selectionIcon)?void 0:R.svg)??k.check},onClick:e=>{this.handleOptionMenuItemClick("archive",e)}}]}getActionOptions(){var e,t,n,i,o,s,l,r,a,d,h,u,c,v,p,g,m,_;const b=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==b?void 0:b.markAllRead)?void 0:i.text)??"Mark All as Read",icon:{color:(null==(s=null==(o=null==b?void 0:b.markAllRead)?void 0:o.icon)?void 0:s.color)??"red",svg:(null==(r=null==(l=null==b?void 0:b.markAllRead)?void 0:l.icon)?void 0:r.svg)??k.inbox},selectionIcon:null,onClick:e=>{B.shared.readAllMessages({canCallApi:!0})}},{id:"archiveAll",text:(null==(a=null==b?void 0:b.archiveAll)?void 0:a.text)??"Archive All",icon:{color:(null==(h=null==(d=null==b?void 0:b.archiveAll)?void 0:d.icon)?void 0:h.color)??"red",svg:(null==(c=null==(u=null==b?void 0:b.archiveAll)?void 0:u.icon)?void 0:c.svg)??k.archive},selectionIcon:null,onClick:e=>{B.shared.archiveAllMessages({canCallApi:!0})}},{id:"archiveRead",text:(null==(v=null==b?void 0:b.archiveRead)?void 0:v.text)??"Archive Read",icon:{color:(null==(g=null==(p=null==b?void 0:b.archiveRead)?void 0:p.icon)?void 0:g.color)??"red",svg:(null==(_=null==(m=null==b?void 0:b.archiveRead)?void 0:m.icon)?void 0:_.svg)??k.archive},selectionIcon:null,onClick:e=>{B.shared.archiveReadMessages({canCallApi:!0})}}]}refreshTheme(){var e,t;this._style&&(this._style.textContent=W.getStyles(this.theme)),null==(e=this._filterMenu)||e.setOptions(this.getFilterOptions()),null==(t=this._actionMenu)||t.setOptions(this.getActionOptions())}handleOptionMenuItemClick(e,t){this._feedType=e,this._titleSection&&this._titleSection.updateSelectedOption(t,this._feedType,"inbox"===this._feedType?this._unreadCount:0),this._onFeedTypeChange(e)}render(e){var t,n;this._feedType=e.feedType,this._unreadCount=e.unreadCount;const i=this.getFilterOptions().find((e=>["inbox","archive"].includes(e.id)&&e.id===this._feedType));i&&(null==(t=this._titleSection)||t.updateSelectedOption(i,this._feedType,"inbox"===this._feedType?this._unreadCount:0),null==(n=this._filterMenu)||n.selectOption(i))}build(e){super.build(e),this.refreshTheme()}defaultElement(){const e=this.getFilterOptions();this._titleSection=new G(this._themeSubscription.manager,e[0]),this._filterMenu=new Z(this._themeSubscription.manager,"filters",!0,e,(()=>{var e;null==(e=this._actionMenu)||e.closeMenu()})),this._actionMenu=new Z(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="header-content",i.appendChild(this._titleSection),i.appendChild(t),i.appendChild(n),i}static getStyles(e){var t,n,i,o;return`\n ${W.id} {\n display: flex;\n align-items: center;\n flex-shrink: 0;\n }\n\n ${W.id} .header-content {\n padding: 10px 10px 10px 16px;\n background-color: ${(null==(n=null==(t=e.inbox)?void 0:t.header)?void 0:n.backgroundColor)??c[500]};\n box-shadow: ${(null==(o=null==(i=e.inbox)?void 0:i.header)?void 0:o.shadow)??"0px 1px 0px 0px red"};\n display: flex;\n align-items: center;\n justify-content: space-between;\n flex: 1;\n z-index: 100;\n }\n\n ${W.id} .spacer {\n flex: 1;\n }\n\n ${W.id} .actions {\n display: flex;\n align-items: center;\n gap: 4px;\n }\n `}}$(W);class J{constructor(e){o(this,"events"),this.events=e}remove(){B.shared.removeDataStoreListener(this)}}const q={popup:{button:{icon:{color:h[500],svg:k.inbox},backgroundColor:"transparent",hoverBackgroundColor:h[50010],activeBackgroundColor:h[50020],unreadDotIndicator:{backgroundColor:v[500],borderRadius:"50%",height:"8px",width:"8px"}},window:{backgroundColor:c[500],borderRadius:"8px",border:`1px solid ${u[500]}`,shadow:`0px 8px 16px -4px ${u[500]}`}},inbox:{header:{backgroundColor:c[500],shadow:`0px 1px 0px 0px ${u[500]}`,filters:{font:{color:h[500],family:void 0,size:"18px"},inbox:{icon:{color:h[500],svg:k.inbox},text:"Inbox"},archive:{icon:{color:h[500],svg:k.archive},text:"Archive"},unreadIndicator:{font:{color:c[500],family:void 0,size:"12px"},backgroundColor:v[500],borderRadius:"4px",padding:"2px 6px"}},menus:{popup:{backgroundColor:c[500],border:`1px solid ${u[500]}`,borderRadius:"4px",shadow:`0px 4px 8px -2px ${u[500]}`,list:{hoverBackgroundColor:u[200],activeBackgroundColor:u[500],divider:"none",font:{color:h[500],family:void 0,size:"14px"},selectionIcon:{color:h[500],svg:k.check}}},filters:{button:{icon:{color:h[500],svg:k.filter},backgroundColor:"transparent",hoverBackgroundColor:h[50010],activeBackgroundColor:h[50020]},inbox:{icon:{color:h[500],svg:k.inbox},text:"Inbox"},archive:{icon:{color:h[500],svg:k.archive},text:"Archive"}},actions:{button:{icon:{color:h[500],svg:k.overflow},backgroundColor:"transparent",hoverBackgroundColor:h[50010],activeBackgroundColor:h[50020]},markAllRead:{icon:{color:h[500],svg:k.read},text:"Read All"},archiveAll:{icon:{color:h[500],svg:k.archive},text:"Archive All"},archiveRead:{icon:{color:h[500],svg:k.archiveRead},text:"Archive Read"}}}},list:{backgroundColor:c[500],item:{backgroundColor:"transparent",unreadIndicatorColor:v[500],hoverBackgroundColor:u[200],activeBackgroundColor:u[500],actions:{backgroundColor:"transparent",hoverBackgroundColor:u[200],activeBackgroundColor:u[500],border:`1px solid ${u[500]}`,borderRadius:"4px",shadow:"0px 1px 2px 0px rgba(0, 0, 0, 0.06)",font:{color:h[500],family:void 0,size:"14px"}},title:{color:h[500],family:void 0,size:"14px"},subtitle:{color:u[600],family:void 0,size:"14px"},time:{color:u[600],family:void 0,size:"14px"},divider:`1px solid ${u[200]}`,menu:{enabled:!0,backgroundColor:c[500],border:`1px solid ${u[500]}`,borderRadius:"4px",shadow:`0px 2px 4px -2px ${u[500]}`,longPress:{displayDuration:4e3,vibrationDuration:50},item:{hoverBackgroundColor:u[200],activeBackgroundColor:u[500],borderRadius:"0px",read:{color:h[500],svg:k.read},unread:{color:h[500],svg:k.unread},archive:{color:h[500],svg:k.archive},unarchive:{color:h[500],svg:k.unarchive}}}}},loading:{animation:{barColor:u[500],barHeight:"14px",barBorderRadius:"14px",duration:"2s"},divider:`1px solid ${u[200]}`},empty:{title:{font:{size:"16px",weight:"500",color:h[500]}},button:{text:"Refresh"}},error:{title:{font:{size:"16px",weight:"500",color:h[500]}},button:{text:"Retry"}}}},X={popup:{button:{icon:{color:c[500],svg:k.inbox},backgroundColor:"transparent",hoverBackgroundColor:c[50010],activeBackgroundColor:c[50020],unreadDotIndicator:{backgroundColor:v[500],borderRadius:"50%",height:"8px",width:"8px"}},window:{backgroundColor:h[500],borderRadius:"8px",border:`1px solid ${u[400]}`,shadow:`0px 4px 8px -2px ${c[50020]}`}},inbox:{header:{backgroundColor:h[500],shadow:`0px 1px 0px 0px ${u[400]}`,filters:{font:{color:c[500],family:void 0,size:"18px"},inbox:{icon:{color:c[500],svg:k.inbox},text:"Inbox"},archive:{icon:{color:c[500],svg:k.archive},text:"Archive"},unreadIndicator:{font:{color:c[500],family:void 0,size:"12px"},backgroundColor:v[500],borderRadius:"4px",padding:"3px 8px"}},menus:{popup:{backgroundColor:h[500],border:`1px solid ${u[400]}`,borderRadius:"4px",shadow:`0px 4px 8px -2px ${c[50020]}`,list:{hoverBackgroundColor:c[50010],activeBackgroundColor:c[50020],divider:"none",font:{color:c[500],family:void 0,size:"14px"},selectionIcon:{color:c[500],svg:k.check}}},filters:{button:{icon:{color:c[500],svg:k.filter},backgroundColor:"transparent",hoverBackgroundColor:c[50010],activeBackgroundColor:c[50020]},inbox:{icon:{color:c[500],svg:k.inbox},text:"Inbox"},archive:{icon:{color:c[500],svg:k.archive},text:"Archive"}},actions:{button:{icon:{color:c[500],svg:k.overflow},backgroundColor:"transparent",hoverBackgroundColor:c[50010],activeBackgroundColor:c[50020]},markAllRead:{icon:{color:c[500],svg:k.read},text:"Read All"},archiveAll:{icon:{color:c[500],svg:k.archive},text:"Archive All"},archiveRead:{icon:{color:c[500],svg:k.archiveRead},text:"Archive Read"}}}},list:{backgroundColor:h[500],item:{backgroundColor:"transparent",unreadIndicatorColor:v[500],hoverBackgroundColor:c[50010],activeBackgroundColor:c[50020],actions:{backgroundColor:"transparent",hoverBackgroundColor:c[50010],activeBackgroundColor:c[50020],border:`1px solid ${u[400]}`,borderRadius:"4px",shadow:`0px 1px 2px 0px ${c[50010]}`,font:{color:c[500],family:void 0,size:"14px"}},title:{color:c[500],family:void 0,size:"14px"},subtitle:{color:u[500],family:void 0,size:"14px"},time:{color:u[500],family:void 0,size:"12px"},divider:`1px solid ${u[400]}`,menu:{enabled:!0,backgroundColor:h[500],border:`1px solid ${u[400]}`,borderRadius:"4px",shadow:`0px 2px 4px -2px ${c[50020]}`,longPress:{displayDuration:4e3,vibrationDuration:50},item:{hoverBackgroundColor:c[50010],activeBackgroundColor:c[50020],borderRadius:"0px",read:{color:c[500],svg:k.read},unread:{color:c[500],svg:k.unread},archive:{color:c[500],svg:k.archive},unarchive:{color:c[500],svg:k.unarchive}}}}},loading:{animation:{barColor:u[400],barHeight:"14px",barBorderRadius:"14px",duration:"2s"},divider:`1px solid ${u[400]}`},empty:{title:{font:{size:"16px",weight:"500",color:c[500]}},button:{text:"Refresh"}},error:{title:{font:{size:"16px",weight:"500",color:c[500]}},button:{text:"Retry"}}}},Y=(e,t)=>{var n,i,o,s,l,r,a,d,h,u,c,v,p,g,m,_,b,x,C,f,y,k,S,M,w,I,E,$,T,D,L,A,P,B,F,R,H,z,O,U,V,N,Z,j,G,W,J,Y,K,Q,ee,te,ne,ie,oe,se,le,re,ae,de,he,ue,ce,ve,pe,ge,me,_e,be,xe,Ce,fe,ye,ke,Se,Me,we,Ie,Ee,$e,Te,De,Le,Ae,Pe,Be,Fe,Re,He,ze,Oe,Ue,Ve,Ne,Ze,je,Ge,We,Je,qe,Xe,Ye,Ke,Qe,et,tt,nt,it,ot,st,lt,rt,at,dt,ht,ut,ct,vt,pt,gt,mt,_t,bt,xt,Ct,ft,yt,kt,St,Mt,wt,It,Et,$t,Tt,Dt,Lt,At,Pt,Bt,Ft,Rt,Ht,zt,Ot,Ut,Vt,Nt,Zt,jt,Gt,Wt,Jt,qt,Xt,Yt,Kt,Qt,en,tn,nn,on,sn,ln,rn,an,dn,hn,un,cn,vn,pn,gn,mn,_n,bn,xn,Cn,fn,yn,kn,Sn,Mn,wn,In,En,$n,Tn,Dn,Ln,An,Pn,Bn,Fn,Rn,Hn,zn,On,Un,Vn,Nn,Zn,jn,Gn,Wn,Jn,qn,Xn,Yn,Kn,Qn,ei,ti,ni,ii,oi,si,li,ri,ai,di,hi,ui,ci,vi,pi,gi,mi,_i,bi,xi,Ci,fi,yi,ki,Si,Mi,wi,Ii,Ei,$i,Ti,Di,Li,Ai,Pi,Bi,Fi,Ri,Hi,zi,Oi,Ui,Vi,Ni,Zi,ji,Gi;const Wi="light"===e?q:X;return{popup:{button:{...null==(n=Wi.popup)?void 0:n.button,...null==(i=t.popup)?void 0:i.button,icon:{...null==(s=null==(o=Wi.popup)?void 0:o.button)?void 0:s.icon,...null==(r=null==(l=t.popup)?void 0:l.button)?void 0:r.icon},unreadDotIndicator:{...null==(d=null==(a=Wi.popup)?void 0:a.button)?void 0:d.unreadDotIndicator,...null==(u=null==(h=t.popup)?void 0:h.button)?void 0:u.unreadDotIndicator}},window:{...null==(c=Wi.popup)?void 0:c.window,...null==(v=t.popup)?void 0:v.window}},inbox:{header:{...null==(p=Wi.inbox)?void 0:p.header,...null==(g=t.inbox)?void 0:g.header,filters:{...null==(_=null==(m=Wi.inbox)?void 0:m.header)?void 0:_.filters,...null==(x=null==(b=t.inbox)?void 0:b.header)?void 0:x.filters,inbox:{...null==(y=null==(f=null==(C=Wi.inbox)?void 0:C.header)?void 0:f.filters)?void 0:y.inbox,...null==(M=null==(S=null==(k=t.inbox)?void 0:k.header)?void 0:S.filters)?void 0:M.inbox,icon:{...null==($=null==(E=null==(I=null==(w=Wi.inbox)?void 0:w.header)?void 0:I.filters)?void 0:E.inbox)?void 0:$.icon,...null==(A=null==(L=null==(D=null==(T=t.inbox)?void 0:T.header)?void 0:D.filters)?void 0:L.inbox)?void 0:A.icon}},archive:{...null==(F=null==(B=null==(P=Wi.inbox)?void 0:P.header)?void 0:B.filters)?void 0:F.archive,...null==(z=null==(H=null==(R=t.inbox)?void 0:R.header)?void 0:H.filters)?void 0:z.archive,icon:{...null==(N=null==(V=null==(U=null==(O=Wi.inbox)?void 0:O.header)?void 0:U.filters)?void 0:V.archive)?void 0:N.icon,...null==(W=null==(G=null==(j=null==(Z=t.inbox)?void 0:Z.header)?void 0:j.filters)?void 0:G.archive)?void 0:W.icon}},unreadIndicator:{...null==(K=null==(Y=null==(J=Wi.inbox)?void 0:J.header)?void 0:Y.filters)?void 0:K.unreadIndicator,...null==(te=null==(ee=null==(Q=t.inbox)?void 0:Q.header)?void 0:ee.filters)?void 0:te.unreadIndicator}},menus:{...null==(ie=null==(ne=Wi.inbox)?void 0:ne.header)?void 0:ie.menus,...null==(se=null==(oe=t.inbox)?void 0:oe.header)?void 0:se.menus,popup:{...null==(ae=null==(re=null==(le=Wi.inbox)?void 0:le.header)?void 0:re.menus)?void 0:ae.popup,...null==(ue=null==(he=null==(de=t.inbox)?void 0:de.header)?void 0:he.menus)?void 0:ue.popup,list:{...null==(ge=null==(pe=null==(ve=null==(ce=Wi.inbox)?void 0:ce.header)?void 0:ve.menus)?void 0:pe.popup)?void 0:ge.list,...null==(xe=null==(be=null==(_e=null==(me=t.inbox)?void 0:me.header)?void 0:_e.menus)?void 0:be.popup)?void 0:xe.list,font:{...null==(Se=null==(ke=null==(ye=null==(fe=null==(Ce=Wi.inbox)?void 0:Ce.header)?void 0:fe.menus)?void 0:ye.popup)?void 0:ke.list)?void 0:Se.font,...null==($e=null==(Ee=null==(Ie=null==(we=null==(Me=t.inbox)?void 0:Me.header)?void 0:we.menus)?void 0:Ie.popup)?void 0:Ee.list)?void 0:$e.font},selectionIcon:{...null==(Pe=null==(Ae=null==(Le=null==(De=null==(Te=Wi.inbox)?void 0:Te.header)?void 0:De.menus)?void 0:Le.popup)?void 0:Ae.list)?void 0:Pe.selectionIcon,...null==(ze=null==(He=null==(Re=null==(Fe=null==(Be=t.inbox)?void 0:Be.header)?void 0:Fe.menus)?void 0:Re.popup)?void 0:He.list)?void 0:ze.selectionIcon}}},filters:{...null==(Ve=null==(Ue=null==(Oe=Wi.inbox)?void 0:Oe.header)?void 0:Ue.menus)?void 0:Ve.filters,...null==(je=null==(Ze=null==(Ne=t.inbox)?void 0:Ne.header)?void 0:Ze.menus)?void 0:je.filters,inbox:{...null==(qe=null==(Je=null==(We=null==(Ge=Wi.inbox)?void 0:Ge.header)?void 0:We.menus)?void 0:Je.filters)?void 0:qe.inbox,...null==(Qe=null==(Ke=null==(Ye=null==(Xe=t.inbox)?void 0:Xe.header)?void 0:Ye.menus)?void 0:Ke.filters)?void 0:Qe.inbox,icon:{...null==(ot=null==(it=null==(nt=null==(tt=null==(et=Wi.inbox)?void 0:et.header)?void 0:tt.menus)?void 0:nt.filters)?void 0:it.inbox)?void 0:ot.icon,...null==(dt=null==(at=null==(rt=null==(lt=null==(st=t.inbox)?void 0:st.header)?void 0:lt.menus)?void 0:rt.filters)?void 0:at.inbox)?void 0:dt.icon}},archive:{...null==(vt=null==(ct=null==(ut=null==(ht=Wi.inbox)?void 0:ht.header)?void 0:ut.menus)?void 0:ct.filters)?void 0:vt.archive,...null==(_t=null==(mt=null==(gt=null==(pt=t.inbox)?void 0:pt.header)?void 0:gt.menus)?void 0:mt.filters)?void 0:_t.archive,icon:{...null==(yt=null==(ft=null==(Ct=null==(xt=null==(bt=Wi.inbox)?void 0:bt.header)?void 0:xt.menus)?void 0:Ct.filters)?void 0:ft.archive)?void 0:yt.icon,...null==(It=null==(wt=null==(Mt=null==(St=null==(kt=t.inbox)?void 0:kt.header)?void 0:St.menus)?void 0:Mt.filters)?void 0:wt.archive)?void 0:It.icon}}},actions:{...null==(Tt=null==($t=null==(Et=Wi.inbox)?void 0:Et.header)?void 0:$t.menus)?void 0:Tt.actions,...null==(At=null==(Lt=null==(Dt=t.inbox)?void 0:Dt.header)?void 0:Lt.menus)?void 0:At.actions,markAllRead:{...null==(Rt=null==(Ft=null==(Bt=null==(Pt=Wi.inbox)?void 0:Pt.header)?void 0:Bt.menus)?void 0:Ft.actions)?void 0:Rt.markAllRead,...null==(Ut=null==(Ot=null==(zt=null==(Ht=t.inbox)?void 0:Ht.header)?void 0:zt.menus)?void 0:Ot.actions)?void 0:Ut.markAllRead,icon:{...null==(Gt=null==(jt=null==(Zt=null==(Nt=null==(Vt=Wi.inbox)?void 0:Vt.header)?void 0:Nt.menus)?void 0:Zt.actions)?void 0:jt.markAllRead)?void 0:Gt.icon,...null==(Yt=null==(Xt=null==(qt=null==(Jt=null==(Wt=t.inbox)?void 0:Wt.header)?void 0:Jt.menus)?void 0:qt.actions)?void 0:Xt.markAllRead)?void 0:Yt.icon}},archiveAll:{...null==(tn=null==(en=null==(Qt=null==(Kt=Wi.inbox)?void 0:Kt.header)?void 0:Qt.menus)?void 0:en.actions)?void 0:tn.archiveAll,...null==(ln=null==(sn=null==(on=null==(nn=t.inbox)?void 0:nn.header)?void 0:on.menus)?void 0:sn.actions)?void 0:ln.archiveAll,icon:{...null==(un=null==(hn=null==(dn=null==(an=null==(rn=Wi.inbox)?void 0:rn.header)?void 0:an.menus)?void 0:dn.actions)?void 0:hn.archiveAll)?void 0:un.icon,...null==(mn=null==(gn=null==(pn=null==(vn=null==(cn=t.inbox)?void 0:cn.header)?void 0:vn.menus)?void 0:pn.actions)?void 0:gn.archiveAll)?void 0:mn.icon}},archiveRead:{...null==(Cn=null==(xn=null==(bn=null==(_n=Wi.inbox)?void 0:_n.header)?void 0:bn.menus)?void 0:xn.actions)?void 0:Cn.archiveRead,...null==(Sn=null==(kn=null==(yn=null==(fn=t.inbox)?void 0:fn.header)?void 0:yn.menus)?void 0:kn.actions)?void 0:Sn.archiveRead,icon:{...null==($n=null==(En=null==(In=null==(wn=null==(Mn=Wi.inbox)?void 0:Mn.header)?void 0:wn.menus)?void 0:In.actions)?void 0:En.archiveRead)?void 0:$n.icon,...null==(Pn=null==(An=null==(Ln=null==(Dn=null==(Tn=t.inbox)?void 0:Tn.header)?void 0:Dn.menus)?void 0:Ln.actions)?void 0:An.archiveRead)?void 0:Pn.icon}}}}},list:{...null==(Bn=Wi.inbox)?void 0:Bn.list,...null==(Fn=t.inbox)?void 0:Fn.list,item:{...null==(Hn=null==(Rn=Wi.inbox)?void 0:Rn.list)?void 0:Hn.item,...null==(On=null==(zn=t.inbox)?void 0:zn.list)?void 0:On.item,menu:{...null==(Nn=null==(Vn=null==(Un=Wi.inbox)?void 0:Un.list)?void 0:Vn.item)?void 0:Nn.menu,...null==(Gn=null==(jn=null==(Zn=t.inbox)?void 0:Zn.list)?void 0:jn.item)?void 0:Gn.menu,item:{...null==(Xn=null==(qn=null==(Jn=null==(Wn=Wi.inbox)?void 0:Wn.list)?void 0:Jn.item)?void 0:qn.menu)?void 0:Xn.item,...null==(ei=null==(Qn=null==(Kn=null==(Yn=t.inbox)?void 0:Yn.list)?void 0:Kn.item)?void 0:Qn.menu)?void 0:ei.item,read:{...null==(si=null==(oi=null==(ii=null==(ni=null==(ti=Wi.inbox)?void 0:ti.list)?void 0:ni.item)?void 0:ii.menu)?void 0:oi.item)?void 0:si.read,...null==(hi=null==(di=null==(ai=null==(ri=null==(li=t.inbox)?void 0:li.list)?void 0:ri.item)?void 0:ai.menu)?void 0:di.item)?void 0:hi.read},unread:{...null==(gi=null==(pi=null==(vi=null==(ci=null==(ui=Wi.inbox)?void 0:ui.list)?void 0:ci.item)?void 0:vi.menu)?void 0:pi.item)?void 0:gi.unread,...null==(Ci=null==(xi=null==(bi=null==(_i=null==(mi=t.inbox)?void 0:mi.list)?void 0:_i.item)?void 0:bi.menu)?void 0:xi.item)?void 0:Ci.unread},archive:{...null==(Mi=null==(Si=null==(ki=null==(yi=null==(fi=Wi.inbox)?void 0:fi.list)?void 0:yi.item)?void 0:ki.menu)?void 0:Si.item)?void 0:Mi.archive,...null==(Ti=null==($i=null==(Ei=null==(Ii=null==(wi=t.inbox)?void 0:wi.list)?void 0:Ii.item)?void 0:Ei.menu)?void 0:$i.item)?void 0:Ti.archive},unarchive:{...null==(Bi=null==(Pi=null==(Ai=null==(Li=null==(Di=Wi.inbox)?void 0:Di.list)?void 0:Li.item)?void 0:Ai.menu)?void 0:Pi.item)?void 0:Bi.unarchive,...null==(Oi=null==(zi=null==(Hi=null==(Ri=null==(Fi=t.inbox)?void 0:Fi.list)?void 0:Ri.item)?void 0:Hi.menu)?void 0:zi.item)?void 0:Oi.unarchive}}}}},loading:{...null==(Ui=Wi.inbox)?void 0:Ui.loading,...null==(Vi=t.inbox)?void 0:Vi.loading},empty:{...null==(Ni=Wi.inbox)?void 0:Ni.empty,...null==(Zi=t.inbox)?void 0:Zi.empty},error:{...null==(ji=Wi.inbox)?void 0:ji.error,...null==(Gi=t.inbox)?void 0:Gi.error}}}};class K{constructor(e){o(this,"THEME_CHANGE_EVENT","courier_inbox_theme_change"),o(this,"_theme"),o(this,"_lightTheme",q),o(this,"_darkTheme",X),o(this,"_target"),o(this,"_subscriptions",[]),o(this,"_userMode"),o(this,"_systemMode"),o(this,"_systemThemeCleanup"),this._theme=e,this._target=new EventTarget,this._userMode="system",this._systemMode=g(),this.setLightTheme(q),this.setDarkTheme(X),this._systemThemeCleanup=m((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="light"===e?this._lightTheme:this._darkTheme,n=Y(e,t);this.setTheme(n)}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()}get mode(){return this._userMode}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=[]}}class Q extends b{constructor(e){super(),o(this,"_currentFeed","inbox"),o(this,"_themeManager"),o(this,"_inboxStyle"),o(this,"_unreadIndicatorStyle"),o(this,"_list"),o(this,"_datastoreListener"),o(this,"_authListener"),o(this,"_header"),o(this,"_headerFactory"),o(this,"_onMessageClick"),o(this,"_onMessageActionClick"),o(this,"_onMessageLongPress"),o(this,"_defaultProps",{title:"Inbox",icon:k.inbox,feedType:this._currentFeed,height:"auto"}),this._themeManager=e??new K(q)}static get id(){return"courier-inbox"}get currentFeed(){return this._currentFeed}get theme(){return this._themeManager.getTheme()}setLightTheme(e){this._themeManager.setLightTheme(e)}setDarkTheme(e){this._themeManager.setDarkTheme(e)}setMode(e){this._themeManager.setMode(e)}static get observedAttributes(){return["height","light-theme","dark-theme","mode","message-click","message-action-click","message-long-press"]}onComponentMounted(){var e,n;this._inboxStyle=T(Q.id,this.getStyles()),this._unreadIndicatorStyle=T(j.id,j.getStyles(this.theme)),this._header=new W({themeManager:this._themeManager,onFeedTypeChange:e=>{this.setFeedType(e)}}),this._header.build(void 0),this.appendChild(this._header),this._list=new V({themeManager:this._themeManager,canClickListItems:!1,canLongPressListItems:!1,onRefresh:()=>{this.refresh()},onPaginationTrigger:async e=>{var n,i;try{await B.shared.fetchNextPageOfMessages({feedType:e})}catch(o){null==(i=null==(n=t.Courier.shared.client)?void 0:n.options.logger)||i.error("Failed to fetch next page of messages:",o)}},onMessageClick:(e,t)=>{var n;B.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.refreshTheme(),this.appendChild(this._list),this._datastoreListener=new J({onError:e=>{var t;null==(t=this._list)||t.setError(e)},onDataSetChange:(e,t)=>{var n;this._currentFeed===t&&(null==(n=this._list)||n.setDataSet(e),this.updateHeader())},onPageAdded:(e,t)=>{var n;this._currentFeed===t&&(null==(n=this._list)||n.addPage(e),this.updateHeader())},onMessageAdd:(e,t,n)=>{var i;this._currentFeed===n&&(null==(i=this._list)||i.addMessage(e,t),this.updateHeader())},onMessageRemove:(e,t,n)=>{var i;this._currentFeed===n&&(null==(i=this._list)||i.removeMessage(t),this.updateHeader())},onMessageUpdate:(e,t,n)=>{var i;this._currentFeed===n&&(null==(i=this._list)||i.updateMessage(e,t),this.updateHeader())},onUnreadCountChange:e=>{this.updateHeader()}}),B.shared.addDataStoreListener(this._datastoreListener),this._themeManager.subscribe((e=>{this.refreshTheme()})),this._authListener=t.Courier.shared.addAuthenticationListener((e=>{this.refresh()})),(null==(e=t.Courier.shared.client)?void 0:e.options.userId)?this.refresh():null==(n=t.Courier.shared.client)||n.options.logger.error("No user signed in. Please call Courier.shared.signIn(...) to load the inbox.")}onComponentUnmounted(){var e,t,n,i;this._themeManager.cleanup(),null==(e=this._datastoreListener)||e.remove(),null==(t=this._authListener)||t.remove(),null==(n=this._inboxStyle)||n.remove(),null==(i=this._unreadIndicatorStyle)||i.remove()}refreshTheme(){var e;null==(e=this._list)||e.refreshInfoStateThemes(),this._inboxStyle&&(this._inboxStyle.textContent=this.getStyles()),this._unreadIndicatorStyle&&(this._unreadIndicatorStyle.textContent=j.getStyles(this.theme))}getStyles(){return`\n ${Q.id} {\n display: flex;\n flex-direction: column;\n width: 100%;\n height: ${this._defaultProps.height};\n }\n\n ${Q.id} courier-inbox-list {\n flex: 1;\n overflow-y: auto;\n overflow-x: hidden;\n }\n `}setHeader(e){this._headerFactory=e,this.updateHeader()}removeHeader(){this._headerFactory=null,this.updateHeader()}setLoadingState(e){var t;null==(t=this._list)||t.setLoadingStateFactory(e)}setEmptyState(e){var t;null==(t=this._list)||t.setEmptyStateFactory(e)}setErrorState(e){var t;null==(t=this._list)||t.setErrorStateFactory(e)}setListItem(e){var t;null==(t=this._list)||t.setListItemFactory(e)}setPaginationItem(e){var t;null==(t=this._list)||t.setPaginationItemFactory(e)}onMessageClick(e){var t;this._onMessageClick=e,null==(t=this._list)||t.setCanClickListItems(void 0!==e)}onMessageActionClick(e){this._onMessageActionClick=e}onMessageLongPress(e){var t;this._onMessageLongPress=e,null==(t=this._list)||t.setCanLongPressListItems(void 0!==e)}setFeedType(e){var t;this._currentFeed!==e&&(this._currentFeed=e,null==(t=this._list)||t.setFeedType(e),this.updateHeader(),this.load({canUseCache:!0}))}updateHeader(){var e,t,n,i;const o={feedType:this._currentFeed,unreadCount:B.shared.unreadCount,messageCount:(null==(e=this._list)?void 0:e.messages.length)??0};switch(this._headerFactory){case void 0:null==(t=this._header)||t.render(o);break;case null:null==(n=this._header)||n.build(null);break;default:const e=this._headerFactory(o);null==(i=this._header)||i.build(e)}}async load(e){await B.shared.load(e),await B.shared.listenForUpdates()}refresh(){this.load({canUseCache:!1})}attributeChangedCallback(e,n,i){var o,s,l,r,a,d;if(n!==i)switch(e){case"height":const e=i||this._defaultProps.height;this.style.height=e;break;case"message-click":if(i)try{this._onMessageClick=new Function("props",i)}catch(h){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Failed to parse message-click handler:",h)}else this._onMessageClick=void 0;break;case"message-action-click":if(i)try{this._onMessageActionClick=new Function("props",i)}catch(h){null==(r=null==(l=t.Courier.shared.client)?void 0:l.options.logger)||r.error("Failed to parse message-action-click handler:",h)}else this._onMessageActionClick=void 0;break;case"message-long-press":if(i)try{this._onMessageLongPress=new Function("props",i)}catch(h){null==(d=null==(a=t.Courier.shared.client)?void 0:a.options.logger)||d.error("Failed to parse message-long-press handler:",h)}else this._onMessageLongPress=void 0;break;case"light-theme":i&&this.setLightTheme(JSON.parse(i));break;case"dark-theme":i&&this.setDarkTheme(JSON.parse(i));break;case"mode":this._themeManager.setMode(i)}}}$(Q);class ee extends w{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_style"),o(this,"_container"),o(this,"_triggerButton"),o(this,"_unreadBadge"),this._themeSubscription=e.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-menu-button"}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this._style=T(ee.id,ee.getStyles(this.theme))}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}defaultElement(){return this._container=document.createElement("div"),this._container.className="menu-button-container",this._triggerButton=new E(k.inbox),this._unreadBadge=document.createElement("div"),this._unreadBadge.className="unread-badge",this._unreadBadge.style.display="none",this._container.appendChild(this._triggerButton),this._container.appendChild(this._unreadBadge),this.appendChild(this._container),this.refreshTheme(),this._container}static getStyles(e){var t,n,i,o,s,l,r,a,d,h,u,c;return`\n ${ee.id} .menu-button-container {\n position: relative;\n display: inline-block;\n }\n \n ${ee.id} .unread-badge {\n position: absolute;\n top: 2px;\n right: 2px;\n pointer-events: none;\n width: ${(null==(i=null==(n=null==(t=e.popup)?void 0:t.button)?void 0:n.unreadDotIndicator)?void 0:i.height)??"8px"};\n height: ${(null==(l=null==(s=null==(o=e.popup)?void 0:o.button)?void 0:s.unreadDotIndicator)?void 0:l.width)??"8px"};\n background: ${(null==(d=null==(a=null==(r=e.popup)?void 0:r.button)?void 0:a.unreadDotIndicator)?void 0:d.backgroundColor)??"red"};\n border-radius: ${(null==(c=null==(u=null==(h=e.popup)?void 0:h.button)?void 0:u.unreadDotIndicator)?void 0:c.borderRadius)??"50%"};\n display: none;\n z-index: 1;\n }\n `}onUnreadCountChange(e){this._unreadBadge&&(this._unreadBadge.style.display=e>0?"block":"none"),this.refreshTheme()}refreshTheme(){var e,t,n,i,o,s,l,r,a,d,u,c,v,p,g,m,_,b,x,C,f,y;null==(o=this._triggerButton)||o.updateIconColor((null==(i=null==(n=null==(t=null==(e=this.theme)?void 0:e.popup)?void 0:t.button)?void 0:n.icon)?void 0:i.color)??h[500]),null==(d=this._triggerButton)||d.updateIconSVG((null==(a=null==(r=null==(l=null==(s=this.theme)?void 0:s.popup)?void 0:l.button)?void 0:r.icon)?void 0:a.svg)??k.inbox),null==(p=this._triggerButton)||p.updateBackgroundColor((null==(v=null==(c=null==(u=this.theme)?void 0:u.popup)?void 0:c.button)?void 0:v.backgroundColor)??"transparent"),null==(b=this._triggerButton)||b.updateHoverBackgroundColor((null==(_=null==(m=null==(g=this.theme)?void 0:g.popup)?void 0:m.button)?void 0:_.hoverBackgroundColor)??h[50010]),null==(y=this._triggerButton)||y.updateActiveBackgroundColor((null==(f=null==(C=null==(x=this.theme)?void 0:x.popup)?void 0:C.button)?void 0:f.activeBackgroundColor)??h[50020])}}$(ee);class te extends b{constructor(){super(),o(this,"_width","440px"),o(this,"_height","440px"),o(this,"_popupAlignment","top-left"),o(this,"_top"),o(this,"_right"),o(this,"_bottom"),o(this,"_left"),o(this,"_themeManager",new K(q)),o(this,"_triggerButton"),o(this,"_popup"),o(this,"_inbox"),o(this,"_style"),o(this,"_datastoreListener"),o(this,"_popupMenuButtonFactory"),o(this,"handleOutsideClick",(e=>{if(!this._popup)return;const t=["courier-inbox-option-menu"];e.composedPath().some((e=>e instanceof HTMLElement&&(!(e!==this._popup&&!this._popup.contains(e))||t.some((t=>e.matches(t))))))||(this._popup.style.display="none")})),this._themeManager.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-popup-menu"}get theme(){return this._themeManager.getTheme()}get currentFeed(){var e;return(null==(e=this._inbox)?void 0:e.currentFeed)??"inbox"}setLightTheme(e){this._themeManager.setLightTheme(e)}setDarkTheme(e){this._themeManager.setDarkTheme(e)}setMode(e){this._themeManager.setMode(e)}static get observedAttributes(){return["popup-alignment","message-click","message-action-click","message-long-press","popup-width","popup-height","top","right","bottom","left","light-theme","dark-theme","mode"]}onComponentMounted(){this._style=T(te.id,te.getStyles(this.theme,this._width,this._height)),this._triggerButton=new ee(this._themeManager),this._triggerButton.build(void 0),this._popup=document.createElement("div"),this._popup.className="popup",this._inbox=new Q(this._themeManager),this._inbox.setAttribute("height","100%"),this.refreshTheme(),this.appendChild(this._triggerButton),this.appendChild(this._popup),this._popup.appendChild(this._inbox),this._triggerButton.addEventListener("click",this.togglePopup.bind(this)),document.addEventListener("click",this.handleOutsideClick.bind(this)),this.updatePopupPosition(),this._datastoreListener=new J(this),B.shared.addDataStoreListener(this._datastoreListener)}onComponentUnmounted(){var e,t;null==(e=this._style)||e.remove(),null==(t=this._datastoreListener)||t.remove(),this._themeManager.cleanup()}refreshTheme(){this._style&&(this._style.textContent=te.getStyles(this.theme,this._width,this._height))}static getStyles(e,t,n){var i,o,s,l,r,a,d,h;return`\n ${te.id} {\n display: inline-block;\n position: relative;\n }\n\n ${te.id} .menu-button-container {\n position: relative;\n display: inline-block;\n }\n\n ${te.id} .popup {\n display: none;\n position: absolute;\n background: ${(null==(o=null==(i=e.popup)?void 0:i.window)?void 0:o.backgroundColor)??"red"};\n border-radius: ${(null==(l=null==(s=e.popup)?void 0:s.window)?void 0:l.borderRadius)??"8px"};\n border: ${(null==(a=null==(r=e.popup)?void 0:r.window)?void 0:a.border)??"1px solid red"};\n box-shadow: ${(null==(h=null==(d=e.popup)?void 0:d.window)?void 0:h.shadow)??"0px 8px 16px -4px red"};\n z-index: 1000;\n width: ${t};\n height: ${n};\n overflow: hidden;\n transform: translateZ(0);\n will-change: transform;\n }\n \n ${te.id} #unread-badge {\n position: absolute;\n top: -8px;\n left: 50%;\n pointer-events: none;\n }\n\n ${te.id} 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){var t;null==(t=this._inbox)||t.onMessageClick((t=>{e&&e(t),this.closePopup()}))}onMessageActionClick(e){var t;null==(t=this._inbox)||t.onMessageActionClick((t=>{e&&e(t),this.closePopup()}))}onMessageLongPress(e){var t;null==(t=this._inbox)||t.onMessageLongPress((t=>{e&&e(t),this.closePopup()}))}isValidPosition(e){return["top-right","top-left","top-center","bottom-right","bottom-left","bottom-center","center-right","center-left","center-center"].includes(e)}updatePopupPosition(){if(this._popup)switch(this._popup.style.top="",this._popup.style.bottom="",this._popup.style.left="",this._popup.style.right="",this._popup.style.margin="",this._popup.style.transform="",this._popupAlignment){case"top-right":this._popup.style.top=this._top??"40px",this._popup.style.right=this._right??"0px";break;case"top-left":this._popup.style.top=this._top??"40px",this._popup.style.left=this._left??"0px";break;case"top-center":this._popup.style.top=this._top??"40px",this._popup.style.left="50%",this._popup.style.transform="translateX(-50%)";break;case"bottom-right":this._popup.style.bottom=this._bottom??"40px",this._popup.style.right=this._right??"0px";break;case"bottom-left":this._popup.style.bottom=this._bottom??"40px",this._popup.style.left=this._left??"0px";break;case"bottom-center":this._popup.style.bottom=this._bottom??"40px",this._popup.style.left="50%",this._popup.style.transform="translateX(-50%)";break;case"center-right":this._popup.style.top="50%",this._popup.style.right=this._right??"40px",this._popup.style.transform="translateY(-50%)";break;case"center-left":this._popup.style.top="50%",this._popup.style.left=this._left??"40px",this._popup.style.transform="translateY(-50%)";break;case"center-center":this._popup.style.top="50%",this._popup.style.left="50%",this._popup.style.transform="translate(-50%, -50%)"}}togglePopup(e){if(e.stopPropagation(),!this._popup)return;const t="block"===this._popup.style.display;this._popup.style.display=t?"none":"block"}closePopup(){this._popup&&(this._popup.style.display="none")}setContent(e){this._inbox&&(this._inbox.innerHTML="",this._inbox.appendChild(e))}setSize(e,t){this._width=e,this._height=t,this._popup&&(this._popup.style.width=e,this._popup.style.height=t)}setPosition(e){var n,i;this.isValidPosition(e)?(this._popupAlignment=e,this.updatePopupPosition()):null==(i=null==(n=t.Courier.shared.client)?void 0:n.options.logger)||i.error(`Invalid position: ${e}`)}setFeedType(e){var t;null==(t=this._inbox)||t.setFeedType(e)}setHeader(e){var t;null==(t=this._inbox)||t.setHeader(e)}removeHeader(){var e;null==(e=this._inbox)||e.removeHeader()}setLoadingState(e){var t;null==(t=this._inbox)||t.setLoadingState(e)}setEmptyState(e){var t;null==(t=this._inbox)||t.setEmptyState(e)}setErrorState(e){var t;null==(t=this._inbox)||t.setErrorState(e)}setListItem(e){var t;null==(t=this._inbox)||t.setListItem(e)}setPaginationItem(e){var t;null==(t=this._inbox)||t.setPaginationItem(e)}setMenuButton(e){this._popupMenuButtonFactory=e,this.render()}render(){const e=B.shared.unreadCount;if(this._triggerButton)switch(this._popupMenuButtonFactory){case void 0:case null:this._triggerButton.build(void 0),this._triggerButton.onUnreadCountChange(e);break;default:const t=this._popupMenuButtonFactory({unreadCount:e});this._triggerButton.build(t)}}}$(te);t.Courier.shared.courierUserAgentName="courier-ui-inbox",t.Courier.shared.courierUserAgentVersion="1.1.0",Object.defineProperty(e,"Courier",{enumerable:!0,get:()=>t.Courier}),e.CourierInbox=Q,e.CourierInboxDataStoreListener=J,e.CourierInboxDatastore=B,e.CourierInboxDatastoreEvents=class{onDataSetChange(e,t){}onPageAdded(e,t){}onUnreadCountChange(e){}onMessageAdd(e,t,n){}onMessageRemove(e,t,n){}onMessageUpdate(e,t,n){}onError(e){}},e.CourierInboxHeader=W,e.CourierInboxListItem=F,e.CourierInboxPopupMenu=te,e.CourierInboxThemeManager=K,e.archiveMessage=function(e){return B.shared.archiveMessage({message:e})},e.clickMessage=function(e){return B.shared.clickMessage({message:e})},e.defaultDarkTheme=X,e.defaultLightTheme=q,e.markAsRead=function(e){return B.shared.readMessage({message:e})},e.markAsUnread=function(e){return B.shared.unreadMessage({message:e})},e.mergeTheme=Y,e.openMessage=U,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@trycourier/courier-js"),require("@trycourier/courier-ui-core")):"function"==typeof define&&define.amd?define(["exports","@trycourier/courier-js","@trycourier/courier-ui-core"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CourierUIInbox={},e.CourierJS,e.CourierUICore)}(this,(function(e,t,i){"use strict";var n=Object.defineProperty,o=(e,t,i)=>((e,t,i)=>t in e?n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i)(e,"symbol"!=typeof t?t+"":t,i);function s(e){const t={...e};return e.actions&&(t.actions=e.actions.map((e=>function(e){const t={...e};e.data&&(t.data=JSON.parse(JSON.stringify(e.data)));return t}(e)))),e.data&&(t.data=JSON.parse(JSON.stringify(e.data))),e.tags&&(t.tags=[...e.tags]),e.trackingIds&&(t.trackingIds={...e.trackingIds}),t}function l(e){if(e)return{...e,messages:e.messages.map((e=>s(e)))}}class r extends i.CourierBaseElement{constructor(e){super(),o(this,"_theme"),o(this,"_options",[]),this._theme=e}static get id(){return"courier-inbox-list-item-menu"}onComponentMounted(){const e=document.createElement("ul");e.className="menu",this.appendChild(e)}static getStyles(e){var t,i,n;const o=null==(n=null==(i=null==(t=e.inbox)?void 0:t.list)?void 0:i.item)?void 0:n.menu;return`\n ${r.id} {\n display: none;\n position: absolute;\n background: ${(null==o?void 0:o.backgroundColor)??"red"};\n border: ${(null==o?void 0:o.border)??"1px solid red"};\n border-radius: ${(null==o?void 0:o.borderRadius)??"0px"};\n box-shadow: ${(null==o?void 0:o.shadow)??"0 2px 8px red"};\n user-select: none;\n opacity: 0;\n pointer-events: none;\n transition: opacity 0.15s;\n overflow: hidden;\n }\n\n ${r.id}.visible {\n display: block;\n opacity: 1;\n pointer-events: auto;\n }\n\n ${r.id} ul.menu {\n list-style: none;\n margin: 0;\n padding: 0;\n display: flex;\n flex-direction: row;\n }\n\n ${r.id} li.menu-item {\n display: flex;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n border-bottom: none;\n background: transparent;\n }\n `}setOptions(e){this._options=e,this.renderMenu()}renderMenu(){var e,t,n;const o=this.querySelector("ul.menu");if(!o)return;o.innerHTML="";const s=null==(n=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:n.menu,l=e=>{e.stopPropagation(),e.preventDefault()};this._options.forEach((e=>{var t,n,r;const a=new i.CourierIconButton(e.icon.svg,e.icon.color,null==s?void 0:s.backgroundColor,null==(t=null==s?void 0:s.item)?void 0:t.hoverBackgroundColor,null==(n=null==s?void 0:s.item)?void 0:n.activeBackgroundColor,null==(r=null==s?void 0:s.item)?void 0:r.borderRadius),d=t=>{l(t),e.onClick()};a.addEventListener("click",d),a.addEventListener("touchstart",l),a.addEventListener("touchend",d),a.addEventListener("touchmove",l),a.addEventListener("mousedown",l),a.addEventListener("mouseup",l),o.appendChild(a)}))}show(){this.style.display="block",this.classList.add("visible")}hide(){this.style.display="none",this.classList.remove("visible")}}i.registerElement(r);const a=class e{constructor(){o(this,"_inboxDataSet"),o(this,"_archiveDataSet"),o(this,"_dataStoreListeners",[]),o(this,"_unreadCount"),o(this,"isPaginatingInbox",!1),o(this,"isPaginatingArchive",!1)}static get shared(){return e.instance||(e.instance=new e),e.instance}get unreadCount(){return this._unreadCount??0}get inboxDataSet(){return this._inboxDataSet??{feedType:"inbox",messages:[],canPaginate:!1,paginationCursor:null}}get archiveDataSet(){return this._archiveDataSet??{feedType:"archive",messages:[],canPaginate:!1,paginationCursor:null}}addDataStoreListener(e){this._dataStoreListeners.push(e)}removeDataStoreListener(e){this._dataStoreListeners=this._dataStoreListeners.filter((t=>t!==e))}async fetchCachableDataSet(e){var t,i,n,o,s,l,r,a;if(e.canUseCache){if("inbox"===e.feedType&&this._inboxDataSet)return this._inboxDataSet;if("archive"===e.feedType&&this._archiveDataSet)return this._archiveDataSet}const d=await e.fetch;return{feedType:e.feedType,messages:(null==(i=null==(t=d.data)?void 0:t.messages)?void 0:i.nodes)??[],canPaginate:(null==(s=null==(o=null==(n=d.data)?void 0:n.messages)?void 0:o.pageInfo)?void 0:s.hasNextPage)??!1,paginationCursor:(null==(a=null==(r=null==(l=d.data)?void 0:l.messages)?void 0:r.pageInfo)?void 0:a.startCursor)??null}}async fetchUnreadCount(e){var i;if(e.canUseCache&&void 0!==this._unreadCount)return this._unreadCount;return await(null==(i=t.Courier.shared.client)?void 0:i.inbox.getUnreadMessageCount())??0}async load(e){var i,n;try{const i=t.Courier.shared.client;if(!(null==i?void 0:i.options.userId))throw new Error("User is not signed in");const n=e??{canUseCache:!0},[o,s,l]=await Promise.all([this.fetchCachableDataSet({fetch:i.inbox.getMessages(),feedType:"inbox",canUseCache:n.canUseCache}),this.fetchCachableDataSet({fetch:i.inbox.getArchivedMessages(),feedType:"archive",canUseCache:n.canUseCache}),this.fetchUnreadCount(n)]);this._inboxDataSet=o,this._archiveDataSet=s,this._unreadCount=l,this._dataStoreListeners.forEach((e=>{var t,i,n,o,s,l;this._inboxDataSet&&(null==(i=(t=e.events).onDataSetChange)||i.call(t,this._inboxDataSet,"inbox")),this._archiveDataSet&&(null==(o=(n=e.events).onDataSetChange)||o.call(n,this._archiveDataSet,"archive")),null==(l=(s=e.events).onUnreadCountChange)||l.call(s,this._unreadCount??0)}))}catch(o){null==(n=null==(i=t.Courier.shared.client)?void 0:i.options.logger)||n.error("Error loading inbox:",o),this._dataStoreListeners.forEach((e=>{var t,i;null==(i=(t=e.events).onError)||i.call(t,o)}))}}async listenForUpdates(){var e,i;try{await this.connectSocket()}catch(n){null==(i=null==(e=t.Courier.shared.client)?void 0:e.options.logger)||i.error("Error listening for updates:",n),this._dataStoreListeners.forEach((e=>{var t,i;null==(i=(t=e.events).onError)||i.call(t,n)}))}}async connectSocket(){var e,i,n,o,s,l,r,a,d,u,h;const c=null==(e=t.Courier.shared.client)?void 0:e.inbox.socket;try{if(!c)return void(null==(n=null==(i=t.Courier.shared.client)?void 0:i.options.logger)||n.info("CourierInbox socket not available"));if(c.addMessageEventListener((e=>{if(e.event===t.InboxMessageEvent.NewMessage){const t=e.data;return void this.addMessage(t,0,"inbox")}const i=this.getMessage({messageId:e.messageId});switch(e.event){case t.InboxMessageEvent.MarkAllRead:this.readAllMessages({canCallApi:!1});break;case t.InboxMessageEvent.Read:i&&this.readMessage({message:i,canCallApi:!1});break;case t.InboxMessageEvent.Unread:i&&this.unreadMessage({message:i,canCallApi:!1});break;case t.InboxMessageEvent.Opened:i&&this.openMessage({message:i,canCallApi:!1});break;case t.InboxMessageEvent.Archive:i&&this.archiveMessage({message:i,canCallApi:!1});break;case t.InboxMessageEvent.ArchiveRead:this.archiveReadMessages({canCallApi:!1});break;case t.InboxMessageEvent.ArchiveAll:this.archiveAllMessages({canCallApi:!1});break;case t.InboxMessageEvent.Clicked:i&&this.clickMessage({message:i,canCallApi:!1});break;case t.InboxMessageEvent.Unarchive:i&&this.unarchiveMessage({message:i,canCallApi:!1});case t.InboxMessageEvent.Unopened:}})),c.isConnecting||c.isOpen)return void(null==(l=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||l.info(`Inbox socket already connecting or open for client ID: [${null==(s=t.Courier.shared.client)?void 0:s.options.connectionId}]`));await c.connect(),null==(d=null==(r=t.Courier.shared.client)?void 0:r.options.logger)||d.info(`Inbox socket connected for client ID: [${null==(a=t.Courier.shared.client)?void 0:a.options.connectionId}]`)}catch(v){null==(h=null==(u=t.Courier.shared.client)?void 0:u.options.logger)||h.error("Failed to connect socket:",v)}}getMessage(e){var t,i;if(e.messageId)return(null==(t=this._inboxDataSet)?void 0:t.messages.find((t=>t.messageId===e.messageId)))??(null==(i=this._archiveDataSet)?void 0:i.messages.find((t=>t.messageId===e.messageId)))}async fetchNextPageOfMessages(e){var i,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,C,x,f,y,S,k,I;switch(e.feedType){case"inbox":if(this.isPaginatingInbox)return null;if((null==(i=this._inboxDataSet)?void 0:i.canPaginate)&&this._inboxDataSet.paginationCursor)try{this.isPaginatingInbox=!0;const e=await(null==(n=t.Courier.shared.client)?void 0:n.inbox.getMessages({paginationLimit:t.Courier.shared.paginationLimit,startCursor:this._inboxDataSet.paginationCursor})),i={feedType:"inbox",messages:(null==(s=null==(o=null==e?void 0:e.data)?void 0:o.messages)?void 0:s.nodes)??[],canPaginate:(null==(a=null==(r=null==(l=null==e?void 0:e.data)?void 0:l.messages)?void 0:r.pageInfo)?void 0:a.hasNextPage)??!1,paginationCursor:(null==(h=null==(u=null==(d=null==e?void 0:e.data)?void 0:d.messages)?void 0:u.pageInfo)?void 0:h.startCursor)??null};return this.addPage(i),i}catch(M){return null==(v=null==(c=t.Courier.shared.client)?void 0:c.options.logger)||v.error("Error fetching next page of inbox messages:",M),null}finally{this.isPaginatingInbox=!1}break;case"archive":if(this.isPaginatingArchive)return null;if((null==(p=this._archiveDataSet)?void 0:p.canPaginate)&&this._archiveDataSet.paginationCursor)try{this.isPaginatingArchive=!0;const e=await(null==(g=t.Courier.shared.client)?void 0:g.inbox.getArchivedMessages({paginationLimit:t.Courier.shared.paginationLimit,startCursor:this._archiveDataSet.paginationCursor})),i={feedType:"archive",messages:(null==(b=null==(m=null==e?void 0:e.data)?void 0:m.messages)?void 0:b.nodes)??[],canPaginate:(null==(x=null==(C=null==(_=null==e?void 0:e.data)?void 0:_.messages)?void 0:C.pageInfo)?void 0:x.hasNextPage)??!1,paginationCursor:(null==(S=null==(y=null==(f=null==e?void 0:e.data)?void 0:f.messages)?void 0:y.pageInfo)?void 0:S.startCursor)??null};return this.addPage(i),i}catch(M){return null==(I=null==(k=t.Courier.shared.client)?void 0:k.options.logger)||I.error("Error fetching next page of archived messages:",M),null}finally{this.isPaginatingArchive=!1}}return null}canMutate(){return!!(t.Courier.shared.client&&this._inboxDataSet&&this._archiveDataSet)}async readMessage({message:e,canCallApi:i=!0}){var n,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet),r=this.getMessageSnapshot(e);if(!r.message.read)try{r.message.read=(new Date).toISOString(),this.applyMessageSnapshot(r),this._unreadCount=l.unreadCount-1,this._dataStoreListeners.forEach((e=>{var t,i;null==(i=(t=e.events).onUnreadCountChange)||i.call(t,this._unreadCount)})),i&&await(null==(n=t.Courier.shared.client)?void 0:n.inbox.read({messageId:e.messageId}))}catch(a){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error reading message:",a),this.applyDatastoreSnapshot(l)}}async unreadMessage({message:e,canCallApi:i=!0}){var n,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet),r=this.getMessageSnapshot(e);if(r.message.read)try{r.message.read=void 0,this.applyMessageSnapshot(r),this._unreadCount=l.unreadCount+1,this._dataStoreListeners.forEach((e=>{var t,i;null==(i=(t=e.events).onUnreadCountChange)||i.call(t,this._unreadCount)})),i&&await(null==(n=t.Courier.shared.client)?void 0:n.inbox.unread({messageId:e.messageId}))}catch(a){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error unreading message:",a),this.applyDatastoreSnapshot(l)}}async openMessage({message:e,canCallApi:i=!0}){var n,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet),r=this.getMessageSnapshot(e);if((void 0!==r.inboxIndex||void 0!==r.archiveIndex)&&!r.message.opened)try{r.message.opened=(new Date).toISOString(),this.applyMessageSnapshot(r),i&&await(null==(n=t.Courier.shared.client)?void 0:n.inbox.open({messageId:e.messageId}))}catch(a){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error opening message:",a),this.applyDatastoreSnapshot(l)}}async clickMessage({message:e,canCallApi:i=!0}){var n,o,s,l,r;if(this.canMutate())try{(null==(n=e.trackingIds)?void 0:n.clickTrackingId)&&i&&await(null==(s=t.Courier.shared.client)?void 0:s.inbox.click({messageId:e.messageId,trackingId:null==(o=e.trackingIds)?void 0:o.clickTrackingId}))}catch(a){null==(r=null==(l=t.Courier.shared.client)?void 0:l.options.logger)||r.error("Error clicking message:",a)}}async archiveMessage({message:e,canCallApi:i=!0}){var n,o,s,l;if(!this.canMutate())return;const r=this.getMessageSnapshot(e);if(void 0===r.inboxIndex)return;const a=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{if(e.archived=(new Date).toISOString(),this.removeMessage(e,r.inboxIndex,"inbox"),null==(n=this._archiveDataSet)?void 0:n.messages){const t=this.findInsertIndex(e,this._archiveDataSet);this.addMessage(e,t,"archive")}i&&await(null==(o=t.Courier.shared.client)?void 0:o.inbox.archive({messageId:e.messageId}))}catch(d){null==(l=null==(s=t.Courier.shared.client)?void 0:s.options.logger)||l.error("Error archiving message:",d),this.applyDatastoreSnapshot(a)}}async unarchiveMessage({message:e,canCallApi:i=!0}){var n,o,s,l;if(!this.canMutate())return;const r=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet),a=this.getMessageSnapshot(e);if(void 0!==a.archiveIndex)try{if(a.message.archived=void 0,this.removeMessage(e,a.archiveIndex,"archive"),null==(n=this._inboxDataSet)?void 0:n.messages){const t=this.findInsertIndex(e,this._inboxDataSet);this.addMessage(e,t,"inbox")}i&&await(null==(o=t.Courier.shared.client)?void 0:o.inbox.unarchive({messageId:e.messageId}))}catch(d){null==(l=null==(s=t.Courier.shared.client)?void 0:s.options.logger)||l.error("Error unarchiving message:",d),this.applyDatastoreSnapshot(r)}}async archiveReadMessages({canCallApi:e=!0}={}){var i,n,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{const o=(new Date).toISOString();((null==(i=this._inboxDataSet)?void 0:i.messages.filter((e=>e.read)))??[]).forEach((e=>{var t,i,n;e.archived=o;const s=null==(t=this._inboxDataSet)?void 0:t.messages.findIndex((t=>t.messageId===e.messageId));if(void 0!==s&&-1!==s&&(null==(i=this._inboxDataSet)||i.messages.splice(s,1)),null==(n=this._archiveDataSet)?void 0:n.messages){const t=this.findInsertIndex(e,this._archiveDataSet);this._archiveDataSet.messages.splice(t,0,e)}})),this._dataStoreListeners.forEach((e=>{var t,i,n,o;this._inboxDataSet&&(null==(i=(t=e.events).onDataSetChange)||i.call(t,this._inboxDataSet,"inbox")),this._archiveDataSet&&(null==(o=(n=e.events).onDataSetChange)||o.call(n,this._archiveDataSet,"archive"))})),e&&await(null==(n=t.Courier.shared.client)?void 0:n.inbox.archiveRead())}catch(r){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error archiving read messages:",r),this.applyDatastoreSnapshot(l)}}async archiveAllMessages({canCallApi:e=!0}={}){var i,n,o,s;if(!this.canMutate())return;const l=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{const o=(new Date).toISOString();null==(i=this._inboxDataSet)||i.messages.forEach((e=>{var t;if(e.archived=o,null==(t=this._archiveDataSet)?void 0:t.messages){const t=this.findInsertIndex(e,this._archiveDataSet);this._archiveDataSet.messages.splice(t,0,e)}})),this._inboxDataSet={messages:[],canPaginate:!1,paginationCursor:null,feedType:"inbox"},this._unreadCount=0,this._dataStoreListeners.forEach((e=>{var t,i,n,o,s,l;this._inboxDataSet&&(null==(i=(t=e.events).onDataSetChange)||i.call(t,this._inboxDataSet,"inbox")),this._archiveDataSet&&(null==(o=(n=e.events).onDataSetChange)||o.call(n,this._archiveDataSet,"archive")),null==(l=(s=e.events).onUnreadCountChange)||l.call(s,this._unreadCount)})),e&&await(null==(n=t.Courier.shared.client)?void 0:n.inbox.archiveAll())}catch(r){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Error archiving all messages:",r),this.applyDatastoreSnapshot(l)}}async readAllMessages({canCallApi:e=!0}={}){var i,n,o,s,l;if(!this.canMutate())return;const r=this.getDatastoreSnapshot(this.unreadCount,this._inboxDataSet,this._archiveDataSet);try{const s=(new Date).toISOString();null==(i=this._inboxDataSet)||i.messages.forEach((e=>{e.read||(e.read=s)})),null==(n=this._archiveDataSet)||n.messages.forEach((e=>{e.read||(e.read=s)})),this._unreadCount=0,this._dataStoreListeners.forEach((e=>{var t,i,n,o,s,l;this._inboxDataSet&&(null==(i=(t=e.events).onDataSetChange)||i.call(t,this._inboxDataSet,"inbox")),this._archiveDataSet&&(null==(o=(n=e.events).onDataSetChange)||o.call(n,this._archiveDataSet,"archive")),null==(l=(s=e.events).onUnreadCountChange)||l.call(s,this._unreadCount)})),e&&await(null==(o=t.Courier.shared.client)?void 0:o.inbox.readAll())}catch(a){null==(l=null==(s=t.Courier.shared.client)?void 0:s.options.logger)||l.error("Error reading all messages:",a),this.applyDatastoreSnapshot(r)}}findInsertIndex(e,t){const i=t.messages;for(let n=0;n<i.length;n++){const t=i[n];if(t.created&&e.created&&t.created<e.created)return n}return i.length}addPage(e){switch(e.feedType){case"inbox":this._inboxDataSet&&(this._inboxDataSet.canPaginate=e.canPaginate,this._inboxDataSet.paginationCursor=e.paginationCursor,this._inboxDataSet.messages=[...this._inboxDataSet.messages,...e.messages]);break;case"archive":this._archiveDataSet&&(this._archiveDataSet.canPaginate=e.canPaginate,this._archiveDataSet.paginationCursor=e.paginationCursor,this._archiveDataSet.messages=[...this._archiveDataSet.messages,...e.messages])}this._dataStoreListeners.forEach((t=>{var i,n;return null==(n=(i=t.events).onPageAdded)?void 0:n.call(i,e,e.feedType)}))}addMessage(e,t,i){var n,o;switch(i){case"inbox":e.read||void 0===this._unreadCount||(this._unreadCount=this._unreadCount+1),null==(n=this._inboxDataSet)||n.messages.splice(t,0,e);break;case"archive":null==(o=this._archiveDataSet)||o.messages.splice(t,0,e)}this._dataStoreListeners.forEach((n=>{var o,s,l,r;null==(s=(o=n.events).onMessageAdd)||s.call(o,e,t,i),null==(r=(l=n.events).onUnreadCountChange)||r.call(l,this._unreadCount??0)}))}removeMessage(e,t,i){var n,o;switch(i){case"inbox":e.read||void 0===this._unreadCount||(this._unreadCount=this._unreadCount-1),null==(n=this._inboxDataSet)||n.messages.splice(t,1);break;case"archive":null==(o=this._archiveDataSet)||o.messages.splice(t,1)}this._dataStoreListeners.forEach((n=>{var o,s,l,r;null==(s=(o=n.events).onMessageRemove)||s.call(o,e,t,i),null==(r=(l=n.events).onUnreadCountChange)||r.call(l,this._unreadCount??0)}))}applyMessageSnapshot(e){void 0!==e.archiveIndex&&this.updateMessage(e.message,e.archiveIndex,"archive"),void 0!==e.inboxIndex&&this.updateMessage(e.message,e.inboxIndex,"inbox")}applyDatastoreSnapshot(e){const{unreadCount:t,inbox:i,archive:n}=e;this._inboxDataSet=i,this._archiveDataSet=n,this._dataStoreListeners.forEach((e=>{var i,n,o,s,l,r;this._inboxDataSet&&(null==(n=(i=e.events).onDataSetChange)||n.call(i,this._inboxDataSet,"inbox")),this._archiveDataSet&&(null==(s=(o=e.events).onDataSetChange)||s.call(o,this._archiveDataSet,"archive")),null==(r=(l=e.events).onUnreadCountChange)||r.call(l,t)}))}updateMessage(e,t,i){switch(i){case"inbox":this._inboxDataSet&&(this._inboxDataSet.messages[t]=e);break;case"archive":this._archiveDataSet&&(this._archiveDataSet.messages[t]=e)}this._dataStoreListeners.forEach((n=>{var o,s,l,r;null==(s=(o=n.events).onMessageUpdate)||s.call(o,e,t,i),null==(r=(l=n.events).onUnreadCountChange)||r.call(l,this._unreadCount??0)}))}getDatastoreSnapshot(e,t,i){return{unreadCount:e,inbox:l(t),archive:l(i)}}getMessageSnapshot(e){const t=this._archiveDataSet?this._archiveDataSet.messages.findIndex((t=>t.messageId===e.messageId)):void 0,i=this._inboxDataSet?this._inboxDataSet.messages.findIndex((t=>t.messageId===e.messageId)):void 0;return{message:s(e),archiveIndex:t,inboxIndex:i}}};o(a,"instance");let d=a;class u extends i.CourierBaseElement{constructor(e,t,i){super(),o(this,"_themeManager"),o(this,"_theme"),o(this,"_message",null),o(this,"_feedType","inbox"),o(this,"_isMobile",!1),o(this,"_canClick",!1),o(this,"_titleElement"),o(this,"_subtitleElement"),o(this,"_timeElement"),o(this,"_menu"),o(this,"_unreadIndicator"),o(this,"_actionsContainer"),o(this,"_longPressTimeout",null),o(this,"_isLongPress",!1),o(this,"_observer"),o(this,"onItemClick",null),o(this,"onItemLongPress",null),o(this,"onItemActionClick",null),o(this,"onItemVisible",null),this._canClick=t,this._themeManager=e,this._theme=e.getTheme(),this._isMobile="ontouchstart"in window,this.render(),this._setupIntersectionObserver()}static get id(){return"courier-inbox-list-item"}render(){const e=document.createElement("div");e.className="content-container",this._titleElement=document.createElement("p"),this._titleElement.className="title",this._subtitleElement=document.createElement("p"),this._subtitleElement.className="subtitle",this._actionsContainer=document.createElement("div"),this._actionsContainer.className="actions-container",e.appendChild(this._titleElement),e.appendChild(this._subtitleElement),e.appendChild(this._actionsContainer),this._timeElement=document.createElement("p"),this._timeElement.className="time",this._unreadIndicator=document.createElement("div"),this._unreadIndicator.className="unread-indicator",this._menu=new r(this._theme),this._menu.setOptions(this._getMenuOptions()),this.append(this._unreadIndicator,e,this._timeElement,this._menu);const t=e=>{e.stopPropagation(),e.preventDefault()};this._menu.addEventListener("mousedown",t),this._menu.addEventListener("pointerdown",t),this._menu.addEventListener("click",t),this.addEventListener("click",(e=>{this._canClick&&(this._menu&&(this._menu.contains(e.target)||e.composedPath().includes(this._menu))||!this._message||!this.onItemClick||e.target instanceof i.CourierIcon||this._isLongPress||this.onItemClick(this._message))})),this._setupHoverBehavior(),this._setupLongPressBehavior(),this._canClick&&this.classList.add("clickable")}_setupIntersectionObserver(){"undefined"!=typeof window&&"undefined"!=typeof IntersectionObserver&&(this._observer&&this._observer.disconnect(),this._observer=new IntersectionObserver((e=>{e.forEach((e=>{1===e.intersectionRatio&&this.onItemVisible&&this._message&&this.onItemVisible(this._message)}))}),{threshold:1}),this._observer.observe(this))}onComponentUnmounted(){var e;null==(e=this._observer)||e.disconnect()}static getStyles(e){var t,i,n,o,s,l,r,a,d,h,c,v,p,g,m,b,_,C,x,f,y,S,k,I,M,w;const E=null==(t=e.inbox)?void 0:t.list;return`\n ${u.id} {\n display: flex;\n flex-direction: row;\n align-items: flex-start;\n justify-content: space-between;\n border-bottom: ${(null==(i=null==E?void 0:E.item)?void 0:i.divider)??"1px solid red"};\n font-family: inherit;\n cursor: default;\n transition: background-color 0.2s ease;\n margin: 0;\n width: 100%;\n box-sizing: border-box;\n padding: 12px 20px;\n position: relative;\n background-color: ${(null==(n=null==E?void 0:E.item)?void 0:n.backgroundColor)??"transparent"};\n user-select: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n touch-action: manipulation;\n }\n\n /* Only apply hover/active background if clickable */\n @media (hover: hover) {\n ${u.id}.clickable:hover {\n cursor: pointer;\n background-color: ${(null==(o=null==E?void 0:E.item)?void 0:o.hoverBackgroundColor)??"red"};\n }\n }\n\n ${u.id}.clickable:active {\n cursor: pointer;\n background-color: ${(null==(s=null==E?void 0:E.item)?void 0:s.activeBackgroundColor)??"red"};\n }\n\n /* Menu hover / active */\n @media (hover: hover) {\n ${u.id}.clickable:hover:has(courier-inbox-list-item-menu:hover, courier-inbox-list-item-menu *:hover, courier-button:hover, courier-button *:hover) {\n background-color: ${(null==(l=null==E?void 0:E.item)?void 0:l.backgroundColor)??"transparent"};\n }\n }\n\n ${u.id}.clickable:active:has(courier-inbox-list-item-menu:active, courier-inbox-list-item-menu *:active, courier-button:active, courier-button *:active) {\n background-color: ${(null==(r=null==E?void 0:E.item)?void 0:r.backgroundColor)??"transparent"};\n }\n\n ${u.id}:last-child {\n border-bottom: none;\n }\n\n ${u.id} .unread-indicator {\n position: absolute;\n top: 28px;\n left: 6px;\n width: 8px;\n height: 8px;\n border-radius: 50%;\n background-color: ${(null==(a=null==E?void 0:E.item)?void 0:a.unreadIndicatorColor)??"red"};\n display: none;\n }\n\n ${u.id}.unread .unread-indicator {\n display: block;\n }\n\n ${u.id} .content-container {\n flex: 1;\n display: flex;\n flex-direction: column;\n margin-right: 12px;\n }\n\n ${u.id} p {\n margin: 0;\n overflow-wrap: break-word;\n word-break: break-word;\n hyphens: auto;\n line-height: 1.4;\n user-select: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n text-align: left;\n }\n\n ${u.id} .title {\n font-family: ${(null==(h=null==(d=null==E?void 0:E.item)?void 0:d.title)?void 0:h.family)??"inherit"};\n font-size: ${(null==(v=null==(c=null==E?void 0:E.item)?void 0:c.title)?void 0:v.size)??"14px"};\n color: ${(null==(g=null==(p=null==E?void 0:E.item)?void 0:p.title)?void 0:g.color)??"red"};\n margin-bottom: 4px;\n }\n\n ${u.id} .subtitle {\n font-family: ${(null==(b=null==(m=null==E?void 0:E.item)?void 0:m.subtitle)?void 0:b.family)??"inherit"};\n font-size: ${(null==(C=null==(_=null==E?void 0:E.item)?void 0:_.subtitle)?void 0:C.size)??"14px"};\n color: ${(null==(f=null==(x=null==E?void 0:E.item)?void 0:x.subtitle)?void 0:f.color)??"red"};\n }\n\n ${u.id} .time {\n font-family: ${(null==(S=null==(y=null==E?void 0:E.item)?void 0:y.time)?void 0:S.family)??"inherit"};\n font-size: ${(null==(I=null==(k=null==E?void 0:E.item)?void 0:k.time)?void 0:I.size)??"14px"};\n color: ${(null==(w=null==(M=null==E?void 0:E.item)?void 0:M.time)?void 0:w.color)??"red"};\n text-align: right;\n white-space: nowrap;\n }\n\n ${u.id} courier-inbox-list-item-menu {\n z-index: 1;\n position: absolute;\n top: 8px;\n right: 8px;\n display: none;\n }\n\n ${u.id} .actions-container {\n display: flex;\n margin-top: 10px;\n flex-wrap: wrap;\n flex-direction: row;\n align-items: center;\n gap: 8px;\n display: none;\n }\n `}_setupHoverBehavior(){this._isMobile||(this.addEventListener("mouseenter",(()=>{this._isLongPress=!1,this._showMenu()})),this.addEventListener("mouseleave",(()=>this._hideMenu())))}_setupLongPressBehavior(){var e,t,i;const n=null==(i=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:i.menu;if(!(null==n?void 0:n.enabled))return;const o=n.longPress;this.addEventListener("touchstart",(()=>{this._longPressTimeout=window.setTimeout((()=>{this._isLongPress=!0,this._showMenu(),this._message&&this.onItemLongPress&&(this.onItemLongPress(this._message),navigator.vibrate&&navigator.vibrate((null==o?void 0:o.vibrationDuration)??50)),setTimeout((()=>{this._hideMenu(),this._isLongPress=!1}),(null==o?void 0:o.displayDuration)??2e3)}),650)}),{passive:!0}),this.addEventListener("touchend",(()=>{this._longPressTimeout&&(window.clearTimeout(this._longPressTimeout),this._longPressTimeout=null)}))}_getMenuOptions(){var e,t,i,n,o,s,l,r,a,u,h,c,v,p,g;const m=null==(n=null==(i=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:i.menu)?void 0:n.item;let b=[];const _="archive"===this._feedType;return _||b.push({id:(null==(o=this._message)?void 0:o.read)?"unread":"read",icon:{svg:(null==(s=this._message)?void 0:s.read)?null==(l=null==m?void 0:m.unread)?void 0:l.svg:null==(r=null==m?void 0:m.read)?void 0:r.svg,color:(null==(a=this._message)?void 0:a.read)?null==(u=null==m?void 0:m.unread)?void 0:u.color:(null==(h=null==m?void 0:m.read)?void 0:h.color)??"red"},onClick:()=>{this._message&&(this._message.read?d.shared.unreadMessage({message:this._message}):d.shared.readMessage({message:this._message}))}}),b.push({id:_?"unarchive":"archive",icon:{svg:_?null==(c=null==m?void 0:m.unarchive)?void 0:c.svg:null==(v=null==m?void 0:m.archive)?void 0:v.svg,color:_?null==(p=null==m?void 0:m.unarchive)?void 0:p.color:(null==(g=null==m?void 0:m.archive)?void 0:g.color)??"red"},onClick:()=>{this._message&&(_?d.shared.unarchiveMessage({message:this._message}):d.shared.archiveMessage({message:this._message}))}}),b}_showMenu(){var e,t,i;const n=null==(i=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:i.menu;n&&n.enabled&&this._menu&&this._timeElement&&(this._menu.setOptions(this._getMenuOptions()),this._menu.style.display="block",this._menu.show(),this._timeElement.style.opacity="0")}_hideMenu(){var e,t,i;const n=null==(i=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:i.menu;n&&n.enabled&&this._menu&&this._timeElement&&(this._menu.hide(),this._menu.style.display="none",this._timeElement.style.opacity="1")}setMessage(e,t){this._message=e,this._feedType=t,this._updateContent()}setOnItemClick(e){this.onItemClick=e}setOnItemActionClick(e){this.onItemActionClick=e}setOnItemLongPress(e){this.onItemLongPress=e}setOnItemVisible(e){this.onItemVisible=e}_updateContent(){var e,t,n;if(!this._message)return this._titleElement&&(this._titleElement.textContent=""),void(this._subtitleElement&&(this._subtitleElement.textContent=""));this.classList.toggle("unread",!this._message.read&&"archive"!==this._feedType),this._titleElement&&(this._titleElement.textContent=this._message.title||"Untitled Message"),this._subtitleElement&&(this._subtitleElement.textContent=this._message.preview||this._message.body||""),this._timeElement&&(this._timeElement.textContent=function(e){if(!e.created)return"Now";const t=new Date,i=new Date(e.created),n=Math.floor((t.getTime()-i.getTime())/1e3);return n<5?"Now":n<60?`${n}s`:n<3600?`${Math.floor(n/60)}m`:n<86400?`${Math.floor(n/3600)}h`:n<604800?`${Math.floor(n/86400)}d`:n<31536e3?`${Math.floor(n/604800)}w`:`${Math.floor(n/31536e3)}y`}(this._message)),this._menu&&this._menu.setOptions(this._getMenuOptions());const o=this._message.actions&&this._message.actions.length>0;this._actionsContainer&&(this._actionsContainer.style.display=o?"flex":"none");const s=null==(n=null==(t=null==(e=this._theme.inbox)?void 0:e.list)?void 0:t.item)?void 0:n.actions;this._actionsContainer&&this._message.actions&&(this._actionsContainer.innerHTML="",this._message.actions.forEach((e=>{var t,n,o,l,r;const a=new i.CourierButton({mode:this._themeManager.mode,text:e.content,variant:"secondary",backgroundColor:null==s?void 0:s.backgroundColor,hoverBackgroundColor:null==s?void 0:s.hoverBackgroundColor,activeBackgroundColor:null==s?void 0:s.activeBackgroundColor,border:null==s?void 0:s.border,borderRadius:null==s?void 0:s.borderRadius,shadow:null==s?void 0:s.shadow,fontFamily:null==(t=null==s?void 0:s.font)?void 0:t.family,fontSize:null==(n=null==s?void 0:s.font)?void 0:n.size,fontWeight:null==(o=null==s?void 0:s.font)?void 0:o.weight,textColor:null==(l=null==s?void 0:s.font)?void 0:l.color,onClick:()=>{this._message&&this.onItemActionClick&&this.onItemActionClick(this._message,e)}});null==(r=this._actionsContainer)||r.appendChild(a)})))}}i.registerElement(u);class h extends i.CourierBaseElement{constructor(e){super(),o(this,"_theme"),o(this,"_style"),this._theme=e}static get id(){return"courier-inbox-skeleton-list-item"}onComponentMounted(){this._style=i.injectGlobalStyle(h.id,h.getStyles(this._theme)),this.render()}onComponentUnmounted(){var e;null==(e=this._style)||e.remove()}render(){const e=new c(this._theme),t=new c(this._theme),i=new c(this._theme);this.appendChild(e),this.appendChild(t),this.appendChild(i)}static getStyles(e){return`\n ${h.id} {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n width: 100%;\n box-sizing: border-box;\n }\n\n ${h.id} > *:first-child {\n width: 35%;\n }\n\n ${h.id} > *:nth-child(2) {\n width: 100%;\n }\n\n ${h.id} > *:nth-child(3) {\n width: 82%;\n }\n `}}i.registerElement(h);class c extends i.CourierBaseElement{constructor(e){super(),o(this,"_theme"),o(this,"_style"),this._theme=e}static get id(){return"courier-skeleton-animated-row"}onComponentMounted(){this._style=i.injectGlobalStyle(c.id,c.getStyles(this._theme)),this.render()}onComponentUnmounted(){var e;null==(e=this._style)||e.remove()}render(){const e=document.createElement("div");e.className="skeleton-item",this.appendChild(e)}static getStyles(e){var t,i,n,o,s,l,r,a,d,u,h,v;const p=(null==(n=null==(i=null==(t=e.inbox)?void 0:t.loading)?void 0:i.animation)?void 0:n.barColor)??"#000",g=4===p.length?`#${p[1]}${p[1]}${p[2]}${p[2]}${p[3]}${p[3]}`:p,m=parseInt(g.slice(1,3),16),b=parseInt(g.slice(3,5),16),_=parseInt(g.slice(5,7),16),C=`rgba(${m}, ${b}, ${_}, 0.8)`,x=`rgba(${m}, ${b}, ${_}, 0.4)`;return`\n ${c.id} {\n display: flex;\n height: 100%;\n width: 100%;\n align-items: flex-start;\n justify-content: flex-start;\n }\n\n ${c.id} .skeleton-item {\n height: ${(null==(l=null==(s=null==(o=e.inbox)?void 0:o.loading)?void 0:s.animation)?void 0:l.barHeight)??"14px"};\n width: 100%;\n background: linear-gradient(\n 90deg,\n ${C} 25%,\n ${x} 50%,\n ${C} 75%\n );\n background-size: 200% 100%;\n animation: ${c.id}-shimmer ${(null==(d=null==(a=null==(r=e.inbox)?void 0:r.loading)?void 0:a.animation)?void 0:d.duration)??"2s"} ease-in-out infinite;\n border-radius: ${(null==(v=null==(h=null==(u=e.inbox)?void 0:u.loading)?void 0:h.animation)?void 0:v.barBorderRadius)??"14px"};\n }\n\n @keyframes ${c.id}-shimmer {\n 0% {\n background-position: 200% 0;\n }\n 100% {\n background-position: -200% 0;\n }\n }\n `}}i.registerElement(c);class v extends i.CourierFactoryElement{constructor(e){super(),o(this,"_theme"),o(this,"_style"),this._theme=e}static get id(){return"courier-inbox-skeleton-list"}onComponentMounted(){this._style=i.injectGlobalStyle(v.id,v.getStyles(this._theme))}onComponentUnmounted(){var e;null==(e=this._style)||e.remove()}defaultElement(){const e=document.createElement("div");e.className="list";for(let t=0;t<3;t++){const t=new h(this._theme);e.appendChild(t)}return this.appendChild(e),e}static getStyles(e){var t,i,n,o;return`\n ${v.id} {\n display: flex;\n height: 100%;\n width: 100%;\n align-items: flex-start;\n justify-content: flex-start;\n overflow: hidden;\n }\n\n ${v.id} .list {\n display: flex;\n flex-direction: column;\n width: 100%;\n overflow: hidden;\n }\n\n ${v.id} .list > * {\n border-bottom: ${(null==(i=null==(t=e.inbox)?void 0:t.loading)?void 0:i.divider)??"1px solid red"};\n opacity: 100%;\n }\n\n ${v.id} .list > *:nth-child(2) {\n border-bottom: ${(null==(o=null==(n=e.inbox)?void 0:n.loading)?void 0:o.divider)??"1px solid red"};\n opacity: 88%;\n }\n\n ${v.id} .list > *:nth-child(3) {\n border-bottom: none;\n opacity: 50%;\n }\n `}}i.registerElement(v);class p extends i.CourierBaseElement{constructor(e){super(),o(this,"_theme"),o(this,"_style"),o(this,"_skeletonLoadingList"),o(this,"_observer"),o(this,"_customItem"),o(this,"_onPaginationTrigger"),this._theme=e.theme,this._customItem=e.customItem,this._onPaginationTrigger=e.onPaginationTrigger}static get id(){return"courier-inbox-pagination-list-item"}onComponentMounted(){if(this._style=i.injectGlobalStyle(p.id,p.getStyles(this._theme)),this._customItem)this.appendChild(this._customItem);else{const e=document.createElement("div");e.className="skeleton-container",this._skeletonLoadingList=new v(this._theme),this._skeletonLoadingList.build(void 0),e.appendChild(this._skeletonLoadingList),this.appendChild(e)}this._observer=new IntersectionObserver((e=>{e.forEach((e=>{e.isIntersecting&&this._onPaginationTrigger()}))})),this._observer.observe(this)}onComponentUnmounted(){var e,t;null==(e=this._observer)||e.disconnect(),null==(t=this._style)||t.remove()}static getStyles(e){return`\n ${p.id} {\n padding: 0;\n margin: 0;\n box-sizing: border-box;\n }\n\n ${p.id} .skeleton-container {\n height: 150%;\n }\n `}}function g(e){return d.shared.openMessage({message:e})}i.registerElement(p);class m extends i.CourierBaseElement{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_messages",[]),o(this,"_feedType","inbox"),o(this,"_isLoading",!0),o(this,"_error",null),o(this,"_canPaginate",!1),o(this,"_canClickListItems",!1),o(this,"_canLongPressListItems",!1),o(this,"_onMessageClick",null),o(this,"_onMessageActionClick",null),o(this,"_onMessageLongPress",null),o(this,"_onRefresh"),o(this,"_onPaginationTrigger"),o(this,"_listItemFactory"),o(this,"_paginationItemFactory"),o(this,"_loadingStateFactory"),o(this,"_emptyStateFactory"),o(this,"_errorStateFactory"),o(this,"_listStyles"),o(this,"_listItemStyles"),o(this,"_listItemMenuStyles"),o(this,"_errorContainer"),o(this,"_emptyContainer"),this._onRefresh=e.onRefresh,this._onPaginationTrigger=e.onPaginationTrigger,this._onMessageClick=e.onMessageClick,this._onMessageActionClick=e.onMessageActionClick,this._onMessageLongPress=e.onMessageLongPress,this._themeSubscription=e.themeManager.subscribe((e=>{this.render()}))}static get id(){return"courier-inbox-list"}get messages(){return this._messages}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this._listStyles=i.injectGlobalStyle(m.id,m.getStyles(this.theme)),this._listItemStyles=i.injectGlobalStyle(u.id,u.getStyles(this.theme)),this._listItemMenuStyles=i.injectGlobalStyle(r.id,r.getStyles(this.theme)),this.render()}onComponentUnmounted(){var e,t,i;this._themeSubscription.unsubscribe(),null==(e=this._listStyles)||e.remove(),null==(t=this._listItemStyles)||t.remove(),null==(i=this._listItemMenuStyles)||i.remove()}setCanClickListItems(e){this._canClickListItems=e}setCanLongPressListItems(e){this._canLongPressListItems=e}static getStyles(e){var t;const i=null==(t=e.inbox)?void 0:t.list;return`\n ${m.id} {\n flex: 1;\n width: 100%;\n background-color: ${(null==i?void 0:i.backgroundColor)??"red"};\n }\n\n ${m.id} ul {\n list-style: none;\n padding: 0;\n margin: 0;\n height: 100%;\n }\n `}setDataSet(e){this._messages=[...e.messages],this._canPaginate=Boolean(e.canPaginate),this._error=null,this._isLoading=!1,this.render()}addPage(e){this._messages=[...this._messages,...e.messages],this._canPaginate=Boolean(e.canPaginate),this._error=null,this._isLoading=!1,this.render()}addMessage(e,t=0){this._messages.splice(t,0,e),this.render()}removeMessage(e=0){this._messages.splice(e,1),this.render()}updateMessage(e,t=0){this._messages[t]=e,this.render()}setFeedType(e){this._feedType=e,this._error=null,this._isLoading=!0,this.render()}setLoading(e){this._error=null,this._isLoading=e,this.render()}setError(e){this._error=e,this._isLoading=!1,this._messages=[],this.render()}setErrorNoClient(){this.setError(new Error("No user signed in"))}handleRetry(){this._onRefresh()}handleRefresh(){this._onRefresh()}refreshInfoStateThemes(){var e,t;null==(e=this._emptyContainer)||e.updateStyles(this.errorProps),null==(t=this._emptyContainer)||t.updateStyles(this.emptyProps)}get errorProps(){var e,t,i,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,C,x,f,y,S,k,I;const M=null==(e=this.theme.inbox)?void 0:e.error,w=this._themeSubscription.manager.mode;return{title:{text:(null==(t=null==M?void 0:M.title)?void 0:t.text)??(null==(i=this._error)?void 0:i.message),textColor:null==(o=null==(n=null==M?void 0:M.title)?void 0:n.font)?void 0:o.color,fontFamily:null==(l=null==(s=null==M?void 0:M.title)?void 0:s.font)?void 0:l.family,fontSize:null==(a=null==(r=null==M?void 0:M.title)?void 0:r.font)?void 0:a.size,fontWeight:null==(u=null==(d=null==M?void 0:M.title)?void 0:d.font)?void 0:u.weight},button:{mode:w,text:null==(h=null==M?void 0:M.button)?void 0:h.text,backgroundColor:null==(c=null==M?void 0:M.button)?void 0:c.backgroundColor,hoverBackgroundColor:null==(v=null==M?void 0:M.button)?void 0:v.hoverBackgroundColor,activeBackgroundColor:null==(p=null==M?void 0:M.button)?void 0:p.activeBackgroundColor,textColor:null==(m=null==(g=null==M?void 0:M.button)?void 0:g.font)?void 0:m.color,fontFamily:null==(_=null==(b=null==M?void 0:M.button)?void 0:b.font)?void 0:_.family,fontSize:null==(x=null==(C=null==M?void 0:M.button)?void 0:C.font)?void 0:x.size,fontWeight:null==(y=null==(f=null==M?void 0:M.button)?void 0:f.font)?void 0:y.weight,shadow:null==(S=null==M?void 0:M.button)?void 0:S.shadow,border:null==(k=null==M?void 0:M.button)?void 0:k.border,borderRadius:null==(I=null==M?void 0:M.button)?void 0:I.borderRadius,onClick:()=>this.handleRetry()}}}get emptyProps(){var e,t,i,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,C,x,f,y,S,k;const I=null==(e=this.theme.inbox)?void 0:e.empty,M=this._themeSubscription.manager.mode;return{title:{text:(null==(t=null==I?void 0:I.title)?void 0:t.text)??`No ${this._feedType} messages yet`,textColor:null==(n=null==(i=null==I?void 0:I.title)?void 0:i.font)?void 0:n.color,fontFamily:null==(s=null==(o=null==I?void 0:I.title)?void 0:o.font)?void 0:s.family,fontSize:null==(r=null==(l=null==I?void 0:I.title)?void 0:l.font)?void 0:r.size,fontWeight:null==(d=null==(a=null==I?void 0:I.title)?void 0:a.font)?void 0:d.weight},button:{mode:M,text:null==(u=null==I?void 0:I.button)?void 0:u.text,backgroundColor:null==(h=null==I?void 0:I.button)?void 0:h.backgroundColor,hoverBackgroundColor:null==(c=null==I?void 0:I.button)?void 0:c.hoverBackgroundColor,activeBackgroundColor:null==(v=null==I?void 0:I.button)?void 0:v.activeBackgroundColor,textColor:null==(g=null==(p=null==I?void 0:I.button)?void 0:p.font)?void 0:g.color,fontFamily:null==(b=null==(m=null==I?void 0:I.button)?void 0:m.font)?void 0:b.family,fontSize:null==(C=null==(_=null==I?void 0:I.button)?void 0:_.font)?void 0:C.size,fontWeight:null==(f=null==(x=null==I?void 0:I.button)?void 0:x.font)?void 0:f.weight,shadow:null==(y=null==I?void 0:I.button)?void 0:y.shadow,border:null==(S=null==I?void 0:I.button)?void 0:S.border,borderRadius:null==(k=null==I?void 0:I.button)?void 0:k.borderRadius,onClick:()=>this.handleRefresh()}}}render(){for(var e,t,n,o;this.firstChild;)this.removeChild(this.firstChild),this._errorContainer=void 0,this._emptyContainer=void 0;if(this._listStyles&&(this._listStyles.textContent=m.getStyles(this.theme)),this._listItemStyles&&(this._listItemStyles.textContent=u.getStyles(this.theme)),this._listItemMenuStyles&&(this._listItemMenuStyles.textContent=r.getStyles(this.theme)),this._error)return this._errorContainer=new i.CourierInfoState(this.errorProps),this._errorContainer.build(null==(e=this._errorStateFactory)?void 0:e.call(this,{feedType:this._feedType,error:this._error})),void this.appendChild(this._errorContainer);if(this._isLoading){const e=new v(this.theme);return e.build(null==(t=this._loadingStateFactory)?void 0:t.call(this,{feedType:this._feedType})),void this.appendChild(e)}if(0===this._messages.length)return this._emptyContainer=new i.CourierInfoState(this.emptyProps),this._emptyContainer.build(null==(n=this._emptyStateFactory)?void 0:n.call(this,{feedType:this._feedType})),void this.appendChild(this._emptyContainer);const s=document.createElement("ul");if(this.appendChild(s),this._messages.forEach(((e,t)=>{if(this._listItemFactory)return void s.appendChild(this._listItemFactory({message:e,index:t}));const i=new u(this._themeSubscription.manager,this._canClickListItems,this._canLongPressListItems);i.setMessage(e,this._feedType),i.setOnItemClick((e=>{var i;return null==(i=this._onMessageClick)?void 0:i.call(this,e,t)})),i.setOnItemActionClick(((e,i)=>{var n;return null==(n=this._onMessageActionClick)?void 0:n.call(this,e,i,t)})),i.setOnItemLongPress((e=>{var i;return null==(i=this._onMessageLongPress)?void 0:i.call(this,e,t)})),i.setOnItemVisible((e=>this.openVisibleMessage(e))),s.appendChild(i)})),this._canPaginate){const e=new p({theme:this.theme,customItem:null==(o=this._paginationItemFactory)?void 0:o.call(this,{feedType:this._feedType}),onPaginationTrigger:()=>{var e;return null==(e=this._onPaginationTrigger)?void 0:e.call(this,this._feedType)}});s.appendChild(e)}}async openVisibleMessage(e){try{await g(e)}catch(t){}}setLoadingStateFactory(e){this._loadingStateFactory=e,this.render()}setEmptyStateFactory(e){this._emptyStateFactory=e,this.render()}setErrorStateFactory(e){this._errorStateFactory=e,this.render()}setListItemFactory(e){this._listItemFactory=e,this.render()}setPaginationItemFactory(e){this._paginationItemFactory=e,this.render()}}i.registerElement(m);class b extends i.CourierBaseElement{constructor(e){super(),o(this,"_option"),o(this,"_isSelectedable"),o(this,"_isSelected"),o(this,"_content"),o(this,"_itemIcon"),o(this,"_title"),o(this,"_selectionIcon"),this._option=e.option,this._isSelected=e.isSelected,this._isSelectedable=e.selectable}static get id(){return"courier-inbox-option-menu-item"}onComponentMounted(){this._content=document.createElement("div"),this._content.className="menu-item",this._itemIcon=new i.CourierIcon(this._option.icon.svg??i.CourierIconSVGs.inbox),this._itemIcon.setAttribute("size","16"),this._title=document.createElement("p"),this._title.textContent=this._option.text;const e=document.createElement("div");e.className="spacer",this._selectionIcon=new i.CourierIcon(i.CourierIconSVGs.check),this._content.appendChild(this._itemIcon),this._content.appendChild(this._title),this._content.appendChild(e),this._isSelectedable&&this._content.appendChild(this._selectionIcon),this.appendChild(this._content),this._selectionIcon.style.display=this._isSelected?"block":"none",this.refreshTheme()}refreshTheme(){var e,t,n,o,s,l,r,a;null==(t=this._selectionIcon)||t.updateColor((null==(e=this._option.selectionIcon)?void 0:e.color)??"red"),null==(o=this._selectionIcon)||o.updateSVG((null==(n=this._option.selectionIcon)?void 0:n.svg)??i.CourierIconSVGs.check),this._title&&(this._title.textContent=this._option.text??"Missing Text"),null==(l=this._itemIcon)||l.updateColor((null==(s=this._option.icon)?void 0:s.color)??"red"),null==(a=this._itemIcon)||a.updateSVG((null==(r=this._option.icon)?void 0:r.svg)??i.CourierIconSVGs.inbox)}}i.registerElement(b);class _ extends i.CourierBaseElement{constructor(e,t,i,n,s){super(),o(this,"_themeSubscription"),o(this,"_type"),o(this,"_selectedIndex",0),o(this,"_options"),o(this,"_selectable"),o(this,"_onMenuOpen"),o(this,"_menuButton"),o(this,"_menu"),o(this,"_style"),this._type=t,this._selectable=i,this._options=n,this._selectedIndex=0,this._onMenuOpen=s,this._themeSubscription=e.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-option-menu"}onComponentMounted(){this._style=i.injectGlobalStyle(_.id,this.getStyles()),this._menuButton=new i.CourierIconButton("filters"===this._type?i.CourierIconSVGs.filter:i.CourierIconSVGs.overflow),this._menu=document.createElement("div"),this._menu.className=`menu ${this._type}`,this.appendChild(this._menuButton),this.appendChild(this._menu),this._menuButton.addEventListener("click",this.toggleMenu.bind(this)),document.addEventListener("click",this.handleOutsideClick.bind(this)),this.refreshTheme()}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}getStyles(){var e,t,i,n,o,s,l,r,a,d,u,h,c,v,p,g,m,C,x,f,y,S,k,I,M,w,E,D,$,T,L,P,B,A,F,R,G,O,V,z,U,N,H,j,J,W,q,X,Y,Z,K,Q,ee,te,ie;const ne=this._themeSubscription.manager.getTheme();return`\n ${_.id} {\n position: relative;\n display: inline-block;\n }\n\n ${_.id} .menu {\n display: none;\n position: absolute;\n top: 42px;\n right: -6px;\n border-radius: ${(null==(n=null==(i=null==(t=null==(e=ne.inbox)?void 0:e.header)?void 0:t.menus)?void 0:i.popup)?void 0:n.borderRadius)??"6px"};\n border: ${(null==(r=null==(l=null==(s=null==(o=ne.inbox)?void 0:o.header)?void 0:s.menus)?void 0:l.popup)?void 0:r.border)??"1px solid red"};\n background: ${(null==(h=null==(u=null==(d=null==(a=ne.inbox)?void 0:a.header)?void 0:d.menus)?void 0:u.popup)?void 0:h.backgroundColor)??"red"};\n box-shadow: ${(null==(g=null==(p=null==(v=null==(c=ne.inbox)?void 0:c.header)?void 0:v.menus)?void 0:p.popup)?void 0:g.shadow)??"0 4px 12px 0 red"};\n z-index: 1000;\n min-width: 200px;\n overflow: hidden;\n padding: 4px 0;\n }\n\n ${_.id} courier-inbox-filter-menu-item {\n border-bottom: ${(null==(y=null==(f=null==(x=null==(C=null==(m=ne.inbox)?void 0:m.header)?void 0:C.menus)?void 0:x.popup)?void 0:f.list)?void 0:y.divider)??"none"};\n }\n\n ${_.id} courier-inbox-filter-menu-item:last-child {\n border-bottom: none;\n }\n\n ${b.id} {\n display: flex;\n flex-direction: row;\n padding: 6px 12px;\n cursor: pointer;\n }\n\n ${b.id}:hover {\n background-color: ${(null==(w=null==(M=null==(I=null==(k=null==(S=ne.inbox)?void 0:S.header)?void 0:k.menus)?void 0:I.popup)?void 0:M.list)?void 0:w.hoverBackgroundColor)??"red"};\n }\n\n ${b.id}:active {\n background-color: ${(null==(L=null==(T=null==($=null==(D=null==(E=ne.inbox)?void 0:E.header)?void 0:D.menus)?void 0:$.popup)?void 0:T.list)?void 0:L.activeBackgroundColor)??"red"};\n }\n\n ${b.id} .menu-item {\n display: flex;\n align-items: center;\n width: 100%;\n gap: 12px;\n }\n\n ${b.id} .spacer {\n flex: 1;\n }\n\n ${b.id} p {\n margin: 0;\n font-family: ${(null==(G=null==(R=null==(F=null==(A=null==(B=null==(P=ne.inbox)?void 0:P.header)?void 0:B.menus)?void 0:A.popup)?void 0:F.list)?void 0:R.font)?void 0:G.family)??"inherit"};\n font-weight: ${(null==(H=null==(N=null==(U=null==(z=null==(V=null==(O=ne.inbox)?void 0:O.header)?void 0:V.menus)?void 0:z.popup)?void 0:U.list)?void 0:N.font)?void 0:H.weight)??"inherit"};\n font-size: ${(null==(Y=null==(X=null==(q=null==(W=null==(J=null==(j=ne.inbox)?void 0:j.header)?void 0:J.menus)?void 0:W.popup)?void 0:q.list)?void 0:X.font)?void 0:Y.size)??"14px"};\n color: ${(null==(ie=null==(te=null==(ee=null==(Q=null==(K=null==(Z=ne.inbox)?void 0:Z.header)?void 0:K.menus)?void 0:Q.popup)?void 0:ee.list)?void 0:te.font)?void 0:ie.color)??"red"};\n white-space: nowrap;\n }\n\n ${b.id} .check-icon {\n display: none;\n }\n `}refreshTheme(){var e,t,n,o,s,l,r,a,d,u,h;this._style&&(this._style.textContent=this.getStyles());const c=null==(t=null==(e=this._themeSubscription.manager.getTheme().inbox)?void 0:e.header)?void 0:t.menus,v="filters"===this._type,p=v?null==(n=null==c?void 0:c.filters)?void 0:n.button:null==(o=null==c?void 0:c.actions)?void 0:o.button,g=v?i.CourierIconSVGs.filter:i.CourierIconSVGs.overflow;null==(l=this._menuButton)||l.updateIconSVG((null==(s=null==p?void 0:p.icon)?void 0:s.svg)??g),null==(a=this._menuButton)||a.updateIconColor((null==(r=null==p?void 0:p.icon)?void 0:r.color)??"red"),null==(d=this._menuButton)||d.updateBackgroundColor((null==p?void 0:p.backgroundColor)??"transparent"),null==(u=this._menuButton)||u.updateHoverBackgroundColor((null==p?void 0:p.hoverBackgroundColor)??"red"),null==(h=this._menuButton)||h.updateActiveBackgroundColor((null==p?void 0:p.activeBackgroundColor)??"red"),this.refreshMenuItems()}setOptions(e){this._options=e,this.refreshMenuItems()}refreshMenuItems(){this._menu&&(this._menu.innerHTML=""),this._options.forEach(((e,t)=>{var i;const n=new b({option:e,selectable:this._selectable,isSelected:this._selectedIndex===t,themeManager:this._themeSubscription.manager});n.addEventListener("click",(()=>{this._selectedIndex=t,e.onClick(e),this.refreshMenuItems(),this.closeMenu()})),null==(i=this._menu)||i.appendChild(n)}))}toggleMenu(e){var t;e.stopPropagation();const i="block"!==(null==(t=this._menu)?void 0:t.style.display);this._menu&&(this._menu.style.display=i?"block":"none"),i&&this._onMenuOpen()}handleOutsideClick(e){this.contains(e.target)||this.closeMenu()}closeMenu(){this._menu&&(this._menu.style.display="none")}selectOption(e){this._selectedIndex=this._options.findIndex((t=>t.id===e.id)),this.refreshMenuItems()}}i.registerElement(_);class C extends i.CourierBaseElement{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_location"),o(this,"_count",0),o(this,"_badge"),o(this,"_style"),this._location=e.location,this._themeSubscription=e.themeBus.subscribe((e=>{this.refreshTheme(this._location)}))}static get id(){return"courier-unread-count-badge"}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this._badge=document.createElement("span"),this._badge.className=`unread-badge ${this._location}`,this.appendChild(this._badge),this.updateBadge()}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}static getStyles(e){var t,i,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,x,f,y,S;return`\n ${C.id} {\n display: inline-block;\n }\n\n ${C.id} .unread-badge {\n padding: 3px 8px;\n font-size: 12px;\n text-align: center;\n display: none;\n pointer-events: none;\n }\n\n ${C.id} .header {\n background-color: ${null==(o=null==(n=null==(i=null==(t=e.inbox)?void 0:t.header)?void 0:i.filters)?void 0:n.unreadIndicator)?void 0:o.backgroundColor};\n color: ${null==(d=null==(a=null==(r=null==(l=null==(s=e.inbox)?void 0:s.header)?void 0:l.filters)?void 0:r.unreadIndicator)?void 0:a.font)?void 0:d.color};\n border-radius: ${null==(v=null==(c=null==(h=null==(u=e.inbox)?void 0:u.header)?void 0:h.filters)?void 0:c.unreadIndicator)?void 0:v.borderRadius};\n font-size: ${null==(_=null==(b=null==(m=null==(g=null==(p=e.inbox)?void 0:p.header)?void 0:g.filters)?void 0:m.unreadIndicator)?void 0:b.font)?void 0:_.size};\n padding: ${null==(S=null==(y=null==(f=null==(x=e.inbox)?void 0:x.header)?void 0:f.filters)?void 0:y.unreadIndicator)?void 0:S.padding};\n }\n `}setCount(e){this._count=e,this.updateBadge()}refreshTheme(e){this._location=e,this.updateBadge()}updateBadge(){this._badge&&(this._count>0?(this._badge.textContent=this._count>99?"99+":this._count.toString(),this._badge.style.display="block"):this._badge.style.display="none")}}i.registerElement(C);class x extends i.CourierBaseElement{constructor(e,t){super(),o(this,"_themeSubscription"),o(this,"_option"),o(this,"_feedType"),o(this,"_style"),o(this,"_titleElement"),o(this,"_iconElement"),o(this,"_unreadBadge"),this._option=t,this._themeSubscription=e.subscribe((e=>{this.refreshTheme(this._feedType??"inbox")}))}static get id(){return"courier-inbox-header-title"}get theme(){return this._themeSubscription.manager.getTheme()}static getStyles(e){var t,i,n,o,s,l,r,a,d,u,h,c,v,p,g,m;return`\n ${x.id} {\n display: flex;\n align-items: center;\n gap: 8px;\n position: relative;\n }\n\n ${x.id} courier-icon {\n display: flex;\n align-items: center;\n }\n\n ${x.id} h2 {\n margin: 0;\n font-family: ${(null==(o=null==(n=null==(i=null==(t=e.inbox)?void 0:t.header)?void 0:i.filters)?void 0:n.font)?void 0:o.family)??"inherit"};\n font-size: ${(null==(a=null==(r=null==(l=null==(s=e.inbox)?void 0:s.header)?void 0:l.filters)?void 0:r.font)?void 0:a.size)??"18px"};\n font-weight: ${(null==(c=null==(h=null==(u=null==(d=e.inbox)?void 0:d.header)?void 0:u.filters)?void 0:h.font)?void 0:c.weight)??"500"};\n color: ${(null==(m=null==(g=null==(p=null==(v=e.inbox)?void 0:v.header)?void 0:p.filters)?void 0:g.font)?void 0:m.color)??"red"};\n }\n\n ${x.id} courier-unread-count-badge {\n margin-left: 4px;\n }\n `}onComponentMounted(){this._style=i.injectGlobalStyle(x.id,x.getStyles(this.theme)),this._iconElement=new i.CourierIcon(void 0,this._option.icon.svg),this._titleElement=document.createElement("h2"),this._unreadBadge=new C({themeBus:this._themeSubscription.manager,location:"header"}),this.appendChild(this._iconElement),this.appendChild(this._titleElement),this.appendChild(this._unreadBadge),this.refreshTheme(this._feedType??"inbox")}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}refreshTheme(e){var t;this._feedType=e,this._style&&(this._style.textContent=x.getStyles(this.theme)),null==(t=this._unreadBadge)||t.refreshTheme("header"),this.updateFilter()}updateSelectedOption(e,t,i){var n;this._option=e,this._feedType=t,null==(n=this._unreadBadge)||n.setCount(i),this.updateFilter()}updateFilter(){var e,t,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,C,x,f,y,S,k,I,M,w,E,D,$,T,L;const P=this._themeSubscription.manager.getTheme();switch(this._feedType){case"inbox":this._titleElement&&(this._titleElement.textContent=(null==(o=null==(n=null==(t=null==(e=P.inbox)?void 0:e.header)?void 0:t.filters)?void 0:n.inbox)?void 0:o.text)??"Inbox"),null==(u=this._iconElement)||u.updateSVG((null==(d=null==(a=null==(r=null==(l=null==(s=P.inbox)?void 0:s.header)?void 0:l.filters)?void 0:r.inbox)?void 0:a.icon)?void 0:d.svg)??i.CourierIconSVGs.inbox),null==(m=this._iconElement)||m.updateColor((null==(g=null==(p=null==(v=null==(c=null==(h=P.inbox)?void 0:h.header)?void 0:c.filters)?void 0:v.inbox)?void 0:p.icon)?void 0:g.color)??"red");break;case"archive":this._titleElement&&(this._titleElement.textContent=(null==(x=null==(C=null==(_=null==(b=P.inbox)?void 0:b.header)?void 0:_.filters)?void 0:C.archive)?void 0:x.text)??"Archive"),null==(M=this._iconElement)||M.updateSVG((null==(I=null==(k=null==(S=null==(y=null==(f=P.inbox)?void 0:f.header)?void 0:y.filters)?void 0:S.archive)?void 0:k.icon)?void 0:I.svg)??i.CourierIconSVGs.archive),null==(L=this._iconElement)||L.updateColor((null==(T=null==($=null==(D=null==(E=null==(w=P.inbox)?void 0:w.header)?void 0:E.filters)?void 0:D.archive)?void 0:$.icon)?void 0:T.color)??"red")}}}i.registerElement(x);class f extends i.CourierFactoryElement{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_feedType","inbox"),o(this,"_unreadCount",0),o(this,"_titleSection"),o(this,"_filterMenu"),o(this,"_actionMenu"),o(this,"_style"),o(this,"_onFeedTypeChange"),this._themeSubscription=e.themeManager.subscribe((e=>{this.refreshTheme()})),this._onFeedTypeChange=e.onFeedTypeChange}static get id(){return"courier-inbox-header"}static get observedAttributes(){return["icon","title","feed-type"]}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this._style=i.injectGlobalStyle(f.id,f.getStyles(this.theme))}onComponentUmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}getFilterOptions(){var e,t,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,C,x,f,y,S,k,I,M,w,E,D,$,T,L,P,B,A,F,R;const G=this._themeSubscription.manager.getTheme(),O=null==(n=null==(t=null==(e=G.inbox)?void 0:e.header)?void 0:t.menus)?void 0:n.filters;return[{id:"inbox",text:(null==(o=null==O?void 0:O.inbox)?void 0:o.text)??"Inbox",icon:{color:(null==(l=null==(s=null==O?void 0:O.inbox)?void 0:s.icon)?void 0:l.color)??"red",svg:(null==(a=null==(r=null==O?void 0:O.inbox)?void 0:r.icon)?void 0:a.svg)??i.CourierIconSVGs.inbox},selectionIcon:{color:(null==(p=null==(v=null==(c=null==(h=null==(u=null==(d=G.inbox)?void 0:d.header)?void 0:u.menus)?void 0:h.popup)?void 0:c.list)?void 0:v.selectionIcon)?void 0:p.color)??"red",svg:(null==(x=null==(C=null==(_=null==(b=null==(m=null==(g=G.inbox)?void 0:g.header)?void 0:m.menus)?void 0:b.popup)?void 0:_.list)?void 0:C.selectionIcon)?void 0:x.svg)??i.CourierIconSVGs.check},onClick:e=>{this.handleOptionMenuItemClick("inbox",e)}},{id:"archive",text:(null==(f=null==O?void 0:O.archive)?void 0:f.text)??"Archive",icon:{color:(null==(S=null==(y=null==O?void 0:O.archive)?void 0:y.icon)?void 0:S.color)??"red",svg:(null==(I=null==(k=null==O?void 0:O.archive)?void 0:k.icon)?void 0:I.svg)??i.CourierIconSVGs.archive},selectionIcon:{color:(null==(T=null==($=null==(D=null==(E=null==(w=null==(M=G.inbox)?void 0:M.header)?void 0:w.menus)?void 0:E.popup)?void 0:D.list)?void 0:$.selectionIcon)?void 0:T.color)??"red",svg:(null==(R=null==(F=null==(A=null==(B=null==(P=null==(L=G.inbox)?void 0:L.header)?void 0:P.menus)?void 0:B.popup)?void 0:A.list)?void 0:F.selectionIcon)?void 0:R.svg)??i.CourierIconSVGs.check},onClick:e=>{this.handleOptionMenuItemClick("archive",e)}}]}getActionOptions(){var e,t,n,o,s,l,r,a,u,h,c,v,p,g,m,b,_,C;const x=null==(n=null==(t=null==(e=this._themeSubscription.manager.getTheme().inbox)?void 0:e.header)?void 0:t.menus)?void 0:n.actions;return[{id:"markAllRead",text:(null==(o=null==x?void 0:x.markAllRead)?void 0:o.text)??"Mark All as Read",icon:{color:(null==(l=null==(s=null==x?void 0:x.markAllRead)?void 0:s.icon)?void 0:l.color)??"red",svg:(null==(a=null==(r=null==x?void 0:x.markAllRead)?void 0:r.icon)?void 0:a.svg)??i.CourierIconSVGs.inbox},selectionIcon:null,onClick:e=>{d.shared.readAllMessages({canCallApi:!0})}},{id:"archiveAll",text:(null==(u=null==x?void 0:x.archiveAll)?void 0:u.text)??"Archive All",icon:{color:(null==(c=null==(h=null==x?void 0:x.archiveAll)?void 0:h.icon)?void 0:c.color)??"red",svg:(null==(p=null==(v=null==x?void 0:x.archiveAll)?void 0:v.icon)?void 0:p.svg)??i.CourierIconSVGs.archive},selectionIcon:null,onClick:e=>{d.shared.archiveAllMessages({canCallApi:!0})}},{id:"archiveRead",text:(null==(g=null==x?void 0:x.archiveRead)?void 0:g.text)??"Archive Read",icon:{color:(null==(b=null==(m=null==x?void 0:x.archiveRead)?void 0:m.icon)?void 0:b.color)??"red",svg:(null==(C=null==(_=null==x?void 0:x.archiveRead)?void 0:_.icon)?void 0:C.svg)??i.CourierIconSVGs.archive},selectionIcon:null,onClick:e=>{d.shared.archiveReadMessages({canCallApi:!0})}}]}refreshTheme(){var e,t;this._style&&(this._style.textContent=f.getStyles(this.theme)),null==(e=this._filterMenu)||e.setOptions(this.getFilterOptions()),null==(t=this._actionMenu)||t.setOptions(this.getActionOptions())}handleOptionMenuItemClick(e,t){this._feedType=e,this._titleSection&&this._titleSection.updateSelectedOption(t,this._feedType,"inbox"===this._feedType?this._unreadCount:0),this._onFeedTypeChange(e)}render(e){var t,i;this._feedType=e.feedType,this._unreadCount=e.unreadCount;const n=this.getFilterOptions().find((e=>["inbox","archive"].includes(e.id)&&e.id===this._feedType));n&&(null==(t=this._titleSection)||t.updateSelectedOption(n,this._feedType,"inbox"===this._feedType?this._unreadCount:0),null==(i=this._filterMenu)||i.selectOption(n))}build(e){super.build(e),this.refreshTheme()}defaultElement(){const e=this.getFilterOptions();this._titleSection=new x(this._themeSubscription.manager,e[0]),this._filterMenu=new _(this._themeSubscription.manager,"filters",!0,e,(()=>{var e;null==(e=this._actionMenu)||e.closeMenu()})),this._actionMenu=new _(this._themeSubscription.manager,"actions",!1,this.getActionOptions(),(()=>{var e;null==(e=this._filterMenu)||e.closeMenu()})),this._filterMenu.selectOption(e[0]);const t=document.createElement("div");t.className="spacer";const i=document.createElement("div");i.className="actions",i.appendChild(this._filterMenu),i.appendChild(this._actionMenu);const n=document.createElement("div");return n.className="header-content",n.appendChild(this._titleSection),n.appendChild(t),n.appendChild(i),n}static getStyles(e){var t,n,o,s;return`\n ${f.id} {\n display: flex;\n align-items: center;\n flex-shrink: 0;\n }\n\n ${f.id} .header-content {\n padding: 10px 10px 10px 16px;\n background-color: ${(null==(n=null==(t=e.inbox)?void 0:t.header)?void 0:n.backgroundColor)??i.CourierColors.white[500]};\n box-shadow: ${(null==(s=null==(o=e.inbox)?void 0:o.header)?void 0:s.shadow)??"0px 1px 0px 0px red"};\n display: flex;\n align-items: center;\n justify-content: space-between;\n flex: 1;\n z-index: 100;\n }\n\n ${f.id} .spacer {\n flex: 1;\n }\n\n ${f.id} .actions {\n display: flex;\n align-items: center;\n gap: 4px;\n }\n `}}i.registerElement(f);class y{constructor(e){o(this,"events"),this.events=e}remove(){d.shared.removeDataStoreListener(this)}}const S={popup:{button:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.inbox},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.black[50010],activeBackgroundColor:i.CourierColors.black[50020],unreadDotIndicator:{backgroundColor:i.CourierColors.blue[500],borderRadius:"50%",height:"8px",width:"8px"}},window:{backgroundColor:i.CourierColors.white[500],borderRadius:"8px",border:`1px solid ${i.CourierColors.gray[500]}`,shadow:`0px 8px 16px -4px ${i.CourierColors.gray[500]}`}},inbox:{header:{backgroundColor:i.CourierColors.white[500],shadow:`0px 1px 0px 0px ${i.CourierColors.gray[500]}`,filters:{font:{color:i.CourierColors.black[500],family:void 0,size:"18px"},inbox:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.inbox},text:"Inbox"},archive:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.archive},text:"Archive"},unreadIndicator:{font:{color:i.CourierColors.white[500],family:void 0,size:"12px"},backgroundColor:i.CourierColors.blue[500],borderRadius:"4px",padding:"2px 6px"}},menus:{popup:{backgroundColor:i.CourierColors.white[500],border:`1px solid ${i.CourierColors.gray[500]}`,borderRadius:"4px",shadow:`0px 4px 8px -2px ${i.CourierColors.gray[500]}`,list:{hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],divider:"none",font:{color:i.CourierColors.black[500],family:void 0,size:"14px"},selectionIcon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.check}}},filters:{button:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.filter},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.black[50010],activeBackgroundColor:i.CourierColors.black[50020]},inbox:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.inbox},text:"Inbox"},archive:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.archive},text:"Archive"}},actions:{button:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.overflow},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.black[50010],activeBackgroundColor:i.CourierColors.black[50020]},markAllRead:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.read},text:"Read All"},archiveAll:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.archive},text:"Archive All"},archiveRead:{icon:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.archiveRead},text:"Archive Read"}}}},list:{backgroundColor:i.CourierColors.white[500],item:{backgroundColor:"transparent",unreadIndicatorColor:i.CourierColors.blue[500],hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],actions:{backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],border:`1px solid ${i.CourierColors.gray[500]}`,borderRadius:"4px",shadow:"0px 1px 2px 0px rgba(0, 0, 0, 0.06)",font:{color:i.CourierColors.black[500],family:void 0,size:"14px"}},title:{color:i.CourierColors.black[500],family:void 0,size:"14px"},subtitle:{color:i.CourierColors.gray[600],family:void 0,size:"14px"},time:{color:i.CourierColors.gray[600],family:void 0,size:"14px"},divider:`1px solid ${i.CourierColors.gray[200]}`,menu:{enabled:!0,backgroundColor:i.CourierColors.white[500],border:`1px solid ${i.CourierColors.gray[500]}`,borderRadius:"4px",shadow:`0px 2px 4px -2px ${i.CourierColors.gray[500]}`,longPress:{displayDuration:4e3,vibrationDuration:50},item:{hoverBackgroundColor:i.CourierColors.gray[200],activeBackgroundColor:i.CourierColors.gray[500],borderRadius:"0px",read:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.read},unread:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.unread},archive:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.archive},unarchive:{color:i.CourierColors.black[500],svg:i.CourierIconSVGs.unarchive}}}}},loading:{animation:{barColor:i.CourierColors.gray[500],barHeight:"14px",barBorderRadius:"14px",duration:"2s"},divider:`1px solid ${i.CourierColors.gray[200]}`},empty:{title:{font:{size:"16px",weight:"500",color:i.CourierColors.black[500]}},button:{text:"Refresh"}},error:{title:{font:{size:"16px",weight:"500",color:i.CourierColors.black[500]}},button:{text:"Retry"}}}},k={popup:{button:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.inbox},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],unreadDotIndicator:{backgroundColor:i.CourierColors.blue[500],borderRadius:"50%",height:"8px",width:"8px"}},window:{backgroundColor:i.CourierColors.black[500],borderRadius:"8px",border:`1px solid ${i.CourierColors.gray[400]}`,shadow:`0px 4px 8px -2px ${i.CourierColors.white[50020]}`}},inbox:{header:{backgroundColor:i.CourierColors.black[500],shadow:`0px 1px 0px 0px ${i.CourierColors.gray[400]}`,filters:{font:{color:i.CourierColors.white[500],family:void 0,size:"18px"},inbox:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.inbox},text:"Inbox"},archive:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.archive},text:"Archive"},unreadIndicator:{font:{color:i.CourierColors.white[500],family:void 0,size:"12px"},backgroundColor:i.CourierColors.blue[500],borderRadius:"4px",padding:"3px 8px"}},menus:{popup:{backgroundColor:i.CourierColors.black[500],border:`1px solid ${i.CourierColors.gray[400]}`,borderRadius:"4px",shadow:`0px 4px 8px -2px ${i.CourierColors.white[50020]}`,list:{hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],divider:"none",font:{color:i.CourierColors.white[500],family:void 0,size:"14px"},selectionIcon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.check}}},filters:{button:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.filter},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020]},inbox:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.inbox},text:"Inbox"},archive:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.archive},text:"Archive"}},actions:{button:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.overflow},backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020]},markAllRead:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.read},text:"Read All"},archiveAll:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.archive},text:"Archive All"},archiveRead:{icon:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.archiveRead},text:"Archive Read"}}}},list:{backgroundColor:i.CourierColors.black[500],item:{backgroundColor:"transparent",unreadIndicatorColor:i.CourierColors.blue[500],hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],actions:{backgroundColor:"transparent",hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],border:`1px solid ${i.CourierColors.gray[400]}`,borderRadius:"4px",shadow:`0px 1px 2px 0px ${i.CourierColors.white[50010]}`,font:{color:i.CourierColors.white[500],family:void 0,size:"14px"}},title:{color:i.CourierColors.white[500],family:void 0,size:"14px"},subtitle:{color:i.CourierColors.gray[500],family:void 0,size:"14px"},time:{color:i.CourierColors.gray[500],family:void 0,size:"12px"},divider:`1px solid ${i.CourierColors.gray[400]}`,menu:{enabled:!0,backgroundColor:i.CourierColors.black[500],border:`1px solid ${i.CourierColors.gray[400]}`,borderRadius:"4px",shadow:`0px 2px 4px -2px ${i.CourierColors.white[50020]}`,longPress:{displayDuration:4e3,vibrationDuration:50},item:{hoverBackgroundColor:i.CourierColors.white[50010],activeBackgroundColor:i.CourierColors.white[50020],borderRadius:"0px",read:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.read},unread:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.unread},archive:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.archive},unarchive:{color:i.CourierColors.white[500],svg:i.CourierIconSVGs.unarchive}}}}},loading:{animation:{barColor:i.CourierColors.gray[400],barHeight:"14px",barBorderRadius:"14px",duration:"2s"},divider:`1px solid ${i.CourierColors.gray[400]}`},empty:{title:{font:{size:"16px",weight:"500",color:i.CourierColors.white[500]}},button:{text:"Refresh"}},error:{title:{font:{size:"16px",weight:"500",color:i.CourierColors.white[500]}},button:{text:"Retry"}}}},I=(e,t)=>{var i,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,C,x,f,y,I,M,w,E,D,$,T,L,P,B,A,F,R,G,O,V,z,U,N,H,j,J,W,q,X,Y,Z,K,Q,ee,te,ie,ne,oe,se,le,re,ae,de,ue,he,ce,ve,pe,ge,me,be,_e,Ce,xe,fe,ye,Se,ke,Ie,Me,we,Ee,De,$e,Te,Le,Pe,Be,Ae,Fe,Re,Ge,Oe,Ve,ze,Ue,Ne,He,je,Je,We,qe,Xe,Ye,Ze,Ke,Qe,et,tt,it,nt,ot,st,lt,rt,at,dt,ut,ht,ct,vt,pt,gt,mt,bt,_t,Ct,xt,ft,yt,St,kt,It,Mt,wt,Et,Dt,$t,Tt,Lt,Pt,Bt,At,Ft,Rt,Gt,Ot,Vt,zt,Ut,Nt,Ht,jt,Jt,Wt,qt,Xt,Yt,Zt,Kt,Qt,ei,ti,ii,ni,oi,si,li,ri,ai,di,ui,hi,ci,vi,pi,gi,mi,bi,_i,Ci,xi,fi,yi,Si,ki,Ii,Mi,wi,Ei,Di,$i,Ti,Li,Pi,Bi,Ai,Fi,Ri,Gi,Oi,Vi,zi,Ui,Ni,Hi,ji,Ji,Wi,qi,Xi,Yi,Zi,Ki,Qi,en,tn,nn,on,sn,ln,rn,an,dn,un,hn,cn,vn,pn,gn,mn,bn,_n,Cn,xn,fn,yn,Sn,kn,In,Mn,wn,En,Dn,$n,Tn,Ln,Pn,Bn,An,Fn,Rn,Gn,On,Vn,zn,Un,Nn,Hn,jn,Jn;const Wn="light"===e?S:k;return{popup:{button:{...null==(i=Wn.popup)?void 0:i.button,...null==(n=t.popup)?void 0:n.button,icon:{...null==(s=null==(o=Wn.popup)?void 0:o.button)?void 0:s.icon,...null==(r=null==(l=t.popup)?void 0:l.button)?void 0:r.icon},unreadDotIndicator:{...null==(d=null==(a=Wn.popup)?void 0:a.button)?void 0:d.unreadDotIndicator,...null==(h=null==(u=t.popup)?void 0:u.button)?void 0:h.unreadDotIndicator}},window:{...null==(c=Wn.popup)?void 0:c.window,...null==(v=t.popup)?void 0:v.window}},inbox:{header:{...null==(p=Wn.inbox)?void 0:p.header,...null==(g=t.inbox)?void 0:g.header,filters:{...null==(b=null==(m=Wn.inbox)?void 0:m.header)?void 0:b.filters,...null==(C=null==(_=t.inbox)?void 0:_.header)?void 0:C.filters,inbox:{...null==(y=null==(f=null==(x=Wn.inbox)?void 0:x.header)?void 0:f.filters)?void 0:y.inbox,...null==(w=null==(M=null==(I=t.inbox)?void 0:I.header)?void 0:M.filters)?void 0:w.inbox,icon:{...null==(T=null==($=null==(D=null==(E=Wn.inbox)?void 0:E.header)?void 0:D.filters)?void 0:$.inbox)?void 0:T.icon,...null==(A=null==(B=null==(P=null==(L=t.inbox)?void 0:L.header)?void 0:P.filters)?void 0:B.inbox)?void 0:A.icon}},archive:{...null==(G=null==(R=null==(F=Wn.inbox)?void 0:F.header)?void 0:R.filters)?void 0:G.archive,...null==(z=null==(V=null==(O=t.inbox)?void 0:O.header)?void 0:V.filters)?void 0:z.archive,icon:{...null==(j=null==(H=null==(N=null==(U=Wn.inbox)?void 0:U.header)?void 0:N.filters)?void 0:H.archive)?void 0:j.icon,...null==(X=null==(q=null==(W=null==(J=t.inbox)?void 0:J.header)?void 0:W.filters)?void 0:q.archive)?void 0:X.icon}},unreadIndicator:{...null==(K=null==(Z=null==(Y=Wn.inbox)?void 0:Y.header)?void 0:Z.filters)?void 0:K.unreadIndicator,...null==(te=null==(ee=null==(Q=t.inbox)?void 0:Q.header)?void 0:ee.filters)?void 0:te.unreadIndicator}},menus:{...null==(ne=null==(ie=Wn.inbox)?void 0:ie.header)?void 0:ne.menus,...null==(se=null==(oe=t.inbox)?void 0:oe.header)?void 0:se.menus,popup:{...null==(ae=null==(re=null==(le=Wn.inbox)?void 0:le.header)?void 0:re.menus)?void 0:ae.popup,...null==(he=null==(ue=null==(de=t.inbox)?void 0:de.header)?void 0:ue.menus)?void 0:he.popup,list:{...null==(ge=null==(pe=null==(ve=null==(ce=Wn.inbox)?void 0:ce.header)?void 0:ve.menus)?void 0:pe.popup)?void 0:ge.list,...null==(Ce=null==(_e=null==(be=null==(me=t.inbox)?void 0:me.header)?void 0:be.menus)?void 0:_e.popup)?void 0:Ce.list,font:{...null==(ke=null==(Se=null==(ye=null==(fe=null==(xe=Wn.inbox)?void 0:xe.header)?void 0:fe.menus)?void 0:ye.popup)?void 0:Se.list)?void 0:ke.font,...null==(De=null==(Ee=null==(we=null==(Me=null==(Ie=t.inbox)?void 0:Ie.header)?void 0:Me.menus)?void 0:we.popup)?void 0:Ee.list)?void 0:De.font},selectionIcon:{...null==(Be=null==(Pe=null==(Le=null==(Te=null==($e=Wn.inbox)?void 0:$e.header)?void 0:Te.menus)?void 0:Le.popup)?void 0:Pe.list)?void 0:Be.selectionIcon,...null==(Oe=null==(Ge=null==(Re=null==(Fe=null==(Ae=t.inbox)?void 0:Ae.header)?void 0:Fe.menus)?void 0:Re.popup)?void 0:Ge.list)?void 0:Oe.selectionIcon}}},filters:{...null==(Ue=null==(ze=null==(Ve=Wn.inbox)?void 0:Ve.header)?void 0:ze.menus)?void 0:Ue.filters,...null==(je=null==(He=null==(Ne=t.inbox)?void 0:Ne.header)?void 0:He.menus)?void 0:je.filters,inbox:{...null==(Xe=null==(qe=null==(We=null==(Je=Wn.inbox)?void 0:Je.header)?void 0:We.menus)?void 0:qe.filters)?void 0:Xe.inbox,...null==(Qe=null==(Ke=null==(Ze=null==(Ye=t.inbox)?void 0:Ye.header)?void 0:Ze.menus)?void 0:Ke.filters)?void 0:Qe.inbox,icon:{...null==(ot=null==(nt=null==(it=null==(tt=null==(et=Wn.inbox)?void 0:et.header)?void 0:tt.menus)?void 0:it.filters)?void 0:nt.inbox)?void 0:ot.icon,...null==(dt=null==(at=null==(rt=null==(lt=null==(st=t.inbox)?void 0:st.header)?void 0:lt.menus)?void 0:rt.filters)?void 0:at.inbox)?void 0:dt.icon}},archive:{...null==(vt=null==(ct=null==(ht=null==(ut=Wn.inbox)?void 0:ut.header)?void 0:ht.menus)?void 0:ct.filters)?void 0:vt.archive,...null==(bt=null==(mt=null==(gt=null==(pt=t.inbox)?void 0:pt.header)?void 0:gt.menus)?void 0:mt.filters)?void 0:bt.archive,icon:{...null==(yt=null==(ft=null==(xt=null==(Ct=null==(_t=Wn.inbox)?void 0:_t.header)?void 0:Ct.menus)?void 0:xt.filters)?void 0:ft.archive)?void 0:yt.icon,...null==(wt=null==(Mt=null==(It=null==(kt=null==(St=t.inbox)?void 0:St.header)?void 0:kt.menus)?void 0:It.filters)?void 0:Mt.archive)?void 0:wt.icon}}},actions:{...null==($t=null==(Dt=null==(Et=Wn.inbox)?void 0:Et.header)?void 0:Dt.menus)?void 0:$t.actions,...null==(Pt=null==(Lt=null==(Tt=t.inbox)?void 0:Tt.header)?void 0:Lt.menus)?void 0:Pt.actions,markAllRead:{...null==(Rt=null==(Ft=null==(At=null==(Bt=Wn.inbox)?void 0:Bt.header)?void 0:At.menus)?void 0:Ft.actions)?void 0:Rt.markAllRead,...null==(zt=null==(Vt=null==(Ot=null==(Gt=t.inbox)?void 0:Gt.header)?void 0:Ot.menus)?void 0:Vt.actions)?void 0:zt.markAllRead,icon:{...null==(Jt=null==(jt=null==(Ht=null==(Nt=null==(Ut=Wn.inbox)?void 0:Ut.header)?void 0:Nt.menus)?void 0:Ht.actions)?void 0:jt.markAllRead)?void 0:Jt.icon,...null==(Zt=null==(Yt=null==(Xt=null==(qt=null==(Wt=t.inbox)?void 0:Wt.header)?void 0:qt.menus)?void 0:Xt.actions)?void 0:Yt.markAllRead)?void 0:Zt.icon}},archiveAll:{...null==(ti=null==(ei=null==(Qt=null==(Kt=Wn.inbox)?void 0:Kt.header)?void 0:Qt.menus)?void 0:ei.actions)?void 0:ti.archiveAll,...null==(si=null==(oi=null==(ni=null==(ii=t.inbox)?void 0:ii.header)?void 0:ni.menus)?void 0:oi.actions)?void 0:si.archiveAll,icon:{...null==(ui=null==(di=null==(ai=null==(ri=null==(li=Wn.inbox)?void 0:li.header)?void 0:ri.menus)?void 0:ai.actions)?void 0:di.archiveAll)?void 0:ui.icon,...null==(gi=null==(pi=null==(vi=null==(ci=null==(hi=t.inbox)?void 0:hi.header)?void 0:ci.menus)?void 0:vi.actions)?void 0:pi.archiveAll)?void 0:gi.icon}},archiveRead:{...null==(Ci=null==(_i=null==(bi=null==(mi=Wn.inbox)?void 0:mi.header)?void 0:bi.menus)?void 0:_i.actions)?void 0:Ci.archiveRead,...null==(Si=null==(yi=null==(fi=null==(xi=t.inbox)?void 0:xi.header)?void 0:fi.menus)?void 0:yi.actions)?void 0:Si.archiveRead,icon:{...null==(Ei=null==(wi=null==(Mi=null==(Ii=null==(ki=Wn.inbox)?void 0:ki.header)?void 0:Ii.menus)?void 0:Mi.actions)?void 0:wi.archiveRead)?void 0:Ei.icon,...null==(Pi=null==(Li=null==(Ti=null==($i=null==(Di=t.inbox)?void 0:Di.header)?void 0:$i.menus)?void 0:Ti.actions)?void 0:Li.archiveRead)?void 0:Pi.icon}}}}},list:{...null==(Bi=Wn.inbox)?void 0:Bi.list,...null==(Ai=t.inbox)?void 0:Ai.list,item:{...null==(Ri=null==(Fi=Wn.inbox)?void 0:Fi.list)?void 0:Ri.item,...null==(Oi=null==(Gi=t.inbox)?void 0:Gi.list)?void 0:Oi.item,menu:{...null==(Ui=null==(zi=null==(Vi=Wn.inbox)?void 0:Vi.list)?void 0:zi.item)?void 0:Ui.menu,...null==(ji=null==(Hi=null==(Ni=t.inbox)?void 0:Ni.list)?void 0:Hi.item)?void 0:ji.menu,item:{...null==(Xi=null==(qi=null==(Wi=null==(Ji=Wn.inbox)?void 0:Ji.list)?void 0:Wi.item)?void 0:qi.menu)?void 0:Xi.item,...null==(Qi=null==(Ki=null==(Zi=null==(Yi=t.inbox)?void 0:Yi.list)?void 0:Zi.item)?void 0:Ki.menu)?void 0:Qi.item,read:{...null==(sn=null==(on=null==(nn=null==(tn=null==(en=Wn.inbox)?void 0:en.list)?void 0:tn.item)?void 0:nn.menu)?void 0:on.item)?void 0:sn.read,...null==(un=null==(dn=null==(an=null==(rn=null==(ln=t.inbox)?void 0:ln.list)?void 0:rn.item)?void 0:an.menu)?void 0:dn.item)?void 0:un.read},unread:{...null==(gn=null==(pn=null==(vn=null==(cn=null==(hn=Wn.inbox)?void 0:hn.list)?void 0:cn.item)?void 0:vn.menu)?void 0:pn.item)?void 0:gn.unread,...null==(xn=null==(Cn=null==(_n=null==(bn=null==(mn=t.inbox)?void 0:mn.list)?void 0:bn.item)?void 0:_n.menu)?void 0:Cn.item)?void 0:xn.unread},archive:{...null==(In=null==(kn=null==(Sn=null==(yn=null==(fn=Wn.inbox)?void 0:fn.list)?void 0:yn.item)?void 0:Sn.menu)?void 0:kn.item)?void 0:In.archive,...null==($n=null==(Dn=null==(En=null==(wn=null==(Mn=t.inbox)?void 0:Mn.list)?void 0:wn.item)?void 0:En.menu)?void 0:Dn.item)?void 0:$n.archive},unarchive:{...null==(An=null==(Bn=null==(Pn=null==(Ln=null==(Tn=Wn.inbox)?void 0:Tn.list)?void 0:Ln.item)?void 0:Pn.menu)?void 0:Bn.item)?void 0:An.unarchive,...null==(Vn=null==(On=null==(Gn=null==(Rn=null==(Fn=t.inbox)?void 0:Fn.list)?void 0:Rn.item)?void 0:Gn.menu)?void 0:On.item)?void 0:Vn.unarchive}}}}},loading:{...null==(zn=Wn.inbox)?void 0:zn.loading,...null==(Un=t.inbox)?void 0:Un.loading},empty:{...null==(Nn=Wn.inbox)?void 0:Nn.empty,...null==(Hn=t.inbox)?void 0:Hn.empty},error:{...null==(jn=Wn.inbox)?void 0:jn.error,...null==(Jn=t.inbox)?void 0:Jn.error}}}};class M extends i.CourierThemeManager{constructor(e){super(e),o(this,"THEME_CHANGE_EVENT","courier_inbox_theme_change")}getDefaultLightTheme(){return S}getDefaultDarkTheme(){return k}mergeTheme(e,t){return I(e,t)}subscribe(e){return{...super.subscribe(e),manager:this}}}class w extends i.CourierBaseElement{constructor(e){super(),o(this,"_currentFeed","inbox"),o(this,"_themeManager"),o(this,"_inboxStyle"),o(this,"_unreadIndicatorStyle"),o(this,"_list"),o(this,"_datastoreListener"),o(this,"_authListener"),o(this,"_header"),o(this,"_headerFactory"),o(this,"_onMessageClick"),o(this,"_onMessageActionClick"),o(this,"_onMessageLongPress"),o(this,"_defaultProps",{title:"Inbox",icon:i.CourierIconSVGs.inbox,feedType:this._currentFeed,height:"auto"}),this._themeManager=e??new M(S)}static get id(){return"courier-inbox"}get currentFeed(){return this._currentFeed}get theme(){return this._themeManager.getTheme()}setLightTheme(e){this._themeManager.setLightTheme(e)}setDarkTheme(e){this._themeManager.setDarkTheme(e)}setMode(e){this._themeManager.setMode(e)}static get observedAttributes(){return["height","light-theme","dark-theme","mode","message-click","message-action-click","message-long-press"]}onComponentMounted(){var e,n;this._inboxStyle=i.injectGlobalStyle(w.id,this.getStyles()),this._unreadIndicatorStyle=i.injectGlobalStyle(C.id,C.getStyles(this.theme)),this._header=new f({themeManager:this._themeManager,onFeedTypeChange:e=>{this.setFeedType(e)}}),this._header.build(void 0),this.appendChild(this._header),this._list=new m({themeManager:this._themeManager,canClickListItems:!1,canLongPressListItems:!1,onRefresh:()=>{this.refresh()},onPaginationTrigger:async e=>{var i,n;try{await d.shared.fetchNextPageOfMessages({feedType:e})}catch(o){null==(n=null==(i=t.Courier.shared.client)?void 0:i.options.logger)||n.error("Failed to fetch next page of messages:",o)}},onMessageClick:(e,t)=>{var i;d.shared.clickMessage({message:e}),this.dispatchEvent(new CustomEvent("message-click",{detail:{message:e,index:t},bubbles:!0,composed:!0})),null==(i=this._onMessageClick)||i.call(this,{message:e,index:t})},onMessageActionClick:(e,t,i)=>{var n;this.dispatchEvent(new CustomEvent("message-action-click",{detail:{message:e,action:t,index:i},bubbles:!0,composed:!0})),null==(n=this._onMessageActionClick)||n.call(this,{message:e,action:t,index:i})},onMessageLongPress:(e,t)=>{var i;this.dispatchEvent(new CustomEvent("message-long-press",{detail:{message:e,index:t},bubbles:!0,composed:!0})),null==(i=this._onMessageLongPress)||i.call(this,{message:e,index:t})}}),this.refreshTheme(),this.appendChild(this._list),this._datastoreListener=new y({onError:e=>{var t;null==(t=this._list)||t.setError(e)},onDataSetChange:(e,t)=>{var i;this._currentFeed===t&&(null==(i=this._list)||i.setDataSet(e),this.updateHeader())},onPageAdded:(e,t)=>{var i;this._currentFeed===t&&(null==(i=this._list)||i.addPage(e),this.updateHeader())},onMessageAdd:(e,t,i)=>{var n;this._currentFeed===i&&(null==(n=this._list)||n.addMessage(e,t),this.updateHeader())},onMessageRemove:(e,t,i)=>{var n;this._currentFeed===i&&(null==(n=this._list)||n.removeMessage(t),this.updateHeader())},onMessageUpdate:(e,t,i)=>{var n;this._currentFeed===i&&(null==(n=this._list)||n.updateMessage(e,t),this.updateHeader())},onUnreadCountChange:e=>{this.updateHeader()}}),d.shared.addDataStoreListener(this._datastoreListener),this._themeManager.subscribe((e=>{this.refreshTheme()})),this._authListener=t.Courier.shared.addAuthenticationListener((e=>{this.refresh()})),(null==(e=t.Courier.shared.client)?void 0:e.options.userId)?this.refresh():null==(n=t.Courier.shared.client)||n.options.logger.error("No user signed in. Please call Courier.shared.signIn(...) to load the inbox.")}onComponentUnmounted(){var e,t,i,n;this._themeManager.cleanup(),null==(e=this._datastoreListener)||e.remove(),null==(t=this._authListener)||t.remove(),null==(i=this._inboxStyle)||i.remove(),null==(n=this._unreadIndicatorStyle)||n.remove()}refreshTheme(){var e;null==(e=this._list)||e.refreshInfoStateThemes(),this._inboxStyle&&(this._inboxStyle.textContent=this.getStyles()),this._unreadIndicatorStyle&&(this._unreadIndicatorStyle.textContent=C.getStyles(this.theme))}getStyles(){return`\n ${w.id} {\n display: flex;\n flex-direction: column;\n width: 100%;\n height: ${this._defaultProps.height};\n }\n\n ${w.id} courier-inbox-list {\n flex: 1;\n overflow-y: auto;\n overflow-x: hidden;\n }\n `}setHeader(e){this._headerFactory=e,this.updateHeader()}removeHeader(){this._headerFactory=null,this.updateHeader()}setLoadingState(e){var t;null==(t=this._list)||t.setLoadingStateFactory(e)}setEmptyState(e){var t;null==(t=this._list)||t.setEmptyStateFactory(e)}setErrorState(e){var t;null==(t=this._list)||t.setErrorStateFactory(e)}setListItem(e){var t;null==(t=this._list)||t.setListItemFactory(e)}setPaginationItem(e){var t;null==(t=this._list)||t.setPaginationItemFactory(e)}onMessageClick(e){var t;this._onMessageClick=e,null==(t=this._list)||t.setCanClickListItems(void 0!==e)}onMessageActionClick(e){this._onMessageActionClick=e}onMessageLongPress(e){var t;this._onMessageLongPress=e,null==(t=this._list)||t.setCanLongPressListItems(void 0!==e)}setFeedType(e){var t;this._currentFeed!==e&&(this._currentFeed=e,null==(t=this._list)||t.setFeedType(e),this.updateHeader(),this.load({canUseCache:!0}))}updateHeader(){var e,t,i,n;const o={feedType:this._currentFeed,unreadCount:d.shared.unreadCount,messageCount:(null==(e=this._list)?void 0:e.messages.length)??0};switch(this._headerFactory){case void 0:null==(t=this._header)||t.render(o);break;case null:null==(i=this._header)||i.build(null);break;default:const e=this._headerFactory(o);null==(n=this._header)||n.build(e)}}async load(e){await d.shared.load(e),await d.shared.listenForUpdates()}refresh(){this.load({canUseCache:!1})}attributeChangedCallback(e,i,n){var o,s,l,r,a,d;if(i!==n)switch(e){case"height":const e=n||this._defaultProps.height;this.style.height=e;break;case"message-click":if(n)try{this._onMessageClick=new Function("props",n)}catch(u){null==(s=null==(o=t.Courier.shared.client)?void 0:o.options.logger)||s.error("Failed to parse message-click handler:",u)}else this._onMessageClick=void 0;break;case"message-action-click":if(n)try{this._onMessageActionClick=new Function("props",n)}catch(u){null==(r=null==(l=t.Courier.shared.client)?void 0:l.options.logger)||r.error("Failed to parse message-action-click handler:",u)}else this._onMessageActionClick=void 0;break;case"message-long-press":if(n)try{this._onMessageLongPress=new Function("props",n)}catch(u){null==(d=null==(a=t.Courier.shared.client)?void 0:a.options.logger)||d.error("Failed to parse message-long-press handler:",u)}else this._onMessageLongPress=void 0;break;case"light-theme":n&&this.setLightTheme(JSON.parse(n));break;case"dark-theme":n&&this.setDarkTheme(JSON.parse(n));break;case"mode":this._themeManager.setMode(n)}}}i.registerElement(w);class E extends i.CourierFactoryElement{constructor(e){super(),o(this,"_themeSubscription"),o(this,"_style"),o(this,"_container"),o(this,"_triggerButton"),o(this,"_unreadBadge"),this._themeSubscription=e.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-menu-button"}get theme(){return this._themeSubscription.manager.getTheme()}onComponentMounted(){this._style=i.injectGlobalStyle(E.id,E.getStyles(this.theme))}onComponentUnmounted(){var e;this._themeSubscription.unsubscribe(),null==(e=this._style)||e.remove()}defaultElement(){return this._container=document.createElement("div"),this._container.className="menu-button-container",this._triggerButton=new i.CourierIconButton(i.CourierIconSVGs.inbox),this._unreadBadge=document.createElement("div"),this._unreadBadge.className="unread-badge",this._unreadBadge.style.display="none",this._container.appendChild(this._triggerButton),this._container.appendChild(this._unreadBadge),this.appendChild(this._container),this.refreshTheme(),this._container}static getStyles(e){var t,i,n,o,s,l,r,a,d,u,h,c;return`\n ${E.id} .menu-button-container {\n position: relative;\n display: inline-block;\n }\n \n ${E.id} .unread-badge {\n position: absolute;\n top: 2px;\n right: 2px;\n pointer-events: none;\n width: ${(null==(n=null==(i=null==(t=e.popup)?void 0:t.button)?void 0:i.unreadDotIndicator)?void 0:n.height)??"8px"};\n height: ${(null==(l=null==(s=null==(o=e.popup)?void 0:o.button)?void 0:s.unreadDotIndicator)?void 0:l.width)??"8px"};\n background: ${(null==(d=null==(a=null==(r=e.popup)?void 0:r.button)?void 0:a.unreadDotIndicator)?void 0:d.backgroundColor)??"red"};\n border-radius: ${(null==(c=null==(h=null==(u=e.popup)?void 0:u.button)?void 0:h.unreadDotIndicator)?void 0:c.borderRadius)??"50%"};\n display: none;\n z-index: 1;\n }\n `}onUnreadCountChange(e){this._unreadBadge&&(this._unreadBadge.style.display=e>0?"block":"none"),this.refreshTheme()}refreshTheme(){var e,t,n,o,s,l,r,a,d,u,h,c,v,p,g,m,b,_,C,x,f,y;null==(s=this._triggerButton)||s.updateIconColor((null==(o=null==(n=null==(t=null==(e=this.theme)?void 0:e.popup)?void 0:t.button)?void 0:n.icon)?void 0:o.color)??i.CourierColors.black[500]),null==(u=this._triggerButton)||u.updateIconSVG((null==(d=null==(a=null==(r=null==(l=this.theme)?void 0:l.popup)?void 0:r.button)?void 0:a.icon)?void 0:d.svg)??i.CourierIconSVGs.inbox),null==(p=this._triggerButton)||p.updateBackgroundColor((null==(v=null==(c=null==(h=this.theme)?void 0:h.popup)?void 0:c.button)?void 0:v.backgroundColor)??"transparent"),null==(_=this._triggerButton)||_.updateHoverBackgroundColor((null==(b=null==(m=null==(g=this.theme)?void 0:g.popup)?void 0:m.button)?void 0:b.hoverBackgroundColor)??i.CourierColors.black[50010]),null==(y=this._triggerButton)||y.updateActiveBackgroundColor((null==(f=null==(x=null==(C=this.theme)?void 0:C.popup)?void 0:x.button)?void 0:f.activeBackgroundColor)??i.CourierColors.black[50020])}}i.registerElement(E);class D extends i.CourierBaseElement{constructor(){super(),o(this,"_width","440px"),o(this,"_height","440px"),o(this,"_popupAlignment","top-left"),o(this,"_top"),o(this,"_right"),o(this,"_bottom"),o(this,"_left"),o(this,"_themeManager",new M(S)),o(this,"_triggerButton"),o(this,"_popup"),o(this,"_inbox"),o(this,"_style"),o(this,"_datastoreListener"),o(this,"_popupMenuButtonFactory"),o(this,"handleOutsideClick",(e=>{if(!this._popup)return;const t=["courier-inbox-option-menu"];e.composedPath().some((e=>e instanceof HTMLElement&&(!(e!==this._popup&&!this._popup.contains(e))||t.some((t=>e.matches(t))))))||(this._popup.style.display="none")})),this._themeManager.subscribe((e=>{this.refreshTheme()}))}static get id(){return"courier-inbox-popup-menu"}get theme(){return this._themeManager.getTheme()}get currentFeed(){var e;return(null==(e=this._inbox)?void 0:e.currentFeed)??"inbox"}setLightTheme(e){this._themeManager.setLightTheme(e)}setDarkTheme(e){this._themeManager.setDarkTheme(e)}setMode(e){this._themeManager.setMode(e)}static get observedAttributes(){return["popup-alignment","message-click","message-action-click","message-long-press","popup-width","popup-height","top","right","bottom","left","light-theme","dark-theme","mode"]}onComponentMounted(){this._style=i.injectGlobalStyle(D.id,D.getStyles(this.theme,this._width,this._height)),this._triggerButton=new E(this._themeManager),this._triggerButton.build(void 0),this._popup=document.createElement("div"),this._popup.className="popup",this._inbox=new w(this._themeManager),this._inbox.setAttribute("height","100%"),this.refreshTheme(),this.appendChild(this._triggerButton),this.appendChild(this._popup),this._popup.appendChild(this._inbox),this._triggerButton.addEventListener("click",this.togglePopup.bind(this)),document.addEventListener("click",this.handleOutsideClick.bind(this)),this.updatePopupPosition(),this._datastoreListener=new y(this),d.shared.addDataStoreListener(this._datastoreListener)}onComponentUnmounted(){var e,t;null==(e=this._style)||e.remove(),null==(t=this._datastoreListener)||t.remove(),this._themeManager.cleanup()}refreshTheme(){this._style&&(this._style.textContent=D.getStyles(this.theme,this._width,this._height))}static getStyles(e,t,i){var n,o,s,l,r,a,d,u;return`\n ${D.id} {\n display: inline-block;\n position: relative;\n }\n\n ${D.id} .menu-button-container {\n position: relative;\n display: inline-block;\n }\n\n ${D.id} .popup {\n display: none;\n position: absolute;\n background: ${(null==(o=null==(n=e.popup)?void 0:n.window)?void 0:o.backgroundColor)??"red"};\n border-radius: ${(null==(l=null==(s=e.popup)?void 0:s.window)?void 0:l.borderRadius)??"8px"};\n border: ${(null==(a=null==(r=e.popup)?void 0:r.window)?void 0:a.border)??"1px solid red"};\n box-shadow: ${(null==(u=null==(d=e.popup)?void 0:d.window)?void 0:u.shadow)??"0px 8px 16px -4px red"};\n z-index: 1000;\n width: ${t};\n height: ${i};\n overflow: hidden;\n transform: translateZ(0);\n will-change: transform;\n }\n \n ${D.id} #unread-badge {\n position: absolute;\n top: -8px;\n left: 50%;\n pointer-events: none;\n }\n\n ${D.id} courier-inbox {\n height: 100%;\n }\n `}attributeChangedCallback(e,t,i){switch(e){case"popup-alignment":this.isValidPosition(i)&&(this._popupAlignment=i,this.updatePopupPosition());break;case"popup-width":this._width=i,this.setSize(i,this._height);break;case"popup-height":this._height=i,this.setSize(this._width,i);break;case"top":this._top=i,this.updatePopupPosition();break;case"right":this._right=i,this.updatePopupPosition();break;case"bottom":this._bottom=i,this.updatePopupPosition();break;case"left":this._left=i,this.updatePopupPosition();break;case"light-theme":i&&this.setLightTheme(JSON.parse(i));break;case"dark-theme":i&&this.setDarkTheme(JSON.parse(i));break;case"mode":this._themeManager.setMode(i)}}onUnreadCountChange(e){this.render()}onMessageClick(e){var t;null==(t=this._inbox)||t.onMessageClick((t=>{e&&e(t),this.closePopup()}))}onMessageActionClick(e){var t;null==(t=this._inbox)||t.onMessageActionClick((t=>{e&&e(t),this.closePopup()}))}onMessageLongPress(e){var t;null==(t=this._inbox)||t.onMessageLongPress((t=>{e&&e(t),this.closePopup()}))}isValidPosition(e){return["top-right","top-left","top-center","bottom-right","bottom-left","bottom-center","center-right","center-left","center-center"].includes(e)}updatePopupPosition(){if(this._popup)switch(this._popup.style.top="",this._popup.style.bottom="",this._popup.style.left="",this._popup.style.right="",this._popup.style.margin="",this._popup.style.transform="",this._popupAlignment){case"top-right":this._popup.style.top=this._top??"40px",this._popup.style.right=this._right??"0px";break;case"top-left":this._popup.style.top=this._top??"40px",this._popup.style.left=this._left??"0px";break;case"top-center":this._popup.style.top=this._top??"40px",this._popup.style.left="50%",this._popup.style.transform="translateX(-50%)";break;case"bottom-right":this._popup.style.bottom=this._bottom??"40px",this._popup.style.right=this._right??"0px";break;case"bottom-left":this._popup.style.bottom=this._bottom??"40px",this._popup.style.left=this._left??"0px";break;case"bottom-center":this._popup.style.bottom=this._bottom??"40px",this._popup.style.left="50%",this._popup.style.transform="translateX(-50%)";break;case"center-right":this._popup.style.top="50%",this._popup.style.right=this._right??"40px",this._popup.style.transform="translateY(-50%)";break;case"center-left":this._popup.style.top="50%",this._popup.style.left=this._left??"40px",this._popup.style.transform="translateY(-50%)";break;case"center-center":this._popup.style.top="50%",this._popup.style.left="50%",this._popup.style.transform="translate(-50%, -50%)"}}togglePopup(e){if(e.stopPropagation(),!this._popup)return;const t="block"===this._popup.style.display;this._popup.style.display=t?"none":"block"}closePopup(){this._popup&&(this._popup.style.display="none")}setContent(e){this._inbox&&(this._inbox.innerHTML="",this._inbox.appendChild(e))}setSize(e,t){this._width=e,this._height=t,this._popup&&(this._popup.style.width=e,this._popup.style.height=t)}setPosition(e){var i,n;this.isValidPosition(e)?(this._popupAlignment=e,this.updatePopupPosition()):null==(n=null==(i=t.Courier.shared.client)?void 0:i.options.logger)||n.error(`Invalid position: ${e}`)}setFeedType(e){var t;null==(t=this._inbox)||t.setFeedType(e)}setHeader(e){var t;null==(t=this._inbox)||t.setHeader(e)}removeHeader(){var e;null==(e=this._inbox)||e.removeHeader()}setLoadingState(e){var t;null==(t=this._inbox)||t.setLoadingState(e)}setEmptyState(e){var t;null==(t=this._inbox)||t.setEmptyState(e)}setErrorState(e){var t;null==(t=this._inbox)||t.setErrorState(e)}setListItem(e){var t;null==(t=this._inbox)||t.setListItem(e)}setPaginationItem(e){var t;null==(t=this._inbox)||t.setPaginationItem(e)}setMenuButton(e){this._popupMenuButtonFactory=e,this.render()}render(){const e=d.shared.unreadCount;if(this._triggerButton)switch(this._popupMenuButtonFactory){case void 0:case null:this._triggerButton.build(void 0),this._triggerButton.onUnreadCountChange(e);break;default:const t=this._popupMenuButtonFactory({unreadCount:e});this._triggerButton.build(t)}}}i.registerElement(D);t.Courier.shared.courierUserAgentName="courier-ui-inbox",t.Courier.shared.courierUserAgentVersion="1.2.0",Object.defineProperty(e,"Courier",{enumerable:!0,get:()=>t.Courier}),e.CourierInbox=w,e.CourierInboxDataStoreListener=y,e.CourierInboxDatastore=d,e.CourierInboxDatastoreEvents=class{onDataSetChange(e,t){}onPageAdded(e,t){}onUnreadCountChange(e){}onMessageAdd(e,t,i){}onMessageRemove(e,t,i){}onMessageUpdate(e,t,i){}onError(e){}},e.CourierInboxHeader=f,e.CourierInboxListItem=u,e.CourierInboxPopupMenu=D,e.CourierInboxThemeManager=M,e.archiveMessage=function(e){return d.shared.archiveMessage({message:e})},e.clickMessage=function(e){return d.shared.clickMessage({message:e})},e.defaultDarkTheme=k,e.defaultLightTheme=S,e.markAsRead=function(e){return d.shared.readMessage({message:e})},e.markAsUnread=function(e){return d.shared.unreadMessage({message:e})},e.mergeTheme=I,e.openMessage=g,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
|
|
2
2
|
//# sourceMappingURL=index.js.map
|