friday-widgets
Version:
Professional embeddable accounting widgets for vertical SaaS platforms. Layer Financial-inspired design with comprehensive financial reporting capabilities.
685 lines (601 loc) • 50.3 kB
JavaScript
var FridayBalanceSheetWidget=function(e){"use strict";function t(e,t,r,s){var a,i=arguments.length,o=i<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,r):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,s);else for(var n=e.length-1;n>=0;n--)(a=e[n])&&(o=(i<3?a(o):i>3?a(t,r,o):a(t,r))||o);return i>3&&o&&Object.defineProperty(t,r,o),o}"function"==typeof SuppressedError&&SuppressedError;
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const r=globalThis,s=r.ShadowRoot&&(void 0===r.ShadyCSS||r.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,a=Symbol(),i=new WeakMap;let o=class{constructor(e,t,r){if(this._$cssResult$=!0,r!==a)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(s&&void 0===e){const r=void 0!==t&&1===t.length;r&&(e=i.get(t)),void 0===e&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),r&&i.set(t,e))}return e}toString(){return this.cssText}};const n=(e,...t)=>{const r=1===e.length?e[0]:t.reduce((t,r,s)=>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.")})(r)+e[s+1],e[0]);return new o(r,e,a)},l=s?e=>e:e=>e instanceof CSSStyleSheet?(e=>{let t="";for(const r of e.cssRules)t+=r.cssText;return(e=>new o("string"==typeof e?e:e+"",void 0,a))(t)})(e):e,{is:d,defineProperty:c,getOwnPropertyDescriptor:h,getOwnPropertyNames:p,getOwnPropertySymbols:u,getPrototypeOf:y}=Object,g=globalThis,m=g.trustedTypes,v=m?m.emptyScript:"",b=g.reactiveElementPolyfillSupport,_=(e,t)=>e,f={toAttribute(e,t){switch(t){case Boolean:e=e?v:null;break;case Object:case Array:e=null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){let r=e;switch(t){case Boolean:r=null!==e;break;case Number:r=null===e?null:Number(e);break;case Object:case Array:try{r=JSON.parse(e)}catch(e){r=null}}return r}},x=(e,t)=>!d(e,t),$={attribute:!0,type:String,converter:f,reflect:!1,useDefault:!1,hasChanged:x};
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/Symbol.metadata??=Symbol("metadata"),g.litPropertyMetadata??=new WeakMap;let w=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 r=Symbol(),s=this.getPropertyDescriptor(e,r,t);void 0!==s&&c(this.prototype,e,s)}}static getPropertyDescriptor(e,t,r){const{get:s,set:a}=h(this.prototype,e)??{get(){return this[t]},set(e){this[t]=e}};return{get:s,set(t){const i=s?.call(this);a?.call(this,t),this.requestUpdate(e,i,r)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)??$}static _$Ei(){if(this.hasOwnProperty(_("elementProperties")))return;const e=y(this);e.finalize(),void 0!==e.l&&(this.l=[...e.l]),this.elementProperties=new Map(e.elementProperties)}static finalize(){if(this.hasOwnProperty(_("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(_("properties"))){const e=this.properties,t=[...p(e),...u(e)];for(const r of t)this.createProperty(r,e[r])}const e=this[Symbol.metadata];if(null!==e){const t=litPropertyMetadata.get(e);if(void 0!==t)for(const[e,r]of t)this.elementProperties.set(e,r)}this._$Eh=new Map;for(const[e,t]of this.elementProperties){const r=this._$Eu(e,t);void 0!==r&&this._$Eh.set(r,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const r=new Set(e.flat(1/0).reverse());for(const e of r)t.unshift(l(e))}else void 0!==e&&t.push(l(e));return t}static _$Eu(e,t){const r=t.attribute;return!1===r?void 0:"string"==typeof r?r:"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 r of t.keys())this.hasOwnProperty(r)&&(e.set(r,this[r]),delete this[r]);e.size>0&&(this._$Ep=e)}createRenderRoot(){const e=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return((e,t)=>{if(s)e.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(const s of t){const t=document.createElement("style"),a=r.litNonce;void 0!==a&&t.setAttribute("nonce",a),t.textContent=s.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,r){this._$AK(e,r)}_$ET(e,t){const r=this.constructor.elementProperties.get(e),s=this.constructor._$Eu(e,r);if(void 0!==s&&!0===r.reflect){const a=(void 0!==r.converter?.toAttribute?r.converter:f).toAttribute(t,r.type);this._$Em=e,null==a?this.removeAttribute(s):this.setAttribute(s,a),this._$Em=null}}_$AK(e,t){const r=this.constructor,s=r._$Eh.get(e);if(void 0!==s&&this._$Em!==s){const e=r.getPropertyOptions(s),a="function"==typeof e.converter?{fromAttribute:e.converter}:void 0!==e.converter?.fromAttribute?e.converter:f;this._$Em=s;const i=a.fromAttribute(t,e.type);this[s]=i??this._$Ej?.get(s)??i,this._$Em=null}}requestUpdate(e,t,r){if(void 0!==e){const s=this.constructor,a=this[e];if(r??=s.getPropertyOptions(e),!((r.hasChanged??x)(a,t)||r.useDefault&&r.reflect&&a===this._$Ej?.get(e)&&!this.hasAttribute(s._$Eu(e,r))))return;this.C(e,t,r)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(e,t,{useDefault:r,reflect:s,wrapped:a},i){r&&!(this._$Ej??=new Map).has(e)&&(this._$Ej.set(e,i??t??this[e]),!0!==a||void 0!==i)||(this._$AL.has(e)||(this.hasUpdated||r||(t=void 0),this._$AL.set(e,t)),!0===s&&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,r]of e){const{wrapped:e}=r,s=this[t];!0!==e||this._$AL.has(t)||void 0===s||this.C(t,void 0,r,s)}}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){}};w.elementStyles=[],w.shadowRootOptions={mode:"open"},w[_("elementProperties")]=new Map,w[_("finalized")]=new Map,b?.({ReactiveElement:w}),(g.reactiveElementVersions??=[]).push("2.1.1");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const A=globalThis,S=A.trustedTypes,E=S?S.createPolicy("lit-html",{createHTML:e=>e}):void 0,F="$lit$",P=`lit$${Math.random().toFixed(9).slice(2)}$`,C="?"+P,k=`<${C}>`,O=document,D=()=>O.createComment(""),I=e=>null===e||"object"!=typeof e&&"function"!=typeof e,q=Array.isArray,N="[ \t\n\f\r]",U=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,T=/-->/g,L=/>/g,R=RegExp(`>|${N}(?:([^\\s"'>=/]+)(${N}*=${N}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),B=/'/g,H=/"/g,z=/^(?:script|style|textarea|title)$/i,M=(e=>(t,...r)=>({_$litType$:e,strings:t,values:r}))(1),j=Symbol.for("lit-noChange"),W=Symbol.for("lit-nothing"),J=new WeakMap,K=O.createTreeWalker(O,129);function V(e,t){if(!q(e)||!e.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==E?E.createHTML(t):t}const G=(e,t)=>{const r=e.length-1,s=[];let a,i=2===t?"<svg>":3===t?"<math>":"",o=U;for(let t=0;t<r;t++){const r=e[t];let n,l,d=-1,c=0;for(;c<r.length&&(o.lastIndex=c,l=o.exec(r),null!==l);)c=o.lastIndex,o===U?"!--"===l[1]?o=T:void 0!==l[1]?o=L:void 0!==l[2]?(z.test(l[2])&&(a=RegExp("</"+l[2],"g")),o=R):void 0!==l[3]&&(o=R):o===R?">"===l[0]?(o=a??U,d=-1):void 0===l[1]?d=-2:(d=o.lastIndex-l[2].length,n=l[1],o=void 0===l[3]?R:'"'===l[3]?H:B):o===H||o===B?o=R:o===T||o===L?o=U:(o=R,a=void 0);const h=o===R&&e[t+1].startsWith("/>")?" ":"";i+=o===U?r+k:d>=0?(s.push(n),r.slice(0,d)+F+r.slice(d)+P+h):r+P+(-2===d?t:h)}return[V(e,i+(e[r]||"<?>")+(2===t?"</svg>":3===t?"</math>":"")),s]};class Z{constructor({strings:e,_$litType$:t},r){let s;this.parts=[];let a=0,i=0;const o=e.length-1,n=this.parts,[l,d]=G(e,t);if(this.el=Z.createElement(l,r),K.currentNode=this.el.content,2===t||3===t){const e=this.el.content.firstChild;e.replaceWith(...e.childNodes)}for(;null!==(s=K.nextNode())&&n.length<o;){if(1===s.nodeType){if(s.hasAttributes())for(const e of s.getAttributeNames())if(e.endsWith(F)){const t=d[i++],r=s.getAttribute(e).split(P),o=/([.?@])?(.*)/.exec(t);n.push({type:1,index:a,name:o[2],strings:r,ctor:"."===o[1]?te:"?"===o[1]?re:"@"===o[1]?se:ee}),s.removeAttribute(e)}else e.startsWith(P)&&(n.push({type:6,index:a}),s.removeAttribute(e));if(z.test(s.tagName)){const e=s.textContent.split(P),t=e.length-1;if(t>0){s.textContent=S?S.emptyScript:"";for(let r=0;r<t;r++)s.append(e[r],D()),K.nextNode(),n.push({type:2,index:++a});s.append(e[t],D())}}}else if(8===s.nodeType)if(s.data===C)n.push({type:2,index:a});else{let e=-1;for(;-1!==(e=s.data.indexOf(P,e+1));)n.push({type:7,index:a}),e+=P.length-1}a++}}static createElement(e,t){const r=O.createElement("template");return r.innerHTML=e,r}}function X(e,t,r=e,s){if(t===j)return t;let a=void 0!==s?r._$Co?.[s]:r._$Cl;const i=I(t)?void 0:t._$litDirective$;return a?.constructor!==i&&(a?._$AO?.(!1),void 0===i?a=void 0:(a=new i(e),a._$AT(e,r,s)),void 0!==s?(r._$Co??=[])[s]=a:r._$Cl=a),void 0!==a&&(t=X(e,a._$AS(e,t.values),a,s)),t}class Q{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:r}=this._$AD,s=(e?.creationScope??O).importNode(t,!0);K.currentNode=s;let a=K.nextNode(),i=0,o=0,n=r[0];for(;void 0!==n;){if(i===n.index){let t;2===n.type?t=new Y(a,a.nextSibling,this,e):1===n.type?t=new n.ctor(a,n.name,n.strings,this,e):6===n.type&&(t=new ae(a,this,e)),this._$AV.push(t),n=r[++o]}i!==n?.index&&(a=K.nextNode(),i++)}return K.currentNode=O,s}p(e){let t=0;for(const r of this._$AV)void 0!==r&&(void 0!==r.strings?(r._$AI(e,r,t),t+=r.strings.length-2):r._$AI(e[t])),t++}}class Y{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(e,t,r,s){this.type=2,this._$AH=W,this._$AN=void 0,this._$AA=e,this._$AB=t,this._$AM=r,this.options=s,this._$Cv=s?.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=X(this,e,t),I(e)?e===W||null==e||""===e?(this._$AH!==W&&this._$AR(),this._$AH=W):e!==this._$AH&&e!==j&&this._(e):void 0!==e._$litType$?this.$(e):void 0!==e.nodeType?this.T(e):(e=>q(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!==W&&I(this._$AH)?this._$AA.nextSibling.data=e:this.T(O.createTextNode(e)),this._$AH=e}$(e){const{values:t,_$litType$:r}=e,s="number"==typeof r?this._$AC(e):(void 0===r.el&&(r.el=Z.createElement(V(r.h,r.h[0]),this.options)),r);if(this._$AH?._$AD===s)this._$AH.p(t);else{const e=new Q(s,this),r=e.u(this.options);e.p(t),this.T(r),this._$AH=e}}_$AC(e){let t=J.get(e.strings);return void 0===t&&J.set(e.strings,t=new Z(e)),t}k(e){q(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let r,s=0;for(const a of e)s===t.length?t.push(r=new Y(this.O(D()),this.O(D()),this,this.options)):r=t[s],r._$AI(a),s++;s<t.length&&(this._$AR(r&&r._$AB.nextSibling,s),t.length=s)}_$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 ee{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(e,t,r,s,a){this.type=1,this._$AH=W,this._$AN=void 0,this.element=e,this.name=t,this._$AM=s,this.options=a,r.length>2||""!==r[0]||""!==r[1]?(this._$AH=Array(r.length-1).fill(new String),this.strings=r):this._$AH=W}_$AI(e,t=this,r,s){const a=this.strings;let i=!1;if(void 0===a)e=X(this,e,t,0),i=!I(e)||e!==this._$AH&&e!==j,i&&(this._$AH=e);else{const s=e;let o,n;for(e=a[0],o=0;o<a.length-1;o++)n=X(this,s[r+o],t,o),n===j&&(n=this._$AH[o]),i||=!I(n)||n!==this._$AH[o],n===W?e=W:e!==W&&(e+=(n??"")+a[o+1]),this._$AH[o]=n}i&&!s&&this.j(e)}j(e){e===W?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,e??"")}}class te extends ee{constructor(){super(...arguments),this.type=3}j(e){this.element[this.name]=e===W?void 0:e}}class re extends ee{constructor(){super(...arguments),this.type=4}j(e){this.element.toggleAttribute(this.name,!!e&&e!==W)}}class se extends ee{constructor(e,t,r,s,a){super(e,t,r,s,a),this.type=5}_$AI(e,t=this){if((e=X(this,e,t,0)??W)===j)return;const r=this._$AH,s=e===W&&r!==W||e.capture!==r.capture||e.once!==r.once||e.passive!==r.passive,a=e!==W&&(r===W||s);s&&this.element.removeEventListener(this.name,this,r),a&&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 ae{constructor(e,t,r){this.element=e,this.type=6,this._$AN=void 0,this._$AM=t,this.options=r}get _$AU(){return this._$AM._$AU}_$AI(e){X(this,e)}}const ie=A.litHtmlPolyfillSupport;ie?.(Z,Y),(A.litHtmlVersions??=[]).push("3.3.1");const oe=globalThis;
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/class ne extends w{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,r)=>{const s=r?.renderBefore??t;let a=s._$litPart$;if(void 0===a){const e=r?.renderBefore??null;s._$litPart$=a=new Y(t.insertBefore(D(),e),e,void 0,r??{})}return a._$AI(e),a})(t,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return j}}ne._$litElement$=!0,ne.finalized=!0,oe.litElementHydrateSupport?.({LitElement:ne});const le=oe.litElementPolyfillSupport;le?.({LitElement:ne}),(oe.litElementVersions??=[]).push("4.2.1");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const de={attribute:!0,type:String,converter:f,reflect:!1,hasChanged:x},ce=(e=de,t,r)=>{const{kind:s,metadata:a}=r;let i=globalThis.litPropertyMetadata.get(a);if(void 0===i&&globalThis.litPropertyMetadata.set(a,i=new Map),"setter"===s&&((e=Object.create(e)).wrapped=!0),i.set(r.name,e),"accessor"===s){const{name:s}=r;return{set(r){const a=t.get.call(this);t.set.call(this,r),this.requestUpdate(s,a,e)},init(t){return void 0!==t&&this.C(s,void 0,e,t),t}}}if("setter"===s){const{name:s}=r;return function(r){const a=this[s];t.call(this,r),this.requestUpdate(s,a,e)}}throw Error("Unsupported decorator location: "+s)};
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/function he(e){return(t,r)=>"object"==typeof r?ce(e,t,r):((e,t,r)=>{const s=t.hasOwnProperty(r);return t.constructor.createProperty(r,e),s?Object.getOwnPropertyDescriptor(t,r):void 0})(e,t,r)}
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/function pe(e){return he({...e,state:!0,attribute:!1})}class ue{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 r=`${this.config.baseURL}${e}`,s={...this.defaultHeaders,...t.headers},a={...t,headers:s,signal:AbortSignal.timeout(this.config.timeout)};try{const e=await fetch(r,a);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 r=new URLSearchParams({business_id:e});return t?.status&&r.append("status",t.status),t?.customer_id&&r.append("customer_id",t.customer_id),t?.date_from&&r.append("date_from",t.date_from),t?.date_to&&r.append("date_to",t.date_to),t?.overdue&&r.append("overdue","true"),t?.outstanding&&r.append("outstanding","true"),t?.search&&r.append("search",t.search),this.request(`/invoices/?${r.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 r=new URLSearchParams({business_id:e});return t?.account_type&&r.append("account_type",t.account_type),void 0!==t?.is_active&&r.append("is_active",t.is_active.toString()),t?.search&&r.append("search",t.search),this.request(`/accounts/?${r.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 r=new URLSearchParams({business_id:e});return t?.status&&r.append("status",t.status),t?.customer_id&&r.append("customer_id",t.customer_id),t?.date_from&&r.append("date_from",t.date_from),t?.date_to&&r.append("date_to",t.date_to),t?.search&&r.append("search",t.search),this.request(`/payments/?${r.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 r=new URLSearchParams({business_id:e});return t&&r.append("effective_date",t),this.request(`/reports/balance-sheet/?${r.toString()}`)}async getPnLData(e,t,r){const s=new URLSearchParams({business_id:e,date_from:t,date_to:r});return this.request(`/reports/pnl/?${s.toString()}`)}async getCashFlowData(e,t,r){const s=new URLSearchParams({business_id:e,date_from:t,date_to:r});return this.request(`/reports/cash-flow/?${s.toString()}`)}async healthCheck(){return this.request("/health/")}formatCurrency(e,t="GBP"){const r="number"==typeof e?e:parseFloat(e.toString());return new Intl.NumberFormat("en-GB",{style:"currency",currency:t}).format(r)}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 ye extends ne{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 t=window.FridayProvider.getWidgetConfig();if(t)return void(this.apiClient=new ue({baseURL:t.baseUrl,apiKey:t.apiKey,businessId:t.businessId}))}this.apiKey?this.apiClient=new ue({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 r=`${t} failed`;e?.error?r=e.error:e?.message?r=e.message:"string"==typeof e&&(r=e),e?.details&&(r+=` (${e.details})`),this.setError(r),this.emitEvent("api-error",{context:t,error:e,message:r})}async makeApiRequest(e,t="Request"){try{if(this.setLoading(!0),!this.apiClient)throw new Error("API client not initialized");const r=await e();return r.success?(this.clearError(),r.data||null):(this.handleApiError(r,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 r={type:e,data:t,timestamp:Date.now()};this.dispatchEvent(new CustomEvent(`friday-${e}`,{detail:r,bubbles:!0,composed:!0}))}renderLoading(){return M`
<div class="Friday__loading">
<div class="Friday__spinner"></div>
<span>Loading...</span>
</div>
`}renderError(){return M`
<div class="Friday__error">
<span>⚠️ ${this.error}</span>
</div>
`}static get baseStyles(){return n`
@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);
}
}
`}}return t([he({type:String,attribute:"api-key"})],ye.prototype,"apiKey",void 0),t([he({type:String,attribute:"business-id"})],ye.prototype,"businessId",void 0),t([he({type:String})],ye.prototype,"theme",void 0),t([he({type:String,attribute:"base-url"})],ye.prototype,"baseUrl",void 0),t([pe()],ye.prototype,"loading",void 0),t([pe()],ye.prototype,"error",void 0),e.BalanceSheetWidget=class extends ye{constructor(){super(...arguments),this.asWidget=!0,this.stringOverrides={typeColumnHeader:"Account",totalColumnHeader:"Amount",assetsLabel:"Assets",liabilitiesEquityLabel:"Liabilities & Equity",expandAllLabel:"Expand All",collapseAllLabel:"Collapse All",downloadLabel:"Download"},this.showDemo=!1,this.balanceSheetData=null,this.expandedItems=new Set,this.allExpanded=!1}static get styles(){return[ye.baseStyles,n`
.Friday__balance-sheet {
background: var(--bg-primary);
border: 1px solid var(--border-primary);
border-radius: var(--radius-lg);
overflow: hidden;
}
.Friday__balance-sheet-header {
padding: var(--spacing-xl);
border-bottom: 1px solid var(--border-primary);
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: var(--spacing-md);
}
.Friday__balance-sheet-title {
font-size: var(--text-xl);
font-weight: var(--font-weight-semibold);
color: var(--text-color-primary);
margin: 0;
}
.Friday__balance-sheet-controls {
display: flex;
gap: var(--spacing-sm);
align-items: center;
}
.Friday__balance-sheet-date-picker {
padding: var(--spacing-sm) var(--spacing-md);
border: 1px solid var(--border-primary);
border-radius: var(--radius-md);
font-size: var(--text-sm);
font-family: inherit;
background: var(--bg-primary);
color: var(--text-color-primary);
}
.Friday__balance-sheet-button {
padding: var(--spacing-sm) var(--spacing-md);
border: 1px solid var(--border-primary);
border-radius: var(--radius-md);
background: var(--bg-primary);
color: var(--text-color-primary);
font-size: var(--text-sm);
font-weight: var(--font-weight-medium);
cursor: pointer;
transition: all var(--transition-fast);
}
.Friday__balance-sheet-button:hover {
background: var(--bg-element-hover);
border-color: var(--color-info);
}
.Friday__balance-sheet-button--primary {
background: var(--color-info);
color: white;
border-color: var(--color-info);
}
.Friday__balance-sheet-button--primary:hover {
background: var(--color-info-hover);
}
.Friday__balance-sheet-table {
width: 100%;
border-collapse: collapse;
font-size: var(--text-sm);
}
.Friday__balance-sheet-table-header {
background: var(--bg-secondary);
border-bottom: 2px solid var(--border-primary);
}
.Friday__balance-sheet-table-header th {
padding: var(--spacing-lg) var(--spacing-md);
text-align: left;
font-weight: var(--font-weight-semibold);
color: var(--text-color-primary);
font-size: var(--text-xs);
text-transform: uppercase;
letter-spacing: 0.05em;
}
.Friday__balance-sheet-table-header th:last-child {
text-align: right;
}
.Friday__balance-sheet-row {
border-bottom: 1px solid var(--border-primary);
transition: background-color var(--transition-fast);
}
.Friday__balance-sheet-row:hover {
background: var(--bg-element-hover);
}
.Friday__balance-sheet-row--major {
background: var(--bg-secondary);
font-weight: var(--font-weight-semibold);
border-top: 2px solid var(--border-secondary);
}
.Friday__balance-sheet-row--total {
background: var(--color-info-bg);
border-top: 2px solid var(--color-info);
font-weight: var(--font-weight-bold);
}
.Friday__balance-sheet-row--expandable {
cursor: pointer;
user-select: none;
}
.Friday__balance-sheet-cell {
padding: var(--spacing-md);
vertical-align: middle;
}
.Friday__balance-sheet-cell--amount {
text-align: right;
font-family: var(--font-family-numeric);
font-weight: var(--font-weight-medium);
}
.Friday__balance-sheet-cell--amount.contra {
color: var(--color-error-fg);
}
.Friday__balance-sheet-account-name {
display: flex;
align-items: center;
gap: var(--spacing-xs);
}
.Friday__balance-sheet-expand-button {
width: 20px;
height: 20px;
border: none;
background: transparent;
color: var(--text-color-secondary);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
border-radius: var(--radius-sm);
transition: all var(--transition-fast);
font-size: 12px;
}
.Friday__balance-sheet-expand-button:hover {
background: var(--bg-element-hover);
color: var(--text-color-primary);
}
.Friday__balance-sheet-expand-button.expanded {
transform: rotate(90deg);
}
.Friday__balance-sheet-indent {
height: 1px;
}
.Friday__balance-sheet-effective-date {
text-align: center;
padding: var(--spacing-md);
background: var(--bg-secondary);
font-size: var(--text-sm);
color: var(--text-color-secondary);
border-top: 1px solid var(--border-primary);
}
.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;
}
@media (max-width: 768px) {
.Friday__balance-sheet-header {
flex-direction: column;
align-items: stretch;
padding: var(--spacing-lg);
}
.Friday__balance-sheet-controls {
justify-content: space-between;
}
.Friday__balance-sheet-cell {
padding: var(--spacing-sm);
}
.Friday__balance-sheet-table-header th {
padding: var(--spacing-md) var(--spacing-sm);
}
}
`]}async loadData(){if(this.apiClient){this.setLoading(!0);try{this.showDemo,this.loadDemoData(),this.emitEvent("balance-sheet-loaded",{data:this.balanceSheetData})}catch(e){this.setError("Failed to load balance sheet data")}finally{this.setLoading(!1)}}}loadDemoData(){const e=this.effectiveDate?.toISOString()||(new Date).toISOString();this.balanceSheetData={businessId:"bus_demo_business",type:"Balance_Sheet",effectiveDate:e,startDate:"2024-01-01T00:00:00Z",endDate:"2024-12-31T23:59:59Z",assets:{displayName:this.stringOverrides.assetsLabel||"Assets",value:325e3,level:0,lineItems:[{name:"current_assets",displayName:"Current Assets",value:185e3,level:1,lineItems:[{name:"cash",displayName:"Cash & Cash Equivalents",value:75e3,level:2},{name:"accounts_receivable",displayName:"Accounts Receivable",value:65e3,level:2},{name:"inventory",displayName:"Inventory",value:35e3,level:2},{name:"prepaid_expenses",displayName:"Prepaid Expenses",value:1e4,level:2}]},{name:"fixed_assets",displayName:"Fixed Assets",value:14e4,level:1,lineItems:[{name:"property_plant_equipment",displayName:"Property, Plant & Equipment",value:2e5,level:2},{name:"accumulated_depreciation",displayName:"Accumulated Depreciation",value:-6e4,level:2,isContra:!0},{name:"intangible_assets",displayName:"Intangible Assets",value:25e3,level:2}]}]},liabilitiesAndEquity:{displayName:this.stringOverrides.liabilitiesEquityLabel||"Liabilities & Equity",value:325e3,level:0,lineItems:[{name:"current_liabilities",displayName:"Current Liabilities",value:85e3,level:1,lineItems:[{name:"accounts_payable",displayName:"Accounts Payable",value:45e3,level:2},{name:"accrued_liabilities",displayName:"Accrued Liabilities",value:25e3,level:2},{name:"short_term_debt",displayName:"Short-term Debt",value:15e3,level:2}]},{name:"long_term_liabilities",displayName:"Long-term Liabilities",value:9e4,level:1,lineItems:[{name:"long_term_debt",displayName:"Long-term Debt",value:75e3,level:2},{name:"deferred_tax_liabilities",displayName:"Deferred Tax Liabilities",value:15e3,level:2}]},{name:"equity",displayName:"Equity",value:15e4,level:1,lineItems:[{name:"retained_earnings",displayName:"Retained Earnings",value:1e5,level:2},{name:"owner_equity",displayName:"Owner's Equity",value:5e4,level:2}]}]},fullyCategorized:!0}}toggleExpand(e){this.expandedItems.has(e)?this.expandedItems.delete(e):this.expandedItems.add(e),this.requestUpdate()}isExpanded(e){return this.expandedItems.has(e)}toggleExpandAll(){this.allExpanded?(this.expandedItems.clear(),this.allExpanded=!1):(this.expandAllItems(),this.allExpanded=!0),this.requestUpdate()}expandAllItems(){if(!this.balanceSheetData)return;const e=(t,r="")=>{const s=t.name?`${r}${t.name}`:`${r}${t.displayName.toLowerCase().replace(/\s+/g,"_")}`;t.lineItems&&t.lineItems.length>0&&(this.expandedItems.add(s),t.lineItems.forEach(t=>e(t,`${s}_`)))};e(this.balanceSheetData.assets,"assets_"),e(this.balanceSheetData.liabilitiesAndEquity,"liabilities_equity_")}handleDateChange(e){const t=e.target,r=new Date(t.value);this.effectiveDate=r,this.loadData(),this.emitEvent("effective-date-changed",{effectiveDate:r.toISOString()})}handleDownload(){this.balanceSheetData&&this.emitEvent("balance-sheet-download-requested",{effectiveDate:this.balanceSheetData.effectiveDate,format:"csv"})}renderLineItem(e,t="",r=!0){const s=[],a=e.name?`${t}${e.name}`:`${t}${e.displayName.toLowerCase().replace(/\s+/g,"_")}`,i=e.lineItems&&e.lineItems.length>0,o=this.isExpanded(a),n=20*(e.level||0);return s.push(M`
<tr
class="Friday__balance-sheet-row ${0===e.level?"Friday__balance-sheet-row--major":""} ${i?"Friday__balance-sheet-row--expandable":""}"
@click=${i?()=>this.toggleExpand(a):void 0}
>
<td class="Friday__balance-sheet-cell">
<div class="Friday__balance-sheet-account-name">
<div class="Friday__balance-sheet-indent" style="width: ${n}px;"></div>
${i?M`
<button
class="Friday__balance-sheet-expand-button ${o?"expanded":""}"
@click=${e=>{e.stopPropagation(),this.toggleExpand(a)}}
>
▶
</button>
`:M`<div style="width: 20px;"></div>`}
${e.displayName}
</div>
</td>
<td class="Friday__balance-sheet-cell Friday__balance-sheet-cell--amount ${e.isContra?"contra":""}">
${void 0!==e.value?this.apiClient?.formatCurrency(100*Math.abs(e.value),"GBP"):"—"}
</td>
</tr>
`),i&&r&&o&&e.lineItems.forEach(e=>{s.push(...this.renderLineItem(e,`${a}_`,!0))}),s}renderBalanceSheetRows(){if(!this.balanceSheetData)return[];const e=[];return e.push(...this.renderLineItem(this.balanceSheetData.assets,"assets_")),e.push(...this.renderLineItem(this.balanceSheetData.liabilitiesAndEquity,"liabilities_equity_")),e}render(){if(this.loading)return M`<div class="Friday__component">${this.renderLoading()}</div>`;if(this.error)return M`<div class="Friday__component">${this.renderError()}</div>`;const e=(this.effectiveDate||new Date).toISOString().split("T")[0];return M`
<div class="Friday__component">
${this.showDemo?M`
<div class="Friday__demo-notice">
<strong>Demo Mode:</strong> Showing sample balance sheet data
</div>
`:""}
<div class="Friday__balance-sheet">
<div class="Friday__balance-sheet-header">
<h2 class="Friday__balance-sheet-title">Balance Sheet</h2>
<div class="Friday__balance-sheet-controls">
<input
type="date"
class="Friday__balance-sheet-date-picker"
.value=${e}
@change=${this.handleDateChange}
title="Effective Date"
/>
<button
class="Friday__balance-sheet-button"
@click=${this.toggleExpandAll}
>
${this.allExpanded?this.stringOverrides.collapseAllLabel:this.stringOverrides.expandAllLabel}
</button>
<button
class="Friday__balance-sheet-button Friday__balance-sheet-button--primary"
@click=${this.handleDownload}
>
${this.stringOverrides.downloadLabel}
</button>
</div>
</div>
<table class="Friday__balance-sheet-table">
<thead class="Friday__balance-sheet-table-header">
<tr>
<th>${this.stringOverrides.typeColumnHeader}</th>
<th>${this.stringOverrides.totalColumnHeader}</th>
</tr>
</thead>
<tbody>
${this.renderBalanceSheetRows()}
</tbody>
</table>
${this.balanceSheetData?M`
<div class="Friday__balance-sheet-effective-date">
As of ${new Date(this.balanceSheetData.effectiveDate).toLocaleDateString()}
</div>
`:""}
</div>
</div>
`}},t([he({type:Date,attribute:"effective-date"})],e.BalanceSheetWidget.prototype,"effectiveDate",void 0),t([he({type:Boolean,attribute:"as-widget"})],e.BalanceSheetWidget.prototype,"asWidget",void 0),t([he({type:Object})],e.BalanceSheetWidget.prototype,"stringOverrides",void 0),t([he({type:Boolean,attribute:"show-demo"})],e.BalanceSheetWidget.prototype,"showDemo",void 0),t([pe()],e.BalanceSheetWidget.prototype,"balanceSheetData",void 0)