UNPKG

friday-widgets

Version:

Professional embeddable accounting widgets for vertical SaaS platforms. Layer Financial-inspired design with comprehensive financial reporting capabilities.

683 lines (600 loc) 274 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).FridayWidgets={})}(this,function(e){"use strict";class t{constructor(e){this.config={timeout:3e4,retryAttempts:3,...e},this.defaultHeaders={"Content-Type":"application/json","X-API-Key":e.apiKey}}setBusinessContext(e){this.config.businessId=e}getBusinessContext(){return this.config.businessId}async request(e,t={}){const a=`${this.config.baseURL}${e}`,r={...this.defaultHeaders,...t.headers},i={...t,headers:r,signal:AbortSignal.timeout(this.config.timeout)};try{const e=await fetch(a,i);if(!e.ok){const t=await e.json().catch(()=>({}));return{success:!1,error:t.error||`HTTP ${e.status}: ${e.statusText}`,details:t.details}}return{success:!0,data:await e.json()}}catch(e){return console.error("API Request failed:",e),{success:!1,error:e instanceof Error?e.message:"Network error occurred"}}}async getBusinesses(){return this.request("/v1/businesses/")}async getBusiness(e){return this.request(`/v1/businesses/${e}/`)}async createBusiness(e){return this.request("/v1/businesses/",{method:"POST",body:JSON.stringify(e)})}async updateBusiness(e,t){return this.request(`/v1/businesses/${e}/`,{method:"PUT",body:JSON.stringify(t)})}async getBusinessStats(e){return this.request(`/v1/businesses/${e}/stats/`)}async lookupBusinessByExternalId(e){return this.request(`/v1/businesses/lookup/?external_id=${encodeURIComponent(e)}`)}async getInvoices(e,t){const a=new URLSearchParams({business_id:e});return t?.status&&a.append("status",t.status),t?.customer_id&&a.append("customer_id",t.customer_id),t?.date_from&&a.append("date_from",t.date_from),t?.date_to&&a.append("date_to",t.date_to),t?.overdue&&a.append("overdue","true"),t?.outstanding&&a.append("outstanding","true"),t?.search&&a.append("search",t.search),this.request(`/invoices/?${a.toString()}`)}async getInvoice(e){return this.request(`/invoices/${e}/`)}async createInvoice(e){return this.request("/invoices/",{method:"POST",body:JSON.stringify(e)})}async updateInvoice(e,t){return this.request(`/invoices/${e}/`,{method:"PUT",body:JSON.stringify(t)})}async deleteInvoice(e){return this.request(`/invoices/${e}/`,{method:"DELETE"})}async recordInvoicePayment(e,t){return this.request(`/invoices/${e}/payment/`,{method:"POST",body:JSON.stringify(t)})}async sendInvoice(e){return this.request(`/invoices/${e}/send/`,{method:"POST"})}async getInvoicePayments(e){return this.request(`/invoices/${e}/payments/list/`)}async getCustomers(e){return this.request(`/customers/?business_id=${e}`)}async getCustomer(e){return this.request(`/customers/${e}/`)}async createCustomer(e){return this.request("/customers/",{method:"POST",body:JSON.stringify(e)})}async updateCustomer(e,t){return this.request(`/customers/${e}/`,{method:"PUT",body:JSON.stringify(t)})}async archiveCustomer(e){return this.request(`/customers/${e}/archive/`,{method:"POST"})}async reactivateCustomer(e){return this.request(`/customers/${e}/reactivate/`,{method:"POST"})}async getAccounts(e,t){const a=new URLSearchParams({business_id:e});return t?.account_type&&a.append("account_type",t.account_type),void 0!==t?.is_active&&a.append("is_active",t.is_active.toString()),t?.search&&a.append("search",t.search),this.request(`/accounts/?${a.toString()}`)}async getAccount(e){return this.request(`/accounts/${e}/`)}async createAccount(e){return this.request("/accounts/",{method:"POST",body:JSON.stringify(e)})}async updateAccount(e,t){return this.request(`/accounts/${e}/`,{method:"PUT",body:JSON.stringify(t)})}async deleteAccount(e){return this.request(`/accounts/${e}/`,{method:"DELETE"})}async getBankAccounts(e){return this.request(`/accounts/bank/?business_id=${e}`)}async getAccountHierarchy(e){return this.request(`/accounts/hierarchy/?business_id=${e}`)}async syncAccount(e){return this.request(`/accounts/${e}/sync/`,{method:"POST"})}async getPayments(e,t){const a=new URLSearchParams({business_id:e});return t?.status&&a.append("status",t.status),t?.customer_id&&a.append("customer_id",t.customer_id),t?.date_from&&a.append("date_from",t.date_from),t?.date_to&&a.append("date_to",t.date_to),t?.search&&a.append("search",t.search),this.request(`/payments/?${a.toString()}`)}async getPayment(e){return this.request(`/payments/${e}/`)}async createPayment(e){return this.request("/payments/",{method:"POST",body:JSON.stringify(e)})}async updatePayment(e,t){return this.request(`/payments/${e}/`,{method:"PUT",body:JSON.stringify(t)})}async completePayment(e){return this.request(`/payments/${e}/complete/`,{method:"POST"})}async failPayment(e){return this.request(`/payments/${e}/fail/`,{method:"POST"})}async getBalanceSheet(e,t){const a=new URLSearchParams({business_id:e});return t&&a.append("effective_date",t),this.request(`/reports/balance-sheet/?${a.toString()}`)}async getPnLData(e,t,a){const r=new URLSearchParams({business_id:e,date_from:t,date_to:a});return this.request(`/reports/pnl/?${r.toString()}`)}async getCashFlowData(e,t,a){const r=new URLSearchParams({business_id:e,date_from:t,date_to:a});return this.request(`/reports/cash-flow/?${r.toString()}`)}async healthCheck(){return this.request("/health/")}formatCurrency(e,t="GBP"){const a="number"==typeof e?e:parseFloat(e.toString());return new Intl.NumberFormat("en-GB",{style:"currency",currency:t}).format(a)}formatDate(e){return new Date(e).toLocaleDateString("en-GB",{year:"numeric",month:"short",day:"numeric"})}validateBusinessAccess(e){return this.config.businessId===e||!!e}handleApiError(e){let t="An unexpected error occurred";return 401===e.response?.status?t="Authentication failed. Check your API key.":404===e.response?.status?t="Business not found or not accessible.":403===e.response?.status?t="Permission denied. Business not accessible.":e.response?.data?.error&&(t=e.response.data.error),{success:!1,error:t,details:e.response?.data?.details}}}class a{static configure(e){this.config=e,this.apiClient=new t({baseURL:e.baseURL||this.getEnvironmentUrl(e.environment||"sandbox"),apiKey:e.apiKey,businessId:e.businessId}),this.injectCSS(),e.theme&&this.applyTheme(e.theme),console.log("Friday Provider configured:",{businessId:e.businessId,environment:e.environment||"sandbox",baseURL:e.baseURL||this.getEnvironmentUrl(e.environment||"sandbox")})}static getConfig(){return this.config}static getApiClient(){return this.apiClient}static setBusinessContext(e){this.config&&(this.config.businessId=e),this.apiClient&&this.apiClient.setBusinessContext(e),this.config?.onBusinessChange&&this.config.onBusinessChange(e)}static handleError(e){console.error("Friday Provider Error:",e),this.config?.onError&&this.config.onError(e)}static getWidgetConfig(){return this.config?{apiKey:this.config.apiKey,businessId:this.config.businessId||"",baseUrl:this.config.baseURL||this.getEnvironmentUrl(this.config.environment||"sandbox")}:null}static getEnvironmentUrl(e){return"production"===e?"https://api.friday.com/api":"http://localhost:8000/api"}static injectCSS(){if(this.cssInjected)return;const e=document.createElement("style");e.id="friday-components-styles",e.textContent=`\n /* Friday Components Global Styles */\n :root {\n --friday-primary: ${this.config?.theme?.primaryColor||"#2563eb"};\n --friday-bg: #ffffff;\n --friday-surface: #f9fafb;\n --friday-border: #e5e7eb;\n --friday-text: #111827;\n --friday-text-muted: #6b7280;\n --friday-success: #10b981;\n --friday-error: #ef4444;\n --friday-warning: #f59e0b;\n }\n\n [data-theme="dark"] {\n --friday-bg: #111827;\n --friday-surface: #1f2937;\n --friday-border: #374151;\n --friday-text: #f9fafb;\n --friday-text-muted: #d1d5db;\n }\n `,document.head.appendChild(e),this.cssInjected=!0}static applyTheme(e){e.mode&&document.documentElement.setAttribute("data-theme","auto"===e.mode?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":e.mode)}}function r(e,t,a,r){var i,o=arguments.length,n=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,a):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,a,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(n=(o<3?i(n):o>3?i(t,a,n):i(t,a))||n);return o>3&&n&&Object.defineProperty(t,a,n),n}a.config=null,a.cssInjected=!1,a.apiClient=null,"undefined"!=typeof window&&(window.FridayProvider=a),"function"==typeof SuppressedError&&SuppressedError; /** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const i=globalThis,o=i.ShadowRoot&&(void 0===i.ShadyCSS||i.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,n=Symbol(),s=new WeakMap;let d=class{constructor(e,t,a){if(this._$cssResult$=!0,a!==n)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const t=this.t;if(o&&void 0===e){const a=void 0!==t&&1===t.length;a&&(e=s.get(t)),void 0===e&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),a&&s.set(t,e))}return e}toString(){return this.cssText}};const c=(e,...t)=>{const a=1===e.length?e[0]:t.reduce((t,a,r)=>t+(e=>{if(!0===e._$cssResult$)return e.cssText;if("number"==typeof e)return e;throw Error("Value passed to 'css' function must be a 'css' function result: "+e+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(a)+e[r+1],e[0]);return new d(a,e,n)},l=o?e=>e:e=>e instanceof CSSStyleSheet?(e=>{let t="";for(const a of e.cssRules)t+=a.cssText;return(e=>new d("string"==typeof e?e:e+"",void 0,n))(t)})(e):e,{is:p,defineProperty:h,getOwnPropertyDescriptor:y,getOwnPropertyNames:_,getOwnPropertySymbols:u,getPrototypeOf:g}=Object,v=globalThis,m=v.trustedTypes,b=m?m.emptyScript:"",f=v.reactiveElementPolyfillSupport,F=(e,t)=>e,x={toAttribute(e,t){switch(t){case Boolean:e=e?b:null;break;case Object:case Array:e=null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){let a=e;switch(t){case Boolean:a=null!==e;break;case Number:a=null===e?null:Number(e);break;case Object:case Array:try{a=JSON.parse(e)}catch(e){a=null}}return a}},w=(e,t)=>!p(e,t),$={attribute:!0,type:String,converter:x,reflect:!1,useDefault:!1,hasChanged:w}; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */Symbol.metadata??=Symbol("metadata"),v.litPropertyMetadata??=new WeakMap;let k=class extends HTMLElement{static addInitializer(e){this._$Ei(),(this.l??=[]).push(e)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(e,t=$){if(t.state&&(t.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(e)&&((t=Object.create(t)).wrapped=!0),this.elementProperties.set(e,t),!t.noAccessor){const a=Symbol(),r=this.getPropertyDescriptor(e,a,t);void 0!==r&&h(this.prototype,e,r)}}static getPropertyDescriptor(e,t,a){const{get:r,set:i}=y(this.prototype,e)??{get(){return this[t]},set(e){this[t]=e}};return{get:r,set(t){const o=r?.call(this);i?.call(this,t),this.requestUpdate(e,o,a)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??$}static _$Ei(){if(this.hasOwnProperty(F("elementProperties")))return;const e=g(this);e.finalize(),void 0!==e.l&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(F("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(F("properties"))){const e=this.properties,t=[..._(e),...u(e)];for(const a of t)this.createProperty(a,e[a])}const e=this[Symbol.metadata];if(null!==e){const t=litPropertyMetadata.get(e);if(void 0!==t)for(const[e,a]of t)this.elementProperties.set(e,a)}this._$Eh=new Map;for(const[e,t]of this.elementProperties){const a=this._$Eu(e,t);void 0!==a&&this._$Eh.set(a,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const a=new Set(e.flat(1/0).reverse());for(const e of a)t.unshift(l(e))}else void 0!==e&&t.push(l(e));return t}static _$Eu(e,t){const a=t.attribute;return!1===a?void 0:"string"==typeof a?a:"string"==typeof e?e.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(e=>this.enableUpdating=e),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(e=>e(this))}addController(e){(this._$EO??=new Set).add(e),void 0!==this.renderRoot&&this.isConnected&&e.hostConnected?.()}removeController(e){this._$EO?.delete(e)}_$E_(){const e=new Map,t=this.constructor.elementProperties;for(const a of t.keys())this.hasOwnProperty(a)&&(e.set(a,this[a]),delete this[a]);e.size>0&&(this._$Ep=e)}createRenderRoot(){const e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return((e,t)=>{if(o)e.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(const a of t){const t=document.createElement("style"),r=i.litNonce;void 0!==r&&t.setAttribute("nonce",r),t.textContent=a.cssText,e.appendChild(t)}})(e,this.constructor.elementStyles),e}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(e=>e.hostConnected?.())}enableUpdating(e){}disconnectedCallback(){this._$EO?.forEach(e=>e.hostDisconnected?.())}attributeChangedCallback(e,t,a){this._$AK(e,a)}_$ET(e,t){const a=this.constructor.elementProperties.get(e),r=this.constructor._$Eu(e,a);if(void 0!==r&&!0===a.reflect){const i=(void 0!==a.converter?.toAttribute?a.converter:x).toAttribute(t,a.type);this._$Em=e,null==i?this.removeAttribute(r):this.setAttribute(r,i),this._$Em=null}}_$AK(e,t){const a=this.constructor,r=a._$Eh.get(e);if(void 0!==r&&this._$Em!==r){const e=a.getPropertyOptions(r),i="function"==typeof e.converter?{fromAttribute:e.converter}:void 0!==e.converter?.fromAttribute?e.converter:x;this._$Em=r;const o=i.fromAttribute(t,e.type);this[r]=o??this._$Ej?.get(r)??o,this._$Em=null}}requestUpdate(e,t,a){if(void 0!==e){const r=this.constructor,i=this[e];if(a??=r.getPropertyOptions(e),!((a.hasChanged??w)(i,t)||a.useDefault&&a.reflect&&i===this._$Ej?.get(e)&&!this.hasAttribute(r._$Eu(e,a))))return;this.C(e,t,a)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(e,t,{useDefault:a,reflect:r,wrapped:i},o){a&&!(this._$Ej??=new Map).has(e)&&(this._$Ej.set(e,o??t??this[e]),!0!==i||void 0!==o)||(this._$AL.has(e)||(this.hasUpdated||a||(t=void 0),this._$AL.set(e,t)),!0===r&&this._$Em!==e&&(this._$Eq??=new Set).add(e))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(e){Promise.reject(e)}const e=this.scheduleUpdate();return null!=e&&await e,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[e,t]of this._$Ep)this[e]=t;this._$Ep=void 0}const e=this.constructor.elementProperties;if(e.size>0)for(const[t,a]of e){const{wrapped:e}=a,r=this[t];!0!==e||this._$AL.has(t)||void 0===r||this.C(t,void 0,a,r)}}let e=!1;const t=this._$AL;try{e=this.shouldUpdate(t),e?(this.willUpdate(t),this._$EO?.forEach(e=>e.hostUpdate?.()),this.update(t)):this._$EM()}catch(t){throw e=!1,this._$EM(),t}e&&this._$AE(t)}willUpdate(e){}_$AE(e){this._$EO?.forEach(e=>e.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(e)),this.updated(e)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(e){return!0}update(e){this._$Eq&&=this._$Eq.forEach(e=>this._$ET(e,this[e])),this._$EM()}updated(e){}firstUpdated(e){}};k.elementStyles=[],k.shadowRootOptions={mode:"open"},k[F("elementProperties")]=new Map,k[F("finalized")]=new Map,f?.({ReactiveElement:k}),(v.reactiveElementVersions??=[]).push("2.1.1"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const C=globalThis,S=C.trustedTypes,D=S?S.createPolicy("lit-html",{createHTML:e=>e}):void 0,A="$lit$",E=`lit$${Math.random().toFixed(9).slice(2)}$`,P="?"+E,I=`<${P}>`,L=document,B=()=>L.createComment(""),O=e=>null===e||"object"!=typeof e&&"function"!=typeof e,T=Array.isArray,z="[ \t\n\f\r]",M=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,W=/-->/g,R=/>/g,q=RegExp(`>|${z}(?:([^\\s"'>=/]+)(${z}*=${z}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),N=/'/g,j=/"/g,U=/^(?:script|style|textarea|title)$/i,H=(e=>(t,...a)=>({_$litType$:e,strings:t,values:a}))(1),G=Symbol.for("lit-noChange"),J=Symbol.for("lit-nothing"),V=new WeakMap,Y=L.createTreeWalker(L,129);function X(e,t){if(!T(e)||!e.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==D?D.createHTML(t):t}const K=(e,t)=>{const a=e.length-1,r=[];let i,o=2===t?"<svg>":3===t?"<math>":"",n=M;for(let t=0;t<a;t++){const a=e[t];let s,d,c=-1,l=0;for(;l<a.length&&(n.lastIndex=l,d=n.exec(a),null!==d);)l=n.lastIndex,n===M?"!--"===d[1]?n=W:void 0!==d[1]?n=R:void 0!==d[2]?(U.test(d[2])&&(i=RegExp("</"+d[2],"g")),n=q):void 0!==d[3]&&(n=q):n===q?">"===d[0]?(n=i??M,c=-1):void 0===d[1]?c=-2:(c=n.lastIndex-d[2].length,s=d[1],n=void 0===d[3]?q:'"'===d[3]?j:N):n===j||n===N?n=q:n===W||n===R?n=M:(n=q,i=void 0);const p=n===q&&e[t+1].startsWith("/>")?" ":"";o+=n===M?a+I:c>=0?(r.push(s),a.slice(0,c)+A+a.slice(c)+E+p):a+E+(-2===c?t:p)}return[X(e,o+(e[a]||"<?>")+(2===t?"</svg>":3===t?"</math>":"")),r]};class Q{constructor({strings:e,_$litType$:t},a){let r;this.parts=[];let i=0,o=0;const n=e.length-1,s=this.parts,[d,c]=K(e,t);if(this.el=Q.createElement(d,a),Y.currentNode=this.el.content,2===t||3===t){const e=this.el.content.firstChild;e.replaceWith(...e.childNodes)}for(;null!==(r=Y.nextNode())&&s.length<n;){if(1===r.nodeType){if(r.hasAttributes())for(const e of r.getAttributeNames())if(e.endsWith(A)){const t=c[o++],a=r.getAttribute(e).split(E),n=/([.?@])?(.*)/.exec(t);s.push({type:1,index:i,name:n[2],strings:a,ctor:"."===n[1]?re:"?"===n[1]?ie:"@"===n[1]?oe:ae}),r.removeAttribute(e)}else e.startsWith(E)&&(s.push({type:6,index:i}),r.removeAttribute(e));if(U.test(r.tagName)){const e=r.textContent.split(E),t=e.length-1;if(t>0){r.textContent=S?S.emptyScript:"";for(let a=0;a<t;a++)r.append(e[a],B()),Y.nextNode(),s.push({type:2,index:++i});r.append(e[t],B())}}}else if(8===r.nodeType)if(r.data===P)s.push({type:2,index:i});else{let e=-1;for(;-1!==(e=r.data.indexOf(E,e+1));)s.push({type:7,index:i}),e+=E.length-1}i++}}static createElement(e,t){const a=L.createElement("template");return a.innerHTML=e,a}}function Z(e,t,a=e,r){if(t===G)return t;let i=void 0!==r?a._$Co?.[r]:a._$Cl;const o=O(t)?void 0:t._$litDirective$;return i?.constructor!==o&&(i?._$AO?.(!1),void 0===o?i=void 0:(i=new o(e),i._$AT(e,a,r)),void 0!==r?(a._$Co??=[])[r]=i:a._$Cl=i),void 0!==i&&(t=Z(e,i._$AS(e,t.values),i,r)),t}class ee{constructor(e,t){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){const{el:{content:t},parts:a}=this._$AD,r=(e?.creationScope??L).importNode(t,!0);Y.currentNode=r;let i=Y.nextNode(),o=0,n=0,s=a[0];for(;void 0!==s;){if(o===s.index){let t;2===s.type?t=new te(i,i.nextSibling,this,e):1===s.type?t=new s.ctor(i,s.name,s.strings,this,e):6===s.type&&(t=new ne(i,this,e)),this._$AV.push(t),s=a[++n]}o!==s?.index&&(i=Y.nextNode(),o++)}return Y.currentNode=L,r}p(e){let t=0;for(const a of this._$AV)void 0!==a&&(void 0!==a.strings?(a._$AI(e,a,t),t+=a.strings.length-2):a._$AI(e[t])),t++}}class te{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(e,t,a,r){this.type=2,this._$AH=J,this._$AN=void 0,this._$AA=e,this._$AB=t,this._$AM=a,this.options=r,this._$Cv=r?.isConnected??!0}get parentNode(){let e=this._$AA.parentNode;const t=this._$AM;return void 0!==t&&11===e?.nodeType&&(e=t.parentNode),e}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(e,t=this){e=Z(this,e,t),O(e)?e===J||null==e||""===e?(this._$AH!==J&&this._$AR(),this._$AH=J):e!==this._$AH&&e!==G&&this._(e):void 0!==e._$litType$?this.$(e):void 0!==e.nodeType?this.T(e):(e=>T(e)||"function"==typeof e?.[Symbol.iterator])(e)?this.k(e):this._(e)}O(e){return this._$AA.parentNode.insertBefore(e,this._$AB)}T(e){this._$AH!==e&&(this._$AR(),this._$AH=this.O(e))}_(e){this._$AH!==J&&O(this._$AH)?this._$AA.nextSibling.data=e:this.T(L.createTextNode(e)),this._$AH=e}$(e){const{values:t,_$litType$:a}=e,r="number"==typeof a?this._$AC(e):(void 0===a.el&&(a.el=Q.createElement(X(a.h,a.h[0]),this.options)),a);if(this._$AH?._$AD===r)this._$AH.p(t);else{const e=new ee(r,this),a=e.u(this.options);e.p(t),this.T(a),this._$AH=e}}_$AC(e){let t=V.get(e.strings);return void 0===t&&V.set(e.strings,t=new Q(e)),t}k(e){T(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let a,r=0;for(const i of e)r===t.length?t.push(a=new te(this.O(B()),this.O(B()),this,this.options)):a=t[r],a._$AI(i),r++;r<t.length&&(this._$AR(a&&a._$AB.nextSibling,r),t.length=r)}_$AR(e=this._$AA.nextSibling,t){for(this._$AP?.(!1,!0,t);e!==this._$AB;){const t=e.nextSibling;e.remove(),e=t}}setConnected(e){void 0===this._$AM&&(this._$Cv=e,this._$AP?.(e))}}class ae{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,a,r,i){this.type=1,this._$AH=J,this._$AN=void 0,this.element=e,this.name=t,this._$AM=r,this.options=i,a.length>2||""!==a[0]||""!==a[1]?(this._$AH=Array(a.length-1).fill(new String),this.strings=a):this._$AH=J}_$AI(e,t=this,a,r){const i=this.strings;let o=!1;if(void 0===i)e=Z(this,e,t,0),o=!O(e)||e!==this._$AH&&e!==G,o&&(this._$AH=e);else{const r=e;let n,s;for(e=i[0],n=0;n<i.length-1;n++)s=Z(this,r[a+n],t,n),s===G&&(s=this._$AH[n]),o||=!O(s)||s!==this._$AH[n],s===J?e=J:e!==J&&(e+=(s??"")+i[n+1]),this._$AH[n]=s}o&&!r&&this.j(e)}j(e){e===J?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class re extends ae{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===J?void 0:e}}class ie extends ae{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==J)}}class oe extends ae{constructor(e,t,a,r,i){super(e,t,a,r,i),this.type=5}_$AI(e,t=this){if((e=Z(this,e,t,0)??J)===G)return;const a=this._$AH,r=e===J&&a!==J||e.capture!==a.capture||e.once!==a.once||e.passive!==a.passive,i=e!==J&&(a===J||r);r&&this.element.removeEventListener(this.name,this,a),i&&this.element.addEventListener(this.name,this,e),this._$AH=e}handleEvent(e){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,e):this._$AH.handleEvent(e)}}class ne{constructor(e,t,a){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=a}get _$AU(){return this._$AM._$AU}_$AI(e){Z(this,e)}}const se=C.litHtmlPolyfillSupport;se?.(Q,te),(C.litHtmlVersions??=[]).push("3.3.1");const de=globalThis; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */class ce extends k{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const e=super.createRenderRoot();return this.renderOptions.renderBefore??=e.firstChild,e}update(e){const t=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=((e,t,a)=>{const r=a?.renderBefore??t;let i=r._$litPart$;if(void 0===i){const e=a?.renderBefore??null;r._$litPart$=i=new te(t.insertBefore(B(),e),e,void 0,a??{})}return i._$AI(e),i})(t,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return G}}ce._$litElement$=!0,ce.finalized=!0,de.litElementHydrateSupport?.({LitElement:ce});const le=de.litElementPolyfillSupport;le?.({LitElement:ce}),(de.litElementVersions??=[]).push("4.2.1"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const pe=e=>(t,a)=>{void 0!==a?a.addInitializer(()=>{customElements.define(e,t)}):customElements.define(e,t)},he={attribute:!0,type:String,converter:x,reflect:!1,hasChanged:w},ye=(e=he,t,a)=>{const{kind:r,metadata:i}=a;let o=globalThis.litPropertyMetadata.get(i);if(void 0===o&&globalThis.litPropertyMetadata.set(i,o=new Map),"setter"===r&&((e=Object.create(e)).wrapped=!0),o.set(a.name,e),"accessor"===r){const{name:r}=a;return{set(a){const i=t.get.call(this);t.set.call(this,a),this.requestUpdate(r,i,e)},init(t){return void 0!==t&&this.C(r,void 0,e,t),t}}}if("setter"===r){const{name:r}=a;return function(a){const i=this[r];t.call(this,a),this.requestUpdate(r,i,e)}}throw Error("Unsupported decorator location: "+r)}; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */function _e(e){return(t,a)=>"object"==typeof a?ye(e,t,a):((e,t,a)=>{const r=t.hasOwnProperty(a);return t.constructor.createProperty(a,e),r?Object.getOwnPropertyDescriptor(t,a):void 0})(e,t,a)} /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */function ue(e){return _e({...e,state:!0,attribute:!1})}class ge extends ce{constructor(){super(...arguments),this.apiKey="",this.businessId="",this.theme="light",this.baseUrl="http://localhost:8000/api",this.loading=!1,this.error=null,this.apiClient=null}connectedCallback(){super.connectedCallback(),this.initializeApiClient(),this.loadData()}initializeApiClient(){if("undefined"!=typeof window&&window.FridayProvider){const e=window.FridayProvider.getApiClient();if(e)return void(this.apiClient=e);const a=window.FridayProvider.getWidgetConfig();if(a)return void(this.apiClient=new t({baseURL:a.baseUrl,apiKey:a.apiKey,businessId:a.businessId}))}this.apiKey?this.apiClient=new t({baseURL:this.baseUrl,apiKey:this.apiKey,businessId:this.businessId||void 0}):this.setError("API key is required. Configure FridayProvider or provide api-key attribute.")}async loadData(){}setError(e){if(this.error=e,this.loading=!1,this.emitEvent("error",{message:e}),"undefined"!=typeof window&&window.FridayProvider)try{window.FridayProvider.handleError(new Error(e))}catch(e){}}clearError(){this.error=null}handleApiError(e,t="API request"){let a=`${t} failed`;e?.error?a=e.error:e?.message?a=e.message:"string"==typeof e&&(a=e),e?.details&&(a+=` (${e.details})`),this.setError(a),this.emitEvent("api-error",{context:t,error:e,message:a})}async makeApiRequest(e,t="Request"){try{if(this.setLoading(!0),!this.apiClient)throw new Error("API client not initialized");const a=await e();return a.success?(this.clearError(),a.data||null):(this.handleApiError(a,t),null)}catch(e){return this.handleApiError(e,t),null}finally{this.setLoading(!1)}}setLoading(e){this.loading=e,e&&this.clearError()}emitEvent(e,t={}){const a={type:e,data:t,timestamp:Date.now()};this.dispatchEvent(new CustomEvent(`friday-${e}`,{detail:a,bubbles:!0,composed:!0}))}renderLoading(){return H` <div class="Friday__loading"> <div class="Friday__spinner"></div> <span>Loading...</span> </div> `}renderError(){return H` <div class="Friday__error"> <span>⚠️ ${this.error}</span> </div> `}static get baseStyles(){return c` @import url('https://rsms.me/inter/inter.css'); :host { display: block; /* Friday Design System - Layer Financial Inspired */ --color-black: #1a1a1a; --color-white: white; --color-info: #0968f8; --color-info-bg: #d6e6ff; --color-info-fg: #0056d7; --color-success: hsl(145deg 45% 42%); --color-success-bg: hsl(145deg 59% 86%); --color-success-fg: hsl(145deg 63% 29%); --color-warning: hsl(43deg 100% 44%); --color-warning-bg: hsl(43deg 100% 84%); --color-warning-fg: hsl(43deg 88% 26%); --color-error: hsl(0deg 76% 50%); --color-error-bg: hsl(0deg 83% 86%); --color-error-fg: hsl(0deg 88% 32%); --color-dark-h: 220; --color-dark-s: 15%; --color-dark-l: 7%; --color-dark: hsl(var(--color-dark-h) var(--color-dark-s) var(--color-dark-l)); --color-base-0: #fff; --color-base-50: hsl(var(--color-dark-h) 5% 98%); --color-base-100: hsl(var(--color-dark-h) 5% 95%); --color-base-200: hsl(var(--color-dark-h) 5% 91%); --color-base-300: hsl(var(--color-dark-h) 6% 85%); --color-base-400: hsl(var(--color-dark-h) 7% 75%); --color-base-500: hsl(var(--color-dark-h) 8% 50%); --color-base-600: hsl(var(--color-dark-h) 10% 40%); --color-base-700: hsl(var(--color-dark-h) 12% 27%); --color-base-800: hsl(var(--color-dark-h) 15% 20%); --color-base-900: hsl(var(--color-dark-h) 18% 14%); --text-color-primary: var(--color-dark); --text-color-secondary: var(--color-base-600); --text-color-muted: var(--color-base-500); --text-color-inverse: var(--color-white); --bg-primary: var(--color-base-0); --bg-secondary: var(--color-base-50); --bg-tertiary: var(--color-base-100); --bg-element-hover: var(--color-base-100); --border-primary: var(--color-base-200); --border-secondary: var(--color-base-300); --border-focus: var(--color-info); --font-family: 'InterVariable', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; --text-2xs: 10px; --text-xs: 11px; --text-sm: 12px; --text-md: 14px; --text-lg: 16px; --text-xl: 18px; --text-2xl: 20px; --text-3xl: 24px; --font-weight-normal: 460; --font-weight-medium: 500; --font-weight-semibold: 540; --font-weight-bold: 600; --spacing-2xs: 6px; --spacing-xs: 8px; --spacing-sm: 12px; --spacing-md: 16px; --spacing-lg: 20px; --spacing-xl: 24px; --spacing-2xl: 32px; --spacing-3xl: 40px; --spacing-4xl: 48px; --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px; --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06); --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); --transition-fast: 150ms ease; } .Friday__component { font-family: var(--font-family); font-size: var(--text-md); line-height: 1.5; color: var(--text-color-primary); background: var(--bg-primary); border: 1px solid var(--border-primary); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); overflow: hidden; } .Friday__loading { display: flex; align-items: center; justify-content: center; padding: var(--spacing-4xl); color: var(--text-color-muted); font-size: var(--text-sm); gap: var(--spacing-xs); } .Friday__spinner { width: 20px; height: 20px; border: 2px solid var(--border-primary); border-top-color: var(--color-info); border-radius: 50%; animation: Friday__spin 1s linear infinite; } @keyframes Friday__spin { to { transform: rotate(360deg); } } .Friday__error { display: flex; align-items: center; gap: var(--spacing-xs); padding: var(--spacing-md); margin: var(--spacing-md); background: var(--color-error-bg); color: var(--color-error-fg); border: 1px solid var(--color-error); border-radius: var(--radius-sm); font-size: var(--text-sm); } .Friday__header { display: flex; align-items: center; justify-content: space-between; padding: var(--spacing-lg) var(--spacing-xl); border-bottom: 1px solid var(--border-primary); background: var(--bg-secondary); } .Friday__header-title { font-size: var(--text-xl); font-weight: var(--font-weight-semibold); color: var(--text-color-primary); margin: 0; } .Friday__header-actions { display: flex; align-items: center; gap: var(--spacing-sm); } .Friday__content { padding: var(--spacing-xl); } .Friday__button { display: inline-flex; align-items: center; justify-content: center; gap: var(--spacing-xs); padding: var(--spacing-xs) var(--spacing-md); border: 1px solid transparent; border-radius: var(--radius-sm); font-family: var(--font-family); font-size: var(--text-sm); font-weight: var(--font-weight-medium); line-height: 1.5; text-decoration: none; cursor: pointer; transition: all var(--transition-fast); white-space: nowrap; user-select: none; } .Friday__button:disabled { opacity: 0.5; cursor: not-allowed; } .Friday__button--primary { background: var(--color-info); color: var(--text-color-inverse); border-color: var(--color-info); } .Friday__button--primary:hover:not(:disabled) { background: var(--color-info-fg); border-color: var(--color-info-fg); } .Friday__button--secondary { background: var(--bg-primary); color: var(--text-color-primary); border-color: var(--border-primary); } .Friday__button--secondary:hover:not(:disabled) { background: var(--bg-element-hover); border-color: var(--border-secondary); } .Friday__button--success { background: var(--color-success); color: var(--text-color-inverse); border-color: var(--color-success); } .Friday__button--success:hover:not(:disabled) { background: var(--color-success-fg); border-color: var(--color-success-fg); } .Friday__button--error { background: var(--color-error); color: var(--text-color-inverse); border-color: var(--color-error); } .Friday__button--sm { padding: var(--spacing-2xs) var(--spacing-sm); font-size: var(--text-xs); } .Friday__input { display: block; width: 100%; padding: var(--spacing-xs) var(--spacing-sm); border: 1px solid var(--border-primary); border-radius: var(--radius-sm); font-family: var(--font-family); font-size: var(--text-sm); line-height: 1.5; color: var(--text-color-primary); background: var(--bg-primary); transition: all var(--transition-fast); } .Friday__input:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px hsla(217, 100%, 50%, 0.1); } .Friday__select { display: block; width: 100%; padding: var(--spacing-xs) var(--spacing-sm); border: 1px solid var(--border-primary); border-radius: var(--radius-sm); font-family: var(--font-family); font-size: var(--text-sm); color: var(--text-color-primary); background: var(--bg-primary); cursor: pointer; transition: all var(--transition-fast); } .Friday__table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); } .Friday__table th, .Friday__table td { padding: var(--spacing-sm) var(--spacing-md); text-align: left; border-bottom: 1px solid var(--border-primary); } .Friday__table th { font-weight: var(--font-weight-semibold); color: var(--text-color-secondary); background: var(--bg-secondary); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; } .Friday__table tbody tr:hover { background: var(--bg-element-hover); } .Friday__badge { display: inline-flex; align-items: center; padding: 2px var(--spacing-xs); border-radius: 9999px; font-size: var(--text-2xs); font-weight: var(--font-weight-medium); text-transform: uppercase; letter-spacing: 0.05em; } .Friday__badge--success { background: var(--color-success-bg); color: var(--color-success-fg); } .Friday__badge--warning { background: var(--color-warning-bg); color: var(--color-warning-fg); } .Friday__badge--error { background: var(--color-error-bg); color: var(--color-error-fg); } .Friday__badge--info { background: var(--color-info-bg); color: var(--color-info-fg); } /* Typography utilities */ .Friday__text-xs { font-size: var(--text-xs); } .Friday__text-sm { font-size: var(--text-sm); } .Friday__text-md { font-size: var(--text-md); } .Friday__text-lg { font-size: var(--text-lg); } .Friday__text-muted { color: var(--text-color-muted); } .Friday__text-secondary { color: var(--text-color-secondary); } .Friday__font-medium { font-weight: var(--font-weight-medium); } .Friday__font-semibold { font-weight: var(--font-weight-semibold); } .Friday__font-bold { font-weight: var(--font-weight-bold); } @media (max-width: 768px) { .Friday__component { border-radius: 0; border-left: none; border-right: none; box-shadow: none; } .Friday__header { padding: var(--spacing-md) var(--spacing-lg); } .Friday__content { padding: var(--spacing-lg); } .Friday__table th, .Friday__table td { padding: var(--spacing-xs) var(--spacing-sm); } } `}}r([_e({type:String,attribute:"api-key"})],ge.prototype,"apiKey",void 0),r([_e({type:String,attribute:"business-id"})],ge.prototype,"businessId",void 0),r([_e({type:String})],ge.prototype,"theme",void 0),r([_e({type:String,attribute:"base-url"})],ge.prototype,"baseUrl",void 0),r([ue()],ge.prototype,"loading",void 0),r([ue()],ge.prototype,"error",void 0),e.InvoiceWidget=class extends ge{constructor(){super(...arguments),this.invoiceHeader="Invoices",this.showDemo=!1,this.invoices=[],this.customers=[],this.selectedInvoice=null,this.showCreateForm=!1,this.filters={status:"",customerId:"",search:""}}static get styles(){return[ge.baseStyles,c` .Friday__invoice-filters { display: flex; align-items: center; gap: var(--spacing-md); padding: var(--spacing-lg); border-bottom: 1px solid var(--border-primary); background: var(--bg-secondary); flex-wrap: wrap; } .Friday__filter-group { display: flex; flex-direction: column; gap: var(--spacing-xs); min-width: 120px; } .Friday__filter-label { font-size: var(--text-xs); font-weight: var(--font-weight-medium); color: var(--text-color-secondary); text-transform: uppercase; letter-spacing: 0.05em; } .Friday__invoice-list { flex: 1; overflow-y: auto; } .Friday__invoice-item { display: grid; grid-template-columns: 1fr auto auto auto; gap: var(--spacing-md); align-items: center; padding: var(--spacing-lg); border-bottom: 1px solid var(--border-primary); transition: all var(--transition-fast); cursor: pointer; } .Friday__invoice-item:hover { background: var(--bg-element-hover); } .Friday__invoice-item:last-child { border-bottom: none; } .Friday__invoice-details { min-width: 0; } .Friday__invoice-number { font-size: var(--text-md); font-weight: var(--font-weight-semibold); color: var(--text-color-primary); margin-bottom: 2px; } .Friday__invoice-customer { font-size: var(--text-sm); color: var(--text-color-secondary); margin-bottom: 2px; } .Friday__invoice-date { font-size: var(--text-xs); color: var(--text-color-muted); } .Friday__invoice-amount { font-size: var(--text-lg); font-weight: var(--font-weight-semibold); color: var(--text-color-primary); text-align: right; } .Friday__invoice-status { text-align: center; } .Friday__invoice-actions { display: flex; gap: var(--spacing-xs); } .Friday__empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--spacing-4xl); color: var(--text-color-muted); text-align: center; } .Friday__empty-icon { font-size: 3rem; margin-bottom: var(--spacing-lg); opacity: 0.3; } .Friday__demo-notice { background: var(--color-info-bg); border: 1px solid var(--color-info); color: var(--color-info-fg); padding: var(--spacing-md); border-radius: var(--radius-sm); margin: var(--spacing-lg); font-size: var(--text-sm); text-align: center; } .Friday__modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; } .Friday__modal { background: var(--bg-primary); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); max-width: 500px; width: 90%; max-height: 80vh; overflow-y: auto; } .Friday__modal-header { padding: var(--spacing-xl); border-bottom: 1px solid var(--border-primary); } .Friday__modal-title { font-size: var(--text-xl); font-weight: var(--font-weight-semibold); margin: 0; } .Friday__modal-content { padding: var(--spacing-xl); } .Friday__modal-actions { display: flex; justify-content: flex-end; gap: var(--spacing-sm); padding: var(--spacing-xl); border-top: 1px solid var(--border-primary); } .Friday__form-group { margin-bottom: var(--spacing-lg); } .Friday__form-label { display: block; font-size: var(--text-sm); font-weight: var(--font-weight-medium); color: var(--text-color-primary); margin-bottom: var(--spacing-xs); } @media (max-width: 768px) { .Friday__invoice-filters { flex-direction: column; align-items: stretch; } .Friday__invoice-item { grid-template-columns: 1fr auto; gap: var(--spacing-sm); } .Friday__invoice-amount, .Friday__invoice-actions { grid-column: 2; } .Friday__modal { width: 95%; margin: var(--spacing-md); } } `]}async loadData(){if(this.apiClient){this.setLoading(!0);try{if(this.showDemo)this.loadDemoData();else{const[e,t]=await Promise.all([this.apiClient.getInvoices(),this.apiClient.getCustomers()]);e.success&&e.data&&(this.invoices=e.data.results),t.success&&t.data&&(this.customers=t.data.results)}this.emitEvent("invoices-loaded",{count:this.invoices.length})}catch(e){this.setError("Failed to load invoices")}finally{this.setLoading(!1)}}}loadDemoData(){const e=[{id:"cust_001",business_id:"bus_demo",name:"Acme Corporation",email:"billing@acme.com",is_active:!0,created_at:(new Date).toISOString(),updated_at:(new Date).toISOString()},{id:"cust_002",business_id:"bus_demo",name:"Tech Solutions Ltd",email:"accounts@techsolutions.com",is_active:!0,created_at:(new Date).toISOString(),updated_at:(new Date).toISOString()}],t=[{id:"inv_001",business_id:"bus_demo",customer_id:"cust_001",invoice_number:"INV-2024-001",amount_cents:15e4,currency:"GBP",status:"pending",due_date:new Date(Date.now()+12096e5).toISOString(),issue_date:(new Date).toISOString(),created_at:(new Date).toISOString(),updated_at:(new Date).toISOString()},{id:"inv_002",business_id:"bus_demo",customer_id:"cust_002",invoice_number:"INV-2024-002",amount_cents:275e3,currency:"GBP",status:"paid",due_date:new Date(Date.now()+6048e5).toISOString(),issue_date:new Date(Date.now()-432e6).toISOString(),created_at:(new Date).toISOString(),updated_at:(new Date).toISOString()},{id:"inv_003",business_id:"bus_demo",customer_id:"cust_001",invoice_number:"INV-2024-003",amount_cents:89500,currency:"GBP",status:"overdue",due_date:new Date(Date.now()-2592e5).toISOString(),issue_date:new Date(Date.now()-1728e6).toISOString(),created_at:(new Date).toISOString(),updated_at:(new Date).toISOString()}];this.customers=e,this.invoices=t}getCustomerName(e){const t=this.customers.find(t=>t.id===e);return t?.name||"Unknown Customer"}getStatusBadgeClass(e){switch(e.toLowerCase()){case"paid":return"Friday__badge--success";case"pending":return"Friday__badge--warning";case"overdue":return"Friday__badge--error";default:return"Friday__badge--info"}}selectInvoice(e){this.selectedInvoice=e,this.emitEvent("invoice-selected",{invoice:e})}closeModal(){this.selectedInvoice=null,this.showCreateForm=!1}async recordPayment(e,t){if(this.apiClient)try{const a=await this.apiClient.recordInvoicePayment(e,{amount_cents:100*t,payment_method:"bank_transfer",payment_date:(new Date).toISOString(),reference:`Payment for ${e}`});if(a.success){const t=this.invoices.findIndex(t=>t.id===e);t>=0&&(this.invoices[t].status="paid",this.requestUpdate()),this.emitEvent("payment-recorded",{invoice:this.invoices[t],payment:a.data}),this.closeModal()}}catch(e){console.error("Failed to record payment:",e)}}renderFilters(){return H` <div class="Friday__invoice-filters"> <div class="Friday__filter-group"> <label class="Friday__filter-label">Status</label> <select class="Friday__select" .value=${this.filters.status}> <option value="">All Statuses</option> <option value="pending">Pending</option> <option value="paid">Paid</option> <option value="overdue">Overdue</option> </select> </div> <div class="Friday__filter-group"> <label class="Friday__filter-label">Customer</label> <select class="Friday__select" .value=${this.filters.customerId}> <option value="">All Customers</option> ${this.customers.map(e=>H` <option value=${e.id}>${e.name}</option> `)} </select> </div> <div class="Friday__filter-group" style="flex: 1; max-width: 300px;"> <label class="Friday__filter-label">Search</label> <input type="text" class="Friday__input" placeholder="Search invoices..." .value=${this.filters.search} /> </div> </div> `}renderInvoiceList(){return 0===this.invoices.length?H` <div class="Friday__empty-state"> <div class="Friday__empty-icon">📄</div> <h3>No invoices found</h3> <p class="Friday__text-muted">Create your first invoice to get started</p> <button class="Friday__button Friday__button--primary" @click=${()=>this.showCreateForm=!0} > Create Invoice </button> </div> `:H` <div class="Friday__invoice-list"> ${this.invoices.map(e=>H` <div class="Friday__invoice-item" @click=${()=>this.selectInvoice(e)} > <div class="Friday__invoice-details"> <div class="Friday__invoice-number">${e.invoice_number}</div> <div class="Friday__invoice-customer">${this.getCustomerName(e.customer_id)}</div> <div class="Friday__invoice-date"> Due: ${this.apiClient?.formatDate(e.due_date)} </div> </div> <div class="Friday__invoice-amount"> ${this.apiClient?.formatCurrency(e.amount_cents,e.currency)} </div> <div class="Friday__invoice-status"> <span class="Friday__badge ${this.getStatusBadgeClass(e.status)}"> ${e.status} </span> </div> <div class="Friday__invoice-actions"> ${"pending"===e.status?H` <button class="Friday__button Friday__button--sm Friday__button--success" @click=${t=>{t.stopPropagation(),this.recordPayment(e.id,e.amount_cents/100)}} > Record Payment </button> `:""} </div> </div> `)} </div> `}renderModal(){return this.selectedInvoice||this.showCreateForm?H` <div class="Friday__modal-overlay" @click=${this.closeModal}> <div class="Friday__modal" @click=${e=>e.stopPropagation()}> <div class="Friday__modal-header"> <h3 class="Friday__modal-title"> ${this.selectedInvoice?`Invoice ${this.selectedInv