"use strict";var le=Object.defineProperty,de=Object.defineProperties;var ce=Object.getOwnPropertyDescriptors;var A=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var Q=(e,t,r)=>t in e?le(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,l=(e,t)=>{for(var r in t||(t={}))j.call(t,r)&&Q(e,r,t[r]);if(A)for(var r of A(t))z.call(t,r)&&Q(e,r,t[r]);return e},m=(e,t)=>de(e,ce(t));var U=(e,t)=>{var r={};for(var i in e)j.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(e!=null&&A)for(var i of A(e))t.indexOf(i)<0&&z.call(e,i)&&(r[i]=e[i]);return r};const F=require("./types-CzgBH2kL.cjs"),d=require("./utils-BwGnDoB0.cjs"),s=require("./apply-styled-options-to-query-23D9br-S.cjs");function ue(e){return e.replace(/\s+/g,"-").replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}function pe(e){return e.charAt(0).toUpperCase()+e.slice(1)}function me(e){const t=/\[(.+?)\s\(Calendar\)\]/;return e.replace(t,"[$1]").trim()}function ge(e){if(e)if(e.metadata){if(!e.model)throw new s.TranslatableError("errors.missingModelTitle")}else throw new s.TranslatableError("errors.missingMetadata");else throw new s.TranslatableError("errors.emptyModel");return e}function fe(e){return!e||!e.jaql.datasource.title||!e.jaql.metadata.length}function V(e){if(![...s.ALL_CHART_TYPES,"pivot","pivot2"].includes(e))throw new s.TranslatableError("errors.chartTypeNotSupported",{chartType:e})}function ye(e){return"widgetType"in e&&e.widgetType==="pivot"}function h(e){var t;return"column"in e&&((t=e.column)==null?void 0:t.expression)&&/\(.*\)/.test(e.column.expression)}function N(e){const t="measures"in e&&g(e.measures)||"values"in e&&g(e.values);return ye(e)?"values"in e.dataOptions&&g(e.dataOptions.values):"chartType"in e?e.chartType==="indicator"?"value"in e.dataOptions&&g(e.dataOptions.value)||"secondary"in e.dataOptions&&g(e.dataOptions.secondary):e.chartType==="table"?!("columns"in e.dataOptions)||!g(e.dataOptions.columns)?!1:e.dataOptions.columns.some(i=>h(i)):e.chartType==="boxplot"?!1:e.chartType==="scatter"?"x"in e.dataOptions&&e.dataOptions.x!==void 0&&h(e.dataOptions.x)||"y"in e.dataOptions&&e.dataOptions.y!==void 0&&h(e.dataOptions.y)||"size"in e.dataOptions&&e.dataOptions.size!==void 0:e.chartType==="scattermap"?"colorBy"in e.dataOptions&&e.dataOptions.colorBy!==void 0&&h(e.dataOptions.colorBy)||"details"in e.dataOptions&&e.dataOptions.details!==void 0&&h(e.dataOptions.details)||"size"in e.dataOptions&&e.dataOptions.size!==void 0&&h(e.dataOptions.size):e.chartType==="areamap"?"geo"in e.dataOptions&&g(e.dataOptions.geo)&&"color"in e.dataOptions&&g(e.dataOptions.color):"value"in e.dataOptions&&g(e.dataOptions.value):t}function g(e){return Array.isArray(e)&&e.length>0}function Se(e){const t=e.split(`
`);for(let r=0;r<t.length-1;r++)if(t[r].trim()===""){const i=t[r+1].trim();if(i.startsWith("import *")||i.startsWith("import {")){t.splice(r,1);break}}return t.join(`
`)}function Oe(e){const t=i=>/^[$A-Z_][0-9A-Z_$]*$/i.test(i);if("composeCode"in e)return e;const r={};for(const[i,a]of Object.entries(e)){const n=t(i)?i:`"${i}"`;r[n]=a}return r}const he={react:{baseChartTmpl:`import { {{componentString}} } from '@sisense/sdk-ui';
{{extraImportsString}}
import * as DM from './{{dataSourceString}}'; // generated with @sisense/sdk-cli

export default function CodeExample() {
  return (
    <{{componentString}}
      title={'{{titleString}}'}
      dataSource={DM.DataSource}
      chartType={'{{chartTypeString}}'}
      dataOptions={ {{dataOptionsString}} }
      filters={ {{filtersString}} }
      styleOptions={ {{styleOptionsString}} }
      drilldownOptions={ {{drilldownOptionsString}} }
    />
  );
}`,chartTmpl:"{{baseChartTmpl}}",chartWidgetTmpl:"{{baseChartTmpl}}",chartWidgetPropsTmpl:`
    {
      id: '{{idString}}',
      widgetType: '{{widgetTypeString}}',
      title: '{{titleString}}',
      dataSource: DM.DataSource,
      chartType: '{{chartTypeString}}',
      dataOptions: {{dataOptionsString}},
      filters: {{filtersString}},
      styleOptions: {{styleOptionsString}},
      drilldownOptions: {{drilldownOptionsString}},
    }`,widgetByIdTmpl:`import { WidgetById } from '@sisense/sdk-ui';

const CodeExample = () => {
    return (
      <>
        <WidgetById
          widgetOid="{{widgetOid}}"
          dashboardOid="{{dashboardOid}}"
          includeDashboardFilters={true}
        />
      </>
    );
};

export default CodeExample;
`,executeQueryByWidgetIdTmpl:`import { useExecuteQueryByWidgetId } from '@sisense/sdk-ui';

const CodeExample = () => {
  const { data, isLoading, isError, error } = useExecuteQueryByWidgetId({
    widgetOid: "{{widgetOid}}",
    dashboardOid: "{{dashboardOid}}"
  });

  if (isLoading) {
    return <div>Loading...</div>;
  }
  if (isError) {
    return <div>Error: {error.message}</div>;
  }
  if (data) {
    return <div>Total Rows: {data.rows.length}</div>;
  }

  return null;
};

export default CodeExample;
`,executeQueryTmpl:`import { useExecuteQuery } from '@sisense/sdk-ui';
{{extraImportsString}}
import * as DM from './{{dataSourceString}}'; // generated with @sisense/sdk-cli

const CodeExample = () => {
  const queryProps = {
    dataSource: DM.DataSource,
    dimensions: {{dimensionsString}},
    measures: {{measuresString}},
    filters: {{filtersString}},
    highlights: {{highlightsString}},
  }

  const { data, isLoading, isError, error } = useExecuteQuery(queryProps);

  if (isLoading) {
    return <div>Loading...</div>;
  }
  if (isError) {
    return <div>Error: {error.message}</div>;
  }
  if (data) {
    return <div>Total Rows: {data.rows.length}</div>;
  }

  return null;
};

export default CodeExample;
`,executePivotQueryTmpl:`import { useExecutePivotQuery, ExecutePivotQueryParams } from '@sisense/sdk-ui';
{{extraImportsString}}
import * as DM from './{{dataSourceString}}'; // generated with @sisense/sdk-cli

const CodeExample = () => {
    const pivotQueryProps: ExecutePivotQueryParams = {
      dataSource: DM.DataSource,
      rows: {{rowsString}},
      values: {{valuesString}},
      filters: {{filtersString}},
    }

    const { data, isLoading, isError, error } = useExecutePivotQuery(pivotQueryProps);

    if (isLoading) {
      return <div>Loading...</div>;
    }
    if (isError) {
      return <div>Error: {error.message}</div>;
    }
    if (data) {
      return <div>Total Rows: {data.table.rows.length}</div>;
    }

    return null;
};

export default CodeExample;
`,pivotTableWidgetTmpl:`import { {{componentString}} } from '@sisense/sdk-ui';
{{extraImportsString}}
import * as DM from './{{dataSourceString}}'; // generated with @sisense/sdk-cli

export default function CodeExample() {
  return (
    <{{componentString}}
      title={'{{titleString}}'}
      dataSource={DM.DataSource}
      dataOptions={ {{dataOptionsString}} }
      filters={ {{filtersString}} }
      styleOptions={ {{styleOptionsString}} }
    />
  );
}`,pivotTableWidgetPropsTmpl:`{
      id: '{{idString}}',
      widgetType: '{{widgetTypeString}}',
      title: '{{titleString}}',
      dataSource: DM.DataSource,
      dataOptions: {{dataOptionsString}},
      filters: {{filtersString}},
      styleOptions: {{styleOptionsString}},
    }`,dashboardByIdTmpl:`import { DashboardById } from '@sisense/sdk-ui';

const CodeExample = () => {
  return (
    <>
      <DashboardById
        dashboardOid="{{dashboardOid}}"
        config={ {{configString}} }
      />
    </>
  );
};

export default CodeExample;`,dashboardTmpl:`import { useMemo } from 'react';
import { Dashboard, DashboardProps, WidgetProps } from '@sisense/sdk-ui';
import { Filter, FilterRelations } from '@sisense/sdk-data';
{{extraImportsString}}
import * as DM from './{{defaultDataSourceString}}'; // generated with @sisense/sdk-cli

export default function CodeExample() {
  const dashboardProps: DashboardProps = useMemo(() => {
    const widgets: WidgetProps[] = {{widgetsString}};
    const filters: Filter[] | FilterRelations = {{filtersString}};

    return {
      title: '{{titleString}}',
      widgets,
      filters,
      config: {{configString}},
      widgetsOptions: {{widgetsOptionsString}},
      layoutOptions: {{layoutOptionsString}},
      styleOptions: {{styleOptionsString}},
    };
  }, []);

  return (
    <Dashboard {...dashboardProps} />
  );
}`},angular:{baseChartTmpl:`import { Component } from '@angular/core';
import { type ChartDataOptions, type ChartStyleOptions } from '@sisense/sdk-ui-angular';
{{extraImportsString}}
import * as DM from './{{dataSourceString}}'; // generated with @sisense/sdk-cli

@Component({
    selector: 'code-example',
    template: \`
      <csdk-chart-widget
        [title]="'{{titleString}}'"
        chartType='{{chartTypeString}}'
        [dataSource]='DM.DataSource'
        [dataOptions]='dataOptions'
        [filters]='filters'
        [styleOptions]='styleOptions'
        [drilldownOptions]='drilldownOptions'
      />
    \`
})
export class CodeExample {
    DM = DM;
    dataOptions: ChartDataOptions = {{dataOptionsString}};
    filters = {{filtersString}};
    styleOptions: ChartStyleOptions = {{styleOptionsString}};
    drilldownOptions = {{drilldownOptionsString}};
}`,chartTmpl:"{{baseChartTmpl}}",chartWidgetTmpl:"{{baseChartTmpl}}",chartWidgetPropsTmpl:`{
      id: '{{idString}}',
      widgetType: '{{widgetTypeString}}',
      title: '{{titleString}}',
      dataSource: DM.DataSource,
      chartType: '{{chartTypeString}}',
      dataOptions: {{dataOptionsString}},
      filters: {{filtersString}},
      styleOptions: {{styleOptionsString}},
      drilldownOptions: {{drilldownOptionsString}},
    }`,widgetByIdTmpl:`import { Component } from '@angular/core';

@Component({
  selector: 'code-example',
  template: \`
    <csdk-widget-by-id
      [widgetOid]="widgetOid"
      [dashboardOid]="dashboardOid"
      [includeDashboardFilters]="includeDashboardFilters"
    />
  \`,
})

export class CodeExample {
  widgetOid = "{{widgetOid}}";
  dashboardOid = "{{dashboardOid}}";
  includeDashboardFilters = true;
}`,executeQueryByWidgetIdTmpl:`import { Component } from '@angular/core';
import { QueryService } from '@sisense/sdk-ui-angular';
import { type QueryResultData } from '@sisense/sdk-data';

@Component({
  selector: 'code-example',
  template: \`<div>
    <div *ngIf="errorMessage">Error: {{ errorMessage }}</div>
    <div *ngIf="!errorMessage">Total Rows: {{ queryResult.rows.length }}</div>
  </div>\`,
})

export class CodeExample {
    queryResult: QueryResultData = { rows: [], columns: [] };

    errorMessage: string | null = null;

    constructor(private queryService: QueryService) {}

    async ngOnInit(): Promise<void> {
      try {
        const { data } = await this.queryService.executeQueryByWidgetId({
          widgetOid: "{{widgetOid}}",
          dashboardOid: "{{dashboardOid}}",
        });
        this.queryResult = data as QueryResultData;
      } catch(error: unknown) {
        if (error instanceof Error) {
          this.errorMessage = error.message;
        }
      }
    }
}
`,executeQueryTmpl:`import { Component } from '@angular/core';
{{extraImportsString}}
import { type QueryResultData } from '@sisense/sdk-data';
import * as DM from './{{dataSourceString}}'; // generated with @sisense/sdk-cli
import { QueryService } from '@sisense/sdk-ui-angular';

@Component({
  selector: 'code-example',
  template: \`<div>
    <div *ngIf="errorMessage">Error: {{ errorMessage }}</div>
    <div *ngIf="!errorMessage">Total Rows: {{ queryResult.rows.length }}</div>
  </div>\`,
})

export class CodeExample {
    queryResult: QueryResultData = { rows: [], columns: [] };

    errorMessage: string | null = null;

    constructor(private queryService: QueryService) {}

    async ngOnInit(): Promise<void> {
      const queryProps = {
        dataSource: DM.DataSource,
        dimensions: {{dimensionsString}},
        measures: {{measuresString}},
        filters: {{filtersString}},
        highlights: {{highlightsString}},
      }

      try {
        const { data } = await this.queryService.executeQuery(queryProps);
        this.queryResult = data as QueryResultData;
      } catch (error: unknown) {
        if (error instanceof Error) {
          this.errorMessage = error.message;
        }
      }
    }
}
`,executePivotQueryTmpl:"Not implemented yet",pivotTableWidgetTmpl:"Not implemented yet",pivotTableWidgetPropsTmpl:`{
      id: '{{idString}}',
      widgetType: '{{widgetTypeString}}',
      title: '{{titleString}}',
      dataSource: DM.DataSource,
      dataOptions: {{dataOptionsString}},
      filters: {{filtersString}},
      styleOptions: {{styleOptionsString}},
    }`,dashboardByIdTmpl:`import { Component } from '@angular/core';

@Component({
  selector: 'code-example',
  template: \`
    <csdk-dashboard-by-id
      [dashboardOid]="dashboardOid"
      [config]="config"
    />
  \`,
})
export class CodeExample {
  dashboardOid = "{{dashboardOid}}";
  config = {{configString}};
}`,dashboardTmpl:"/** COMING SOON */"},vue:{baseChartTmpl:`<script setup lang="ts">
  import { ref } from 'vue';
  import { {{componentString}}, type ChartStyleOptions } from '@sisense/sdk-ui-vue';
  {{extraImportsString}}
  import * as DM from './{{dataSourceString}}'; // generated with @sisense/sdk-cli

  const dataOptions = ref({{dataOptionsString}});
  const filters = ref({{filtersString}});
  const styleOptions = ref<ChartStyleOptions>({{styleOptionsString}});
  const drilldownOptions = ref({{drilldownOptionsString}});
<\/script>

<template>
  <{{componentString}}
    chartType="{{chartTypeString}}"
    :dataOptions="dataOptions"
    :filters="filters"
    :styleOptions="styleOptions"
    :drilldownOptions="drilldownOptions"
    :dataSource="DM.DataSource"
    title="{{titleString}}" />
</template>`,chartTmpl:"{{baseChartTmpl}}",chartWidgetTmpl:"{{baseChartTmpl}}",chartWidgetPropsTmpl:`{
      id: '{{idString}}',
      widgetType: '{{widgetTypeString}}',
      title: '{{titleString}}',
      dataSource: DM.DataSource,
      chartType: '{{chartTypeString}}',
      dataOptions: {{dataOptionsString}},
      filters: {{filtersString}},
      styleOptions: {{styleOptionsString}},
      drilldownOptions: {{drilldownOptionsString}},
    }`,widgetByIdTmpl:`<script setup lang="ts">
import { WidgetById } from '@sisense/sdk-ui-vue';
<\/script>
<template>
  <WidgetById
    :widgetOid="'{{widgetOid}}'"
    :dashboardOid="'{{dashboardOid}}'"
  />
</template>
`,executeQueryByWidgetIdTmpl:`<script setup lang="ts">
import { useExecuteQueryByWidgetId } from '@sisense/sdk-ui-vue';

const { data, isLoading, isError, error } = useExecuteQueryByWidgetId({
  widgetOid: "{{widgetOid}}",
  dashboardOid: "{{dashboardOid}}"
});
<\/script>
<template>
  <div>
    <div v-if="isLoading">Loading...</div>
    <div v-else-if="isError">Error: {{error.message}}</div>
    <div v-else-if="data">Total Rows: {{data.rows.length}}</div>
  </div>
</template>
`,executeQueryTmpl:`<script setup lang="ts">
import { useExecuteQuery } from '@sisense/sdk-ui-vue';
{{extraImportsString}}
import * as DM from './{{dataSourceString}}'; // generated with @sisense/sdk-cli

const queryProps = {
  dataSource: DM.DataSource,
  dimensions: {{dimensionsString}},
  measures: {{measuresString}},
  filters: {{filtersString}},
  highlights: {{highlightsString}},
}
const { data, isLoading, isError, error } = useExecuteQuery(queryProps);
<\/script>
<template>
  <div>
    <div v-if="isLoading">Loading...</div>
    <div v-else-if="isError">Error: {{error.message}}</div>
    <div v-else-if="data">Total Rows: {{data.rows.length}}</div>
  </div>
</template>`,executePivotQueryTmpl:"Not implemented yet",pivotTableWidgetTmpl:"Not implemented yet",pivotTableWidgetPropsTmpl:`{
      id: '{{idString}}',
      widgetType: '{{widgetTypeString}}',
      title: '{{titleString}}',
      dataSource: DM.DataSource,
      dataOptions: {{dataOptionsString}},
      filters: {{filtersString}},
      styleOptions: {{styleOptionsString}},
    }`,dashboardByIdTmpl:`<script setup lang="ts">
import { DashboardById } from '@sisense/sdk-ui-vue';

const config = {{configString}};
<\/script>

<template>
  <DashboardById :dashboardOid="'{{dashboardOid}}'" :config="config" />
</template>`,dashboardTmpl:"/** COMING SOON */"}};function be(e){return e.replace(/\[\[([^\]]+)\]\]/g,(t,r)=>s.normalizeName(r))}const H=(e,t)=>he[t][e].replace(/{{(.*?)Tmpl}}/g,(i,a)=>H(`${a}Tmpl`,t)),Z=(e,t)=>e.replace(/{{(.*?)}}/g,(r,i)=>i in t?t[i]:(console.warn(`Placeholder ${i} not found in data`),r)),P=(e,t,r="react")=>{const i=H(e,r),a=Z(i,t);return Se(be(a))},Te=()=>Object.values(s.AggregationTypes).map(t=>s.DimensionalBaseMeasure.aggregationToJAQL(t)).join("|"),G=e=>{const{formula:t,context:r,filter:i}=e;if(!r||!t)return e;const a=Object.keys(r);if(a.length!==1)return e;const n=a[0];if(typeof n!="string")return e;const o=r[`${n}`],p=Te(),c=new RegExp(`^\\s*(${p})\\(\\[\\w+\\]\\)$`),y=t.match(c);if(y&&t.includes(n)){const u=y[1];return l({dim:o.dim,table:o.table,column:o.column,datatype:o.datatype,agg:u,title:e.title},i?{filter:l({},i)}:{})}return e},_=e=>{let t=e;if("formula"in e&&(t=G(e)),"context"in t){const r=l({},t.context);Object.keys(r).forEach(i=>{r[`${i}`]=_(r[`${i}`])}),t.context=r}return t},ve=e=>{var i;const t=e;if(t.panel!=="scope")return t;const{jaql:r}=t;return(i=r.filter)!=null&&i.by&&(r.filter.by=G(r.filter.by)),m(l({},t),{jaql:r})},X=e=>{let t=e;t=ve(t);const{jaql:r,measure:i,by:a}=t;return l(l(m(l({},t),{jaql:_(r)}),a?{by:_(a)}:{}),i?{measure:_(i)}:{})},v=6;function Ee(e){switch(e){case"line":case"area":case"bar":case"column":case"polar":return{category:[],value:[],breakBy:[]};case"pie":case"funnel":case"treemap":case"sunburst":return{category:[],value:[]};case"scatter":return{};case"indicator":return{};case"arearange":return{category:[],value:[],breakBy:[]};case"boxplot":return{};case"areamap":return{};case"scattermap":return{geo:[]};case"table":return{columns:[]};case"pivot":case"pivot2":return{};case"image":default:return{}}}const xe={subtype:"indicator/numeric",numericSubtype:"numericSimple",skin:"vertical",indicatorComponents:{title:{shouldBeShown:!0,text:void 0},secondaryTitle:{text:""},ticks:{shouldBeShown:!1},labels:{shouldBeShown:!1}}},De={legend:{enabled:!0,position:"bottom"},xAxis:{enabled:!0,gridLines:!0,intervalJumps:null,isIntervalEnabled:!0,min:void 0,max:void 0,logarithmic:void 0,title:{enabled:!1,text:null},labels:{enabled:!0}},yAxis:{enabled:!1,gridLines:!0,intervalJumps:null,isIntervalEnabled:!1,min:void 0,max:void 0,logarithmic:!1,title:{enabled:!1,text:null},labels:{enabled:!0}},y2Axis:{enabled:!0,gridLines:!1,intervalJumps:void 0,isIntervalEnabled:!0,min:void 0,max:void 0,logarithmic:!1,title:{enabled:!1,text:void 0},labels:{enabled:!0}},seriesLabels:{enabled:!1,rotation:0,showValue:!1,showPercentage:!1},dataLimits:{seriesCapacity:50,categoriesCapacity:1e5},navigator:{enabled:!0}},Ce={subtype:"line/basic",lineWidth:{width:"bold"},markers:{enabled:!1,size:"small",fill:"filled"}},we={subtype:"area/basic",lineWidth:{width:"bold"},markers:{enabled:!1,size:"small",fill:"filled"}},Le={subtype:"bar/classic"},Ae={subtype:"column/classic"},Ie={subtype:"polar/column",yAxis:{enabled:!0,gridLines:!0,intervalJumps:void 0,isIntervalEnabled:!1,min:void 0,max:void 0,logarithmic:!1,labels:{enabled:!0},title:{enabled:!1}},dataLimits:{seriesCapacity:50,categoriesCapacity:200}};function T(e){return s.merge({},De,e)}const _e={subtype:"pie/classic",legend:{enabled:!1,position:"left"},labels:{enabled:!0,categories:!0,percent:!0,decimals:!1,value:!1},dataLimits:{seriesCapacity:1e5,categoriesCapacity:void 0},convolution:{enabled:!0,independentSlicesCount:7,minimalIndependentSlicePercentage:3,selectedConvolutionType:"byPercentage"}},Pe={legend:{enabled:!1,position:"left"},seriesLabels:{enabled:!0,showCategory:!0,showPercentage:!0,showPercentDecimals:!1,showValue:!0},funnelSize:"regular",funnelType:"regular",funnelDirection:"regular"},Me={rowsPerPage:25,isAutoHeight:!0,rowHeight:null,alternatingRowsColor:!0,alternatingColumnsColor:!1,headersColor:!1,membersColor:!1,totalsColor:!1},We={labels:{category:[{enabled:!0},{enabled:!0},{enabled:!0}]},tooltip:{mode:"value"}},Fe={subtype:d.CALENDAR_HEATMAP_DEFAULTS.SUBTYPE,viewType:"month",startOfWeek:"sunday",cellLabels:{enabled:!0},dayLabels:{enabled:!0},monthLabels:{enabled:!0},weekends:{days:[],cellColor:"#e6e6e6",hideValues:!0}},Ne={legend:{enabled:!0,position:"bottom"},tooltip:{mode:"value"}},$e={legend:{enabled:!0,position:"bottom"},xAxis:{enabled:!0,gridLines:!0,intervalJumps:null,isIntervalEnabled:!1,min:void 0,max:void 0,logarithmic:null,title:{enabled:!1,text:null},labels:{enabled:!0}},yAxis:{enabled:!0,gridLines:!0,intervalJumps:null,isIntervalEnabled:!1,min:void 0,max:void 0,logarithmic:null,title:{enabled:!1,text:null},labels:{enabled:!0}},dataLimits:{seriesCapacity:50,categoriesCapacity:void 0},seriesLabels:{enabled:!1,rotation:0,showValue:!1,showPercentage:!1},markerSize:{scatterDefaultSize:10,scatterBubbleMinSize:10,scatterBubbleMaxSize:10}},ke={header:{color:{enabled:!1}},rows:{alternatingColor:{enabled:!1}},columns:{alternatingColor:{enabled:!1}}},qe={subtype:"scattermap",markers:{fill:"filled",size:{defaultSize:4,minSize:4,maxSize:24}}},Be={mapType:"world"},Re={subtype:"boxplot/full",legend:{enabled:!0,position:"bottom"},xAxis:{enabled:!0,gridLines:!0,intervalJumps:void 0,isIntervalEnabled:!0,min:void 0,max:void 0,logarithmic:void 0,title:{enabled:!1,text:void 0},labels:{enabled:!0}},yAxis:{enabled:!0,gridLines:!0,intervalJumps:void 0,isIntervalEnabled:!0,min:void 0,max:void 0,logarithmic:void 0,title:{enabled:!1,text:void 0},labels:{enabled:!0}},seriesLabels:{enabled:!1,rotation:0,showValue:!1,showPercentage:!1},dataLimits:{seriesCapacity:50,categoriesCapacity:1e5},navigator:{enabled:!0}};function Qe(e){switch(e){case"indicator":return s.cloneDeep(xe);case"line":return T(Ce);case"area":return T(we);case"bar":return T(Le);case"column":return T(Ae);case"polar":return T(Ie);case"pie":return s.cloneDeep(_e);case"funnel":return s.cloneDeep(Pe);case"treemap":return s.cloneDeep(We);case"calendar-heatmap":return s.cloneDeep(Fe);case"sunburst":return s.cloneDeep(Ne);case"scatter":return s.cloneDeep($e);case"scattermap":return s.cloneDeep(qe);case"areamap":return s.cloneDeep(Be);case"boxplot":return s.cloneDeep(Re);case"table":return s.cloneDeep(ke);case"pivot":return s.cloneDeep(Me);case"pivot2":return{};case"image":return{};default:return{}}}const I=`
`,$="UNKNOWN",je=(e,t)=>{let r="";return r+=`measureFactory.customFormula(
`,r+=" ".repeat(t),r+=`  '${s.escapeSingleQuotes(e.title)}',
`,r+=" ".repeat(t),r+=`  '${e.formula}',
`,r+=" ".repeat(t),r+=`  {
`,Object.entries(e.context).forEach(([i,a])=>{const n=s.normalizeAttributeName(a.table||$,a.column||$,void 0,"DM");r+=" ".repeat(t),r+=`    '${i.slice(1,-1)}': ${n},
`}),r+=" ".repeat(t),r+=`  }
`,r+=" ".repeat(t),r+=")",r},ze=e=>{const{level:t,table:r,column:i,agg:a,title:n}=e;let o;return r&&i&&(o=s.normalizeAttributeName(r,i,t,"DM")),a&&r&&i&&n&&(o=`measureFactory.${s.DimensionalBaseMeasure.aggregationFromJAQL(a)}(${o}, '${s.escapeSingleQuotes(n)}')`),o||$},Ue=(e,t)=>{const r=e.jaql(!1).jaql;return"formula"in r?je(r,t):ze(r)},f=(e,t=0,r=!1)=>{if(!e)return"";if(typeof e=="string")return`'${s.escapeSingleQuotes(e)}'`;if(e instanceof F.JaqlElement)return Ue(e,t);if(e instanceof s.DimensionalElement)return e.composeCode||"";let i="";return Array.isArray(e)?i+=`[${e.map(a=>f(a,t+2))}${e.length?I+" ".repeat(t+2):""}]`:(i+=`{${I}`,Object.entries(e).forEach(([a,n])=>{if(r&&typeof a=="string"&&(a=`'${s.escapeSingleQuotes(a)}'`),i+=" ".repeat(t+2),Array.isArray(n))i+=`${a}: [${n.map(o=>f(o,t+4,r))}${n.length?I+" ".repeat(t+2):""}]`;else if(typeof n=="object"&&n!==null){const o=Array.isArray(n)?n:Oe(n);i+=`${a}: ${f(o,t+2,r)}`}else["number","boolean","undefined"].includes(typeof n)||n===null?i+=`${a}: ${n}`:typeof n=="string"?i+=`${a}: '${s.escapeSingleQuotes(n)}'`:i+=`${a}: ${n}`;i+=`,${I}`}),i+=" ".repeat(t),i+="}"),i};function R(e,t){if(t===void 0||t&&typeof t=="object"&&!Array.isArray(t)&&Object.keys(t).length===0)return e;if(!s.isEqual(e,t)){if(e&&typeof e=="object"&&!Array.isArray(e)){const r={};for(const i of Object.keys(e)){const a=R(e[i],t==null?void 0:t[i]),n=t&&Object.prototype.hasOwnProperty.call(t,i),o=n?t[i]:void 0;(a!==void 0||!n||e[i]===void 0&&o!==void 0)&&(r[i]=a)}return Object.keys(r).length?r:void 0}return e}}function Y(e,t){if(!e||Object.keys(e).length===0)return{};const r=Qe(t);if(s.isEqual(e,r))return{};const i=R(e,r);return i!=null?i:{}}function J(e,t){const r=Ee(t);if(s.isEqual(e,r))return e;const i=R(e,r);return i!=null?i:{}}function Ye(e){return f(e,v)}function k(e,t="data-source-placeholder"){if(!e)return t;const r=typeof e=="object"&&"title"in e?e.title:e;return ue(r)}function q(e,t=!0){const r=[];return t&&r.push("measureFactory"),g(e)&&r.push("filterFactory"),r.length>0?`import { ${r.join(", ")} } from '@sisense/sdk-data';`:""}const K=`
`,Je=(e,t)=>{if(e.composeCode)return`${K}${" ".repeat(t)}${e.composeCode}`;const r=e.jaql().jaql;return`${K}${" ".repeat(t)}filterFactory.customFilter(${f(r,t,!0)})`},Ke=(e,t=0)=>{if(!e)return"";let r="";return r+=`[${e.map(i=>Je(i,t+2))}${e.length?`
`+" ".repeat(t+2):""}]`,r},B=e=>e?Array.isArray(e)?Ke(e,6):"/** Filter relations not supported yet */":"[]",Ve=["executeQueryByWidgetIdTmpl","widgetByIdTmpl"],He="chartWidgetTmpl",Ze="pivotTableWidgetTmpl",Ge=e=>e,Xe=({dashboardOid:e,widgetOid:t,uiFramework:r="react",chartType:i="table",includeChart:a=!0})=>{V(i);const n={dashboardOid:e,widgetOid:t},o=Ve[Number(a)];return P(o,n,r)},ee=(e,t,r,i)=>{if(d.isChartWidgetProps(e)){V(e.chartType);const a=N(e),n={idString:e.id,widgetTypeString:"chart",titleString:e.title,dataSourceString:k(e.dataSource),chartTypeString:Ge(e.chartType),dataOptionsString:Ye(i?J(e.dataOptions,e.chartType):e.dataOptions),filtersString:B(e.filters),componentString:"ChartWidget",extraImportsString:q(e.filters||[],a),styleOptionsString:f(i?Y(e.styleOptions||{},e.chartType):e.styleOptions||{},v),drilldownOptionsString:f(e.drilldownOptions||{},v)};return P(r.chart,n,t)}if(d.isPivotTableWidgetProps(e)){const a=N(e),n={idString:e.id,widgetTypeString:"pivot",titleString:e.title,dataSourceString:k(e.dataSource),dataOptionsString:f(i?J(e.dataOptions,e.widgetType):e.dataOptions),filtersString:B(e.filters),componentString:"PivotTableWidget",extraImportsString:q(e.filters||[],a),styleOptionsString:f(i?Y(e.styleOptions||{},e.widgetType):e.styleOptions||{},v)};return P(r.pivot,n,t)}if(d.isCustomWidgetProps(e))return"/** Custom widget code not supported yet */";throw new s.TranslatableError("errors.otherWidgetTypesNotSupported")},et=({widgetProps:e,uiFramework:t="react",removeDefaultProps:r=!1})=>ee(e,t,{chart:He,pivot:Ze},r);function tt(e){return!!(e&&(e.top!==void 0||e.bottom!==void 0))}const rt=e=>{const t=e.find(r=>r.panel==="rows");return t?e.map(r=>{const i=r.jaql.filter;if(!(r.panel==="scope"&&tt(i)&&i.by===void 0))return r;const u=r.jaql,{type:n,context:o,formula:p,filter:c}=u,y=U(u,["type","context","formula","filter"]);return m(l({},r),{jaql:l({dim:t.jaql.dim,table:t.jaql.table,column:t.jaql.column,datatype:t.jaql.datatype,filter:m(l({},c),{by:{type:n,context:o,formula:p}})},y)})}):e},it=e=>"chartType"in e.chartRecommendations?e.chartRecommendations:{chartType:"table",chartFamily:"table",axesMapping:{}},at=e=>({dataOptions:{columns:e.map(F.createDimensionalElementFromMetadataItem)}}),nt=Object.freeze({convolution:{enabled:!0,selectedConvolutionType:"bySlicesCount",independentSlicesCount:7},lineWidth:{width:"bold"},markers:{enabled:!1},legend:{enabled:!1},yAxis:{gridLines:!1},xAxis:{gridLines:!1}}),M=Object.freeze({area:"area/stacked",arearange:"arearange/spline",bar:"bar/stacked",boxplot:"boxplot/full",column:"column/stackedcolumn",line:"line/spline",pie:"pie/donut",polar:"polar/column"}),te=(e,t,r)=>{const i=e.reduce((n,o)=>(n[o.jaql.title]=o,n),{}),a=Object.entries(r).reduce((n,o)=>{const[p,c]=o;return n[`${p}`]=Array.isArray(c)?c.map(y=>{var E,x;const u=d.normalizeAnyColumn(y);delete u.enabled;const S=i[u.column.name];if(!S)return{column:{type:"",name:u.column.name}};const O=F.createDimensionalElementFromMetadataItem(S);if(S.panel==="measures")return m(l({},u),{column:O});if(s.isDatetime(O.type)){const D=S.jaql,C=D.dateTimeLevel||D.level,w=C?(x=(E=S.format)==null?void 0:E.mask)==null?void 0:x[C]:void 0;if(w)return m(l({},u),{column:O,dateFormat:w})}return m(l({},u),{column:O})}):c,n},{});switch(t){case"cartesian":return l({category:[],value:[],breakBy:[]},a);case"categorical":return l({category:[],value:[]},a);case"scatter":return Object.keys(a).forEach(n=>{a[`${n}`]=a[`${n}`][0]}),a;case"scattermap":return Object.keys(a).forEach(n=>{n!=="geo"&&(a[`${n}`]=a[`${n}`][0])}),a;case"table":return Object.keys(a).length===0?at(e).dataOptions:a;case"boxplot":case"areamap":case"indicator":default:return a}},b=(e,t)=>{var r,i,a,n;return t==="x"?(i=(r=e.category)!=null?r:e.x)==null?void 0:i.map(o=>d.normalizeAnyColumn(o).column.name).join(", "):(n=(a=e.value)!=null?a:e.y)==null?void 0:n.map(o=>d.normalizeAnyColumn(o).column.name).join(", ")},W=(e,t)=>{var r;return(r=e[t])==null?void 0:r.map(i=>d.normalizeAnyColumn(i).column.name).join(", ")},st=(e,t)=>{var r;if(e in M){const i=M[`${e}`];return s.isCartesian(e)?{subtype:i,yAxis:{title:{enabled:!0,text:b(t,"y")}},xAxis:{title:{enabled:!0,text:b(t,"x")}}}:{subtype:i}}if(e==="scatter")return{xAxis:{title:{enabled:!0,text:b(t,"x")}},yAxis:{title:{enabled:!0,text:b(t,"y")}}};if(e==="indicator"){const i={title:{shouldBeShown:!0,text:(r=W(t,"value"))!=null?r:""}},a=W(t,"secondary");return a&&(i.secondaryTitle={text:a}),{indicatorComponents:i}}return{}},re=(e,t,r,i)=>{let a;if(i&&e in M)a=d.merge(d.merge(nt,{subtype:M[`${e}`]}),{legend:{enabled:!0,position:"right"},yAxis:{title:{enabled:!0,text:b(t,"y")}},xAxis:{title:{enabled:!0,text:b(t,"x")}}},r);else if(i&&e==="indicator"){const n={indicatorComponents:{title:{shouldBeShown:!0,text:W(t,"value")}}},o=W(t,"secondary");o&&(n!=null&&n.indicatorComponents)&&(n.indicatorComponents.secondaryTitle={text:o}),a=d.merge(d.getDefaultStyleOptions(),n,r)}else a=d.merge(d.getDefaultStyleOptions(),r);return a},ie=(e,t,r=!0)=>{const{chartFamily:i,chartType:a,axesMapping:n={},styleOptions:o={}}=t,p=te(e,i,n),c=re(a,n,o,r);return{dataOptions:p,chartStyleOptions:c}},ot=e=>"chartType"in e?e:{chartType:"table",chartFamily:"table",axesMapping:{}},lt=e=>e.map(t=>s.createFilterFromJaql(t.jaql)),dt=e=>e.reduce((t,r)=>{if((r.panel==="scope"||r.jaql.filter)&&t.metadataFilters.push(s.cloneDeep(r)),r.panel!=="scope"){const i=s.cloneDeep(r);delete i.jaql.filter,t.metadataColumns.push(i)}return t},{metadataColumns:[],metadataFilters:[]}),ct=(e,t)=>{if(!fe(e))try{const{useCustomizedStyleOptions:r=!1}=t||{},{jaql:i,chartRecommendations:a,queryTitle:n}=e,{metadata:o,datasource:p}=i,c=m(l({},p),{type:p.type||"elasticube"}),y=s.convertJaqlDataSourceForDto(c),S=rt(o).map(L=>X(L)).map(L=>m(l({},L),{jaql:m(l({},L.jaql),{datasource:y})})),O=ot(a),E=O.chartType.toLowerCase(),x={cornerRadius:"Small",header:{renderToolbar:()=>null}},{metadataColumns:D,metadataFilters:C}=dt(S),w=lt(C),{dataOptions:ne,chartStyleOptions:se}=ie(D,O,r),oe=l(l({},se),x);return{widgetType:"chart",id:n,title:n,chartType:E,dataSource:c,dataOptions:ne,filters:w,styleOptions:oe}}catch(r){console.error(r);return}},ae=(e,t)=>ct(e,t),ut=e=>F.isByIdWidgetCodeParams(e)?Xe(e):et(e),pt=Object.freeze(Object.defineProperty({__proto__:null,toWidgetCode:ut,toWidgetProps:ae},Symbol.toStringTag,{value:"Module"}));exports.CODE_TEMPLATES_INDENT=v;exports.capitalizeFirstLetter=pe;exports.checkIfMeasuresExist=N;exports.generateCode=P;exports.getChartDataOptions=te;exports.getChartOptions=ie;exports.getChartRecommendationsOrDefault=it;exports.getChartStyleOptions=re;exports.getMinimalChartStyleOptions=st;exports.getWidgetCode=ee;exports.populatePlaceholders=Z;exports.sanitizeDimensionId=me;exports.simplifyMetadataItem=X;exports.stringifyDataSource=k;exports.stringifyExtraImports=q;exports.stringifyFilters=B;exports.stringifyProps=f;exports.toWidgetProps=ae;exports.validateQueryModel=ge;exports.widgetComposer=pt;
