deepspotscreen-sdk 0.1.1 → 0.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.
@@ -1,962 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class ae{constructor(e,t){this.tokenCache=new Map,this.baseUrl=e.replace(/\/$/,""),this.apiKey=t}async getEmbedToken(e){var i,a,o,l;const t=[e.dashboardId,e.embedType,(i=e.embedLevel)!=null?i:"",(a=e.componentId)!=null?a:"",(o=e.userId)!=null?o:""].join(":"),s=this.tokenCache.get(t);if(s&&s.expiresAt>Date.now()+6e4)return s.token;const r=await this.post("/dashboard-builder/embed-token",{dashboardId:e.dashboardId,embedType:e.embedType,embedLevel:(l=e.embedLevel)!=null?l:"dashboard",componentId:e.componentId,userId:e.userId,tenantId:e.tenantId,expiresIn:3600},{"x-deepspot-api-key":this.apiKey});return this.tokenCache.set(t,{token:r.token,expiresAt:new Date(r.expiresAt).getTime()}),r.token}async getDashboardRender(e,t,s={}){var i;const r=new URLSearchParams({embedType:"dashboard",embedLevel:(i=s.embedLevel)!=null?i:"dashboard"});return s.pageId&&r.set("pageId",s.pageId),s.tabId&&r.set("tabId",s.tabId),s.filters&&Object.entries(s.filters).forEach(([a,o])=>{o!=null&&o!==""&&r.set(`filter[${a}]`,Array.isArray(o)?o.join(","):String(o))}),this.get(`/dashboard-builder/embed/${e}/render?${r}`,{"x-embed-token":t})}async getReportRender(e,t,s,r={}){const i=new URLSearchParams({embedType:"report",embedLevel:"report",componentId:t});return r.filters&&Object.entries(r.filters).forEach(([a,o])=>{o!=null&&o!==""&&i.set(`filter[${a}]`,Array.isArray(o)?o.join(","):String(o))}),this.get(`/dashboard-builder/embed/${e}/render?${i}`,{"x-embed-token":s})}async createApiKey(e,t){return this.post("/dashboard-builder/api-keys",e,{Authorization:`Bearer ${t}`})}async listApiKeys(e){return this.get("/dashboard-builder/api-keys",{Authorization:`Bearer ${e}`})}async deleteApiKey(e,t){await this.delete(`/dashboard-builder/api-keys/${e}`,{Authorization:`Bearer ${t}`})}async getTablePage(e,t,s,r,i){return this.get(`/dashboard-builder/embed/${e}/table/${t}/data?page=${s}&pageSize=${r}`,{"x-embed-token":i})}async getFilterOptions(e,t,s){try{const r=await this.get(`/dashboard-builder/embed/${e}/filters/${t}/options`,{"x-embed-token":s});return Array.isArray(r)?r:Array.isArray(r==null?void 0:r.options)?r.options:Array.isArray(r==null?void 0:r.data)?r.data:[]}catch(r){return[]}}clearTokenCache(){this.tokenCache.clear()}async get(e,t={}){const s=await fetch(`${this.baseUrl}${e}`,{method:"GET",headers:{"Content-Type":"application/json",...t}});return this.handleResponse(s)}async post(e,t,s={}){const r=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:{"Content-Type":"application/json",...s},body:JSON.stringify(t)});return this.handleResponse(r)}async delete(e,t={}){const s=await fetch(`${this.baseUrl}${e}`,{method:"DELETE",headers:{"Content-Type":"application/json",...t}});if(!s.ok)throw new Error(`Deepspot SDK: DELETE ${e} failed (${s.status})`)}async handleResponse(e){if(!e.ok){let s=`HTTP ${e.status}`;try{const r=await e.json();s=(r==null?void 0:r.message)||(r==null?void 0:r.error)||s}catch(r){}throw new Error(`Deepspot SDK: ${s}`)}const t=await e.json();return(t==null?void 0:t.data)!==void 0?t.data:t}}class Q{constructor(e){var t,s;this.destroyed=!1,this.refreshTimer=null,this.opts=e,this.filters={...e.activeFilters},this.activePageId=(t=e.activePageId)!=null?t:"",this.activeTabId=(s=e.activeTabId)!=null?s:""}getActiveFilters(){return{...this.filters}}setFilter(e,t){this.filters[e]=t,this.scheduleRefresh()}setFilters(e){Object.assign(this.filters,e),this.scheduleRefresh()}setGlobalFilter(e,t){this.setFilter(e,t)}clearFilters(){this.filters={},this.scheduleRefresh()}goToPage(e){this.opts.embedType==="dashboard"&&(this.activePageId=e,this.opts.renderer.goToPage(e))}goToTab(e,t){this.opts.embedType==="dashboard"&&(this.activePageId=e,this.activeTabId=t,this.opts.renderer.goToTab(e,t))}async refresh(){if(!this.destroyed)try{const e=await this.fetchData();this.opts.renderer.update(e)}catch(e){console.error("Deepspot SDK: refresh failed",e)}}exportPDF(){this.opts.embedType==="dashboard"&&this.opts.renderer.exportPDF()}destroy(){this.destroyed=!0,this.refreshTimer&&clearTimeout(this.refreshTimer),this.opts.renderer.destroy(),this.opts.apiClient.clearTokenCache()}scheduleRefresh(){this.refreshTimer&&clearTimeout(this.refreshTimer),this.refreshTimer=setTimeout(()=>this.refresh(),300)}async fetchData(){const{apiClient:e,dashboardId:t,componentId:s,token:r,embedType:i,embedLevel:a}=this.opts;return i==="report"&&s?e.getReportRender(t,s,r,{filters:this.filters}):e.getDashboardRender(t,r,{embedLevel:a,pageId:this.activePageId||void 0,tabId:this.activeTabId||void 0,filters:this.filters})}}const oe=24,D=10,E=12;class V{constructor(e,t=0){this.containerWidth=e,this.minY=t}get colWidth(){return this.containerWidth/oe}toPx(e){const t=this.colWidth,s=E/2;return{left:e.x*t+s,top:(e.y-this.minY)*D+s,width:e.w*t-E,height:e.h*D-E}}static totalHeight(e){if(!e.length)return 400;const t=Math.min(...e.map(r=>r.y));return(Math.max(...e.map(r=>r.y+r.h))-t)*D+40}applyStyles(e,t){const s=this.toPx(t);e.style.position="absolute",e.style.left=`${s.left}px`,e.style.top=`${s.top}px`,e.style.width=`${s.width}px`,e.style.height=`${s.height}px`}}let j=null;function de(){return j||(j=Promise.resolve().then(()=>require("./apexcharts.common-DGzslxI3.cjs")).then(w=>w.apexcharts_common)),j}class se{constructor(e){this.chart=null,this.container=e}async render(e,t,s,r){if(!t||t.length===0){this.renderEmpty(e.title);return}const i=this.buildOptions(e,t,s,r);if(!i){this.renderEmpty(e.title);return}this.container.innerHTML=`
2
- <div class="ds-chart-card">
3
- <div class="ds-chart-title">${e.title||""}</div>
4
- <div class="ds-chart-body" id="ds-chart-body-${e.id}"></div>
5
- </div>
6
- `;const a=this.container.querySelector(`#ds-chart-body-${e.id}`);if(a)try{this.chart&&this.chart.destroy();const{default:o}=await de();this.chart=new o(a,i),this.chart.render()}catch(o){console.error("[Deepspot SDK] ChartRenderer error:",o),a.innerHTML='<div class="ds-chart-empty">Chart render error</div>'}}async update(e,t,s){if(!this.chart||!t||t.length===0){await this.render(e,t,s);return}const{series:r,categories:i}=this.extractSeriesAndCategories(e,t);try{this.chart.updateOptions({series:r,xaxis:{categories:i},theme:{mode:s}})}catch(a){this.render(e,t,s)}}destroy(){var e;try{(e=this.chart)==null||e.destroy()}catch(t){}this.chart=null}buildOptions(e,t,s,r){const i=e.type;return i==="pie"||i==="donut"?this.buildPieOptions(e,t,s,r):i==="bar"||i==="line"||i==="area"?this.buildCartesianOptions(e,t,s,r):null}buildCartesianOptions(e,t,s,r){var n;const{series:i,categories:a,xAxisLabel:o,yAxisLabel:l}=this.extractSeriesAndCategories(e,t),d=e.properties||{},f=d.colors?Object.values(d.colors):["#6366f1","#8b5cf6","#ec4899","#f59e0b","#10b981","#3b82f6"],h=s==="dark";return{chart:{type:e.type==="area"?"area":e.type==="line"?"line":"bar",toolbar:{show:!1},background:"transparent",animations:{enabled:!0,speed:400},fontFamily:"inherit",height:r!=null?r:"100%"},theme:{mode:s},series:i,xaxis:{categories:a,title:{text:o},labels:{rotate:a.length>8?-45:0,style:{colors:h?"#94a3b8":"#6b7280",fontSize:"11px"}},axisBorder:{color:h?"#334155":"#e5e7eb"},axisTicks:{color:h?"#334155":"#e5e7eb"}},yaxis:{title:{text:l},labels:{style:{colors:h?"#94a3b8":"#6b7280",fontSize:"11px"}}},colors:f,legend:{show:i.length>1||((n=d.showLegend)!=null?n:!1),position:"bottom",labels:{colors:h?"#94a3b8":"#6b7280"}},grid:{borderColor:h?"#1e293b":"#f3f4f6",strokeDashArray:4,padding:{bottom:a.length>8?60:10}},tooltip:{theme:s},stroke:{curve:"smooth",width:e.type==="bar"?0:2},fill:e.type==="area"?{type:"gradient",gradient:{shadeIntensity:.5,opacityFrom:.4,opacityTo:0}}:{},dataLabels:{enabled:!1},plotOptions:{bar:{borderRadius:4,distributed:i.length===1}}}}buildPieOptions(e,t,s,r){const i=e.properties||{},a=t.length>0?Object.keys(t[0]):[],o=a[0]||"label",l=a[1]||"value",d=t.map(p=>{var b;return String((b=p[o])!=null?b:"")}),f=t.map(p=>Number(p[l])||0),h=s==="dark",n=i.colors?Object.values(i.colors):["#6366f1","#8b5cf6","#ec4899","#f59e0b","#10b981","#3b82f6"];return{chart:{type:e.type,toolbar:{show:!1},background:"transparent",fontFamily:"inherit",height:r!=null?r:"100%"},theme:{mode:s},series:f,labels:d,colors:n,legend:{position:"bottom",labels:{colors:h?"#94a3b8":"#6b7280"}},tooltip:{theme:s},dataLabels:{enabled:d.length<=8},plotOptions:{pie:{donut:{size:e.type==="donut"?"65%":"0%"}}}}}extractSeriesAndCategories(e,t){const s=e.properties||{},r=t.length>0?Object.keys(t[0]):[],i=s.xAxis||r[0]||"x";let a=[];if(s.selectedYAxisColumn)try{const n=typeof s.selectedYAxisColumn=="string"?JSON.parse(s.selectedYAxisColumn):s.selectedYAxisColumn;Array.isArray(n)&&(a=n.map(p=>typeof p=="string"?{column:p}:p))}catch(n){}if(!a.length&&s.yAxis){const n=s.yAxis;a=(Array.isArray(n)?n:[n]).map(b=>({column:String(b)}))}!a.length&&r.length>1&&(a=r.slice(1).map(n=>({column:n})));const o=t.map(n=>{var p;return String((p=n[i])!=null?p:"")}),l=t.length>0?Object.keys(t[0]):[],d=a.map(n=>{const p=l.includes(n.column)?n.column:null,b=p?null:l.find(u=>u.includes(n.column)||n.column.includes(u)),x=!p&&!b?l.find(u=>{var y;return u!==i&&!isNaN(Number((y=t[0])==null?void 0:y[u]))}):null,c=p||b||x||n.column;return{name:n.label||n.column.replace(/_/g," "),data:t.map(u=>{const y=u[c];return y!=null?Number(y):null})}}),f=s.xAxisLabel||i.replace(/_/g," "),h=s.yAxisLabel||(a.length===1?a[0].column:"Values");return{series:d,categories:o,xAxisLabel:f,yAxisLabel:h}}renderEmpty(e){this.container.innerHTML=`
7
- <div class="ds-chart-card">
8
- ${e?`<div class="ds-chart-title">${e}</div>`:""}
9
- <div class="ds-chart-empty">No data available</div>
10
- </div>
11
- `}}class re{constructor(){this.columns=[],this.allData=[],this.currentRows=[],this.totalRows=0,this.currentPage=1,this.currentPageSize=10,this.searchTerm="",this.isLoading=!1}render(e,t,s,r){var f;this.container=e,this.component=t,this.fetchPage=r,this.searchTerm="",this.currentPage=1,this.currentPageSize=10;const i=s&&!Array.isArray(s)&&"rows"in s;if(i){const h=s;this.currentRows=h.rows,this.allData=[],this.totalRows=h.total,this.currentPage=h.page,this.currentPageSize=h.pageSize}else this.allData=s||[],this.currentRows=[],this.totalRows=this.allData.length,this.currentPage=1;if(i&&s.rows.length===0&&s.total===0||!i&&this.allData.length===0){e.innerHTML=`
12
- <div class="ds-table-card">
13
- <div class="ds-table-header-row">
14
- <span class="ds-table-dot"></span>
15
- <div class="ds-table-title">${this.escape(t.title||"")}</div>
16
- </div>
17
- <div class="ds-chart-empty">No data available</div>
18
- </div>
19
- `;return}const a=i?s.rows[0]:this.allData[0],o=a?Object.keys(a):[],l=((f=t.properties)==null?void 0:f.columns)||[],d=l.length?l.filter(h=>o.includes(h)):[];this.columns=d.length?d:o,this.paint()}paint(){const{rows:e,startNum:t}=this.getPageRows(),s=Math.max(1,Math.ceil(this.totalRows/this.currentPageSize)),r=(this.currentPage-1)*this.currentPageSize+1,i=this.fetchPage?Math.min(r-1+(this.isLoading?this.currentPageSize:e.length),this.totalRows):Math.min(this.currentPage*this.currentPageSize,this.totalRows),a=this.columns.map(n=>`<th>${this.escape(this.formatHeader(n))}</th>`).join(""),o=e.length===0?`<tr><td colspan="${this.columns.length+1}" style="text-align:center;padding:20px;color:#9ca3af">No results found</td></tr>`:e.map((n,p)=>{const b=this.columns.map(x=>{const c=n[x];return`<td title="${this.escape(String(c!=null?c:""))}">${this.escape(this.formatValue(c))}</td>`}).join("");return`<tr><td class="ds-table-sno">${t+p}</td>${b}</tr>`}).join(""),l=this.currentPageSize,d=[10,25,50,100].map(n=>`<option value="${n}"${n===l?" selected":""}>${n}</option>`).join(""),f=this.currentPage<=1,h=this.currentPage>=s;this.container.innerHTML=`
20
- <div class="ds-table-card">
21
- <div class="ds-table-header-row">
22
- <div class="ds-table-title-wrap">
23
- <span class="ds-table-dot"></span>
24
- <span class="ds-table-title">${this.escape(this.component.title||"")}</span>
25
- </div>
26
- </div>
27
- <div class="ds-table-scroll">
28
- <table class="ds-table">
29
- <thead><tr><th class="ds-table-sno-th">S.No</th>${a}</tr></thead>
30
- <tbody>${o}</tbody>
31
- </table>
32
- </div>
33
- <div class="ds-table-footer">
34
- <div class="ds-table-info">
35
- <span>${r.toLocaleString()}–${i.toLocaleString()} of ${this.totalRows.toLocaleString()}</span>
36
- <span class="ds-table-rows-label">Rows:</span>
37
- <select class="ds-table-page-size">${d}</select>
38
- </div>
39
- <div class="ds-table-pagination">
40
- <button class="ds-table-pg-btn" data-action="first" ${f?"disabled":""}>&#171;</button>
41
- <button class="ds-table-pg-btn" data-action="prev" ${f?"disabled":""}>Previous</button>
42
- <span class="ds-table-pg-info">Page ${this.currentPage} of ${s}</span>
43
- <button class="ds-table-pg-btn" data-action="next" ${h?"disabled":""}>Next</button>
44
- <button class="ds-table-pg-btn" data-action="last" ${h?"disabled":""}>&#187;</button>
45
- </div>
46
- </div>
47
- ${this.isLoading?'<div class="ds-table-loading-overlay"><div class="ds-embed-spinner"></div></div>':""}
48
- </div>
49
- `,this.attachEvents()}attachEvents(){const e=this.container.querySelector(".ds-table-search");e==null||e.addEventListener("input",()=>{this.searchTerm=e.value,this.currentPage=1,this.fetchPage||(this.totalRows=this.filteredRows().length,this.paint())});const t=this.container.querySelector(".ds-table-page-size");t==null||t.addEventListener("change",()=>{this.currentPageSize=parseInt(t.value,10),this.currentPage=1,this.fetchPage?this.loadPage(1):(this.totalRows=this.filteredRows().length,this.paint())}),this.container.querySelectorAll("[data-action]").forEach(s=>{s.addEventListener("click",()=>{if(s.disabled)return;const r=Math.max(1,Math.ceil(this.totalRows/this.currentPageSize)),i=s.dataset.action;let a=this.currentPage;i==="first"?a=1:i==="prev"?a=Math.max(1,this.currentPage-1):i==="next"?a=Math.min(r,this.currentPage+1):i==="last"&&(a=r),(a!==this.currentPage||i==="first"||i==="last")&&(this.currentPage=a,this.fetchPage?this.loadPage(a):this.paint())})})}async loadPage(e){if(this.fetchPage){this.isLoading=!0,this.currentPage=e,this.paint();try{const t=await this.fetchPage(e,this.currentPageSize);this.currentRows=t.rows||[],this.totalRows=Number(t.total)||this.currentRows.length,this.currentPage=Number(t.page)||e}catch(t){console.error("[Deepspot SDK] TableRenderer: page fetch failed",t)}finally{this.isLoading=!1,this.paint()}}}getPageRows(){const e=(this.currentPage-1)*this.currentPageSize+1;if(this.fetchPage)return{rows:this.currentRows,startNum:e};const t=this.filteredRows(),s=(this.currentPage-1)*this.currentPageSize;return{rows:t.slice(s,s+this.currentPageSize),startNum:e}}filteredRows(){if(!this.searchTerm)return this.allData;const e=this.searchTerm.toLowerCase();return this.allData.filter(t=>this.columns.some(s=>{var r;return String((r=t[s])!=null?r:"").toLowerCase().includes(e)}))}formatHeader(e){return e.replace(/_/g," ").replace(/\b\w/g,t=>t.toUpperCase())}formatValue(e){return e==null?"—":typeof e=="number"?e%1===0?e.toLocaleString():e.toFixed(2):String(e)}escape(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}}class ie{render(e,t,s){const r=t.properties||{};let i=null;if(s&&s.length>0){const b=s[0],x=r.metric||Object.keys(b)[0],c=b[x];if(c!==void 0)i=c;else{const u=Object.keys(b).find(y=>y.includes(x)||x.includes(y));i=b[u!=null?u:Object.keys(b)[0]]}}const a=this.formatValue(i,r),o=r.styleConfig||{},l=o.backgroundColor||r.backgroundColor||"",d=o.color||o.textColor||r.textColor||"",f=t.title||"",h=l?`background:${l};border-color:${l};`:"",n=d?`color:${d};`:"",p=d?`color:${d};opacity:0.7;`:"";e.innerHTML=`
50
- <div class="ds-card"${h?` style="${h}"`:""}>
51
- <div class="ds-card-label"${p?` style="${p}"`:""}>${f}</div>
52
- <div class="ds-card-value"${n?` style="${n}"`:""}>${a}</div>
53
- </div>
54
- `}formatValue(e,t){if(e==null)return"—";const s=Number(e);if(isNaN(s))return String(e);const r=(t==null?void 0:t.prefix)||(t==null?void 0:t.currencySymbol)||"",i=(t==null?void 0:t.suffix)||"";let a;return Math.abs(s)>=1e6?a=(s/1e6).toFixed(1)+"M":Math.abs(s)>=1e3?a=(s/1e3).toFixed(1)+"K":a=s%1===0?s.toLocaleString():s.toFixed(2),`${r}${a}${i}`}}class ne{constructor(e,t){this.currentValues={},this.container=e,this.onFilterChange=t}render(e,t={}){if(!e||e.length===0){this.container.style.display="none";return}this.container.style.display="",this.currentValues={...t},this.container.innerHTML=`<div class="ds-filter-bar">${e.map(s=>this.renderFilter(s,t[s.applyToField||s.filterId])).join("")}</div>`,this.attachListeners(e)}updateOptions(e,t){const s=this.container.querySelector(`select[data-filter-id="${e}"]`);if(!s)return;const r=s.value;s.innerHTML='<option value="">All</option>'+t.map(i=>`<option value="${this.escAttr(i)}">${this.escText(i)}</option>`).join(""),r&&t.includes(r)&&(s.value=r)}updateValues(e){Object.assign(this.currentValues,e),Object.entries(e).forEach(([t,s])=>{const r=this.container.querySelector(`[data-filter-id="${t}"]`);r&&s!==void 0&&(r.value=String(s))})}renderFilter(e,t){const s=`ds-filter-${e.filterId}`,r=`<label class="ds-filter-label" for="${s}">${e.label}</label>`;switch(e.type){case"dropdown":return`
55
- <div class="ds-filter-item">
56
- ${r}
57
- <select class="ds-filter-select" id="${s}" data-filter-id="${e.filterId}">
58
- <option value="">All</option>
59
- ${(e.options||[]).map(o=>`
60
- <option value="${this.escAttr(o)}" ${t===o?"selected":""}>
61
- ${this.escText(o)}
62
- </option>
63
- `).join("")}
64
- </select>
65
- </div>`;case"multi-select":return`
66
- <div class="ds-filter-item">
67
- ${r}
68
- <select class="ds-filter-select" id="${s}" data-filter-id="${e.filterId}" multiple size="1">
69
- ${(e.options||[]).map(o=>`
70
- <option value="${this.escAttr(o)}">${this.escText(o)}</option>
71
- `).join("")}
72
- </select>
73
- </div>`;case"date-range":const i=(t==null?void 0:t.from)||"",a=(t==null?void 0:t.to)||"";return`
74
- <div class="ds-filter-item">
75
- ${r}
76
- <div class="ds-date-range-inputs">
77
- <input type="date" class="ds-filter-input"
78
- data-filter-id="${e.filterId}" data-date-part="from"
79
- value="${i}" />
80
- <span>–</span>
81
- <input type="date" class="ds-filter-input"
82
- data-filter-id="${e.filterId}" data-date-part="to"
83
- value="${a}" />
84
- </div>
85
- </div>`;case"text-input":return`
86
- <div class="ds-filter-item">
87
- ${r}
88
- <input type="text" class="ds-filter-input" id="${s}"
89
- data-filter-id="${e.filterId}"
90
- value="${this.escAttr(String(t!=null?t:""))}"
91
- placeholder="Search..." />
92
- </div>`;case"number-input":return`
93
- <div class="ds-filter-item">
94
- ${r}
95
- <input type="number" class="ds-filter-input" id="${s}"
96
- data-filter-id="${e.filterId}"
97
- value="${this.escAttr(String(t!=null?t:""))}" />
98
- </div>`;default:return""}}attachListeners(e){const t={};this.container.querySelectorAll("[data-filter-id]").forEach(s=>{const r=s.dataset.filterId,i=s.dataset.datePart,a=e.find(l=>l.filterId===r),o=()=>{let l;if((a==null?void 0:a.type)==="date-range"&&i)t[r]=t[r]||{},t[r][i]=s.value,l={...t[r]};else if((a==null?void 0:a.type)==="multi-select"){const d=s;l=Array.from(d.selectedOptions).map(f=>f.value).filter(Boolean)}else l=s.value;this.currentValues[r]=l,this.onFilterChange(r,l)};s.addEventListener((a==null?void 0:a.type)==="text-input"?"input":"change",o)})}escAttr(e){return String(e!=null?e:"").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}escText(e){return String(e!=null?e:"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}}const A=class A{constructor(e,t){this.activePageId="",this.activeTabId="",this.activeFilters={},this.chartRenderers=new Map,this.tableRenderer=new re,this.cardRenderer=new ie,this.isLoadingTab=!1,this.root=e,this.opts=t,this.activeFilters={...t.initialFilters}}render(e){var t,s;this.renderData=e,this.activePageId=e.activePage,this.activeTabId=e.activeTab,this.buildShell(),this.renderNavigation(),this.renderFilterBar(),this.renderGrid(),(s=(t=this.opts).onReady)==null||s.call(t)}update(e){this.renderData=e,this.activePageId=e.activePage,this.activeTabId=e.activeTab,this.isLoadingTab=!1,this.syncNavHighlight(),this.updateFilterBar(),this.renderGrid()}goToPage(e){const t=this.getTabsForPage(e)[0];t&&this.triggerTabSwitch(e,t.id)}goToTab(e,t){this.triggerTabSwitch(e,t)}destroy(){this.chartRenderers.forEach(e=>e.destroy()),this.chartRenderers.clear(),this.root.innerHTML=""}exportPDF(){var n,p;const e=this.root.querySelector("#ds-grid");if(!e)return;const t=this.root.style.height,s=this.root.style.overflow;this.root.style.height="auto",this.root.style.overflow="visible";const r=this.root.querySelector("#ds-canvas"),i=(n=r==null?void 0:r.style.height)!=null?n:"",a=(p=r==null?void 0:r.style.overflow)!=null?p:"";r&&(r.style.height="auto",r.style.overflow="visible");const o=Array.from(e.querySelectorAll(".ds-table-scroll")),l=o.map(b=>({el:b,overflow:b.style.overflow,maxHeight:b.style.maxHeight,height:b.style.height}));o.forEach(b=>{b.style.overflow="visible",b.style.maxHeight="none",b.style.height="auto"});const d=e.offsetWidth,f=parseInt(e.style.height,10)||e.offsetHeight,h=e.getBoundingClientRect().top+window.scrollY;Promise.resolve().then(()=>require("./html2canvas.esm-EoNFmhrp.cjs")).then(({default:b})=>b(e,{scale:2,useCORS:!0,allowTaint:!0,logging:!1,width:d,height:f,windowWidth:d,windowHeight:f,scrollX:0,scrollY:-h}).then(x=>{this.root.style.height=t,this.root.style.overflow=s,r&&(r.style.height=i,r.style.overflow=a),l.forEach(({el:c,overflow:u,maxHeight:y,height:T})=>{c.style.overflow=u,c.style.maxHeight=y,c.style.height=T}),Promise.resolve().then(()=>require("./jspdf.es.min-D6GjoB2T.cjs")).then(c=>c.jspdf_es_min).then(({jsPDF:c})=>{const u=x.width/2,y=x.height/2,T=new c({orientation:u>=y?"landscape":"portrait",unit:"px",format:[u,y]});T.addImage(x.toDataURL("image/png"),"PNG",0,0,u,y),T.save(`${this.renderData.dashboard.name||"dashboard"}.pdf`)})}))}exportCSV(){this.renderData.components.forEach(e=>{const t=this.renderData.data[e.id];if(!(t!=null&&t.length)||!["table","bar","line","area"].includes(e.type))return;const s=Object.keys(t[0]),r=[s.join(","),...t.map(a=>s.map(o=>{var l;return JSON.stringify((l=a[o])!=null?l:"")}).join(","))].join(`
99
- `);Object.assign(document.createElement("a"),{href:URL.createObjectURL(new Blob([r],{type:"text/csv"})),download:`${e.title||e.id}.csv`}).click()})}updateFilterValues(e){var t;Object.assign(this.activeFilters,e),(t=this.filterRenderer)==null||t.updateValues(e)}buildShell(){const e=this.opts.embedLevel,t=this.renderData.dashboard.pages,s=e==="dashboard"&&t.length>1,r=e==="page"||e==="dashboard";this.root.innerHTML=`
100
- ${this.opts.hideExport?"":'<div class="ds-toolbar" id="ds-toolbar"></div>'}
101
- ${s?'<nav class="ds-page-nav" id="ds-page-nav"></nav>':""}
102
- ${r?'<nav class="ds-page-nav" id="ds-tab-nav"></nav>':""}
103
- <div id="ds-filter-container"></div>
104
- <div class="ds-canvas" id="ds-canvas">
105
- <div class="ds-grid" id="ds-grid"></div>
106
- </div>
107
- <div id="ds-tab-loading" style="display:none;position:absolute;inset:0;
108
- background:rgba(255,255,255,0.5);align-items:center;justify-content:center;">
109
- <div class="ds-embed-spinner"></div>
110
- </div>
111
- `,this.root.style.position="relative",this.opts.hideExport||this.buildExportToolbar();const i=this.root.querySelector("#ds-filter-container");this.filterRenderer=new ne(i,(a,o)=>{var h,n,p,b,x;const l=(h=this.renderData.filters)==null?void 0:h.find(c=>c.filterId===a),d=(n=this.renderData.components)==null?void 0:n.find(c=>c.type==="inline-filter"&&c.id===a),f=(l==null?void 0:l.applyToField)||((p=d==null?void 0:d.properties)==null?void 0:p.applyToField)||a;this.activeFilters[f]=o,(x=(b=this.opts).onFilterChange)==null||x.call(b,this.activeFilters),this.opts.onTabSwitch(this.activePageId,this.activeTabId)})}buildExportToolbar(){var t,s;const e=this.root.querySelector("#ds-toolbar");e&&(e.innerHTML=`
112
- <button class="ds-toolbar-btn" id="ds-btn-pdf">⬇ PDF</button>
113
- <button class="ds-toolbar-btn" id="ds-btn-csv" style="display:none">⬇ CSV</button>
114
- `,(t=e.querySelector("#ds-btn-pdf"))==null||t.addEventListener("click",()=>this.exportPDF()),(s=e.querySelector("#ds-btn-csv"))==null||s.addEventListener("click",()=>this.exportCSV()))}renderNavigation(){this.renderPageNav(),this.renderTabNav(this.activePageId)}renderPageNav(){const e=this.root.querySelector("#ds-page-nav");e&&(e.innerHTML=this.renderData.dashboard.pages.map(t=>`
115
- <button class="ds-page-tab ${t.pageId===this.activePageId?"ds-active":""}"
116
- data-page-id="${t.pageId}">${t.title}</button>
117
- `).join(""),e.querySelectorAll(".ds-page-tab").forEach(t=>{t.addEventListener("click",()=>{var r,i;const s=t.dataset.pageId;s===this.activePageId&&!this.isLoadingTab||this.triggerTabSwitch(s,(i=(r=this.getTabsForPage(s)[0])==null?void 0:r.id)!=null?i:"")})}))}renderTabNav(e){const t=this.root.querySelector("#ds-tab-nav");t&&this.buildTabButtons(t,e)}buildTabButtons(e,t){const s=this.getTabsForPage(t);if(s.length<=1){e.style.display="none";return}e.style.display="",e.innerHTML=s.map(r=>`
118
- <button class="ds-page-tab ${r.id===this.activeTabId?"ds-active":""}"
119
- data-tab-id="${r.id}" data-page-id="${t}">${r.title}</button>
120
- `).join(""),e.querySelectorAll(".ds-page-tab").forEach(r=>{r.addEventListener("click",()=>{const i=r.dataset.tabId,a=r.dataset.pageId;i===this.activeTabId&&a===this.activePageId&&!this.isLoadingTab||this.triggerTabSwitch(a,i)})})}triggerTabSwitch(e,t){this.isLoadingTab||!e||!t||(this.isLoadingTab=!0,this.activePageId=e,this.activeTabId=t,this.syncNavHighlight(),this.showTabSpinner(),this.opts.onTabSwitch(e,t))}syncNavHighlight(){this.root.querySelectorAll("#ds-page-nav .ds-page-tab").forEach(t=>{t.classList.toggle("ds-active",t.dataset.pageId===this.activePageId)});const e=this.root.querySelector("#ds-tab-nav");e&&this.buildTabButtons(e,this.activePageId)}renderFilterBar(){if(this.opts.hideGlobalFilters)return;const e=[...this.renderData.filters||[],...this.inlineFiltersAsDefinitions()];this.filterRenderer.render(e,this.activeFilters),this.fetchFilterOptions()}updateFilterBar(){if(this.opts.hideGlobalFilters)return;const e=[...this.renderData.filters||[],...this.inlineFiltersAsDefinitions()];this.filterRenderer.render(e,this.activeFilters),this.fetchFilterOptions()}inlineFiltersAsDefinitions(){return this.opts.hideInlineFilters?[]:(this.renderData.components||[]).filter(e=>e.type==="inline-filter").map(e=>{var t,s,r,i,a,o,l,d;return{filterId:e.id,label:((t=e.properties)==null?void 0:t.filterLabel)||e.title||"",type:((s=e.properties)==null?void 0:s.filterType)||"dropdown",options:((r=e.properties)==null?void 0:r.filterOptions)||((i=e.properties)==null?void 0:i.options)||[],defaultValue:(a=e.properties)==null?void 0:a.defaultValue,targetComponents:((o=e.properties)==null?void 0:o.targetComponents)||[],filterOperator:(l=e.properties)==null?void 0:l.filterOperator,applyToField:((d=e.properties)==null?void 0:d.applyToField)||e.id}})}async fetchFilterOptions(){if(this.opts.onFetchFilterOptions)for(const e of this.renderData.filters){if(e.type!=="dropdown"&&e.type!=="multi-select"||e.options&&e.options.length>0)continue;const t=await this.opts.onFetchFilterOptions(e.filterId);t.length>0&&this.filterRenderer.updateOptions(e.filterId,t)}}renderGrid(){this.hideTabSpinner();const e=this.root.querySelector("#ds-grid");if(!e)return;if(!this.opts.hideBackground){const d=this.root.querySelector("#ds-canvas"),f=this.renderData.dashboard.pages.find(n=>n.pageId===this.activePageId),h=(f==null?void 0:f.backgroundColor)||"";d&&(d.style.background=h),this.root.style.background=h}this.chartRenderers.forEach(d=>d.destroy()),this.chartRenderers.clear();const t=(this.renderData.components||[]).filter(d=>d.type!=="inline-filter");if(!t.length){e.style.height="200px",e.innerHTML='<div class="ds-chart-empty" style="padding-top:80px;">No components on this tab.</div>';return}const s=e.clientWidth||this.root.clientWidth||800,r=t.map(d=>d.position),i=r.length?Math.min(...r.map(d=>d.y)):0,a=new V(s,i);e.style.height=`${V.totalHeight(r)}px`,e.innerHTML="";const o=36,l=[];t.forEach(d=>{var p,b,x;const f=document.createElement("div");if(f.className="ds-component-wrapper",f.dataset.componentId=d.id,a.applyStyles(f,d.position),!this.opts.hideBackground){const c=((b=(p=d.properties)==null?void 0:p.styleConfig)==null?void 0:b.backgroundColor)||((x=d.properties)==null?void 0:x.backgroundColor);c&&(f.style.background=c)}e.appendChild(f);const h=a.toPx(d.position),n=Math.max(50,h.height-o);l.push(this.renderComponent(f,d,n).catch(c=>{console.error(`[Deepspot SDK] Failed to render component ${d.id} (${d.type}):`,c),f.innerHTML=`<div style="padding:8px;color:#ef4444;font-size:12px;">⚠ ${d.type} render error</div>`}))}),Promise.all(l).catch(()=>{})}async renderComponent(e,t,s){var a,o,l,d,f,h,n,p,b,x,c,u,y,T,$,I,C,R,L,P,O,H,M,N,K,q,B,G,W,U,_,Y,J,X,Z;const r=this.renderData.data[t.id]||[],i=this.opts.theme;switch(t.type){case"bar":case"line":case"pie":case"donut":case"area":case"scatter":case"stacked-bar":{const v=new se(e);await v.render(t,r,i,s),this.chartRenderers.set(t.id,v);break}case"table":{const v=this.opts.onFetchTablePage?(m,k)=>this.opts.onFetchTablePage(t.id,m,k):void 0;this.tableRenderer.render(e,t,r,v);break}case"number-card":this.cardRenderer.render(e,t,r);break;case"text-heading":{if(this.opts.hideText)break;const v=((o=(a=t.properties)==null?void 0:a.data)==null?void 0:o.dataContent)||((l=t.properties)==null?void 0:l.content)||t.title||"",m=((d=t.properties)==null?void 0:d.styleConfig)||{},k=this.scToInlineStyle(m),g=this.opts.hideBackground?{}:this.parseTwColor((h=(f=t.properties)==null?void 0:f.color)!=null?h:""),S=[[g.bg?`background:${g.bg}`:"",g.text?`color:${g.text}`:""].filter(Boolean).join(";"),k].filter(Boolean).join(";");e.innerHTML=`<div class="ds-text-heading" style="${S}">${v}</div>`;break}case"text-subheading":{if(this.opts.hideText)break;const v=((p=(n=t.properties)==null?void 0:n.data)==null?void 0:p.dataContent)||((b=t.properties)==null?void 0:b.content)||t.title||"",m=((x=t.properties)==null?void 0:x.styleConfig)||{},k=this.scToInlineStyle(m),g=this.opts.hideBackground?{}:this.parseTwColor((u=(c=t.properties)==null?void 0:c.color)!=null?u:""),S=[[g.bg?`background:${g.bg}`:"",g.text?`color:${g.text}`:""].filter(Boolean).join(";"),k].filter(Boolean).join(";");e.innerHTML=`<div class="ds-text-subheading" style="${S}">${v}</div>`;break}case"text-body":{if(this.opts.hideText)break;const v=((T=(y=t.properties)==null?void 0:y.data)==null?void 0:T.dataContent)||(($=t.properties)==null?void 0:$.content)||"",m=((I=t.properties)==null?void 0:I.styleConfig)||{},k=this.scToInlineStyle(m),g=this.opts.hideBackground?{}:this.parseTwColor((R=(C=t.properties)==null?void 0:C.color)!=null?R:""),S=[[g.bg?`background:${g.bg}`:"",g.text?`color:${g.text}`:""].filter(Boolean).join(";"),k].filter(Boolean).join(";");e.innerHTML=`<div class="ds-text-body" style="${S}">${v}</div>`;break}case"text-box":{if(this.opts.hideText)break;const v=((P=(L=t.properties)==null?void 0:L.data)==null?void 0:P.dataContent)||((O=t.properties)==null?void 0:O.content)||"",m=((H=t.properties)==null?void 0:H.styleConfig)||{},k=this.scToInlineStyle(m),g=this.opts.hideBackground?{}:this.parseTwColor((N=(M=t.properties)==null?void 0:M.color)!=null?N:""),S=[[g.bg?`background:${g.bg}`:"",g.text?`color:${g.text}`:""].filter(Boolean).join(";"),k].filter(Boolean).join(";");e.innerHTML=`<div class="ds-text-box" style="${S}">${v}</div>`;break}case"text":{if(this.opts.hideText)break;const v=((q=(K=t.properties)==null?void 0:K.data)==null?void 0:q.dataContent)||((B=t.properties)==null?void 0:B.content)||"",m=((G=t.properties)==null?void 0:G.styleConfig)||{},k=this.scToInlineStyle(m),g=this.opts.hideBackground?{}:this.parseTwColor((U=(W=t.properties)==null?void 0:W.color)!=null?U:""),S=[[g.bg?`background:${g.bg}`:"",g.text?`color:${g.text}`:""].filter(Boolean).join(";"),k].filter(Boolean).join(";");e.innerHTML=`<div class="ds-text-body" style="${S}">${v}</div>`;break}case"header":{if(this.opts.hideHeader)break;const v=((Y=(_=t.properties)==null?void 0:_.data)==null?void 0:Y.dataContent)||((J=t.properties)==null?void 0:J.content)||t.title||"",m=((X=t.properties)==null?void 0:X.styleConfig)||{},k=!this.opts.hideBackground&&m.backgroundColor?`background:${m.backgroundColor};`:"",g=m.color?`color:${m.color};`:m.textColor?`color:${m.textColor};`:"";e.innerHTML=`
121
- <div class="ds-header-component" style="${k}${g}">
122
- <div class="ds-header-content">${v}</div>
123
- </div>`;break}case"section":{const v=((Z=t.properties)==null?void 0:Z.styleConfig)||{},m=!this.opts.hideBackground&&v.backgroundColor?`background:${v.backgroundColor};`:"";e.innerHTML=`
124
- <div class="ds-section-wrapper" style="${m}">
125
- ${t.title?`<div class="ds-section-title">${t.title}</div>`:""}
126
- </div>`;break}}}showTabSpinner(){const e=this.root.querySelector("#ds-tab-loading"),t=this.root.querySelector("#ds-grid");e&&(e.style.display="flex"),t&&(t.style.opacity="0.35")}hideTabSpinner(){const e=this.root.querySelector("#ds-tab-loading"),t=this.root.querySelector("#ds-grid");e&&(e.style.display="none"),t&&(t.style.opacity="1")}scToInlineStyle(e){const t=new Set(["backgroundColor"]),s=r=>r.replace(/([A-Z])/g,"-$1").toLowerCase();return Object.entries(e).filter(([r,i])=>!t.has(r)&&i!=null&&i!=="").map(([r,i])=>`${s(r)}:${i}`).join(";")}parseTwColor(e){if(!e)return{};const t={};for(const s of e.split(/\s+/)){if(!s)continue;if(s==="bg-white"){t.bg="#ffffff";continue}if(s==="bg-black"){t.bg="#000000";continue}if(s==="bg-transparent"){t.bg="transparent";continue}if(s==="text-white"){t.text="#ffffff";continue}if(s==="text-black"){t.text="#000000";continue}const r=/^(bg|text)-([a-z]+)-(\d+)$/.exec(s);if(!r)continue;const i=A.TW_PALETTE[r[2]],a=i==null?void 0:i[Number(r[3])];a&&(r[1]==="bg"&&(t.bg=a),r[1]==="text"&&(t.text=a))}return t}getTabsForPage(e){var t,s;return(s=(t=this.renderData.dashboard.pages.find(r=>r.pageId===e))==null?void 0:t.tabs)!=null?s:[]}};A.TW_PALETTE={slate:{50:"#f8fafc",100:"#f1f5f9",200:"#e2e8f0",300:"#cbd5e1",400:"#94a3b8",500:"#64748b",600:"#475569",700:"#334155",800:"#1e293b",900:"#0f172a"},gray:{50:"#f9fafb",100:"#f3f4f6",200:"#e5e7eb",300:"#d1d5db",400:"#9ca3af",500:"#6b7280",600:"#4b5563",700:"#374151",800:"#1f2937",900:"#111827"},zinc:{50:"#fafafa",100:"#f4f4f5",200:"#e4e4e7",300:"#d4d4d8",400:"#a1a1aa",500:"#71717a",600:"#52525b",700:"#3f3f46",800:"#27272a",900:"#18181b"},neutral:{50:"#fafafa",100:"#f5f5f5",200:"#e5e5e5",300:"#d4d4d4",400:"#a3a3a3",500:"#737373",600:"#525252",700:"#404040",800:"#262626",900:"#171717"},stone:{50:"#fafaf9",100:"#f5f5f4",200:"#e7e5e4",300:"#d6d3d1",400:"#a8a29e",500:"#78716c",600:"#57534e",700:"#44403c",800:"#292524",900:"#1c1917"},red:{50:"#fef2f2",100:"#fee2e2",200:"#fecaca",300:"#fca5a5",400:"#f87171",500:"#ef4444",600:"#dc2626",700:"#b91c1c",800:"#991b1b",900:"#7f1d1d"},orange:{50:"#fff7ed",100:"#ffedd5",200:"#fed7aa",300:"#fdba74",400:"#fb923c",500:"#f97316",600:"#ea580c",700:"#c2410c",800:"#9a3412",900:"#7c2d12"},amber:{50:"#fffbeb",100:"#fef3c7",200:"#fde68a",300:"#fcd34d",400:"#fbbf24",500:"#f59e0b",600:"#d97706",700:"#b45309",800:"#92400e",900:"#78350f"},yellow:{50:"#fefce8",100:"#fef9c3",200:"#fef08a",300:"#fde047",400:"#facc15",500:"#eab308",600:"#ca8a04",700:"#a16207",800:"#854d0e",900:"#713f12"},lime:{50:"#f7fee7",100:"#ecfccb",200:"#d9f99d",300:"#bef264",400:"#a3e635",500:"#84cc16",600:"#65a30d",700:"#4d7c0f",800:"#3f6212",900:"#365314"},green:{50:"#f0fdf4",100:"#dcfce7",200:"#bbf7d0",300:"#86efac",400:"#4ade80",500:"#22c55e",600:"#16a34a",700:"#15803d",800:"#166534",900:"#14532d"},emerald:{50:"#ecfdf5",100:"#d1fae5",200:"#a7f3d0",300:"#6ee7b7",400:"#34d399",500:"#10b981",600:"#059669",700:"#047857",800:"#065f46",900:"#064e3b"},teal:{50:"#f0fdfa",100:"#ccfbf1",200:"#99f6e4",300:"#5eead4",400:"#2dd4bf",500:"#14b8a6",600:"#0d9488",700:"#0f766e",800:"#115e59",900:"#134e4a"},cyan:{50:"#ecfeff",100:"#cffafe",200:"#a5f3fc",300:"#67e8f9",400:"#22d3ee",500:"#06b6d4",600:"#0891b2",700:"#0e7490",800:"#155e75",900:"#164e63"},sky:{50:"#f0f9ff",100:"#e0f2fe",200:"#bae6fd",300:"#7dd3fc",400:"#38bdf8",500:"#0ea5e9",600:"#0284c7",700:"#0369a1",800:"#075985",900:"#0c4a6e"},blue:{50:"#eff6ff",100:"#dbeafe",200:"#bfdbfe",300:"#93c5fd",400:"#60a5fa",500:"#3b82f6",600:"#2563eb",700:"#1d4ed8",800:"#1e40af",900:"#1e3a8a"},indigo:{50:"#eef2ff",100:"#e0e7ff",200:"#c7d2fe",300:"#a5b4fc",400:"#818cf8",500:"#6366f1",600:"#4f46e5",700:"#4338ca",800:"#3730a3",900:"#312e81"},violet:{50:"#f5f3ff",100:"#ede9fe",200:"#ddd6fe",300:"#c4b5fd",400:"#a78bfa",500:"#8b5cf6",600:"#7c3aed",700:"#6d28d9",800:"#5b21b6",900:"#4c1d95"},purple:{50:"#faf5ff",100:"#f3e8ff",200:"#e9d5ff",300:"#d8b4fe",400:"#c084fc",500:"#a855f7",600:"#9333ea",700:"#7e22ce",800:"#6b21a8",900:"#581c87"},fuchsia:{50:"#fdf4ff",100:"#fae8ff",200:"#f5d0fe",300:"#f0abfc",400:"#e879f9",500:"#d946ef",600:"#c026d3",700:"#a21caf",800:"#86198f",900:"#701a75"},pink:{50:"#fdf2f8",100:"#fce7f3",200:"#fbcfe8",300:"#f9a8d4",400:"#f472b6",500:"#ec4899",600:"#db2777",700:"#be185d",800:"#9d174d",900:"#831843"},rose:{50:"#fff1f2",100:"#ffe4e6",200:"#fecdd3",300:"#fda4af",400:"#fb7185",500:"#f43f5e",600:"#e11d48",700:"#be123c",800:"#9f1239",900:"#881337"}};let z=A;class le{constructor(e,t){this.chartRenderer=null,this.tableRenderer=new re,this.cardRenderer=new ie,this.root=e,this.theme=t}render(e,t){const s=e.components[0];if(!s){this.root.innerHTML=`<div class="ds-embed-error">
127
- <div class="ds-embed-error-icon">⚠</div>
128
- <div>Component not found.</div>
129
- </div>`;return}const r=e.data[s.id]||[];this.renderComponent(s,r),t==null||t()}update(e){const t=e.components[0];if(!t)return;const s=e.data[t.id]||[];switch(t.type){case"bar":case"line":case"pie":case"donut":case"area":this.chartRenderer?this.chartRenderer.update(t,s,this.theme):this.renderComponent(t,s);break;case"table":this.tableRenderer.render(this.root,t,s);break;case"number-card":this.cardRenderer.render(this.root,t,s);break}}destroy(){var e;(e=this.chartRenderer)==null||e.destroy(),this.chartRenderer=null,this.root.innerHTML=""}renderComponent(e,t){var s;switch(e.type){case"bar":case"line":case"pie":case"donut":case"area":(s=this.chartRenderer)==null||s.destroy(),this.chartRenderer=new se(this.root),this.chartRenderer.render(e,t,this.theme);break;case"table":this.tableRenderer.render(this.root,e,t);break;case"number-card":this.cardRenderer.render(this.root,e,t);break;default:this.root.innerHTML=`<div class="ds-chart-empty">Unsupported component type: ${e.type}</div>`}}}let ee=!1;function ce(){if(!(ee||typeof document=="undefined")){ee=!0;try{const w=`/* ─────────────────────────────────────────────────────────────────────────────
130
- Deepspot SDK — Base Embed Styles
131
- Injected once into the host page's <head> by the SDK.
132
- All selectors are scoped under .ds-embed-* to avoid leaking into host styles.
133
- ───────────────────────────────────────────────────────────────────────────── */
134
-
135
- /* ── Reset inside SDK containers ──────────────────────────────────────────── */
136
- .ds-embed-root *,
137
- .ds-embed-root *::before,
138
- .ds-embed-root *::after {
139
- box-sizing: border-box;
140
- margin: 0;
141
- padding: 0;
142
- }
143
-
144
- /* ── Root container ────────────────────────────────────────────────────────── */
145
- .ds-embed-root {
146
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
147
- Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
148
- font-size: 14px;
149
- line-height: 1.5;
150
- width: 100%;
151
- height: 100%;
152
- overflow: auto;
153
- position: relative;
154
- /* Default white background — overridden by page backgroundColor from publish page */
155
- background: #ffffff;
156
- color: #111827;
157
- }
158
-
159
- .ds-embed-root.ds-theme-light {
160
- /* No forced background — let component styleConfig backgrounds show through */
161
- color: #111827;
162
- }
163
-
164
- .ds-embed-root.ds-theme-dark {
165
- /* No forced background — let component styleConfig backgrounds show through */
166
- color: #f1f5f9;
167
- }
168
-
169
- /* ── Loading state ─────────────────────────────────────────────────────────── */
170
- .ds-embed-loading {
171
- display: flex;
172
- flex-direction: column;
173
- align-items: center;
174
- justify-content: center;
175
- height: 100%;
176
- min-height: 200px;
177
- gap: 12px;
178
- color: #6b7280;
179
- }
180
-
181
- .ds-embed-spinner {
182
- width: 36px;
183
- height: 36px;
184
- border: 3px solid #e5e7eb;
185
- border-top-color: #6366f1;
186
- border-radius: 50%;
187
- animation: ds-spin 0.8s linear infinite;
188
- }
189
-
190
- @keyframes ds-spin {
191
- to { transform: rotate(360deg); }
192
- }
193
-
194
- .ds-embed-loading-text {
195
- font-size: 13px;
196
- }
197
-
198
- /* ── Error state ───────────────────────────────────────────────────────────── */
199
- .ds-embed-error {
200
- display: flex;
201
- flex-direction: column;
202
- align-items: center;
203
- justify-content: center;
204
- height: 100%;
205
- min-height: 200px;
206
- gap: 8px;
207
- padding: 24px;
208
- text-align: center;
209
- color: #ef4444;
210
- }
211
-
212
- .ds-embed-error-icon {
213
- font-size: 32px;
214
- }
215
-
216
- .ds-embed-error-message {
217
- font-size: 13px;
218
- color: #6b7280;
219
- }
220
-
221
- /* ── Filter bar ────────────────────────────────────────────────────────────── */
222
- .ds-filter-bar {
223
- display: flex;
224
- flex-wrap: wrap;
225
- align-items: center;
226
- gap: 10px;
227
- padding: 10px 16px;
228
- border-bottom: 1px solid #e5e7eb;
229
- background: inherit;
230
- }
231
-
232
- .ds-theme-dark .ds-filter-bar {
233
- border-bottom-color: #1e293b;
234
- }
235
-
236
- .ds-filter-item {
237
- display: flex;
238
- flex-direction: column;
239
- gap: 4px;
240
- }
241
-
242
- .ds-filter-label {
243
- font-size: 11px;
244
- font-weight: 600;
245
- text-transform: uppercase;
246
- letter-spacing: 0.05em;
247
- color: #6b7280;
248
- }
249
-
250
- .ds-filter-select,
251
- .ds-filter-input {
252
- height: 32px;
253
- padding: 0 10px;
254
- border: 1px solid #d1d5db;
255
- border-radius: 6px;
256
- font-size: 13px;
257
- background: #ffffff;
258
- color: #111827;
259
- cursor: pointer;
260
- min-width: 130px;
261
- }
262
-
263
- .ds-theme-dark .ds-filter-select,
264
- .ds-theme-dark .ds-filter-input {
265
- background: #1e293b;
266
- border-color: #334155;
267
- color: #f1f5f9;
268
- }
269
-
270
- .ds-filter-select:focus,
271
- .ds-filter-input:focus {
272
- outline: none;
273
- border-color: #6366f1;
274
- box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
275
- }
276
-
277
- .ds-date-range-inputs {
278
- display: flex;
279
- gap: 6px;
280
- align-items: center;
281
- }
282
-
283
- .ds-date-range-inputs input[type="date"] {
284
- height: 32px;
285
- padding: 0 8px;
286
- border: 1px solid #d1d5db;
287
- border-radius: 6px;
288
- font-size: 13px;
289
- background: #ffffff;
290
- color: #111827;
291
- }
292
-
293
- .ds-theme-dark .ds-date-range-inputs input[type="date"] {
294
- background: #1e293b;
295
- border-color: #334155;
296
- color: #f1f5f9;
297
- }
298
-
299
- /* ── Page / Tab navigation ─────────────────────────────────────────────────── */
300
- .ds-page-nav {
301
- display: flex;
302
- gap: 4px;
303
- padding: 8px 16px 0;
304
- border-bottom: 1px solid #e5e7eb;
305
- overflow-x: auto;
306
- }
307
-
308
- .ds-theme-dark .ds-page-nav {
309
- border-bottom-color: #1e293b;
310
- }
311
-
312
- .ds-page-tab {
313
- padding: 6px 16px;
314
- font-size: 13px;
315
- font-weight: 500;
316
- border: none;
317
- border-bottom: 2px solid transparent;
318
- background: transparent;
319
- color: #6b7280;
320
- cursor: pointer;
321
- white-space: nowrap;
322
- transition: color 0.15s, border-color 0.15s;
323
- }
324
-
325
- .ds-page-tab:hover {
326
- color: #111827;
327
- }
328
-
329
- .ds-theme-dark .ds-page-tab:hover {
330
- color: #f1f5f9;
331
- }
332
-
333
- .ds-page-tab.ds-active {
334
- color: #6366f1;
335
- border-bottom-color: #6366f1;
336
- }
337
-
338
- /* ── Grid canvas ───────────────────────────────────────────────────────────── */
339
- .ds-canvas {
340
- position: relative;
341
- width: 100%;
342
- /* No horizontal padding — grid.clientWidth must equal container width so
343
- GridLayout.colWidth = containerWidth/24 matches the dashboard builder.
344
- 16px on each side was shrinking the grid by 32px and misaligning positions. */
345
- padding: 8px 0 16px;
346
- overflow-x: hidden;
347
- }
348
-
349
- .ds-grid {
350
- position: relative;
351
- width: 100%;
352
- /* Clip absolutely-positioned children to the grid boundary so rounding
353
- errors or miscalculated widths don't create a horizontal scrollbar. */
354
- overflow: hidden;
355
- }
356
-
357
- .ds-component-wrapper {
358
- position: absolute;
359
- overflow: hidden;
360
- }
361
-
362
- /* ── Chart component ───────────────────────────────────────────────────────── */
363
- .ds-chart-card {
364
- width: 100%;
365
- height: 100%;
366
- background: #ffffff;
367
- border: 1px solid #e5e7eb;
368
- border-radius: 10px;
369
- overflow: hidden;
370
- display: flex;
371
- flex-direction: column;
372
- }
373
-
374
- .ds-theme-dark .ds-chart-card {
375
- background: #1e293b;
376
- border-color: #334155;
377
- }
378
-
379
- .ds-chart-title {
380
- padding: 10px 14px 4px;
381
- font-size: 13px;
382
- font-weight: 600;
383
- color: #374151;
384
- flex-shrink: 0;
385
- }
386
-
387
- .ds-theme-dark .ds-chart-title {
388
- color: #e2e8f0;
389
- }
390
-
391
- .ds-chart-body {
392
- flex: 1;
393
- min-height: 0;
394
- }
395
-
396
- .ds-chart-empty {
397
- display: flex;
398
- align-items: center;
399
- justify-content: center;
400
- height: 100%;
401
- color: #9ca3af;
402
- font-size: 13px;
403
- }
404
-
405
- /* ── Table component ───────────────────────────────────────────────────────── */
406
- .ds-table-card {
407
- width: 100%;
408
- height: 100%;
409
- background: #ffffff;
410
- border: 1px solid #e5e7eb;
411
- border-radius: 10px;
412
- overflow: hidden;
413
- display: flex;
414
- flex-direction: column;
415
- position: relative;
416
- }
417
-
418
- .ds-theme-dark .ds-table-card {
419
- background: #1e293b;
420
- border-color: #334155;
421
- }
422
-
423
- /* ── Table header: dot + title on left, search on right ──────────────────────*/
424
- .ds-table-header-row {
425
- display: flex;
426
- align-items: center;
427
- justify-content: space-between;
428
- padding: 10px 14px 8px;
429
- flex-shrink: 0;
430
- gap: 8px;
431
- border-bottom: 1px solid #f3f4f6;
432
- }
433
-
434
- .ds-theme-dark .ds-table-header-row {
435
- border-bottom-color: #334155;
436
- }
437
-
438
- .ds-table-title-wrap {
439
- display: flex;
440
- align-items: center;
441
- gap: 6px;
442
- min-width: 0;
443
- }
444
-
445
- .ds-table-dot {
446
- width: 8px;
447
- height: 8px;
448
- border-radius: 50%;
449
- background: #6366f1;
450
- flex-shrink: 0;
451
- }
452
-
453
- .ds-table-title {
454
- font-size: 13px;
455
- font-weight: 600;
456
- color: #374151;
457
- white-space: nowrap;
458
- overflow: hidden;
459
- text-overflow: ellipsis;
460
- }
461
-
462
- .ds-theme-dark .ds-table-title {
463
- color: #e2e8f0;
464
- }
465
-
466
- /* ── Search ──────────────────────────────────────────────────────────────────*/
467
- .ds-table-search-wrap {
468
- position: relative;
469
- flex-shrink: 0;
470
- }
471
-
472
- .ds-table-search-icon {
473
- position: absolute;
474
- left: 8px;
475
- top: 50%;
476
- transform: translateY(-50%);
477
- width: 14px;
478
- height: 14px;
479
- color: #9ca3af;
480
- pointer-events: none;
481
- }
482
-
483
- .ds-table-search {
484
- height: 30px;
485
- padding: 0 10px 0 28px;
486
- border: 1px solid #e5e7eb;
487
- border-radius: 6px;
488
- font-size: 12px;
489
- background: #f9fafb;
490
- color: #374151;
491
- width: 180px;
492
- outline: none;
493
- transition: border-color 0.15s, box-shadow 0.15s;
494
- }
495
-
496
- .ds-table-search:focus {
497
- border-color: #6366f1;
498
- box-shadow: 0 0 0 2px rgba(99,102,241,0.15);
499
- background: #fff;
500
- }
501
-
502
- .ds-theme-dark .ds-table-search {
503
- background: #0f172a;
504
- border-color: #334155;
505
- color: #e2e8f0;
506
- }
507
-
508
- .ds-theme-dark .ds-table-search:focus {
509
- background: #1e293b;
510
- }
511
-
512
- /* ── Scroll area ─────────────────────────────────────────────────────────────*/
513
- .ds-table-scroll {
514
- flex: 1;
515
- overflow: auto;
516
- min-height: 0;
517
- }
518
-
519
- .ds-table {
520
- width: 100%;
521
- border-collapse: collapse;
522
- font-size: 12px;
523
- }
524
-
525
- .ds-table-sno-th {
526
- width: 48px;
527
- text-align: center !important;
528
- }
529
-
530
- .ds-table-sno {
531
- text-align: center;
532
- color: #9ca3af;
533
- font-size: 11px;
534
- }
535
-
536
- .ds-theme-dark .ds-table-sno {
537
- color: #64748b;
538
- }
539
-
540
- .ds-table th {
541
- position: sticky;
542
- top: 0;
543
- padding: 8px 12px;
544
- text-align: left;
545
- font-weight: 600;
546
- font-size: 11px;
547
- text-transform: uppercase;
548
- letter-spacing: 0.05em;
549
- background: #f9fafb;
550
- color: #6b7280;
551
- border-bottom: 1px solid #e5e7eb;
552
- white-space: nowrap;
553
- }
554
-
555
- .ds-theme-dark .ds-table th {
556
- background: #0f172a;
557
- color: #94a3b8;
558
- border-bottom-color: #334155;
559
- }
560
-
561
- .ds-table td {
562
- padding: 8px 12px;
563
- border-bottom: 1px solid #f3f4f6;
564
- color: #374151;
565
- max-width: 200px;
566
- overflow: hidden;
567
- text-overflow: ellipsis;
568
- white-space: nowrap;
569
- }
570
-
571
- .ds-theme-dark .ds-table td {
572
- color: #cbd5e1;
573
- border-bottom-color: #1e293b;
574
- }
575
-
576
- .ds-table tr:hover td {
577
- background: #f9fafb;
578
- }
579
-
580
- .ds-theme-dark .ds-table tr:hover td {
581
- background: #0f172a;
582
- }
583
-
584
- /* ── Footer: info + pagination ───────────────────────────────────────────────*/
585
- .ds-table-footer {
586
- display: flex;
587
- align-items: center;
588
- justify-content: space-between;
589
- padding: 8px 14px;
590
- border-top: 1px solid #f3f4f6;
591
- flex-shrink: 0;
592
- gap: 8px;
593
- flex-wrap: wrap;
594
- }
595
-
596
- .ds-theme-dark .ds-table-footer {
597
- border-top-color: #334155;
598
- }
599
-
600
- .ds-table-info {
601
- display: flex;
602
- align-items: center;
603
- gap: 8px;
604
- font-size: 12px;
605
- color: #6b7280;
606
- }
607
-
608
- .ds-theme-dark .ds-table-info {
609
- color: #94a3b8;
610
- }
611
-
612
- .ds-table-rows-label {
613
- margin-left: 4px;
614
- }
615
-
616
- .ds-table-page-size {
617
- height: 28px;
618
- padding: 0 6px;
619
- border: 1px solid #e5e7eb;
620
- border-radius: 5px;
621
- font-size: 12px;
622
- background: #fff;
623
- color: #374151;
624
- cursor: pointer;
625
- outline: none;
626
- }
627
-
628
- .ds-theme-dark .ds-table-page-size {
629
- background: #0f172a;
630
- border-color: #334155;
631
- color: #e2e8f0;
632
- }
633
-
634
- .ds-table-pagination {
635
- display: flex;
636
- align-items: center;
637
- gap: 6px;
638
- }
639
-
640
- .ds-table-pg-btn {
641
- height: 28px;
642
- padding: 0 10px;
643
- border: 1px solid #e5e7eb;
644
- border-radius: 5px;
645
- font-size: 12px;
646
- font-weight: 500;
647
- background: #fff;
648
- color: #374151;
649
- cursor: pointer;
650
- transition: background 0.12s, border-color 0.12s;
651
- white-space: nowrap;
652
- }
653
-
654
- .ds-table-pg-btn:hover:not(:disabled) {
655
- background: #f3f4f6;
656
- border-color: #d1d5db;
657
- }
658
-
659
- .ds-table-pg-btn:disabled {
660
- opacity: 0.4;
661
- cursor: not-allowed;
662
- }
663
-
664
- .ds-theme-dark .ds-table-pg-btn {
665
- background: #1e293b;
666
- border-color: #334155;
667
- color: #e2e8f0;
668
- }
669
-
670
- .ds-theme-dark .ds-table-pg-btn:hover:not(:disabled) {
671
- background: #0f172a;
672
- }
673
-
674
- .ds-table-pg-info {
675
- font-size: 12px;
676
- color: #6b7280;
677
- white-space: nowrap;
678
- }
679
-
680
- .ds-theme-dark .ds-table-pg-info {
681
- color: #94a3b8;
682
- }
683
-
684
- /* ── Loading overlay while fetching a page ───────────────────────────────────*/
685
- .ds-table-loading-overlay {
686
- position: absolute;
687
- inset: 0;
688
- background: rgba(255,255,255,0.6);
689
- display: flex;
690
- align-items: center;
691
- justify-content: center;
692
- border-radius: 10px;
693
- z-index: 10;
694
- }
695
-
696
- .ds-theme-dark .ds-table-loading-overlay {
697
- background: rgba(30,41,59,0.7);
698
- }
699
-
700
- /* ── KPI Number Card ───────────────────────────────────────────────────────── */
701
- .ds-card {
702
- width: 100%;
703
- height: 100%;
704
- border: 1px solid #e5e7eb;
705
- border-radius: 10px;
706
- display: flex;
707
- flex-direction: column;
708
- align-items: center;
709
- justify-content: center;
710
- padding: 16px;
711
- text-align: center;
712
- background: #ffffff;
713
- }
714
-
715
- .ds-theme-dark .ds-card {
716
- background: #1e293b;
717
- border-color: #334155;
718
- }
719
-
720
- .ds-card-label {
721
- font-size: 12px;
722
- font-weight: 500;
723
- color: #6b7280;
724
- margin-bottom: 6px;
725
- text-transform: uppercase;
726
- letter-spacing: 0.05em;
727
- }
728
-
729
- .ds-card-value {
730
- font-size: 32px;
731
- font-weight: 700;
732
- color: #111827;
733
- line-height: 1.1;
734
- }
735
-
736
- .ds-theme-dark .ds-card-value {
737
- color: #f1f5f9;
738
- }
739
-
740
- /* ── v2: Text / content components ────────────────────────────────────────── */
741
-
742
- .ds-text-heading {
743
- width: 100%;
744
- height: 100%;
745
- display: flex;
746
- flex-direction: column;
747
- justify-content: center;
748
- padding: 8px 12px;
749
- font-size: 20px;
750
- font-weight: 700;
751
- color: #111827;
752
- line-height: 1.3;
753
- overflow: hidden;
754
- }
755
-
756
- .ds-theme-dark .ds-text-heading {
757
- color: #f1f5f9;
758
- }
759
-
760
- .ds-text-subheading {
761
- width: 100%;
762
- height: 100%;
763
- display: flex;
764
- flex-direction: column;
765
- justify-content: center;
766
- padding: 6px 12px;
767
- font-size: 15px;
768
- font-weight: 600;
769
- color: #374151;
770
- line-height: 1.4;
771
- overflow: hidden;
772
- }
773
-
774
- .ds-theme-dark .ds-text-subheading {
775
- color: #cbd5e1;
776
- }
777
-
778
- .ds-text-body {
779
- width: 100%;
780
- height: 100%;
781
- padding: 8px 12px;
782
- font-size: 14px;
783
- color: #374151;
784
- line-height: 1.6;
785
- overflow: auto;
786
- }
787
-
788
- .ds-theme-dark .ds-text-body {
789
- color: #94a3b8;
790
- }
791
-
792
- .ds-text-box {
793
- width: 100%;
794
- height: 100%;
795
- padding: 10px 14px;
796
- font-size: 13px;
797
- color: #374151;
798
- line-height: 1.6;
799
- border: 1px solid #e5e7eb;
800
- border-radius: 8px;
801
- background: #f9fafb;
802
- overflow: auto;
803
- }
804
-
805
- .ds-theme-dark .ds-text-box {
806
- color: #cbd5e1;
807
- border-color: #334155;
808
- background: #1e293b;
809
- }
810
-
811
- /* ── v2: Header component ──────────────────────────────────────────────────── */
812
-
813
- .ds-header-component {
814
- width: 100%;
815
- height: 100%;
816
- display: flex;
817
- align-items: center;
818
- padding: 12px 20px;
819
- background: #f3f4f6;
820
- border-bottom: 1px solid #e5e7eb;
821
- overflow: hidden;
822
- }
823
-
824
- .ds-theme-dark .ds-header-component {
825
- background: #1e293b;
826
- border-bottom-color: #334155;
827
- }
828
-
829
- .ds-header-content {
830
- font-size: 18px;
831
- font-weight: 700;
832
- color: #111827;
833
- white-space: nowrap;
834
- overflow: hidden;
835
- text-overflow: ellipsis;
836
- }
837
-
838
- .ds-theme-dark .ds-header-content {
839
- color: #f1f5f9;
840
- }
841
-
842
- /* ── v2: Section container ─────────────────────────────────────────────────── */
843
-
844
- .ds-section-wrapper {
845
- width: 100%;
846
- height: 100%;
847
- border: 1px solid #e5e7eb;
848
- border-radius: 10px;
849
- background: #f9fafb;
850
- overflow: hidden;
851
- }
852
-
853
- .ds-theme-dark .ds-section-wrapper {
854
- border-color: #334155;
855
- background: #1e293b;
856
- }
857
-
858
- .ds-section-title {
859
- padding: 8px 14px;
860
- font-size: 12px;
861
- font-weight: 600;
862
- text-transform: uppercase;
863
- letter-spacing: 0.05em;
864
- color: #6b7280;
865
- border-bottom: 1px solid #e5e7eb;
866
- }
867
-
868
- .ds-theme-dark .ds-section-title {
869
- color: #94a3b8;
870
- border-bottom-color: #334155;
871
- }
872
-
873
- /* ── v2: Inline filter (selection-filter placed in-grid) ───────────────────── */
874
-
875
- .ds-inline-filter {
876
- width: 100%;
877
- height: 100%;
878
- display: flex;
879
- flex-direction: column;
880
- justify-content: center;
881
- gap: 4px;
882
- padding: 6px 10px;
883
- }
884
-
885
- .ds-inline-filter-select,
886
- .ds-inline-filter-input {
887
- width: 100%;
888
- height: 34px;
889
- padding: 0 10px;
890
- border: 1px solid #d1d5db;
891
- border-radius: 6px;
892
- font-size: 13px;
893
- background: #ffffff;
894
- color: #111827;
895
- cursor: pointer;
896
- outline: none;
897
- transition: border-color 0.15s, box-shadow 0.15s;
898
- }
899
-
900
- .ds-inline-filter-select:focus,
901
- .ds-inline-filter-input:focus {
902
- border-color: #6366f1;
903
- box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
904
- }
905
-
906
- .ds-theme-dark .ds-inline-filter-select,
907
- .ds-theme-dark .ds-inline-filter-input {
908
- background: #1e293b;
909
- border-color: #334155;
910
- color: #f1f5f9;
911
- }
912
-
913
- /* ── Export toolbar ────────────────────────────────────────────────────────── */
914
- .ds-toolbar {
915
- display: flex;
916
- justify-content: flex-end;
917
- padding: 8px 16px 0;
918
- gap: 8px;
919
- }
920
-
921
- .ds-toolbar-btn {
922
- height: 30px;
923
- padding: 0 12px;
924
- border: 1px solid #d1d5db;
925
- border-radius: 6px;
926
- font-size: 12px;
927
- font-weight: 500;
928
- background: #ffffff;
929
- color: #374151;
930
- cursor: pointer;
931
- display: flex;
932
- align-items: center;
933
- gap: 5px;
934
- transition: background 0.15s, border-color 0.15s;
935
- }
936
-
937
- .ds-toolbar-btn:hover {
938
- background: #f9fafb;
939
- border-color: #9ca3af;
940
- }
941
-
942
- .ds-theme-dark .ds-toolbar-btn {
943
- background: #1e293b;
944
- border-color: #334155;
945
- color: #e2e8f0;
946
- }
947
-
948
- .ds-theme-dark .ds-toolbar-btn:hover {
949
- background: #0f172a;
950
- }
951
- `,e=document.createElement("style");e.id="deepspot-sdk-styles",e.textContent=w,document.head.appendChild(e)}catch(w){}}}function te(w){if(typeof w=="string"){const e=document.querySelector(w);if(!e)throw new Error(`Deepspot SDK: container "${w}" not found in DOM`);return e}return w}class he{constructor(e){if(!e.apiKey)throw new Error("Deepspot SDK: apiKey is required");if(!e.baseUrl)throw new Error("Deepspot SDK: baseUrl is required");this.apiClient=new ae(e.baseUrl,e.apiKey),ce()}async embedDashboard(e){var a,o,l,d,f,h,n,p,b,x;const t=te(e.container),s=(a=e.embedLevel)!=null?a:"dashboard",r=(o=e.theme)!=null?o:"light";t.style.height=e.height||"600px",t.style.display="block";const i=this.createRoot(t,r);this.showLoading(i);try{const c=await this.apiClient.getEmbedToken({dashboardId:e.dashboardId,embedType:"dashboard",embedLevel:s,userId:e.userId,tenantId:e.tenantId}),u=await this.apiClient.getDashboardRender(e.dashboardId,c,{embedLevel:s,pageId:e.pageId,tabId:e.tabId,filters:e.filters||{}});let y;const T=new z(i,{embedLevel:s,theme:r,hideFilters:(l=e.hideGlobalFilters)!=null?l:!1,hideExport:(d=e.hideExport)!=null?d:!1,hideGlobalFilters:(f=e.hideGlobalFilters)!=null?f:!1,hideInlineFilters:(h=e.hideInlineFilters)!=null?h:!1,hideText:(n=e.hideText)!=null?n:!1,hideHeader:(p=e.hideHeader)!=null?p:!1,hideBackground:(b=e.hideBackground)!=null?b:!1,initialFilters:e.filters||{},onFilterChange:e.onFilterChange,onReady:e.onReady,onFetchFilterOptions:$=>this.apiClient.getFilterOptions(e.dashboardId,$,c),onFetchTablePage:($,I,C)=>this.apiClient.getTablePage(e.dashboardId,$,I,C,c),onTabSwitch:async($,I)=>{var C,R,L;(C=e.onTabSwitch)==null||C.call(e,$,I);try{const P=await this.apiClient.getDashboardRender(e.dashboardId,c,{embedLevel:s,pageId:$,tabId:I,filters:(L=(R=y==null?void 0:y.getActiveFilters())!=null?R:e.filters)!=null?L:{}});T.update(P)}catch(P){console.error("Deepspot SDK: tab fetch failed",P)}}});return T.render(u),y=new Q({dashboardId:e.dashboardId,token:c,embedType:"dashboard",embedLevel:s,activePageId:u.activePage,activeTabId:u.activeTab,activeFilters:e.filters||{},apiClient:this.apiClient,renderer:T,onFilterChange:e.onFilterChange}),y}catch(c){throw this.showError(i,(c==null?void 0:c.message)||"Failed to load dashboard"),(x=e.onError)==null||x.call(e,(c==null?void 0:c.message)||"Failed to load dashboard"),c}}async embedReport(e){var r;const t=te(e.container);t.style.height=e.height||"400px",t.style.display="block";const s=this.createRoot(t,e.theme||"light");this.showLoading(s);try{const i=await this.apiClient.getEmbedToken({dashboardId:e.dashboardId,embedType:"report",componentId:e.componentId,userId:e.userId,tenantId:e.tenantId}),a=await this.apiClient.getReportRender(e.dashboardId,e.componentId,i,{filters:e.filters||{}}),o=new le(s,e.theme||"light");return o.render(a,e.onReady),new Q({dashboardId:e.dashboardId,componentId:e.componentId,token:i,embedType:"report",activeFilters:e.filters||{},apiClient:this.apiClient,renderer:o})}catch(i){throw this.showError(s,(i==null?void 0:i.message)||"Failed to load report"),(r=e.onError)==null||r.call(e,(i==null?void 0:i.message)||"Failed to load report"),i}}createRoot(e,t){e.innerHTML="";const s=document.createElement("div");return s.className=`ds-embed-root ds-theme-${t}`,s.style.width="100%",s.style.height="100%",e.appendChild(s),s}showLoading(e){e.innerHTML=`
952
- <div class="ds-embed-loading">
953
- <div class="ds-embed-spinner"></div>
954
- <div class="ds-embed-loading-text">Loading…</div>
955
- </div>
956
- `}showError(e,t){e.innerHTML=`
957
- <div class="ds-embed-error">
958
- <div class="ds-embed-error-icon">⚠</div>
959
- <div>${t}</div>
960
- <div class="ds-embed-error-message">Check your SDK configuration.</div>
961
- </div>
962
- `}}exports.DeepspotSDK=he;