var le = Object.defineProperty, de = Object.defineProperties;
var ce = Object.getOwnPropertyDescriptors;
var L = Object.getOwnPropertySymbols;
var q = Object.prototype.hasOwnProperty, B = Object.prototype.propertyIsEnumerable;
var k = (e, t, r) => t in e ? le(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, o = (e, t) => {
  for (var r in t || (t = {}))
    q.call(t, r) && k(e, r, t[r]);
  if (L)
    for (var r of L(t))
      B.call(t, r) && k(e, r, t[r]);
  return e;
}, p = (e, t) => de(e, ce(t));
var R = (e, t) => {
  var r = {};
  for (var i in e)
    q.call(e, i) && t.indexOf(i) < 0 && (r[i] = e[i]);
  if (e != null && L)
    for (var i of L(e))
      t.indexOf(i) < 0 && B.call(e, i) && (r[i] = e[i]);
  return r;
};
import { J as ue, c as X, i as pe } from "./types-CzqDZ83C.js";
import { C as me, i as ge, a as fe, b as ye, n as P, m as A, g as j } from "./utils-Db3U6oHa.js";
import { T as b, A as Se, n as he, k as ee, l as Oe, m as l, o as be, q as T, D as Te, r as N, s as te, t as ve, u as Ee, v as xe } from "./apply-styled-options-to-query-BzMAmDnD.js";
function Ce(e) {
  return e.replace(/\s+/g, "-").replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
}
function Mt(e) {
  return e.charAt(0).toUpperCase() + e.slice(1);
}
function Pt(e) {
  const t = /\[(.+?)\s\(Calendar\)\]/;
  return e.replace(t, "[$1]").trim();
}
function Wt(e) {
  if (e)
    if (e.metadata) {
      if (!e.model)
        throw new b("errors.missingModelTitle");
    } else throw new b("errors.missingMetadata");
  else throw new b("errors.emptyModel");
  return e;
}
function De(e) {
  return !e || !e.jaql.datasource.title || !e.jaql.metadata.length;
}
function re(e) {
  if (![...Se, "pivot", "pivot2"].includes(e))
    throw new b("errors.chartTypeNotSupported", { chartType: e });
}
function we(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 Q(e) {
  const t = "measures" in e && m(e.measures) || "values" in e && m(e.values);
  return we(e) ? "values" in e.dataOptions && m(e.dataOptions.values) : "chartType" in e ? e.chartType === "indicator" ? "value" in e.dataOptions && m(e.dataOptions.value) || "secondary" in e.dataOptions && m(e.dataOptions.secondary) : e.chartType === "table" ? !("columns" in e.dataOptions) || !m(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 && m(e.dataOptions.geo) && "color" in e.dataOptions && m(e.dataOptions.color) : "value" in e.dataOptions && m(e.dataOptions.value) : t;
}
function m(e) {
  return Array.isArray(e) && e.length > 0;
}
function Le(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 Ae(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 Ie = {
  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 _e(e) {
  return e.replace(/\[\[([^\]]+)\]\]/g, (t, r) => he(r));
}
const ie = (e, t) => Ie[t][e].replace(
  /{{(.*?)Tmpl}}/g,
  (i, a) => ie(`${a}Tmpl`, t)
), Me = (e, t) => e.replace(/{{(.*?)}}/g, (r, i) => i in t ? t[i] : (console.warn(`Placeholder ${i} not found in data`), r)), W = (e, t, r = "react") => {
  const i = ie(e, r), a = Me(i, t);
  return Le(_e(a));
}, Pe = () => Object.values(Oe).map((t) => ee.aggregationToJAQL(t)).join("|"), ae = (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 s = r[`${n}`], u = Pe(), d = new RegExp(`^\\s*(${u})\\(\\[\\w+\\]\\)$`), f = t.match(d);
  if (f && t.includes(n)) {
    const c = f[1];
    return o({
      dim: s.dim,
      table: s.table,
      column: s.column,
      datatype: s.datatype,
      agg: c,
      title: e.title
    }, i ? { filter: o({}, i) } : {});
  }
  return e;
}, _ = (e) => {
  let t = e;
  if ("formula" in e && (t = ae(e)), "context" in t) {
    const r = o({}, t.context);
    Object.keys(r).forEach((i) => {
      r[`${i}`] = _(r[`${i}`]);
    }), t.context = r;
  }
  return t;
}, We = (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 = ae(r.filter.by)), p(o({}, t), { jaql: r });
}, Fe = (e) => {
  let t = e;
  t = We(t);
  const { jaql: r, measure: i, by: a } = t;
  return o(o(p(o({}, t), {
    jaql: _(r)
  }), a ? { by: _(a) } : {}), i ? { measure: _(i) } : {});
}, M = 6;
function Ne(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 $e = {
  subtype: "indicator/numeric",
  numericSubtype: "numericSimple",
  skin: "vertical",
  indicatorComponents: {
    title: {
      shouldBeShown: !0,
      text: void 0
    },
    secondaryTitle: {
      text: ""
    },
    ticks: {
      shouldBeShown: !1
    },
    labels: {
      shouldBeShown: !1
    }
  }
}, ke = {
  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
  }
}, qe = {
  subtype: "line/basic",
  lineWidth: {
    width: "bold"
  },
  markers: {
    enabled: !1,
    size: "small",
    fill: "filled"
  }
}, Be = {
  subtype: "area/basic",
  lineWidth: {
    width: "bold"
  },
  markers: {
    enabled: !1,
    size: "small",
    fill: "filled"
  }
}, Re = {
  subtype: "bar/classic"
}, je = {
  subtype: "column/classic"
}, Qe = {
  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 O(e) {
  return be({}, ke, e);
}
const Ue = {
  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"
  }
}, ze = {
  legend: {
    enabled: !1,
    position: "left"
  },
  seriesLabels: {
    enabled: !0,
    showCategory: !0,
    showPercentage: !0,
    showPercentDecimals: !1,
    showValue: !0
  },
  funnelSize: "regular",
  funnelType: "regular",
  funnelDirection: "regular"
}, Ye = {
  rowsPerPage: 25,
  isAutoHeight: !0,
  rowHeight: null,
  alternatingRowsColor: !0,
  alternatingColumnsColor: !1,
  headersColor: !1,
  membersColor: !1,
  totalsColor: !1
}, Je = {
  labels: {
    category: [
      {
        enabled: !0
      },
      {
        enabled: !0
      },
      {
        enabled: !0
      }
    ]
  },
  tooltip: {
    mode: "value"
  }
}, Ke = {
  subtype: me.SUBTYPE,
  viewType: "month",
  startOfWeek: "sunday",
  cellLabels: {
    enabled: !0
  },
  dayLabels: {
    enabled: !0
  },
  monthLabels: {
    enabled: !0
  },
  weekends: {
    days: [],
    cellColor: "#e6e6e6",
    hideValues: !0
  }
}, Ve = {
  legend: {
    enabled: !0,
    position: "bottom"
  },
  tooltip: {
    mode: "value"
  }
}, He = {
  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
  }
}, Ze = {
  header: {
    color: {
      enabled: !1
    }
  },
  rows: {
    alternatingColor: {
      enabled: !1
    }
  },
  columns: {
    alternatingColor: {
      enabled: !1
    }
  }
}, Ge = {
  subtype: "scattermap",
  markers: {
    fill: "filled",
    size: {
      defaultSize: 4,
      minSize: 4,
      maxSize: 24
    }
  }
}, Xe = {
  mapType: "world"
}, et = {
  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 tt(e) {
  switch (e) {
    case "indicator":
      return l($e);
    case "line":
      return O(qe);
    case "area":
      return O(Be);
    case "bar":
      return O(Re);
    case "column":
      return O(je);
    case "polar":
      return O(Qe);
    case "pie":
      return l(Ue);
    case "funnel":
      return l(ze);
    case "treemap":
      return l(Je);
    case "calendar-heatmap":
      return l(Ke);
    case "sunburst":
      return l(Ve);
    case "scatter":
      return l(He);
    case "scattermap":
      return l(Ge);
    case "areamap":
      return l(Xe);
    case "boxplot":
      return l(et);
    case "table":
      return l(Ze);
    case "pivot":
      return l(Ye);
    case "pivot2":
      return {};
    case "image":
      return {};
    default:
      return {};
  }
}
const I = `
`, F = "UNKNOWN", rt = (e, t) => {
  let r = "";
  return r += `measureFactory.customFormula(
`, r += " ".repeat(t), r += `  '${T(e.title)}',
`, r += " ".repeat(t), r += `  '${e.formula}',
`, r += " ".repeat(t), r += `  {
`, Object.entries(e.context).forEach(([i, a]) => {
    const n = te(
      a.table || F,
      a.column || F,
      void 0,
      "DM"
    );
    r += " ".repeat(t), r += `    '${i.slice(1, -1)}': ${n},
`;
  }), r += " ".repeat(t), r += `  }
`, r += " ".repeat(t), r += ")", r;
}, it = (e) => {
  const { level: t, table: r, column: i, agg: a, title: n } = e;
  let s;
  return r && i && (s = te(r, i, t, "DM")), a && r && i && n && (s = `measureFactory.${ee.aggregationFromJAQL(
    a
  )}(${s}, '${T(n)}')`), s || F;
}, at = (e, t) => {
  const r = e.jaql(!1).jaql;
  return "formula" in r ? rt(r, t) : it(r);
}, g = (e, t = 0, r = !1) => {
  if (!e)
    return "";
  if (typeof e == "string")
    return `'${T(e)}'`;
  if (e instanceof ue)
    return at(e, t);
  if (e instanceof Te)
    return e.composeCode || "";
  let i = "";
  return Array.isArray(e) ? i += `[${e.map((a) => g(a, t + 2))}${e.length ? I + " ".repeat(t + 2) : ""}]` : (i += `{${I}`, Object.entries(e).forEach(([a, n]) => {
    if (r && typeof a == "string" && (a = `'${T(a)}'`), i += " ".repeat(t + 2), Array.isArray(n))
      i += `${a}: [${n.map((s) => g(s, t + 4, r))}${n.length ? I + " ".repeat(t + 2) : ""}]`;
    else if (typeof n == "object" && n !== null) {
      const s = Array.isArray(n) ? n : Ae(n);
      i += `${a}: ${g(s, t + 2, r)}`;
    } else ["number", "boolean", "undefined"].includes(typeof n) || n === null ? i += `${a}: ${n}` : typeof n == "string" ? i += `${a}: '${T(n)}'` : i += `${a}: ${n}`;
    i += `,${I}`;
  }), i += " ".repeat(t), i += "}"), i;
};
function $(e, t) {
  if (t === void 0 || t && typeof t == "object" && !Array.isArray(t) && Object.keys(t).length === 0)
    return e;
  if (!N(e, t)) {
    if (e && typeof e == "object" && !Array.isArray(e)) {
      const r = {};
      for (const i of Object.keys(e)) {
        const a = $(e[i], t == null ? void 0 : t[i]), n = t && Object.prototype.hasOwnProperty.call(t, i), s = n ? t[i] : void 0;
        (a !== void 0 || !n || e[i] === void 0 && s !== void 0) && (r[i] = a);
      }
      return Object.keys(r).length ? r : void 0;
    }
    return e;
  }
}
function U(e, t) {
  if (!e || Object.keys(e).length === 0)
    return {};
  const r = tt(t);
  if (N(e, r))
    return {};
  const i = $(e, r);
  return i != null ? i : {};
}
function z(e, t) {
  const r = Ne(t);
  if (N(e, r))
    return e;
  const i = $(e, r);
  return i != null ? i : {};
}
function nt(e) {
  return g(e, M);
}
function Y(e, t = "data-source-placeholder") {
  if (!e)
    return t;
  const r = typeof e == "object" && "title" in e ? e.title : e;
  return Ce(r);
}
function J(e, t = !0) {
  const r = [];
  return t && r.push("measureFactory"), m(e) && r.push("filterFactory"), r.length > 0 ? `import { ${r.join(", ")} } from '@sisense/sdk-data';` : "";
}
const K = `
`, st = (e, t) => {
  if (e.composeCode)
    return `${K}${" ".repeat(t)}${e.composeCode}`;
  const r = e.jaql().jaql;
  return `${K}${" ".repeat(t)}filterFactory.customFilter(${g(
    r,
    t,
    !0
  )})`;
}, ot = (e, t = 0) => {
  if (!e)
    return "";
  let r = "";
  return r += `[${e.map((i) => st(i, t + 2))}${e.length ? `
` + " ".repeat(t + 2) : ""}]`, r;
}, V = (e) => e ? Array.isArray(e) ? ot(e, 6) : "/** Filter relations not supported yet */" : "[]", lt = ["executeQueryByWidgetIdTmpl", "widgetByIdTmpl"], dt = "chartWidgetTmpl", ct = "pivotTableWidgetTmpl", ut = (e) => e, pt = ({
  dashboardOid: e,
  widgetOid: t,
  uiFramework: r = "react",
  chartType: i = "table",
  includeChart: a = !0
}) => {
  re(i);
  const n = { dashboardOid: e, widgetOid: t }, s = lt[Number(a)];
  return W(s, n, r);
}, mt = (e, t, r, i) => {
  if (ge(e)) {
    re(e.chartType);
    const a = Q(e), n = {
      idString: e.id,
      widgetTypeString: "chart",
      titleString: e.title,
      dataSourceString: Y(e.dataSource),
      chartTypeString: ut(e.chartType),
      dataOptionsString: nt(
        i ? z(e.dataOptions, e.chartType) : e.dataOptions
      ),
      filtersString: V(e.filters),
      componentString: "ChartWidget",
      extraImportsString: J(e.filters || [], a),
      styleOptionsString: g(
        i ? U(e.styleOptions || {}, e.chartType) : e.styleOptions || {},
        M
      ),
      drilldownOptionsString: g(
        e.drilldownOptions || {},
        M
      )
    };
    return W(r.chart, n, t);
  }
  if (fe(e)) {
    const a = Q(e), n = {
      idString: e.id,
      widgetTypeString: "pivot",
      titleString: e.title,
      dataSourceString: Y(e.dataSource),
      dataOptionsString: g(
        i ? z(e.dataOptions, e.widgetType) : e.dataOptions
      ),
      filtersString: V(e.filters),
      componentString: "PivotTableWidget",
      extraImportsString: J(e.filters || [], a),
      styleOptionsString: g(
        i ? U(e.styleOptions || {}, e.widgetType) : e.styleOptions || {},
        M
      )
    };
    return W(r.pivot, n, t);
  }
  if (ye(e))
    return "/** Custom widget code not supported yet */";
  throw new b("errors.otherWidgetTypesNotSupported");
}, gt = ({
  widgetProps: e,
  uiFramework: t = "react",
  removeDefaultProps: r = !1
}) => mt(e, t, {
  chart: dt,
  pivot: ct
}, r);
function ft(e) {
  return !!(e && (e.top !== void 0 || e.bottom !== void 0));
}
const yt = (e) => {
  const t = e.find((r) => r.panel === "rows");
  return t ? e.map((r) => {
    const i = r.jaql.filter;
    if (!(r.panel === "scope" && ft(i) && i.by === void 0))
      return r;
    const c = r.jaql, { type: n, context: s, formula: u, filter: d } = c, f = R(c, ["type", "context", "formula", "filter"]);
    return p(o({}, r), {
      jaql: o({
        // Copy dimension properties from rows dimension
        dim: t.jaql.dim,
        table: t.jaql.table,
        column: t.jaql.column,
        datatype: t.jaql.datatype,
        // Keep the filter but add the by clause
        filter: p(o({}, d), {
          by: {
            type: n,
            context: s,
            formula: u
          }
        })
      }, f)
    });
  }) : e;
}, Ft = (e) => "chartType" in e.chartRecommendations ? e.chartRecommendations : {
  chartType: "table",
  chartFamily: "table",
  axesMapping: {}
}, St = (e) => ({
  dataOptions: { columns: e.map(X) }
}), ht = Object.freeze({
  convolution: {
    enabled: !0,
    selectedConvolutionType: "bySlicesCount",
    independentSlicesCount: 7
  },
  lineWidth: { width: "bold" },
  markers: {
    enabled: !1
  },
  legend: {
    enabled: !1
  },
  yAxis: {
    gridLines: !1
  },
  xAxis: {
    gridLines: !1
  }
}), H = Object.freeze({
  line: "line/spline",
  pie: "pie/donut",
  bar: "bar/stacked",
  column: "column/stackedcolumn"
}), Ot = (e, t, r) => {
  const i = e.reduce((n, s) => (n[s.jaql.title] = s, n), {}), a = Object.entries(r).reduce((n, s) => {
    const [u, d] = s;
    return n[`${u}`] = Array.isArray(d) ? d.map((f) => {
      var v, E;
      const c = P(f);
      delete c.enabled;
      const y = i[c.column.name];
      if (!y) return { column: { type: "", name: c.column.name } };
      const S = X(y);
      if (y.panel === "measures")
        return p(o({}, c), {
          column: S
        });
      if (ve(S.type)) {
        const x = y.jaql, C = x.dateTimeLevel || x.level, D = C ? (E = (v = y.format) == null ? void 0 : v.mask) == null ? void 0 : E[C] : void 0;
        if (D)
          return p(o({}, c), {
            column: S,
            dateFormat: D
          });
      }
      return p(o({}, c), { column: S });
    }) : d, n;
  }, {});
  switch (t) {
    case "cartesian":
      return o({
        category: [],
        value: [],
        breakBy: []
      }, a);
    case "categorical":
      return o({
        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 ? St(e).dataOptions : a;
    case "boxplot":
    case "areamap":
    case "indicator":
    default:
      return a;
  }
}, Z = (e, t) => {
  var r, i, a, n;
  return t === "x" ? (i = (r = e.category) != null ? r : e.x) == null ? void 0 : i.map((s) => P(s).column.name).join(", ") : (n = (a = e.value) != null ? a : e.y) == null ? void 0 : n.map((s) => P(s).column.name).join(", ");
}, G = (e, t) => {
  var r;
  return (r = e[t]) == null ? void 0 : r.map((i) => P(i).column.name).join(", ");
}, bt = (e, t, r, i) => {
  let a;
  if (i && e in H)
    a = A(
      A(ht, {
        subtype: H[`${e}`]
      }),
      {
        legend: {
          enabled: !0,
          position: "right"
        },
        yAxis: {
          title: {
            enabled: !0,
            text: Z(t, "y")
          }
        },
        xAxis: {
          title: {
            enabled: !0,
            text: Z(t, "x")
          }
        }
      },
      r
    );
  else if (i && e === "indicator") {
    const n = {
      indicatorComponents: {
        title: {
          shouldBeShown: !0,
          text: G(t, "value")
        }
      }
    }, s = G(t, "secondary");
    s && (n != null && n.indicatorComponents) && (n.indicatorComponents.secondaryTitle = {
      text: s
    }), a = A(
      j(),
      n,
      r
    );
  } else
    a = A(j(), r);
  return a;
}, Tt = (e, t, r = !0) => {
  const {
    chartFamily: i,
    chartType: a,
    axesMapping: n = {},
    styleOptions: s = {}
  } = t, u = Ot(e, i, n), d = bt(
    a,
    n,
    s,
    r
  );
  return {
    dataOptions: u,
    chartStyleOptions: d
  };
}, vt = (e) => "chartType" in e ? e : {
  chartType: "table",
  chartFamily: "table",
  axesMapping: {}
}, Et = (e) => e.map((t) => Ee(t.jaql)), xt = (e) => e.reduce(
  (t, r) => {
    if ((r.panel === "scope" || r.jaql.filter) && t.metadataFilters.push(l(r)), r.panel !== "scope") {
      const i = l(r);
      delete i.jaql.filter, t.metadataColumns.push(i);
    }
    return t;
  },
  { metadataColumns: [], metadataFilters: [] }
), Ct = (e, t) => {
  if (!De(e))
    try {
      const { useCustomizedStyleOptions: r = !1 } = t || {}, { jaql: i, chartRecommendations: a, queryTitle: n } = e, { metadata: s, datasource: u } = i, d = p(o({}, u), { type: u.type || "elasticube" }), f = xe(d), y = yt(s).map((w) => Fe(w)).map((w) => p(o({}, w), {
        jaql: p(o({}, w.jaql), {
          datasource: f
        })
      })), S = vt(a), v = S.chartType.toLowerCase(), E = {
        cornerRadius: "Small",
        header: {
          // remove info button and render empty toolbar instead
          renderToolbar: () => null
        }
      }, { metadataColumns: x, metadataFilters: C } = xt(y), D = Et(C), { dataOptions: ne, chartStyleOptions: se } = Tt(
        x,
        S,
        r
      ), oe = o(o({}, se), E);
      return {
        widgetType: "chart",
        id: n,
        title: n,
        chartType: v,
        dataSource: d,
        dataOptions: ne,
        filters: D,
        styleOptions: oe
      };
    } catch (r) {
      console.error(r);
      return;
    }
}, Dt = (e, t) => Ct(e, t), wt = (e) => pe(e) ? pt(e) : gt(e), Nt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  toWidgetCode: wt,
  toWidgetProps: Dt
}, Symbol.toStringTag, { value: "Module" }));
export {
  M as C,
  g as a,
  W as b,
  Mt as c,
  Q as d,
  Y as e,
  V as f,
  mt as g,
  J as h,
  Fe as i,
  Ft as j,
  Ot as k,
  bt as l,
  Tt as m,
  Me as p,
  Pt as s,
  Dt as t,
  Wt as v,
  Nt as w
};
