react-semaphor 0.1.376 → 0.1.378

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.
Files changed (64) hide show
  1. package/dist/analytics-protocol/index.cjs +1 -1
  2. package/dist/analytics-protocol/index.js +47 -43
  3. package/dist/brand-studio/index.cjs +4 -4
  4. package/dist/brand-studio/index.js +10 -8
  5. package/dist/chunks/braces-BT-ZyB-g.js +6 -0
  6. package/dist/chunks/braces-DOxxfERN.js +23 -0
  7. package/dist/chunks/calendar-preferences-dialog-CRvQz4TE.js +1 -0
  8. package/dist/chunks/{calendar-preferences-dialog-B6fsethx.js → calendar-preferences-dialog-DZe8Nd-4.js} +14 -14
  9. package/dist/chunks/catalog-field-grounding-8L9I0zdg.js +1 -0
  10. package/dist/chunks/catalog-field-grounding-BK4BX8sZ.js +200 -0
  11. package/dist/chunks/dashboard-briefing-launcher-BWyHpn2M.js +111 -0
  12. package/dist/chunks/{dashboard-briefing-launcher-BKCRO7Qw.js → dashboard-briefing-launcher-DURdx5Ox.js} +3147 -2386
  13. package/dist/chunks/dashboard-controls-D5mjF67R.js +2279 -0
  14. package/dist/chunks/dashboard-controls-J71GLAxt.js +52 -0
  15. package/dist/chunks/{dashboard-json-QT0T2ad_.js → dashboard-json-BumvCRuk.js} +14 -13
  16. package/dist/chunks/dashboard-json-Cv8jXh0X.js +1 -0
  17. package/dist/chunks/{edit-dashboard-visual-DNzPgXMh.js → edit-dashboard-visual-dvhQzG_h.js} +33 -33
  18. package/dist/chunks/{edit-dashboard-visual-kNoMQRmH.js → edit-dashboard-visual-eYJMy7aw.js} +677 -677
  19. package/dist/chunks/{index-CPpqPJba.js → index-c_0nwsOM.js} +199 -194
  20. package/dist/chunks/{index-DX_0OcRv.js → index-hhH5F_tQ.js} +20665 -20527
  21. package/dist/chunks/layout-grid-DTbOIOsE.js +16 -0
  22. package/dist/chunks/layout-grid-DccceHv4.js +6 -0
  23. package/dist/chunks/{palette-2HWSR5wb.js → palette-DCzLwqIw.js} +1 -1
  24. package/dist/chunks/{palette-BcHHAmOU.js → palette-SimHJELn.js} +1 -1
  25. package/dist/chunks/{save-MoF1T13_.js → save-D2O96E5A.js} +1 -1
  26. package/dist/chunks/{save-B-YfAPhu.js → save-zNVYH02T.js} +1 -1
  27. package/dist/chunks/{switch-DmE_MY3L.js → switch-DMPsMpHW.js} +1 -1
  28. package/dist/chunks/{switch-CmHP5dT7.js → switch-Jhyl63RF.js} +1 -1
  29. package/dist/chunks/{use-create-flow-overlay-state-BLPQgGuz.js → use-create-flow-overlay-state-D9UKBuCA.js} +2 -2
  30. package/dist/chunks/{use-create-flow-overlay-state-D_Ntx-_C.js → use-create-flow-overlay-state-hlsTNh2b.js} +113 -112
  31. package/dist/chunks/{validation-DlrTIf1N.js → validation-BM3-ShHV.js} +1 -1
  32. package/dist/chunks/{validation-1V7bWmYw.js → validation-BVpqRFar.js} +1 -1
  33. package/dist/dashboard/index.cjs +1 -1
  34. package/dist/dashboard/index.js +1 -1
  35. package/dist/dashboard-authoring/index.cjs +1 -1
  36. package/dist/dashboard-authoring/index.js +1 -1
  37. package/dist/data-app-builder/index.cjs +1 -1
  38. package/dist/data-app-builder/index.js +3 -3
  39. package/dist/data-app-sdk/index.cjs +1 -1
  40. package/dist/data-app-sdk/index.js +22 -21
  41. package/dist/data-app-sdk-validation/index.cjs +1 -1
  42. package/dist/data-app-sdk-validation/index.js +2 -2
  43. package/dist/index.cjs +1 -1
  44. package/dist/index.js +128 -126
  45. package/dist/style.css +1 -1
  46. package/dist/surfboard/index.cjs +1 -1
  47. package/dist/surfboard/index.js +2 -2
  48. package/dist/types/analytics-protocol.d.ts +128 -0
  49. package/dist/types/dashboard-assistant.d.ts +42 -0
  50. package/dist/types/data-app-sdk-validation.d.ts +42 -0
  51. package/dist/types/data-app-sdk.d.ts +42 -0
  52. package/dist/types/main.d.ts +7 -0
  53. package/package.json +1 -1
  54. package/dist/chunks/calendar-preferences-dialog-Dh1b0ytN.js +0 -1
  55. package/dist/chunks/catalog-field-grounding-DoEBOXQd.js +0 -100
  56. package/dist/chunks/catalog-field-grounding-Du6mKDcF.js +0 -1
  57. package/dist/chunks/chevrons-up-down-D2fZD4N_.js +0 -6
  58. package/dist/chunks/chevrons-up-down-lahj6tQy.js +0 -14
  59. package/dist/chunks/dashboard-briefing-launcher-Gv1cwT0I.js +0 -111
  60. package/dist/chunks/dashboard-controls-BDJZarV7.js +0 -52
  61. package/dist/chunks/dashboard-controls-CchLBVDv.js +0 -3037
  62. package/dist/chunks/dashboard-json-ZhIEMXN0.js +0 -1
  63. package/dist/chunks/layout-grid-BOTLt36V.js +0 -36
  64. package/dist/chunks/layout-grid-CS6BSCJF.js +0 -11
@@ -0,0 +1,16 @@
1
+ import { c as t } from "./switch-DMPsMpHW.js";
2
+ /**
3
+ * @license lucide-react v0.453.0 - ISC
4
+ *
5
+ * This source code is licensed under the ISC license.
6
+ * See the LICENSE file in the root directory of this source tree.
7
+ */
8
+ const r = t("LayoutGrid", [
9
+ ["rect", { width: "7", height: "7", x: "3", y: "3", rx: "1", key: "1g98yp" }],
10
+ ["rect", { width: "7", height: "7", x: "14", y: "3", rx: "1", key: "6d4xhi" }],
11
+ ["rect", { width: "7", height: "7", x: "14", y: "14", rx: "1", key: "nxv5o0" }],
12
+ ["rect", { width: "7", height: "7", x: "3", y: "14", rx: "1", key: "1bb6yr" }]
13
+ ]);
14
+ export {
15
+ r as L
16
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";const t=require("./switch-Jhyl63RF.js");/**
2
+ * @license lucide-react v0.453.0 - ISC
3
+ *
4
+ * This source code is licensed under the ISC license.
5
+ * See the LICENSE file in the root directory of this source tree.
6
+ */const e=t.createLucideIcon("LayoutGrid",[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]]);exports.LayoutGrid=e;
@@ -1,4 +1,4 @@
1
- import { c } from "./switch-DmE_MY3L.js";
1
+ import { c } from "./switch-DMPsMpHW.js";
2
2
  /**
3
3
  * @license lucide-react v0.453.0 - ISC
4
4
  *
@@ -1,4 +1,4 @@
1
- "use strict";const c=require("./switch-CmHP5dT7.js");/**
1
+ "use strict";const c=require("./switch-Jhyl63RF.js");/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- "use strict";const a=require("./switch-CmHP5dT7.js");/**
1
+ "use strict";const a=require("./switch-Jhyl63RF.js");/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import { c as a } from "./switch-DmE_MY3L.js";
1
+ import { c as a } from "./switch-DMPsMpHW.js";
2
2
  /**
3
3
  * @license lucide-react v0.453.0 - ISC
4
4
  *
@@ -2,11 +2,11 @@ import { jsx as x, jsxs as be, Fragment as Dr } from "react/jsx-runtime";
2
2
  import * as f from "react";
3
3
  import Ce, { createContext as ef, useContext as tf, forwardRef as Bs, createElement as Oo, useLayoutEffect as rf, useState as nf, useMemo as of, useId as af } from "react";
4
4
  import { j as ui } from "./index-CuHybtft.js";
5
+ import { c as fi } from "./catalog-field-grounding-BK4BX8sZ.js";
5
6
  import * as Tn from "react-dom";
6
7
  import sf from "react-dom";
7
8
  import { S as lf, b as ua, c as $s, d as cf, e as df, r as uf } from "./index-CJdxSyQq.js";
8
9
  import "react-dom/client";
9
- import { b as fi } from "./catalog-field-grounding-DoEBOXQd.js";
10
10
  import { createFrameLayouts as ff } from "../layouts/index.js";
11
11
  import { t as Us, c as Mo, f as js, h as Cr, i as pf } from "./index-DFOb_6HB.js";
12
12
  import { a as fa, C as zs } from "./common-types-4bjoIgvm.js";
@@ -1,4 +1,4 @@
1
- "use strict";const x=require("react/jsx-runtime"),ie=require("react"),_i=require("./index-BxM99sFL.js"),gl=require("react-dom"),ut=require("./index-DRlMUglg.js");require("react-dom/client");const Oi=require("./catalog-field-grounding-Du6mKDcF.js"),gp=require("../layouts/index.cjs"),xe=require("./index-D7KJindZ.js"),xn=require("./common-types-C73-Ud1-.js");function yl(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const f=yl(ie),Bn=yl(gl),Xa=e=>{let r;const t=new Set,n=(c,u)=>{const d=typeof c=="function"?c(r):c;if(!Object.is(d,r)){const p=r;r=u??(typeof d!="object"||d===null)?d:Object.assign({},r,d),t.forEach(h=>h(r,p))}},o=()=>r,s={setState:n,getState:o,getInitialState:()=>l,subscribe:c=>(t.add(c),()=>t.delete(c))},l=r=e(n,o,s);return s},yp=e=>e?Xa(e):Xa,bp=e=>e;function vp(e,r=bp){const t=ie.useSyncExternalStore(e.subscribe,ie.useCallback(()=>r(e.getState()),[e,r]),ie.useCallback(()=>r(e.getInitialState()),[e,r]));return ie.useDebugValue(t),t}const Za=e=>{const r=yp(e),t=n=>vp(r,n);return Object.assign(t,r),t},_t=e=>e?Za(e):Za;var bl=Symbol.for("immer-nothing"),Qa=Symbol.for("immer-draftable"),Q=Symbol.for("immer-state"),Cp=process.env.NODE_ENV!=="production"?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(e){return`'current' expects a draft, got: ${e}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(e){return`'original' expects a draft, got: ${e}`}]:[];function ye(e,...r){if(process.env.NODE_ENV!=="production"){const t=Cp[e],n=typeof t=="function"?t.apply(null,r):t;throw new Error(`[Immer] ${n}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var Fr=Object.getPrototypeOf;function Qt(e){return!!e&&!!e[Q]}function Ze(e){var r;return e?vl(e)||Array.isArray(e)||!!e[Qa]||!!((r=e.constructor)!=null&&r[Qa])||Br(e)||jn(e):!1}var Sp=Object.prototype.constructor.toString(),Ja=new WeakMap;function vl(e){if(!e||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);if(r===null||r===Object.prototype)return!0;const t=Object.hasOwnProperty.call(r,"constructor")&&r.constructor;if(t===Object)return!0;if(typeof t!="function")return!1;let n=Ja.get(t);return n===void 0&&(n=Function.toString.call(t),Ja.set(t,n)),n===Sp}function Dr(e,r,t=!0){$n(e)===0?(t?Reflect.ownKeys(e):Object.keys(e)).forEach(o=>{r(o,e[o],e)}):e.forEach((n,o)=>r(o,n,e))}function $n(e){const r=e[Q];return r?r.type_:Array.isArray(e)?1:Br(e)?2:jn(e)?3:0}function ei(e,r){return $n(e)===2?e.has(r):Object.prototype.hasOwnProperty.call(e,r)}function Cl(e,r,t){const n=$n(e);n===2?e.set(r,t):n===3?e.add(t):e[r]=t}function xp(e,r){return e===r?e!==0||1/e===1/r:e!==e&&r!==r}function Br(e){return e instanceof Map}function jn(e){return e instanceof Set}function ue(e){return e.copy_||e.base_}function ti(e,r){if(Br(e))return new Map(e);if(jn(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);const t=vl(e);if(r===!0||r==="class_only"&&!t){const n=Object.getOwnPropertyDescriptors(e);delete n[Q];let o=Reflect.ownKeys(n);for(let i=0;i<o.length;i++){const a=o[i],s=n[a];s.writable===!1&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(n[a]={configurable:!0,writable:!0,enumerable:s.enumerable,value:e[a]})}return Object.create(Fr(e),n)}else{const n=Fr(e);if(n!==null&&t)return{...e};const o=Object.create(n);return Object.assign(o,e)}}function Mi(e,r=!1){return Un(e)||Qt(e)||!Ze(e)||($n(e)>1&&Object.defineProperties(e,{set:tn,add:tn,clear:tn,delete:tn}),Object.freeze(e),r&&Object.values(e).forEach(t=>Mi(t,!0))),e}function wp(){ye(2)}var tn={value:wp};function Un(e){return e===null||typeof e!="object"?!0:Object.isFrozen(e)}var ri={};function Tt(e){const r=ri[e];return r||ye(0,e),r}function Ip(e,r){ri[e]||(ri[e]=r)}var Rr;function wn(){return Rr}function Ep(e,r){return{drafts_:[],parent_:e,immer_:r,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function es(e,r){r&&(Tt("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=r)}function ni(e){oi(e),e.drafts_.forEach(Tp),e.drafts_=null}function oi(e){e===Rr&&(Rr=e.parent_)}function ts(e){return Rr=Ep(Rr,e)}function Tp(e){const r=e[Q];r.type_===0||r.type_===1?r.revoke_():r.revoked_=!0}function rs(e,r){r.unfinalizedDrafts_=r.drafts_.length;const t=r.drafts_[0];return e!==void 0&&e!==t?(t[Q].modified_&&(ni(r),ye(4)),Ze(e)&&(e=In(r,e),r.parent_||En(r,e)),r.patches_&&Tt("Patches").generateReplacementPatches_(t[Q].base_,e,r.patches_,r.inversePatches_)):e=In(r,t,[]),ni(r),r.patches_&&r.patchListener_(r.patches_,r.inversePatches_),e!==bl?e:void 0}function In(e,r,t){if(Un(r))return r;const n=e.immer_.shouldUseStrictIteration(),o=r[Q];if(!o)return Dr(r,(i,a)=>ns(e,o,r,i,a,t),n),r;if(o.scope_!==e)return r;if(!o.modified_)return En(e,o.base_,!0),o.base_;if(!o.finalized_){o.finalized_=!0,o.scope_.unfinalizedDrafts_--;const i=o.copy_;let a=i,s=!1;o.type_===3&&(a=new Set(i),i.clear(),s=!0),Dr(a,(l,c)=>ns(e,o,i,l,c,t,s),n),En(e,i,!1),t&&e.patches_&&Tt("Patches").generatePatches_(o,t,e.patches_,e.inversePatches_)}return o.copy_}function ns(e,r,t,n,o,i,a){if(o==null||typeof o!="object"&&!a)return;const s=Un(o);if(!(s&&!a)){if(process.env.NODE_ENV!=="production"&&o===t&&ye(5),Qt(o)){const l=i&&r&&r.type_!==3&&!ei(r.assigned_,n)?i.concat(n):void 0,c=In(e,o,l);if(Cl(t,n,c),Qt(c))e.canAutoFreeze_=!1;else return}else a&&t.add(o);if(Ze(o)&&!s){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1||r&&r.base_&&r.base_[n]===o&&s)return;In(e,o),(!r||!r.scope_.parent_)&&typeof n!="symbol"&&(Br(t)?t.has(n):Object.prototype.propertyIsEnumerable.call(t,n))&&En(e,o)}}}function En(e,r,t=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&Mi(r,t)}function Ap(e,r){const t=Array.isArray(e),n={type_:t?1:0,scope_:r?r.scope_:wn(),modified_:!1,finalized_:!1,assigned_:{},parent_:r,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let o=n,i=Ni;t&&(o=[n],i=Pr);const{revoke:a,proxy:s}=Proxy.revocable(o,i);return n.draft_=s,n.revoke_=a,s}var Ni={get(e,r){if(r===Q)return e;const t=ue(e);if(!ei(t,r))return Fp(e,t,r);const n=t[r];return e.finalized_||!Ze(n)?n:n===Eo(e.base_,r)?(To(e),e.copy_[r]=_r(n,e)):n},has(e,r){return r in ue(e)},ownKeys(e){return Reflect.ownKeys(ue(e))},set(e,r,t){const n=Sl(ue(e),r);if(n!=null&&n.set)return n.set.call(e.draft_,t),!0;if(!e.modified_){const o=Eo(ue(e),r),i=o==null?void 0:o[Q];if(i&&i.base_===t)return e.copy_[r]=t,e.assigned_[r]=!1,!0;if(xp(t,o)&&(t!==void 0||ei(e.base_,r)))return!0;To(e),Ye(e)}return e.copy_[r]===t&&(t!==void 0||r in e.copy_)||Number.isNaN(t)&&Number.isNaN(e.copy_[r])||(e.copy_[r]=t,e.assigned_[r]=!0),!0},deleteProperty(e,r){return Eo(e.base_,r)!==void 0||r in e.base_?(e.assigned_[r]=!1,To(e),Ye(e)):delete e.assigned_[r],e.copy_&&delete e.copy_[r],!0},getOwnPropertyDescriptor(e,r){const t=ue(e),n=Reflect.getOwnPropertyDescriptor(t,r);return n&&{writable:!0,configurable:e.type_!==1||r!=="length",enumerable:n.enumerable,value:t[r]}},defineProperty(){ye(11)},getPrototypeOf(e){return Fr(e.base_)},setPrototypeOf(){ye(12)}},Pr={};Dr(Ni,(e,r)=>{Pr[e]=function(){return arguments[0]=arguments[0][0],r.apply(this,arguments)}});Pr.deleteProperty=function(e,r){return process.env.NODE_ENV!=="production"&&isNaN(parseInt(r))&&ye(13),Pr.set.call(this,e,r,void 0)};Pr.set=function(e,r,t){return process.env.NODE_ENV!=="production"&&r!=="length"&&isNaN(parseInt(r))&&ye(14),Ni.set.call(this,e[0],r,t,e[0])};function Eo(e,r){const t=e[Q];return(t?ue(t):e)[r]}function Fp(e,r,t){var o;const n=Sl(r,t);return n?"value"in n?n.value:(o=n.get)==null?void 0:o.call(e.draft_):void 0}function Sl(e,r){if(!(r in e))return;let t=Fr(e);for(;t;){const n=Object.getOwnPropertyDescriptor(t,r);if(n)return n;t=Fr(t)}}function Ye(e){e.modified_||(e.modified_=!0,e.parent_&&Ye(e.parent_))}function To(e){e.copy_||(e.copy_=ti(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var Dp=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(r,t,n)=>{if(typeof r=="function"&&typeof t!="function"){const i=t;t=r;const a=this;return function(l=i,...c){return a.produce(l,u=>t.call(this,u,...c))}}typeof t!="function"&&ye(6),n!==void 0&&typeof n!="function"&&ye(7);let o;if(Ze(r)){const i=ts(this),a=_r(r,void 0);let s=!0;try{o=t(a),s=!1}finally{s?ni(i):oi(i)}return es(i,n),rs(o,i)}else if(!r||typeof r!="object"){if(o=t(r),o===void 0&&(o=r),o===bl&&(o=void 0),this.autoFreeze_&&Mi(o,!0),n){const i=[],a=[];Tt("Patches").generateReplacementPatches_(r,o,i,a),n(i,a)}return o}else ye(1,r)},this.produceWithPatches=(r,t)=>{if(typeof r=="function")return(a,...s)=>this.produceWithPatches(a,l=>r(l,...s));let n,o;return[this.produce(r,t,(a,s)=>{n=a,o=s}),n,o]},typeof(e==null?void 0:e.autoFreeze)=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof(e==null?void 0:e.useStrictShallowCopy)=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),typeof(e==null?void 0:e.useStrictIteration)=="boolean"&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){Ze(e)||ye(8),Qt(e)&&(e=Rp(e));const r=ts(this),t=_r(e,void 0);return t[Q].isManual_=!0,oi(r),t}finishDraft(e,r){const t=e&&e[Q];(!t||!t.isManual_)&&ye(9);const{scope_:n}=t;return es(n,r),rs(void 0,n)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,r){let t;for(t=r.length-1;t>=0;t--){const o=r[t];if(o.path.length===0&&o.op==="replace"){e=o.value;break}}t>-1&&(r=r.slice(t+1));const n=Tt("Patches").applyPatches_;return Qt(e)?n(e,r):this.produce(e,o=>n(o,r))}};function _r(e,r){const t=Br(e)?Tt("MapSet").proxyMap_(e,r):jn(e)?Tt("MapSet").proxySet_(e,r):Ap(e,r);return(r?r.scope_:wn()).drafts_.push(t),t}function Rp(e){return Qt(e)||ye(10,e),xl(e)}function xl(e){if(!Ze(e)||Un(e))return e;const r=e[Q];let t,n=!0;if(r){if(!r.modified_)return r.base_;r.finalized_=!0,t=ti(e,r.scope_.immer_.useStrictShallowCopy_),n=r.scope_.immer_.shouldUseStrictIteration()}else t=ti(e,!0);return Dr(t,(o,i)=>{Cl(t,o,xl(i))},n),r&&(r.finalized_=!1),t}function Pp(){class e extends Map{constructor(l,c){super(),this[Q]={type_:2,parent_:c,scope_:c?c.scope_:wn(),modified_:!1,finalized_:!1,copy_:void 0,assigned_:void 0,base_:l,draft_:this,isManual_:!1,revoked_:!1}}get size(){return ue(this[Q]).size}has(l){return ue(this[Q]).has(l)}set(l,c){const u=this[Q];return a(u),(!ue(u).has(l)||ue(u).get(l)!==c)&&(t(u),Ye(u),u.assigned_.set(l,!0),u.copy_.set(l,c),u.assigned_.set(l,!0)),this}delete(l){if(!this.has(l))return!1;const c=this[Q];return a(c),t(c),Ye(c),c.base_.has(l)?c.assigned_.set(l,!1):c.assigned_.delete(l),c.copy_.delete(l),!0}clear(){const l=this[Q];a(l),ue(l).size&&(t(l),Ye(l),l.assigned_=new Map,Dr(l.base_,c=>{l.assigned_.set(c,!1)}),l.copy_.clear())}forEach(l,c){const u=this[Q];ue(u).forEach((d,p,h)=>{l.call(c,this.get(p),p,this)})}get(l){const c=this[Q];a(c);const u=ue(c).get(l);if(c.finalized_||!Ze(u)||u!==c.base_.get(l))return u;const d=_r(u,c);return t(c),c.copy_.set(l,d),d}keys(){return ue(this[Q]).keys()}values(){const l=this.keys();return{[Symbol.iterator]:()=>this.values(),next:()=>{const c=l.next();return c.done?c:{done:!1,value:this.get(c.value)}}}}entries(){const l=this.keys();return{[Symbol.iterator]:()=>this.entries(),next:()=>{const c=l.next();if(c.done)return c;const u=this.get(c.value);return{done:!1,value:[c.value,u]}}}}[Symbol.iterator](){return this.entries()}}function r(s,l){return new e(s,l)}function t(s){s.copy_||(s.assigned_=new Map,s.copy_=new Map(s.base_))}class n extends Set{constructor(l,c){super(),this[Q]={type_:3,parent_:c,scope_:c?c.scope_:wn(),modified_:!1,finalized_:!1,copy_:void 0,base_:l,draft_:this,drafts_:new Map,revoked_:!1,isManual_:!1}}get size(){return ue(this[Q]).size}has(l){const c=this[Q];return a(c),c.copy_?!!(c.copy_.has(l)||c.drafts_.has(l)&&c.copy_.has(c.drafts_.get(l))):c.base_.has(l)}add(l){const c=this[Q];return a(c),this.has(l)||(i(c),Ye(c),c.copy_.add(l)),this}delete(l){if(!this.has(l))return!1;const c=this[Q];return a(c),i(c),Ye(c),c.copy_.delete(l)||(c.drafts_.has(l)?c.copy_.delete(c.drafts_.get(l)):!1)}clear(){const l=this[Q];a(l),ue(l).size&&(i(l),Ye(l),l.copy_.clear())}values(){const l=this[Q];return a(l),i(l),l.copy_.values()}entries(){const l=this[Q];return a(l),i(l),l.copy_.entries()}keys(){return this.values()}[Symbol.iterator](){return this.values()}forEach(l,c){const u=this.values();let d=u.next();for(;!d.done;)l.call(c,d.value,d.value,this),d=u.next()}}function o(s,l){return new n(s,l)}function i(s){s.copy_||(s.copy_=new Set,s.base_.forEach(l=>{if(Ze(l)){const c=_r(l,s);s.drafts_.set(l,c),s.copy_.add(c)}else s.copy_.add(l)}))}function a(s){s.revoked_&&ye(3,JSON.stringify(ue(s)))}Ip("MapSet",{proxyMap_:r,proxySet_:o})}var _p=new Dp,Op=_p.produce;const Mp=e=>(r,t,n)=>(n.setState=(o,i,...a)=>{const s=typeof o=="function"?Op(o):o;return r(s,i,...a)},e(n.setState,t,n)),zn=Mp;var Ee=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function qn(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Np(e){if(e.__esModule)return e;var r=e.default;if(typeof r=="function"){var t=function n(){return this instanceof n?Reflect.construct(r,arguments,this.constructor):r.apply(this,arguments)};t.prototype=r.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}),t}var kp=function e(r,t){if(r===t)return!0;if(r&&t&&typeof r=="object"&&typeof t=="object"){if(r.constructor!==t.constructor)return!1;var n,o,i;if(Array.isArray(r)){if(n=r.length,n!=t.length)return!1;for(o=n;o--!==0;)if(!e(r[o],t[o]))return!1;return!0}if(r.constructor===RegExp)return r.source===t.source&&r.flags===t.flags;if(r.valueOf!==Object.prototype.valueOf)return r.valueOf()===t.valueOf();if(r.toString!==Object.prototype.toString)return r.toString()===t.toString();if(i=Object.keys(r),n=i.length,n!==Object.keys(t).length)return!1;for(o=n;o--!==0;)if(!Object.prototype.hasOwnProperty.call(t,i[o]))return!1;for(o=n;o--!==0;){var a=i[o];if(!(a==="_owner"&&r.$$typeof)&&!e(r[a],t[a]))return!1}return!0}return r!==r&&t!==t};const ii=qn(kp),xt=new Map;function Lp(e,r){return xt.has(e)||xt.set(e,new Set),xt.get(e).add(r),()=>{var t;(t=xt.get(e))==null||t.delete(r)}}function ki(e){const r=xt.get(e);r&&r.forEach(t=>{try{t()}catch(n){console.error(`Error in store event callback for '${e}':`,n)}})}function Vp(e){e?xt.delete(e):xt.clear()}const et={subscribe:Lp,emit:ki,clear:Vp},Bp=()=>ki("dashboard:load"),$p=()=>ki("dashboard:unload"),os={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Or=new Map,rn=e=>{const r=Or.get(e);return r?Object.fromEntries(Object.entries(r.stores).map(([t,n])=>[t,n.getState()])):{}},jp=(e,r,t)=>{if(e===void 0)return{type:"untracked",connection:r.connect(t)};const n=Or.get(t.name);if(n)return{type:"tracked",store:e,...n};const o={connection:r.connect(t),stores:{}};return Or.set(t.name,o),{type:"tracked",store:e,...o}},Up=(e,r)=>{if(r===void 0)return;const t=Or.get(e);t&&(delete t.stores[r],Object.keys(t.stores).length===0&&Or.delete(e))},zp=e=>{var r,t;if(!e)return;const n=e.split(`
1
+ "use strict";const x=require("react/jsx-runtime"),ie=require("react"),_i=require("./index-BxM99sFL.js"),Oi=require("./catalog-field-grounding-8L9I0zdg.js"),gl=require("react-dom"),ut=require("./index-DRlMUglg.js");require("react-dom/client");const gp=require("../layouts/index.cjs"),xe=require("./index-D7KJindZ.js"),xn=require("./common-types-C73-Ud1-.js");function yl(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return r.default=e,Object.freeze(r)}const f=yl(ie),Bn=yl(gl),Xa=e=>{let r;const t=new Set,n=(c,u)=>{const d=typeof c=="function"?c(r):c;if(!Object.is(d,r)){const p=r;r=u??(typeof d!="object"||d===null)?d:Object.assign({},r,d),t.forEach(h=>h(r,p))}},o=()=>r,s={setState:n,getState:o,getInitialState:()=>l,subscribe:c=>(t.add(c),()=>t.delete(c))},l=r=e(n,o,s);return s},yp=e=>e?Xa(e):Xa,bp=e=>e;function vp(e,r=bp){const t=ie.useSyncExternalStore(e.subscribe,ie.useCallback(()=>r(e.getState()),[e,r]),ie.useCallback(()=>r(e.getInitialState()),[e,r]));return ie.useDebugValue(t),t}const Za=e=>{const r=yp(e),t=n=>vp(r,n);return Object.assign(t,r),t},_t=e=>e?Za(e):Za;var bl=Symbol.for("immer-nothing"),Qa=Symbol.for("immer-draftable"),Q=Symbol.for("immer-state"),Cp=process.env.NODE_ENV!=="production"?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){return`produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.","Immer forbids circular references","The first or second argument to `produce` must be a function","The third argument to `produce` must be a function or undefined","First argument to `createDraft` must be a plain object, an array, or an immerable object","First argument to `finishDraft` must be a draft returned by `createDraft`",function(e){return`'current' expects a draft, got: ${e}`},"Object.defineProperty() cannot be used on an Immer draft","Object.setPrototypeOf() cannot be used on an Immer draft","Immer only supports deleting array indices","Immer only supports setting array indices and the 'length' property",function(e){return`'original' expects a draft, got: ${e}`}]:[];function ye(e,...r){if(process.env.NODE_ENV!=="production"){const t=Cp[e],n=typeof t=="function"?t.apply(null,r):t;throw new Error(`[Immer] ${n}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var Fr=Object.getPrototypeOf;function Qt(e){return!!e&&!!e[Q]}function Ze(e){var r;return e?vl(e)||Array.isArray(e)||!!e[Qa]||!!((r=e.constructor)!=null&&r[Qa])||Br(e)||jn(e):!1}var Sp=Object.prototype.constructor.toString(),Ja=new WeakMap;function vl(e){if(!e||typeof e!="object")return!1;const r=Object.getPrototypeOf(e);if(r===null||r===Object.prototype)return!0;const t=Object.hasOwnProperty.call(r,"constructor")&&r.constructor;if(t===Object)return!0;if(typeof t!="function")return!1;let n=Ja.get(t);return n===void 0&&(n=Function.toString.call(t),Ja.set(t,n)),n===Sp}function Dr(e,r,t=!0){$n(e)===0?(t?Reflect.ownKeys(e):Object.keys(e)).forEach(o=>{r(o,e[o],e)}):e.forEach((n,o)=>r(o,n,e))}function $n(e){const r=e[Q];return r?r.type_:Array.isArray(e)?1:Br(e)?2:jn(e)?3:0}function ei(e,r){return $n(e)===2?e.has(r):Object.prototype.hasOwnProperty.call(e,r)}function Cl(e,r,t){const n=$n(e);n===2?e.set(r,t):n===3?e.add(t):e[r]=t}function xp(e,r){return e===r?e!==0||1/e===1/r:e!==e&&r!==r}function Br(e){return e instanceof Map}function jn(e){return e instanceof Set}function ue(e){return e.copy_||e.base_}function ti(e,r){if(Br(e))return new Map(e);if(jn(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);const t=vl(e);if(r===!0||r==="class_only"&&!t){const n=Object.getOwnPropertyDescriptors(e);delete n[Q];let o=Reflect.ownKeys(n);for(let i=0;i<o.length;i++){const a=o[i],s=n[a];s.writable===!1&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(n[a]={configurable:!0,writable:!0,enumerable:s.enumerable,value:e[a]})}return Object.create(Fr(e),n)}else{const n=Fr(e);if(n!==null&&t)return{...e};const o=Object.create(n);return Object.assign(o,e)}}function Mi(e,r=!1){return Un(e)||Qt(e)||!Ze(e)||($n(e)>1&&Object.defineProperties(e,{set:tn,add:tn,clear:tn,delete:tn}),Object.freeze(e),r&&Object.values(e).forEach(t=>Mi(t,!0))),e}function wp(){ye(2)}var tn={value:wp};function Un(e){return e===null||typeof e!="object"?!0:Object.isFrozen(e)}var ri={};function Tt(e){const r=ri[e];return r||ye(0,e),r}function Ip(e,r){ri[e]||(ri[e]=r)}var Rr;function wn(){return Rr}function Ep(e,r){return{drafts_:[],parent_:e,immer_:r,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function es(e,r){r&&(Tt("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=r)}function ni(e){oi(e),e.drafts_.forEach(Tp),e.drafts_=null}function oi(e){e===Rr&&(Rr=e.parent_)}function ts(e){return Rr=Ep(Rr,e)}function Tp(e){const r=e[Q];r.type_===0||r.type_===1?r.revoke_():r.revoked_=!0}function rs(e,r){r.unfinalizedDrafts_=r.drafts_.length;const t=r.drafts_[0];return e!==void 0&&e!==t?(t[Q].modified_&&(ni(r),ye(4)),Ze(e)&&(e=In(r,e),r.parent_||En(r,e)),r.patches_&&Tt("Patches").generateReplacementPatches_(t[Q].base_,e,r.patches_,r.inversePatches_)):e=In(r,t,[]),ni(r),r.patches_&&r.patchListener_(r.patches_,r.inversePatches_),e!==bl?e:void 0}function In(e,r,t){if(Un(r))return r;const n=e.immer_.shouldUseStrictIteration(),o=r[Q];if(!o)return Dr(r,(i,a)=>ns(e,o,r,i,a,t),n),r;if(o.scope_!==e)return r;if(!o.modified_)return En(e,o.base_,!0),o.base_;if(!o.finalized_){o.finalized_=!0,o.scope_.unfinalizedDrafts_--;const i=o.copy_;let a=i,s=!1;o.type_===3&&(a=new Set(i),i.clear(),s=!0),Dr(a,(l,c)=>ns(e,o,i,l,c,t,s),n),En(e,i,!1),t&&e.patches_&&Tt("Patches").generatePatches_(o,t,e.patches_,e.inversePatches_)}return o.copy_}function ns(e,r,t,n,o,i,a){if(o==null||typeof o!="object"&&!a)return;const s=Un(o);if(!(s&&!a)){if(process.env.NODE_ENV!=="production"&&o===t&&ye(5),Qt(o)){const l=i&&r&&r.type_!==3&&!ei(r.assigned_,n)?i.concat(n):void 0,c=In(e,o,l);if(Cl(t,n,c),Qt(c))e.canAutoFreeze_=!1;else return}else a&&t.add(o);if(Ze(o)&&!s){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1||r&&r.base_&&r.base_[n]===o&&s)return;In(e,o),(!r||!r.scope_.parent_)&&typeof n!="symbol"&&(Br(t)?t.has(n):Object.prototype.propertyIsEnumerable.call(t,n))&&En(e,o)}}}function En(e,r,t=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&Mi(r,t)}function Ap(e,r){const t=Array.isArray(e),n={type_:t?1:0,scope_:r?r.scope_:wn(),modified_:!1,finalized_:!1,assigned_:{},parent_:r,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let o=n,i=Ni;t&&(o=[n],i=Pr);const{revoke:a,proxy:s}=Proxy.revocable(o,i);return n.draft_=s,n.revoke_=a,s}var Ni={get(e,r){if(r===Q)return e;const t=ue(e);if(!ei(t,r))return Fp(e,t,r);const n=t[r];return e.finalized_||!Ze(n)?n:n===Eo(e.base_,r)?(To(e),e.copy_[r]=_r(n,e)):n},has(e,r){return r in ue(e)},ownKeys(e){return Reflect.ownKeys(ue(e))},set(e,r,t){const n=Sl(ue(e),r);if(n!=null&&n.set)return n.set.call(e.draft_,t),!0;if(!e.modified_){const o=Eo(ue(e),r),i=o==null?void 0:o[Q];if(i&&i.base_===t)return e.copy_[r]=t,e.assigned_[r]=!1,!0;if(xp(t,o)&&(t!==void 0||ei(e.base_,r)))return!0;To(e),Ye(e)}return e.copy_[r]===t&&(t!==void 0||r in e.copy_)||Number.isNaN(t)&&Number.isNaN(e.copy_[r])||(e.copy_[r]=t,e.assigned_[r]=!0),!0},deleteProperty(e,r){return Eo(e.base_,r)!==void 0||r in e.base_?(e.assigned_[r]=!1,To(e),Ye(e)):delete e.assigned_[r],e.copy_&&delete e.copy_[r],!0},getOwnPropertyDescriptor(e,r){const t=ue(e),n=Reflect.getOwnPropertyDescriptor(t,r);return n&&{writable:!0,configurable:e.type_!==1||r!=="length",enumerable:n.enumerable,value:t[r]}},defineProperty(){ye(11)},getPrototypeOf(e){return Fr(e.base_)},setPrototypeOf(){ye(12)}},Pr={};Dr(Ni,(e,r)=>{Pr[e]=function(){return arguments[0]=arguments[0][0],r.apply(this,arguments)}});Pr.deleteProperty=function(e,r){return process.env.NODE_ENV!=="production"&&isNaN(parseInt(r))&&ye(13),Pr.set.call(this,e,r,void 0)};Pr.set=function(e,r,t){return process.env.NODE_ENV!=="production"&&r!=="length"&&isNaN(parseInt(r))&&ye(14),Ni.set.call(this,e[0],r,t,e[0])};function Eo(e,r){const t=e[Q];return(t?ue(t):e)[r]}function Fp(e,r,t){var o;const n=Sl(r,t);return n?"value"in n?n.value:(o=n.get)==null?void 0:o.call(e.draft_):void 0}function Sl(e,r){if(!(r in e))return;let t=Fr(e);for(;t;){const n=Object.getOwnPropertyDescriptor(t,r);if(n)return n;t=Fr(t)}}function Ye(e){e.modified_||(e.modified_=!0,e.parent_&&Ye(e.parent_))}function To(e){e.copy_||(e.copy_=ti(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var Dp=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(r,t,n)=>{if(typeof r=="function"&&typeof t!="function"){const i=t;t=r;const a=this;return function(l=i,...c){return a.produce(l,u=>t.call(this,u,...c))}}typeof t!="function"&&ye(6),n!==void 0&&typeof n!="function"&&ye(7);let o;if(Ze(r)){const i=ts(this),a=_r(r,void 0);let s=!0;try{o=t(a),s=!1}finally{s?ni(i):oi(i)}return es(i,n),rs(o,i)}else if(!r||typeof r!="object"){if(o=t(r),o===void 0&&(o=r),o===bl&&(o=void 0),this.autoFreeze_&&Mi(o,!0),n){const i=[],a=[];Tt("Patches").generateReplacementPatches_(r,o,i,a),n(i,a)}return o}else ye(1,r)},this.produceWithPatches=(r,t)=>{if(typeof r=="function")return(a,...s)=>this.produceWithPatches(a,l=>r(l,...s));let n,o;return[this.produce(r,t,(a,s)=>{n=a,o=s}),n,o]},typeof(e==null?void 0:e.autoFreeze)=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof(e==null?void 0:e.useStrictShallowCopy)=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),typeof(e==null?void 0:e.useStrictIteration)=="boolean"&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){Ze(e)||ye(8),Qt(e)&&(e=Rp(e));const r=ts(this),t=_r(e,void 0);return t[Q].isManual_=!0,oi(r),t}finishDraft(e,r){const t=e&&e[Q];(!t||!t.isManual_)&&ye(9);const{scope_:n}=t;return es(n,r),rs(void 0,n)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,r){let t;for(t=r.length-1;t>=0;t--){const o=r[t];if(o.path.length===0&&o.op==="replace"){e=o.value;break}}t>-1&&(r=r.slice(t+1));const n=Tt("Patches").applyPatches_;return Qt(e)?n(e,r):this.produce(e,o=>n(o,r))}};function _r(e,r){const t=Br(e)?Tt("MapSet").proxyMap_(e,r):jn(e)?Tt("MapSet").proxySet_(e,r):Ap(e,r);return(r?r.scope_:wn()).drafts_.push(t),t}function Rp(e){return Qt(e)||ye(10,e),xl(e)}function xl(e){if(!Ze(e)||Un(e))return e;const r=e[Q];let t,n=!0;if(r){if(!r.modified_)return r.base_;r.finalized_=!0,t=ti(e,r.scope_.immer_.useStrictShallowCopy_),n=r.scope_.immer_.shouldUseStrictIteration()}else t=ti(e,!0);return Dr(t,(o,i)=>{Cl(t,o,xl(i))},n),r&&(r.finalized_=!1),t}function Pp(){class e extends Map{constructor(l,c){super(),this[Q]={type_:2,parent_:c,scope_:c?c.scope_:wn(),modified_:!1,finalized_:!1,copy_:void 0,assigned_:void 0,base_:l,draft_:this,isManual_:!1,revoked_:!1}}get size(){return ue(this[Q]).size}has(l){return ue(this[Q]).has(l)}set(l,c){const u=this[Q];return a(u),(!ue(u).has(l)||ue(u).get(l)!==c)&&(t(u),Ye(u),u.assigned_.set(l,!0),u.copy_.set(l,c),u.assigned_.set(l,!0)),this}delete(l){if(!this.has(l))return!1;const c=this[Q];return a(c),t(c),Ye(c),c.base_.has(l)?c.assigned_.set(l,!1):c.assigned_.delete(l),c.copy_.delete(l),!0}clear(){const l=this[Q];a(l),ue(l).size&&(t(l),Ye(l),l.assigned_=new Map,Dr(l.base_,c=>{l.assigned_.set(c,!1)}),l.copy_.clear())}forEach(l,c){const u=this[Q];ue(u).forEach((d,p,h)=>{l.call(c,this.get(p),p,this)})}get(l){const c=this[Q];a(c);const u=ue(c).get(l);if(c.finalized_||!Ze(u)||u!==c.base_.get(l))return u;const d=_r(u,c);return t(c),c.copy_.set(l,d),d}keys(){return ue(this[Q]).keys()}values(){const l=this.keys();return{[Symbol.iterator]:()=>this.values(),next:()=>{const c=l.next();return c.done?c:{done:!1,value:this.get(c.value)}}}}entries(){const l=this.keys();return{[Symbol.iterator]:()=>this.entries(),next:()=>{const c=l.next();if(c.done)return c;const u=this.get(c.value);return{done:!1,value:[c.value,u]}}}}[Symbol.iterator](){return this.entries()}}function r(s,l){return new e(s,l)}function t(s){s.copy_||(s.assigned_=new Map,s.copy_=new Map(s.base_))}class n extends Set{constructor(l,c){super(),this[Q]={type_:3,parent_:c,scope_:c?c.scope_:wn(),modified_:!1,finalized_:!1,copy_:void 0,base_:l,draft_:this,drafts_:new Map,revoked_:!1,isManual_:!1}}get size(){return ue(this[Q]).size}has(l){const c=this[Q];return a(c),c.copy_?!!(c.copy_.has(l)||c.drafts_.has(l)&&c.copy_.has(c.drafts_.get(l))):c.base_.has(l)}add(l){const c=this[Q];return a(c),this.has(l)||(i(c),Ye(c),c.copy_.add(l)),this}delete(l){if(!this.has(l))return!1;const c=this[Q];return a(c),i(c),Ye(c),c.copy_.delete(l)||(c.drafts_.has(l)?c.copy_.delete(c.drafts_.get(l)):!1)}clear(){const l=this[Q];a(l),ue(l).size&&(i(l),Ye(l),l.copy_.clear())}values(){const l=this[Q];return a(l),i(l),l.copy_.values()}entries(){const l=this[Q];return a(l),i(l),l.copy_.entries()}keys(){return this.values()}[Symbol.iterator](){return this.values()}forEach(l,c){const u=this.values();let d=u.next();for(;!d.done;)l.call(c,d.value,d.value,this),d=u.next()}}function o(s,l){return new n(s,l)}function i(s){s.copy_||(s.copy_=new Set,s.base_.forEach(l=>{if(Ze(l)){const c=_r(l,s);s.drafts_.set(l,c),s.copy_.add(c)}else s.copy_.add(l)}))}function a(s){s.revoked_&&ye(3,JSON.stringify(ue(s)))}Ip("MapSet",{proxyMap_:r,proxySet_:o})}var _p=new Dp,Op=_p.produce;const Mp=e=>(r,t,n)=>(n.setState=(o,i,...a)=>{const s=typeof o=="function"?Op(o):o;return r(s,i,...a)},e(n.setState,t,n)),zn=Mp;var Ee=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function qn(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Np(e){if(e.__esModule)return e;var r=e.default;if(typeof r=="function"){var t=function n(){return this instanceof n?Reflect.construct(r,arguments,this.constructor):r.apply(this,arguments)};t.prototype=r.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}),t}var kp=function e(r,t){if(r===t)return!0;if(r&&t&&typeof r=="object"&&typeof t=="object"){if(r.constructor!==t.constructor)return!1;var n,o,i;if(Array.isArray(r)){if(n=r.length,n!=t.length)return!1;for(o=n;o--!==0;)if(!e(r[o],t[o]))return!1;return!0}if(r.constructor===RegExp)return r.source===t.source&&r.flags===t.flags;if(r.valueOf!==Object.prototype.valueOf)return r.valueOf()===t.valueOf();if(r.toString!==Object.prototype.toString)return r.toString()===t.toString();if(i=Object.keys(r),n=i.length,n!==Object.keys(t).length)return!1;for(o=n;o--!==0;)if(!Object.prototype.hasOwnProperty.call(t,i[o]))return!1;for(o=n;o--!==0;){var a=i[o];if(!(a==="_owner"&&r.$$typeof)&&!e(r[a],t[a]))return!1}return!0}return r!==r&&t!==t};const ii=qn(kp),xt=new Map;function Lp(e,r){return xt.has(e)||xt.set(e,new Set),xt.get(e).add(r),()=>{var t;(t=xt.get(e))==null||t.delete(r)}}function ki(e){const r=xt.get(e);r&&r.forEach(t=>{try{t()}catch(n){console.error(`Error in store event callback for '${e}':`,n)}})}function Vp(e){e?xt.delete(e):xt.clear()}const et={subscribe:Lp,emit:ki,clear:Vp},Bp=()=>ki("dashboard:load"),$p=()=>ki("dashboard:unload"),os={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Or=new Map,rn=e=>{const r=Or.get(e);return r?Object.fromEntries(Object.entries(r.stores).map(([t,n])=>[t,n.getState()])):{}},jp=(e,r,t)=>{if(e===void 0)return{type:"untracked",connection:r.connect(t)};const n=Or.get(t.name);if(n)return{type:"tracked",store:e,...n};const o={connection:r.connect(t),stores:{}};return Or.set(t.name,o),{type:"tracked",store:e,...o}},Up=(e,r)=>{if(r===void 0)return;const t=Or.get(e);t&&(delete t.stores[r],Object.keys(t.stores).length===0&&Or.delete(e))},zp=e=>{var r,t;if(!e)return;const n=e.split(`
2
2
  `),o=n.findIndex(a=>a.includes("api.setState"));if(o<0)return;const i=((r=n[o+1])==null?void 0:r.trim())||"";return(t=/.+ (.+) .+/.exec(i))==null?void 0:t[1]},qp=(e,r={})=>(t,n,o)=>{const{enabled:i,anonymousActionType:a,store:s,...l}=r;let c;try{c=(i??(os?"production":void 0)!=="production")&&window.__REDUX_DEVTOOLS_EXTENSION__}catch{}if(!c)return e(t,n,o);const{connection:u,...d}=jp(s,c,l);let p=!0;o.setState=(m,b,S)=>{const g=t(m,b);if(!p)return g;const y=S===void 0?{type:a||zp(new Error().stack)||"anonymous"}:typeof S=="string"?{type:S}:S;return s===void 0?(u==null||u.send(y,n()),g):(u==null||u.send({...y,type:`${s}/${y.type}`},{...rn(l.name),[s]:o.getState()}),g)},o.devtools={cleanup:()=>{u&&typeof u.unsubscribe=="function"&&u.unsubscribe(),Up(l.name,s)}};const h=(...m)=>{const b=p;p=!1,t(...m),p=b},v=e(o.setState,n,o);if(d.type==="untracked"?u==null||u.init(v):(d.stores[d.store]=o,u==null||u.init(Object.fromEntries(Object.entries(d.stores).map(([m,b])=>[m,m===d.store?v:b.getState()])))),o.dispatchFromDevtools&&typeof o.dispatch=="function"){let m=!1;const b=o.dispatch;o.dispatch=(...S)=>{(os?"production":void 0)!=="production"&&S[0].type==="__setState"&&!m&&(console.warn('[zustand devtools middleware] "__setState" action type is reserved to set state from the devtools. Avoid using it.'),m=!0),b(...S)}}return u.subscribe(m=>{var b;switch(m.type){case"ACTION":if(typeof m.payload!="string"){console.error("[zustand devtools middleware] Unsupported action format");return}return Ao(m.payload,S=>{if(S.type==="__setState"){if(s===void 0){h(S.state);return}Object.keys(S.state).length!==1&&console.error(`
3
3
  [zustand devtools middleware] Unsupported __setState action format.
4
4
  When using 'store' option in devtools(), the 'state' should have only one key, which is a value of 'store' that was passed in devtools(),
@@ -1,4 +1,4 @@
1
- "use strict";const s=require("./switch-CmHP5dT7.js"),C=require("react"),m=require("./index-CPpqPJba.js"),e=require("react/jsx-runtime");require("./index-BxM99sFL.js");const Se=require("./save-MoF1T13_.js");/**
1
+ "use strict";const s=require("./switch-Jhyl63RF.js"),C=require("react"),m=require("./index-c_0nwsOM.js"),e=require("react/jsx-runtime");require("./index-BxM99sFL.js");require("./catalog-field-grounding-8L9I0zdg.js");const Se=require("./save-D2O96E5A.js");/**
2
2
  * @license lucide-react v0.453.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -18,4 +18,4 @@
18
18
  *
19
19
  * This source code is licensed under the ISC license.
20
20
  * See the LICENSE file in the root directory of this source tree.
21
- */const Ie=s.createLucideIcon("SendHorizontal",[["path",{d:"M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z",key:"117uat"}],["path",{d:"M6 12h16",key:"s4cdu5"}]]);function Ve(){const r=s.useEditorStore(f=>f.card.dataSource),{setSelectedConnectionId:a,setSelectedDatabaseName:o,setSelectedSchemaName:n,setSelectedTableName:i,setSelectedDatamodelId:c}=s.useEditorActions();C.useEffect(()=>{var w;if(!r)return;const{tableName:f,schemaName:h,databaseName:p,connectionId:v}=m.extractTableMetadata(r),g=(w=r.selectedEntities)==null?void 0:w[0],S=(g==null?void 0:g.type)==="model"&&"id"in g?g.id:"";a(v||""),o(p||""),n(h||""),i(f||""),c(S)},[r,a,o,n,i,c])}const ce=new Set;function Te(r){return ce.add(r),()=>{ce.delete(r)}}function Ne(){ce.forEach(r=>{r()})}function ue(){var p,v;const r=s.useEditorStore(g=>g.card),a=s.useEditorStore(g=>g.frame),o=C.useMemo(()=>m.findCustomVisualConfigCard(a,r),[a,r]),{manifest:n}=m.useCustomVisual(((p=o==null?void 0:o.customCardPreferences)==null?void 0:p.url)||""),i=C.useMemo(()=>{var g;return(g=n==null?void 0:n.visuals)==null?void 0:g.find(x=>{var S;return x.name===((S=o==null?void 0:o.customCardPreferences)==null?void 0:S.componentName)})},[n,(v=o==null?void 0:o.customCardPreferences)==null?void 0:v.componentName]),c=m.resolveMultiInputType(o,i),f=C.useMemo(()=>m.getCustomVisualInputCards({frame:a,configCard:o,isMultiInputVisual:c==="multiple"}),[a,o,c]),h=C.useMemo(()=>{const g=f.findIndex(x=>(x==null?void 0:x.id)===r.id);return g<0?-1:m.getSlotIndexForCard(r,g)},[f,r]);return C.useMemo(()=>!o||c!=="multiple"||h<0?r.type:m.getEffectiveCardTypeForSlot(r,h,i==null?void 0:i.slots)??r.type,[o,c,h,r,i==null?void 0:i.slots])}function Le(r){const[a,o]=C.useState(null),[n,i]=C.useState(null),c=m.useEnsureReactGlobals();return C.useEffect(()=>{if(!r||r.trim()===""){o(null),i(null);return}if(!c)return;(async()=>{try{if(!r.startsWith("http://")&&!r.startsWith("https://"))throw new Error(`Invalid URL format: ${r}`);try{new URL(r)}catch{throw new Error(`Invalid URL: ${r}`)}const p=`${r.endsWith("/")?r:`${r}/`}index.js`;try{if(!(await fetch(p,{method:"HEAD"})).ok)throw new Error(`Module not found at ${p}`)}catch{}const v=await import(p);if(typeof v.useChartStore!="function")throw new Error("useChartStore is not a function");o(()=>v.useChartStore),i(null)}catch(h){const p=h instanceof Error?h.message:"Unknown error";console.error("Failed to load remote chart store:",p),i(p),o(null)}})()},[r,c]),a}function Ae(r,a){if(r.length===0)return"";const o=r.find(n=>{var i,c;return((i=n.customCardPreferences)==null?void 0:i.visualType)==="multiple"||!!((c=n.customCardPreferences)!=null&&c.dataInputCardIds)});if(o)return o.id;if(a){const n=r.find(i=>i.id===a);if(n){const i=n.tabTitle;if(i=="All__Header")return r[0].id;if(i&&i.endsWith("__Header")){const f=i.split("__")[0],h=r.find(p=>p.tabTitle===f);return h?h.id:r[0].id}return a}}return r[0].id}const _e=r=>{if(!r||!("detailTableBackup"in r))return r;const{detailTableBackup:a,...o}=r;return o};async function be(r,a,o,n,i="Opening library visual..."){if(!a||!o)throw new Error("Missing auth token or visual ID");const c=["resource-by-id","visual",o],f=n.getQueryData(c);if(f)return console.log("Using cached visual data for:",o),{data:f,fromCache:!0};console.log("Fetching visual data from network for:",o);const h=m.ue.loading(i,{position:"top-center"});try{const p=await fetch(`${r}/management/v1/visuals/${o}`,{headers:{Authorization:`Bearer ${a}`}});if(!p.ok)throw new Error("Failed to load visual");const v=await p.json();return n.setQueryData(c,v),m.ue.dismiss(h),{data:v,fromCache:!1}}catch(p){throw m.ue.dismiss(h),p}}function Ee(r){if(typeof r=="string")return JSON.parse(r);if(typeof r=="object")return r;throw new Error("Invalid frame object format")}function Be(r,a){var c,f;const o=(r==null?void 0:r.frameObject)??((c=r==null?void 0:r.visual)==null?void 0:c.frameObject);if(!o)return!1;const n=Ee(o);if(!(n!=null&&n.cards)||n.cards.length===0)return!1;const i=(f=n.cards)==null?void 0:f.find(h=>h.id===n.activeCardId);return i?(m.setupEditorWithCard({...a,frame:n,card:i,visualId:(r==null?void 0:r.id)||n.visualId}),!0):!1}function Me(){const r=s.useEditorStore(n=>{var i;return((i=n.card.customCardPreferences)==null?void 0:i.url)||""}),a=Le(r);return{getUpdatedFrame:C.useCallback(()=>{var V;Ne();const{frame:n,card:i,isDevMode:c,isShowingVisual:f,selectedSchemaName:h,selectedDatamodelId:p,selectedDatabaseName:v,selectedTableName:g,selectedConnectionId:x}=s.useEditorStore.getState(),S=i.sql,w=(V=a==null?void 0:a.getState())==null?void 0:V.settings,k=s.buildSavedEditorCard(i,{isDevMode:c,cardSql:S,isShowingVisual:f,selectedSchemaName:h,selectedDatamodelId:p,selectedDatabaseName:v,selectedTableName:g,selectedConnectionId:x,remoteChartSettings:w,stripConfig:_e}),E=n.cards.map(U=>U.id===i.id?k:U);return{...n,cards:E,activeCardId:Ae(E,n.activeCardId)}},[a])}}function se(){const{authToken:r,tokenProps:a}=m.useSemaphorContext(),o=m.useQueryClient(),n=m.useAddFrameWithFreshSemanticExecutionPayload(),i=m.useSelectedVisual(),{selectVisual:c}=m.useManagementActions(),{setFrame:f,setCard:h,setIsDevMode:p,initializeModeDrafts:v,setActiveTabCardId:g,updateDataSource:x,setQueryResultColumns:S,setSelectedConnectionId:w,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:V,setSelectedDatamodelId:U,setFilterValues:H,setInlineFilterValuesMap:W,setApplyFilters:Y,clearEditorContext:J}=s.useEditorActions(),{setIsDashboardEditing:M,setIsVisualEditing:l,setSelectedFrameId:D,clearSelectedFrameId:T}=s.useDashboardActions(),q=s.useDashboardStore(A=>A.selectedSheetId),Q=s.useDashboardStore(A=>A.selectedFrameId),K=s.useDashboardStore(A=>A.dashboard),G=s.useDashboardStore(A=>A.filterValues),_=s.useDashboardStore(A=>A.inlineFilterValuesMap),z=m.useVisualById((i==null?void 0:i.id)||"",{enabled:!!(i!=null&&i.id)&&!!(r!=null&&r.accessToken)}),$=C.useCallback(async A=>{try{c(A),T(),J();const{data:F,fromCache:P}=await be(a.apiServiceUrl,(r==null?void 0:r.accessToken)||"",A.id,o,"Opening library visual...");if(!Be(F,{setFrame:f,setCard:h,setIsDevMode:p,initializeModeDrafts:v,setActiveTabCardId:g,updateDataSource:x,setQueryResultColumns:S,setSelectedConnectionId:w,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:V,setSelectedDatamodelId:U,setFilterValues:H,setInlineFilterValuesMap:W,setApplyFilters:Y,setIsDashboardEditing:M,setIsVisualEditing:l,dashboard:K,selectedSheetId:q,selectedFrameId:Q,filterValues:G,inlineFilterValuesMap:_}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:P}}catch(F){return console.error("Error editing visual:",F),{success:!1,error:"Failed to load visual for editing"}}},[r==null?void 0:r.accessToken,a.apiServiceUrl,o,c,f,h,M,l,p,v,g,x,S,w,k,E,V,U,H,W,Y,J,T,K,q,Q,G,_]),ae=C.useCallback(async A=>{var P;const F=B=>(m.ue.error(B),{success:!1,error:B});try{if(c(A),!q)return F("No sheet selected. Please select a sheet first.");const{data:B,fromCache:ne}=await be(a.apiServiceUrl,(r==null?void 0:r.accessToken)||"",A.id,o,"Adding visual to dashboard..."),te=(B==null?void 0:B.frameObject)??((P=B==null?void 0:B.visual)==null?void 0:P.frameObject);if(!te)return F("Visual has no frame data");const R=Ee(te);if(!(R!=null&&R.cards)||R.cards.length===0)return F("Visual frame is malformed");const ee={...m.cloneLinkedFrameWithSourceMapping(R),visualId:A.id};return await n(q,ee,"end"),M(!0),D(ee.id),{success:!0,fromCache:ne}}catch(B){return console.error("Error adding visual:",B),F(B instanceof Error?B.message:"Failed to add visual to dashboard")}},[r==null?void 0:r.accessToken,a.apiServiceUrl,o,c,q,M,D,n]);return{visual:z.data,isLoading:z.isLoading,isError:z.isError,error:z.error,handleEditLibraryVisual:$,handleAddLibraryVisual:ae,getUpdatedFrame:Me().getUpdatedFrame,refetch:z.refetch}}function qe({type:r,isLinked:a,className:o,showLabel:n=!1,showLocal:i=!1}){const c=s.useDashboardStore(E=>E.selectedFrameId),f=m.useManagementStore(E=>E.selectedVisual),h=s.useEditorStore(E=>E.frame);let p;if(r)p=r;else if(a!==void 0)p=a?"linked":"library";else if(!!!(h!=null&&h.visualId||f!=null&&f.id)&&c)p="local";else if(f&&!c)p="library";else if(h!=null&&h.visualId&&c)p="linked";else if(f!=null&&f.id&&c)p="library";else return null;if(p==="local"&&!i)return null;const v={local:"border-slate-200/70 bg-slate-50/80 text-slate-700 shadow-sm hover:bg-slate-100/80 dark:border-slate-700 dark:bg-slate-900/70 dark:text-slate-200 dark:hover:bg-slate-800/80",linked:"border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",library:"border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"},g={local:"Local to this dashboard: Changes made here only affect this dashboard copy.",linked:"Linked to library: Changes made here update the library visual and all linked instances.",library:"Library visual: Share and reuse this visual across multiple dashboards."},x={local:"border-slate-200 bg-slate-50 text-slate-900 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100",linked:"border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",library:"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"},S={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},w={local:e.jsx("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:e.jsx(ke,{className:"h-3.5 w-3.5"}),library:e.jsx(je,{className:"h-3.5 w-3.5"})},k={local:"Local",linked:"Linked",library:"Library"};return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(m.Badge,{variant:"outline",className:s.cn("cursor-help select-none transition-all",v[p],o),children:[w[p],n&&e.jsx("span",{className:"ml-1 text-xs font-medium leading-none",children:k[p]})]})}),e.jsxs(s.TooltipContent,{side:"bottom",className:s.cn("max-w-xs",x[p]),children:[e.jsx(s.TooltipArrow,{className:S[p]}),e.jsx("p",{children:g[p]})]})]})})}function Oe(r,a){return{...r,sql:"",python:"",config:void 0,customCfg:"",preferences:{},interactionConfig:void 0,linkedInteractionTargetOverrides:void 0,dynamicCardPreferences:void 0,customCardPreferences:a?r.customCardPreferences:void 0,visualizationMode:"builtin",type:a?r.type:"bar"}}function pe(r){const a=s.getDynamicFrameSaveIssue(r);return a?(m.ue.error(a),!1):!0}function Ue({className:r,variant:a="outline"}){const o=s.useEditorStore(c=>c.onSave),{getUpdatedFrame:n}=se();function i(){const c=n();pe(c)&&(o==null||o(c))}return e.jsxs(s.Button,{onClick:i,className:r,size:"xs",variant:a,children:[e.jsx(s.Check,{className:"h-3.5 w-3.5"}),"Accept"]})}function ze({className:r,variant:a="default"}){const o=m.useQueryClient(),[n,i]=C.useState(!1),{setIsVisualEditing:c}=s.useDashboardActions(),{getUpdatedFrame:f}=se(),h=m.useSelectedVisual(),p=s.useEditorStore(x=>x.frame),v=m.useUpdateVisualMutation(),g=()=>{const x=f();if(!pe(x))return;const S=(p==null?void 0:p.visualId)||(h==null?void 0:h.id);if(!S){m.ue.error("No visual to save");return}i(!0),v.mutate({visualId:S,data:{frameObject:x}},{onSuccess:()=>{i(!1),m.ue.success("Visual updated successfully"),o.invalidateQueries({queryKey:["resource-by-id","visual",S],exact:!0})},onError:()=>{i(!1),m.ue.error("Failed to update visual")}})};return e.jsx(s.Button,{onClick:g,className:r,size:"xs",variant:a,children:n?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving"]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save to Library"]})})}function Re({className:r}){const a=m.useQueryClient(),[o,n]=C.useState(!1),i=m.useSelectedVisual(),c=s.useEditorStore(k=>k.frame),f=s.useDashboardStore(k=>k.selectedSheetId),h=s.useDashboardStore(k=>k.dashboard),{updateFrame:p,setIsVisualEditing:v}=s.useDashboardActions(),{getUpdatedFrame:g}=se(),x=m.useUpdateVisualMutation(),S=m.useResolveExistingFrameSemanticExecutionPayload(),w=async()=>{if(!f){m.ue.error("No sheet selected");return}const k=(c==null?void 0:c.visualId)||(i==null?void 0:i.id);if(!k){m.ue.error("No visual to update");return}n(!0);try{const E=g();if(!pe(E)){n(!1);return}const V={...E,visualId:k},U=m.findDashboardFrameById(h,V.id),H=await S(V,{previousFrame:U});await x.mutateAsync({visualId:k,data:{frameObject:E}}),p(f,V,{semanticExecutionPayload:H}),a.invalidateQueries({queryKey:["visuals"]}),a.invalidateQueries({queryKey:["visual",k]}),m.ue.success("Saved to library and applied locally"),setTimeout(()=>{v(!1)},300)}catch(E){console.error("Failed to save and apply:",E),m.ue.error(E instanceof Error?E.message:"Failed to save and apply changes")}finally{n(!1)}};return e.jsx(s.Button,{onClick:w,className:r,size:"xs",variant:"default",disabled:o,children:o?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save & Apply"]})})}function Qe({className:r}){const{setTempQueryData:a,setSqlGen:o}=s.useEditorActions(),n=m.useQueryClient(),i=s.useEditorStore(x=>x.tempQueryData),c=s.useEditorStore(x=>x.onClose),f=s.useEditorStore(x=>x.card),h=ue(),p=C.useMemo(()=>h!==f.type?{...f,type:h}:f,[f,h]),{queryKey:v}=m.useEditorCardQuery(p);function g(){if(i){const{queryKey:x,queryData:S}=i;x&&S&&n.setQueryData(x,S)}o({}),c==null||c()}return e.jsxs(s.Button,{onClick:g,className:r,size:"xs",variant:"outline",children:[e.jsx(s.X,{className:"h-3.5 w-3.5"}),"Close"]})}function Pe({label:r="Clear",variant:a="secondary",className:o}={}){const{setTempQueryData:n}=s.useEditorActions(),i=m.useQueryClient(),c=s.useEditorStore(M=>M.tempQueryData),f=s.useEditorStore(M=>M.card),h=ue(),p=C.useMemo(()=>h!==f.type?{...f,type:h}:f,[f,h]),{queryKey:v}=m.useEditorCardQuery(p),{setCardSql:g,setSqlGen:x,setCardPython:S,setCardCustomCfg:w,setCardPreferences:k,clearQueryConfig:E,setCardConfig:V,setCardType:U,setFrame:H,setCard:W,setActiveTabCardId:Y}=s.useEditorActions();function J(){var K,G,_,z;const M=i.getQueryData(v);c!=null&&c.queryData||n({queryKey:v,queryData:M}),i.setQueryData(v,null),i.removeQueries({queryKey:v,exact:!0}),g(""),x({}),E(),V(void 0),S(""),w(""),k({});const l=s.useEditorStore.getState().frame,D=s.useEditorStore.getState().card,T=m.findCustomVisualConfigCard(l,D),q=((K=T==null?void 0:T.customCardPreferences)==null?void 0:K.visualType)==="multiple"||!!((G=T==null?void 0:T.customCardPreferences)!=null&&G.dataInputCardIds)||(((_=T==null?void 0:T.customCardPreferences)==null?void 0:_.minInputs)||0)>1||(((z=T==null?void 0:T.customCardPreferences)==null?void 0:z.maxInputs)||0)>1,Q=Oe(D,q);H({...l,cards:l.cards.map($=>$.id===Q.id?Q:$)}),Y(Q.id),W(Q),q||U("bar")}return e.jsxs(s.Button,{onClick:J,className:o,size:"xs",variant:a,children:[e.jsx(s.X,{className:"h-3.5 w-3.5"}),r]})}function we(r){const{control:a,onChange:o}=r;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:a.label,placeholder:"Control label",onChange:n=>o(n.target.value)})]})}function $e(r){const{currentStep:a,labels:o}=r;return e.jsx("div",{className:"sticky top-0 z-10 -mx-1 border-b border-border/60 bg-background/95 px-1 pb-2.5 pt-1 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:e.jsx("div",{className:"flex flex-wrap items-center gap-2 sm:gap-2.5",children:o.map((n,i)=>{const c=i+1,f=c===a,h=c<a;return e.jsxs(C.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:s.cn("flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",f?"border-foreground bg-foreground text-background":h?"border-foreground/30 bg-foreground/10 text-foreground":"border-border/60 bg-background text-muted-foreground"),children:c}),e.jsx("span",{className:s.cn("text-[12px]",f?"font-medium text-foreground":"text-muted-foreground"),children:n})]}),i<o.length-1?e.jsx("span",{className:"h-px w-4 bg-border/60 sm:w-6","aria-hidden":"true"}):null]},n)})})})}function re(r){const{secondary:a,tertiary:o,primary:n}=r;return e.jsxs("div",{className:"sticky bottom-0 z-10 -mx-1 flex justify-end gap-2 border-t bg-background/95 px-1 pb-1 pt-3 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:[a,o,n]})}function He(r){const{control:a,scope:o,detail:n}=r;return e.jsxs("div",{className:"flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5",children:[e.jsx(m.CircleCheck,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground"}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:a.label}),e.jsxs("div",{className:"text-[12px] text-muted-foreground",children:[s.getFriendlyTypeOption(a.type).label," ·"," ",s.getControlOptionPreview(a)," ·"," ",s.getPlacementLabel(o,a.placement)]}),n?e.jsx("div",{className:"text-[12px] text-muted-foreground",children:n}):null]})]})}function ye(r){const{control:a,defaultValue:o,availableFieldChoices:n,availableMetricChoices:i,previewControlDefinitions:c,previewControlValues:f,onControlChange:h,onLabelChange:p,onDefaultValueChange:v,onBack:g,onNext:x,nextDisabled:S}=r;return e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:a,onChange:p}),e.jsx(m.ControlDefinitionOptionsEditor,{control:a,availableFieldChoices:n,availableMetricChoices:i,previewControlDefinitions:c,previewControlValues:f,controlLifecycle:"create",onChange:h}),e.jsx(m.ControlDefaultValueEditor,{control:a,value:o,onChange:v,allowNoDefault:!0,allowCardDefault:!0,hint:"This is the value viewers will see first.",previewControlDefinitions:c,previewControlValues:f}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:g,children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:x,disabled:S,children:"Next"})})]})}const Ye=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function ve(r){const{text:a,ariaLabel:o}=r,[n,i]=C.useState(!1);return e.jsxs("button",{type:"button","aria-label":o,onClick:async()=>{try{await navigator.clipboard.writeText(a),i(!0),setTimeout(()=>i(!1),1200)}catch(c){console.error("Failed to copy",c)}},className:"group flex w-full items-center justify-between gap-2 rounded-control bg-muted/40 px-2 py-1 text-left transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",children:[e.jsx("code",{className:"min-w-0 truncate font-mono text-[12px] text-foreground",children:a}),e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:n?"Copied":"Click to copy"})]})}function Ce(r){const{control:a,scope:o,createdReference:n,explorerContent:i,sqlDescription:c,summaryDetail:f,onBack:h,onCancel:p,onDone:v}=r,g=Ye.has(a.type),x=n.match(/\[\[param\.(.+?)\]\]/),S=x?`{{ param('${x[1]}') }}`:"";return e.jsxs("div",{className:"space-y-4",children:[e.jsx(He,{control:a,scope:o,detail:f}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-foreground",children:"How cards use this control"}),e.jsxs("div",{className:"divide-y divide-border/60 overflow-hidden rounded-control border border-border/60",children:[g?e.jsxs("div",{className:"space-y-1 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Explorer cards"}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:i})]}):null,e.jsxs("div",{className:"space-y-1.5 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL cards"}),e.jsx(ve,{text:n,ariaLabel:"Copy SQL control reference"}),S?e.jsx(ve,{text:S,ariaLabel:"Copy Jinja control reference"}):null,e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[c," ",e.jsx("a",{href:"https://docs.semaphor.cloud/docs/concepts/template-expressions",target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:"Template expressions docs"}),"."]})]})]})]}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:h,children:"Back"}),tertiary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:p,children:"Cancel"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:v,children:"Done"})})]})}function Ke(r){const a=s.createBlankControl(r.scope,r.existingControls,r.reservedIds),o=r.type===a.type?{...a,label:s.DEFAULT_LABEL_BY_TYPE[r.type]}:{...s.applyControlTypeChange({controls:[{...a,label:s.DEFAULT_LABEL_BY_TYPE[r.type]}],controlId:a.id,nextType:r.type}).controls[0],label:s.DEFAULT_LABEL_BY_TYPE[r.type]};return{step:2,control:o,defaultValue:s.getDefaultValueForType(o,void 0)}}function We({scope:r,controls:a,reservedControlIds:o,defaultValues:n,onChange:i,emptyMessage:c,initialCreateFlow:f=!1,usageByControlId:h,availableFieldChoices:p,availableMetricChoices:v,structuralParticipants:g,structuralParticipantIdsByControlId:x,card:S,allowedControlTypes:w,onCreateFlowActiveChange:k,onCreateFlowComplete:E}){const V=C.useMemo(()=>new Set(o||[]),[o]),U=s.getPlacementOptionsForScope(r),H=s.getDefaultPlacement(r),[W,Y]=C.useState(null),[J,M]=C.useState(null),[l,D]=C.useState(()=>f?{step:1,control:s.createBlankControl(r,a,Array.from(V))}:null),T=C.useRef({}),q=C.useRef(void 0),Q=C.useRef(f),K=C.useMemo(()=>{const t=s.getFriendlyControlTypeOptions({scope:r,card:S});if(!w)return t;const u=new Set(w);return t.filter(d=>u.has(d.value))},[w,S,r]),G=C.useCallback(t=>{const u=s.getFriendlyControlTypeOptions({scope:r,card:S,includeType:w?void 0:t});if(!w)return u;const d=new Set(w);return u.filter(b=>d.has(b.value))},[w,S,r]),_=C.useCallback(t=>r==="dashboard"&&(t==="field_selector"||t==="metric_selector"),[r]),z=C.useMemo(()=>l?s.getEligibleParticipantsForStructuralControl(g||[],l.control.type):[],[l,g]),$=C.useMemo(()=>{if(!l)return{fields:p||[],metrics:v||[]};if(!_(l.control.type))return{fields:p||[],metrics:v||[]};const t=l.selectedCardIds||[],u=s.getCompatibleStructuralChoiceCatalog({controlType:l.control.type,participants:g||[],selectedCardIds:t});return{fields:l.control.type==="field_selector"?u.choices.map(d=>({option:d,target:u.fieldTargetMap[d.value]})):[],metrics:l.control.type==="metric_selector"?u.choices.map(d=>({option:d,target:u.metricTargetMap[d.value]})):[]}},[p,v,l,_,g]);C.useEffect(()=>{k==null||k(!!l)},[l,k]),C.useEffect(()=>{const t=f&&!Q.current;Q.current=f,t&&(D({step:1,control:s.createBlankControl(r,a,Array.from(V))}),M(null),Y(null))},[a,f,V,r]);const ae=t=>{if(!_(t.type))return{fields:p||[],metrics:v||[]};const u=(x==null?void 0:x[t.id])||[];if(u.length===0)return{fields:p||[],metrics:v||[]};const d=s.getCompatibleStructuralChoiceCatalog({controlType:t.type,participants:g||[],selectedCardIds:u});return{fields:t.type==="field_selector"?d.choices.map(b=>({option:b,target:d.fieldTargetMap[b.value]})):[],metrics:t.type==="metric_selector"?d.choices.map(b=>({option:b,target:d.metricTargetMap[b.value]})):[]}},A=t=>{if(!_(t.control.type))return{nextControl:t.control,cardBindingsById:void 0};const u=(x==null?void 0:x[t.control.id])||[],d=s.getCompatibleStructuralChoiceCatalog({controlType:t.control.type,participants:g||[],selectedCardIds:t.nextSelectedCardIds}),b=s.reconcileStructuralControlChoices({control:t.control,choices:d.choices}),j=Object.fromEntries(u.filter(N=>!t.nextSelectedCardIds.includes(N)).map(N=>[N,void 0]));return t.nextSelectedCardIds.length>0&&b.source.kind==="manual"&&b.source.options.length>0&&Object.assign(j,s.buildStructuralControlBindingsForParticipants({control:b,participants:g||[],selectedCardIds:t.nextSelectedCardIds})),{nextControl:b,cardBindingsById:j}},F=C.useCallback((t,u=n,d={type:"update"})=>{const b=t.map(j=>(s.resolveAuthoringControlDefaultValue({control:j,defaultValues:u}),s.syncSqlQueryControlExecutionRequirement(j)));i(b,u,d)},[n,i]),P=(t,u)=>{const d=a.find(L=>L.id===t);let b=a.map(L=>L.id!==t?L:u(L));const j=b.find(L=>L.id===t);let N,y;if(j&&r==="dashboard"&&(j.type==="field_selector"||j.type==="metric_selector")){const L=(x==null?void 0:x[j.id])||[],Z=A({control:j,nextSelectedCardIds:L});b=b.map(X=>X.id===t?Z.nextControl:X),N=Z.cardBindingsById,y=[j.id]}else if(d&&r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")){const L=(x==null?void 0:x[d.id])||[];N=Object.fromEntries(L.map(Z=>[Z,void 0])),y=[d.id]}const I=b.find(L=>L.id===t);let O=n;if(d&&I){const L=s.resolveAuthoringControlDefaultValue({control:d,defaultValues:n});d.source.kind==="manual"&&I.source.kind==="sql_query"&&(T.current[t]=L);const Z=L===void 0&&d.source.kind==="sql_query"&&I.source.kind==="manual"?T.current[t]:L,X=s.getNextEditedControlDefaultValue({previousControl:d,nextControl:I,currentDefaultValue:Z});I.source.kind==="manual"&&(T.current[t]=X),n&&(O={...n},X===void 0?delete O[t]:O[t]=X),b=b.map(ge=>ge.id===t?{...I,defaultValue:X}:ge)}F(b,O,{type:"update",cardBindingsById:N,affectedBindingControlIds:y})},B=(t,u)=>{if(!u.trim())return;const d=m.normalizeDashboardInputVariableName(u);if(d===t||V.has(d)||a.some(N=>N.id===d&&N.id!==t))return;const b=a.map(N=>N.id===t?{...N,id:d}:N);if(!n){F(b,void 0,{type:"rename",oldId:t,newId:d});return}const j={...n};Object.prototype.hasOwnProperty.call(j,t)&&(j[d]=j[t],delete j[t]),F(b,j,{type:"rename",oldId:t,newId:d})},ne=t=>{const u=a.filter(b=>b.id!==t);if(!n){F(u,void 0,{type:"remove",controlId:t});return}const d={...n};delete d[t],F(u,d,{type:"remove",controlId:t})},te=C.useCallback(()=>{q.current=void 0,D({step:1,control:s.createBlankControl(r,a,Array.from(V))}),M(null),Y(null)},[a,V,r]),R=t=>{D(u=>u&&(()=>{const d=t(u.control);u.control.source.kind==="manual"&&d.source.kind==="sql_query"&&(q.current=u.defaultValue);const b=u.defaultValue===void 0&&u.control.source.kind==="sql_query"&&d.source.kind==="manual"?q.current:u.defaultValue,j=s.getNextEditedControlDefaultValue({previousControl:u.control,nextControl:d,currentDefaultValue:b});return d.source.kind==="manual"&&(q.current=j),{...u,control:d,defaultValue:j}})())},ee=t=>{D(u=>u&&(u.control.source.kind==="manual"&&(q.current=t),{...u,defaultValue:t}))},oe=(()=>{if(!l)return!1;if(l.step===2&&_(l.control.type))return(l.selectedCardIds||[]).length>0;if(l.step!==2&&l.step!==3||!l.control.label.trim())return!1;const u=l.control.source.kind==="sql_query"?l.control:s.ensureManualSource(l.control);if(u.source.kind==="manual"&&(s.needsManualOptions(u)&&u.source.options.length===0||u.source.options.some(b=>b.label.trim().length===0||b.value.trim().length===0)))return!1;if(u.source.kind==="sql_query"){const{connectionId:d,sql:b,valueColumn:j}=u.source;return d.trim().length>0&&b.trim().length>0&&j.trim().length>0}return s.hasConcreteDefaultValue(s.getDefaultValueForType(u,l.defaultValue))})(),me=()=>{var N;if(!l)return;const t=s.ensureManualSource(l.control),u=s.deriveUniqueControlId({label:t.label,fallbackId:t.id,existingControls:a,reservedIds:Array.from(V)}),d={...t,id:u},b=r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")&&((N=l.selectedCardIds)!=null&&N.length)?s.buildStructuralControlBindingsForParticipants({control:d,participants:g||[],selectedCardIds:l.selectedCardIds}):void 0,j=s.getDefaultValueForType(d,l.defaultValue);D({step:r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")?4:3,control:d,defaultValue:j,createdControlId:u,selectedCardIds:l.selectedCardIds,cardBindingsById:b})},le=C.useCallback(()=>{D(null)},[]),fe=C.useCallback(()=>{if(!(l!=null&&l.createdControlId)){D(null);return}const t=l.control,u=l.createdControlId,d=s.getDefaultValueForType(t,l.defaultValue);if(n){const b={...n};d===void 0?delete b[u]:b[u]=d,F([...a,{...t,defaultValue:d}],b,{type:"add",cardBindingsById:l.cardBindingsById})}else F([...a,{...t,defaultValue:d}],void 0,{type:"add",cardBindingsById:l.cardBindingsById});M(u),D(null),E==null||E()},[a,l,n,F,E]),De=l?_(l.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],he=l!=null&&l.createdControlId?`[[param.${l.createdControlId}]]`:l?`[[param.${s.slugifyControlValue(l.control.label)||l.control.id}]]`:"",ie=s.buildAuthoringPreviewControlValues({controls:a,defaultValues:n}),de=l?[...a,l.control]:a,xe=l?s.buildAuthoringPreviewControlValues({controls:de,defaultValues:n,overrides:[{controlId:l.control.id,value:l.defaultValue}]}):ie;return e.jsxs("div",{className:"space-y-4",children:[l?e.jsxs("div",{className:"space-y-4 pb-1",children:[e.jsx($e,{currentStep:l.step,labels:De}),l.step===1&&(()=>{const t=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),u=new Set(["date","text"]),d=K.filter(N=>!t.has(N.value)&&!u.has(N.value)),b=K.filter(N=>t.has(N.value)),j=N=>e.jsxs("button",{type:"button",className:"rounded-control border border-border/60 bg-background px-3 py-2.5 text-left transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:outline-none",onClick:()=>D(Ke({scope:r,existingControls:a,reservedIds:Array.from(V),type:N.value})),children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:N.label}),e.jsx("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:N.description})]},N.value);return e.jsxs("div",{className:"space-y-4",children:[r==="card"&&(S==null?void 0:S.sql)==null?e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Explorer cards support displayed metric, group by field, aggregation, and time grain controls here."}):null,d.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Input controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:d.map(j)})]}),b.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data-driven controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:b.map(j)})]}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:le,children:"Back to controls"})})]})})(),l.step===2&&_(l.control.type)&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:l.control,onChange:t=>R(u=>({...u,label:t}))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),z.length===0?e.jsx("div",{className:"rounded-control border border-border/60 bg-muted/30 px-3 py-2.5 text-[12px] text-muted-foreground",children:"No eligible cards are available yet. Add compatible metrics or group-by fields to cards first."}):e.jsx("div",{className:"space-y-1 rounded-control border border-border/60 bg-background p-2",children:z.map(t=>{const u=(l.selectedCardIds||[]).includes(t.cardId);return e.jsxs("label",{className:"flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",children:[e.jsx(m.Checkbox,{checked:u,onCheckedChange:d=>D(b=>b&&{...b,selectedCardIds:d===!0?[...b.selectedCardIds||[],t.cardId]:(b.selectedCardIds||[]).filter(j=>j!==t.cardId)})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground",children:t.title}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:l.control.type==="field_selector"?`${t.fieldChoices.length} compatible group-by fields`:`${t.metricChoices.length} compatible metrics`})]})]},t.cardId)})}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>D(t=>t&&{...t,step:1,selectedCardIds:[]}),children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:()=>D(t=>t&&{...t,step:3}),disabled:!oe,children:"Next"})})]}),l.step===2&&!_(l.control.type)&&e.jsx(ye,{control:l.control,defaultValue:l.defaultValue,availableFieldChoices:$.fields,availableMetricChoices:$.metrics,previewControlDefinitions:de,previewControlValues:xe,onControlChange:t=>R(()=>t),onLabelChange:t=>R(u=>({...u,label:t})),onDefaultValueChange:ee,onBack:()=>D(t=>t&&{...t,step:1}),onNext:me,nextDisabled:!oe}),l.step===3&&_(l.control.type)&&e.jsx(ye,{control:l.control,defaultValue:l.defaultValue,availableFieldChoices:$.fields,availableMetricChoices:$.metrics,previewControlDefinitions:de,previewControlValues:xe,onControlChange:t=>R(()=>t),onLabelChange:t=>R(u=>({...u,label:t})),onDefaultValueChange:ee,onBack:()=>D(t=>t&&{...t,step:2}),onNext:me,nextDisabled:!oe}),l.step===3&&!_(l.control.type)&&e.jsx(Ce,{control:l.control,scope:r,createdReference:he,explorerContent:e.jsxs(e.Fragment,{children:["Open the card and use"," ",e.jsx("span",{className:"font-medium text-foreground",children:"Settings → Controls"})," ","to choose what this control changes."]}),sqlDescription:"Reference this control directly in the SQL editor.",onBack:()=>D(t=>t&&{...t,step:2}),onCancel:le,onDone:fe}),l.step===4&&_(l.control.type)&&e.jsx(Ce,{control:l.control,scope:r,createdReference:he,summaryDetail:e.jsxs(e.Fragment,{children:["Used by ",(l.selectedCardIds||[]).length," selected card",(l.selectedCardIds||[]).length===1?"":"s"]}),explorerContent:e.jsx(e.Fragment,{children:"Selected cards have been set up to respond to this control automatically."}),sqlDescription:"SQL cards can still reference this control directly in the SQL editor.",onBack:()=>D(t=>t&&{...t,step:3}),onCancel:le,onDone:fe})]}):null,!l&&a.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:c}):null,!l&&a.map(t=>{const u=ae(t),d=h==null?void 0:h[t.id],b=s.resolveAuthoringControlDefaultValue({control:t,defaultValues:n}),j=J===t.id,N="inline-flex shrink-0 items-center rounded-[4px] border border-border/60 bg-muted/40 px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground";return e.jsxs("div",{className:"rounded-control border border-border/60",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 rounded-control text-left focus:outline-none focus-visible:bg-muted/40",onClick:()=>M(y=>y===t.id?null:t.id),children:[j?e.jsx(s.ChevronDown,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(m.ChevronRight,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-foreground",children:t.label||"Untitled control"}),e.jsx("span",{className:N,children:s.getFriendlyTypeOption(t.type).label}),e.jsx("span",{className:N,children:s.getPlacementLabel(r,t.placement)})]}),e.jsxs("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[s.getControlOptionPreview(t),d!=null&&d.status?` · ${d.status}`:""]})]})]}),e.jsx(s.Button,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>ne(t.id),"aria-label":`Remove ${t.label}`,children:e.jsx(m.Trash2,{className:"h-3.5 w-3.5"})})]}),j&&e.jsxs("div",{className:"space-y-4 border-t border-border/60 px-3 py-3",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:t.label,placeholder:"Control label",onChange:y=>P(t.id,I=>({...I,label:y.target.value}))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),e.jsxs(s.Select,{value:t.type,onValueChange:y=>{const I=s.applyControlTypeChange({controls:a,controlId:t.id,nextType:y,defaultValues:n});F(I.controls,I.defaultValues)},children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:G(t.type).map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),e.jsxs(s.Select,{value:t.placement||H,onValueChange:y=>P(t.id,I=>({...I,placement:y})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:U.map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]})]}),_(t.type)?e.jsx(m.StructuralParticipantSelector,{type:t.type,participants:s.getEligibleParticipantsForStructuralControl(g||[],t.type).map(y=>({cardId:y.cardId,title:y.title,choiceCount:t.type==="field_selector"?y.fieldChoices.length:y.metricChoices.length})),selectedCardIds:(x==null?void 0:x[t.id])||[],onChange:y=>{const I=A({control:t,nextSelectedCardIds:y}),O=a.map(L=>L.id===t.id?I.nextControl:L);F(O,n,{type:"update",cardBindingsById:I.cardBindingsById})}}):null,e.jsx(m.ControlDefinitionOptionsEditor,{control:t,availableFieldChoices:u.fields,availableMetricChoices:u.metrics,previewControlDefinitions:a,previewControlValues:ie,controlLifecycle:"edit",onChange:y=>P(t.id,()=>y)}),t.initialValueStrategy==="saved_default"&&e.jsx(m.ControlDefaultValueEditor,{control:t,value:b,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:a,previewControlValues:ie,onChange:y=>{const I=a.map(O=>O.id===t.id?{...O,defaultValue:y}:O);if(t.source.kind==="manual"&&(T.current[t.id]=y),n){const O={...n};y===void 0?delete O[t.id]:O[t.id]=y,F(I,O);return}F(I,void 0)}}),e.jsxs(m.Collapsible,{open:W===t.id,onOpenChange:y=>Y(y?t.id:null),children:[e.jsx(m.CollapsibleTrigger,{asChild:!0,children:e.jsxs(s.Button,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 gap-1 text-muted-foreground hover:text-foreground",children:[W===t.id?e.jsx(s.ChevronDown,{className:"h-3.5 w-3.5"}):e.jsx(m.ChevronRight,{className:"h-3.5 w-3.5"}),"Advanced"]})}),e.jsxs(m.CollapsibleContent,{className:"space-y-3 pt-2",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Variable name"}),e.jsx(m.ControlIdInput,{controlId:t.id,onCommit:y=>B(t.id,y)},t.id)]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),e.jsxs(s.Select,{value:t.initialValueStrategy,onValueChange:y=>P(t.id,I=>({...I,initialValueStrategy:y})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:s.INITIAL_VALUE_STRATEGY_OPTIONS.map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]})]}),e.jsx(m.ControlVisibilitySettings,{control:t,onChange:y=>P(t.id,()=>y)})]})]})]})]},t.id)}),!l&&e.jsxs(s.Button,{type:"button",variant:"outline",size:"xs",onClick:te,children:[e.jsx(m.Plus,{className:"h-3.5 w-3.5"}),"Add control"]})]})}function Ge(r){const{open:a,onOpenChange:o,initialCreateFlowActive:n=!1,dismissMode:i="passive"}=r,c=a!==void 0,[f,h]=C.useState(!1),[p,v]=C.useState(n),g=c?a:f,x=C.useCallback(k=>{!k&&p&&i==="passive"||(c||h(k),k||v(!1),o==null||o(k))},[c,p,i,o]),S=C.useCallback(()=>{c||h(!1),v(!1),o==null||o(!1)},[c,o]);C.useEffect(()=>{g||v(!1)},[g]);const w=C.useCallback(k=>{p&&k.preventDefault()},[p]);return{forceClose:S,handleOpenChange:x,isCreateFlowActive:p,preventPassiveDismissDuringCreate:w,resolvedOpen:g,setIsCreateFlowActive:v}}exports.ControlDefinitionListEditor=We;exports.EditorAcceptButton=Ue;exports.EditorCancelButton=Qe;exports.EditorClearButton=Pe;exports.Library=je;exports.Link2=ke;exports.Rows3=Fe;exports.SendHorizontal=Ie;exports.VisualBadge=qe;exports.VisualSaveAndApplyButton=Re;exports.VisualSaveButton=ze;exports.flushPendingEditorDrafts=Ne;exports.registerPendingEditorDraftFlusher=Te;exports.useCreateFlowOverlayState=Ge;exports.useEffectiveEditorCardType=ue;exports.useSyncLegacyEditorState=Ve;exports.useVisualUtils=se;
21
+ */const Ie=s.createLucideIcon("SendHorizontal",[["path",{d:"M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z",key:"117uat"}],["path",{d:"M6 12h16",key:"s4cdu5"}]]);function Ve(r){const[a,o]=C.useState(null),[n,i]=C.useState(null),c=m.useEnsureReactGlobals();return C.useEffect(()=>{if(!r||r.trim()===""){o(null),i(null);return}if(!c)return;(async()=>{try{if(!r.startsWith("http://")&&!r.startsWith("https://"))throw new Error(`Invalid URL format: ${r}`);try{new URL(r)}catch{throw new Error(`Invalid URL: ${r}`)}const p=`${r.endsWith("/")?r:`${r}/`}index.js`;try{if(!(await fetch(p,{method:"HEAD"})).ok)throw new Error(`Module not found at ${p}`)}catch{}const v=await import(p);if(typeof v.useChartStore!="function")throw new Error("useChartStore is not a function");o(()=>v.useChartStore),i(null)}catch(h){const p=h instanceof Error?h.message:"Unknown error";console.error("Failed to load remote chart store:",p),i(p),o(null)}})()},[r,c]),a}function Te(r,a){if(r.length===0)return"";const o=r.find(n=>{var i,c;return((i=n.customCardPreferences)==null?void 0:i.visualType)==="multiple"||!!((c=n.customCardPreferences)!=null&&c.dataInputCardIds)});if(o)return o.id;if(a){const n=r.find(i=>i.id===a);if(n){const i=n.tabTitle;if(i=="All__Header")return r[0].id;if(i&&i.endsWith("__Header")){const f=i.split("__")[0],h=r.find(p=>p.tabTitle===f);return h?h.id:r[0].id}return a}}return r[0].id}const ce=new Set;function Le(r){return ce.add(r),()=>{ce.delete(r)}}function Ne(){ce.forEach(r=>{r()})}const Ae=r=>{if(!r||!("detailTableBackup"in r))return r;const{detailTableBackup:a,...o}=r;return o};async function be(r,a,o,n,i="Opening library visual..."){if(!a||!o)throw new Error("Missing auth token or visual ID");const c=["resource-by-id","visual",o],f=n.getQueryData(c);if(f)return console.log("Using cached visual data for:",o),{data:f,fromCache:!0};console.log("Fetching visual data from network for:",o);const h=m.ue.loading(i,{position:"top-center"});try{const p=await fetch(`${r}/management/v1/visuals/${o}`,{headers:{Authorization:`Bearer ${a}`}});if(!p.ok)throw new Error("Failed to load visual");const v=await p.json();return n.setQueryData(c,v),m.ue.dismiss(h),{data:v,fromCache:!1}}catch(p){throw m.ue.dismiss(h),p}}function Ee(r){if(typeof r=="string")return JSON.parse(r);if(typeof r=="object")return r;throw new Error("Invalid frame object format")}function _e(r,a){var c,f;const o=(r==null?void 0:r.frameObject)??((c=r==null?void 0:r.visual)==null?void 0:c.frameObject);if(!o)return!1;const n=Ee(o);if(!(n!=null&&n.cards)||n.cards.length===0)return!1;const i=(f=n.cards)==null?void 0:f.find(h=>h.id===n.activeCardId);return i?(m.setupEditorWithCard({...a,frame:n,card:i,visualId:(r==null?void 0:r.id)||n.visualId}),!0):!1}function Be(){const r=s.useEditorStore(n=>{var i;return((i=n.card.customCardPreferences)==null?void 0:i.url)||""}),a=Ve(r);return{getUpdatedFrame:C.useCallback(()=>{var V;Ne();const{frame:n,card:i,isDevMode:c,isShowingVisual:f,selectedSchemaName:h,selectedDatamodelId:p,selectedDatabaseName:v,selectedTableName:g,selectedConnectionId:x}=s.useEditorStore.getState(),S=i.sql,w=(V=a==null?void 0:a.getState())==null?void 0:V.settings,k=s.buildSavedEditorCard(i,{isDevMode:c,cardSql:S,isShowingVisual:f,selectedSchemaName:h,selectedDatamodelId:p,selectedDatabaseName:v,selectedTableName:g,selectedConnectionId:x,remoteChartSettings:w,stripConfig:Ae}),E=n.cards.map(U=>U.id===i.id?k:U);return{...n,cards:E,activeCardId:Te(E,n.activeCardId)}},[a])}}function se(){const{authToken:r,tokenProps:a}=m.useSemaphorContext(),o=m.useQueryClient(),n=m.useAddFrameWithFreshSemanticExecutionPayload(),i=m.useSelectedVisual(),{selectVisual:c}=m.useManagementActions(),{setFrame:f,setCard:h,setIsDevMode:p,initializeModeDrafts:v,setActiveTabCardId:g,updateDataSource:x,setQueryResultColumns:S,setSelectedConnectionId:w,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:V,setSelectedDatamodelId:U,setFilterValues:H,setInlineFilterValuesMap:W,setApplyFilters:Y,clearEditorContext:J}=s.useEditorActions(),{setIsDashboardEditing:M,setIsVisualEditing:l,setSelectedFrameId:D,clearSelectedFrameId:T}=s.useDashboardActions(),q=s.useDashboardStore(A=>A.selectedSheetId),Q=s.useDashboardStore(A=>A.selectedFrameId),K=s.useDashboardStore(A=>A.dashboard),G=s.useDashboardStore(A=>A.filterValues),_=s.useDashboardStore(A=>A.inlineFilterValuesMap),z=m.useVisualById((i==null?void 0:i.id)||"",{enabled:!!(i!=null&&i.id)&&!!(r!=null&&r.accessToken)}),$=C.useCallback(async A=>{try{c(A),T(),J();const{data:F,fromCache:P}=await be(a.apiServiceUrl,(r==null?void 0:r.accessToken)||"",A.id,o,"Opening library visual...");if(!_e(F,{setFrame:f,setCard:h,setIsDevMode:p,initializeModeDrafts:v,setActiveTabCardId:g,updateDataSource:x,setQueryResultColumns:S,setSelectedConnectionId:w,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:V,setSelectedDatamodelId:U,setFilterValues:H,setInlineFilterValuesMap:W,setApplyFilters:Y,setIsDashboardEditing:M,setIsVisualEditing:l,dashboard:K,selectedSheetId:q,selectedFrameId:Q,filterValues:G,inlineFilterValuesMap:_}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:P}}catch(F){return console.error("Error editing visual:",F),{success:!1,error:"Failed to load visual for editing"}}},[r==null?void 0:r.accessToken,a.apiServiceUrl,o,c,f,h,M,l,p,v,g,x,S,w,k,E,V,U,H,W,Y,J,T,K,q,Q,G,_]),ae=C.useCallback(async A=>{var P;const F=B=>(m.ue.error(B),{success:!1,error:B});try{if(c(A),!q)return F("No sheet selected. Please select a sheet first.");const{data:B,fromCache:ne}=await be(a.apiServiceUrl,(r==null?void 0:r.accessToken)||"",A.id,o,"Adding visual to dashboard..."),te=(B==null?void 0:B.frameObject)??((P=B==null?void 0:B.visual)==null?void 0:P.frameObject);if(!te)return F("Visual has no frame data");const R=Ee(te);if(!(R!=null&&R.cards)||R.cards.length===0)return F("Visual frame is malformed");const ee={...m.cloneLinkedFrameWithSourceMapping(R),visualId:A.id};return await n(q,ee,"end"),M(!0),D(ee.id),{success:!0,fromCache:ne}}catch(B){return console.error("Error adding visual:",B),F(B instanceof Error?B.message:"Failed to add visual to dashboard")}},[r==null?void 0:r.accessToken,a.apiServiceUrl,o,c,q,M,D,n]);return{visual:z.data,isLoading:z.isLoading,isError:z.isError,error:z.error,handleEditLibraryVisual:$,handleAddLibraryVisual:ae,getUpdatedFrame:Be().getUpdatedFrame,refetch:z.refetch}}function Me(){const r=s.useEditorStore(f=>f.card.dataSource),{setSelectedConnectionId:a,setSelectedDatabaseName:o,setSelectedSchemaName:n,setSelectedTableName:i,setSelectedDatamodelId:c}=s.useEditorActions();C.useEffect(()=>{var w;if(!r)return;const{tableName:f,schemaName:h,databaseName:p,connectionId:v}=m.extractTableMetadata(r),g=(w=r.selectedEntities)==null?void 0:w[0],S=(g==null?void 0:g.type)==="model"&&"id"in g?g.id:"";a(v||""),o(p||""),n(h||""),i(f||""),c(S)},[r,a,o,n,i,c])}function ue(){var p,v;const r=s.useEditorStore(g=>g.card),a=s.useEditorStore(g=>g.frame),o=C.useMemo(()=>m.findCustomVisualConfigCard(a,r),[a,r]),{manifest:n}=m.useCustomVisual(((p=o==null?void 0:o.customCardPreferences)==null?void 0:p.url)||""),i=C.useMemo(()=>{var g;return(g=n==null?void 0:n.visuals)==null?void 0:g.find(x=>{var S;return x.name===((S=o==null?void 0:o.customCardPreferences)==null?void 0:S.componentName)})},[n,(v=o==null?void 0:o.customCardPreferences)==null?void 0:v.componentName]),c=m.resolveMultiInputType(o,i),f=C.useMemo(()=>m.getCustomVisualInputCards({frame:a,configCard:o,isMultiInputVisual:c==="multiple"}),[a,o,c]),h=C.useMemo(()=>{const g=f.findIndex(x=>(x==null?void 0:x.id)===r.id);return g<0?-1:m.getSlotIndexForCard(r,g)},[f,r]);return C.useMemo(()=>!o||c!=="multiple"||h<0?r.type:m.getEffectiveCardTypeForSlot(r,h,i==null?void 0:i.slots)??r.type,[o,c,h,r,i==null?void 0:i.slots])}function qe({type:r,isLinked:a,className:o,showLabel:n=!1,showLocal:i=!1}){const c=s.useDashboardStore(E=>E.selectedFrameId),f=m.useManagementStore(E=>E.selectedVisual),h=s.useEditorStore(E=>E.frame);let p;if(r)p=r;else if(a!==void 0)p=a?"linked":"library";else if(!!!(h!=null&&h.visualId||f!=null&&f.id)&&c)p="local";else if(f&&!c)p="library";else if(h!=null&&h.visualId&&c)p="linked";else if(f!=null&&f.id&&c)p="library";else return null;if(p==="local"&&!i)return null;const v={local:"border-slate-200/70 bg-slate-50/80 text-slate-700 shadow-sm hover:bg-slate-100/80 dark:border-slate-700 dark:bg-slate-900/70 dark:text-slate-200 dark:hover:bg-slate-800/80",linked:"border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",library:"border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"},g={local:"Local to this dashboard: Changes made here only affect this dashboard copy.",linked:"Linked to library: Changes made here update the library visual and all linked instances.",library:"Library visual: Share and reuse this visual across multiple dashboards."},x={local:"border-slate-200 bg-slate-50 text-slate-900 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100",linked:"border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",library:"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"},S={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},w={local:e.jsx("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:e.jsx(ke,{className:"h-3.5 w-3.5"}),library:e.jsx(je,{className:"h-3.5 w-3.5"})},k={local:"Local",linked:"Linked",library:"Library"};return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(m.Badge,{variant:"outline",className:s.cn("cursor-help select-none transition-all",v[p],o),children:[w[p],n&&e.jsx("span",{className:"ml-1 text-xs font-medium leading-none",children:k[p]})]})}),e.jsxs(s.TooltipContent,{side:"bottom",className:s.cn("max-w-xs",x[p]),children:[e.jsx(s.TooltipArrow,{className:S[p]}),e.jsx("p",{children:g[p]})]})]})})}function Oe(r,a){return{...r,sql:"",python:"",config:void 0,customCfg:"",preferences:{},interactionConfig:void 0,linkedInteractionTargetOverrides:void 0,dynamicCardPreferences:void 0,customCardPreferences:a?r.customCardPreferences:void 0,visualizationMode:"builtin",type:a?r.type:"bar"}}function pe(r){const a=s.getDynamicFrameSaveIssue(r);return a?(m.ue.error(a),!1):!0}function Ue({className:r,variant:a="outline"}){const o=s.useEditorStore(c=>c.onSave),{getUpdatedFrame:n}=se();function i(){const c=n();pe(c)&&(o==null||o(c))}return e.jsxs(s.Button,{onClick:i,className:r,size:"xs",variant:a,children:[e.jsx(s.Check,{className:"h-3.5 w-3.5"}),"Accept"]})}function ze({className:r,variant:a="default"}){const o=m.useQueryClient(),[n,i]=C.useState(!1),{setIsVisualEditing:c}=s.useDashboardActions(),{getUpdatedFrame:f}=se(),h=m.useSelectedVisual(),p=s.useEditorStore(x=>x.frame),v=m.useUpdateVisualMutation(),g=()=>{const x=f();if(!pe(x))return;const S=(p==null?void 0:p.visualId)||(h==null?void 0:h.id);if(!S){m.ue.error("No visual to save");return}i(!0),v.mutate({visualId:S,data:{frameObject:x}},{onSuccess:()=>{i(!1),m.ue.success("Visual updated successfully"),o.invalidateQueries({queryKey:["resource-by-id","visual",S],exact:!0})},onError:()=>{i(!1),m.ue.error("Failed to update visual")}})};return e.jsx(s.Button,{onClick:g,className:r,size:"xs",variant:a,children:n?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving"]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save to Library"]})})}function Re({className:r}){const a=m.useQueryClient(),[o,n]=C.useState(!1),i=m.useSelectedVisual(),c=s.useEditorStore(k=>k.frame),f=s.useDashboardStore(k=>k.selectedSheetId),h=s.useDashboardStore(k=>k.dashboard),{updateFrame:p,setIsVisualEditing:v}=s.useDashboardActions(),{getUpdatedFrame:g}=se(),x=m.useUpdateVisualMutation(),S=m.useResolveExistingFrameSemanticExecutionPayload(),w=async()=>{if(!f){m.ue.error("No sheet selected");return}const k=(c==null?void 0:c.visualId)||(i==null?void 0:i.id);if(!k){m.ue.error("No visual to update");return}n(!0);try{const E=g();if(!pe(E)){n(!1);return}const V={...E,visualId:k},U=m.findDashboardFrameById(h,V.id),H=await S(V,{previousFrame:U});await x.mutateAsync({visualId:k,data:{frameObject:E}}),p(f,V,{semanticExecutionPayload:H}),a.invalidateQueries({queryKey:["visuals"]}),a.invalidateQueries({queryKey:["visual",k]}),m.ue.success("Saved to library and applied locally"),setTimeout(()=>{v(!1)},300)}catch(E){console.error("Failed to save and apply:",E),m.ue.error(E instanceof Error?E.message:"Failed to save and apply changes")}finally{n(!1)}};return e.jsx(s.Button,{onClick:w,className:r,size:"xs",variant:"default",disabled:o,children:o?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save & Apply"]})})}function Qe({className:r}){const{setTempQueryData:a,setSqlGen:o}=s.useEditorActions(),n=m.useQueryClient(),i=s.useEditorStore(x=>x.tempQueryData),c=s.useEditorStore(x=>x.onClose),f=s.useEditorStore(x=>x.card),h=ue(),p=C.useMemo(()=>h!==f.type?{...f,type:h}:f,[f,h]),{queryKey:v}=m.useEditorCardQuery(p);function g(){if(i){const{queryKey:x,queryData:S}=i;x&&S&&n.setQueryData(x,S)}o({}),c==null||c()}return e.jsxs(s.Button,{onClick:g,className:r,size:"xs",variant:"outline",children:[e.jsx(s.X,{className:"h-3.5 w-3.5"}),"Close"]})}function Pe({label:r="Clear",variant:a="secondary",className:o}={}){const{setTempQueryData:n}=s.useEditorActions(),i=m.useQueryClient(),c=s.useEditorStore(M=>M.tempQueryData),f=s.useEditorStore(M=>M.card),h=ue(),p=C.useMemo(()=>h!==f.type?{...f,type:h}:f,[f,h]),{queryKey:v}=m.useEditorCardQuery(p),{setCardSql:g,setSqlGen:x,setCardPython:S,setCardCustomCfg:w,setCardPreferences:k,clearQueryConfig:E,setCardConfig:V,setCardType:U,setFrame:H,setCard:W,setActiveTabCardId:Y}=s.useEditorActions();function J(){var K,G,_,z;const M=i.getQueryData(v);c!=null&&c.queryData||n({queryKey:v,queryData:M}),i.setQueryData(v,null),i.removeQueries({queryKey:v,exact:!0}),g(""),x({}),E(),V(void 0),S(""),w(""),k({});const l=s.useEditorStore.getState().frame,D=s.useEditorStore.getState().card,T=m.findCustomVisualConfigCard(l,D),q=((K=T==null?void 0:T.customCardPreferences)==null?void 0:K.visualType)==="multiple"||!!((G=T==null?void 0:T.customCardPreferences)!=null&&G.dataInputCardIds)||(((_=T==null?void 0:T.customCardPreferences)==null?void 0:_.minInputs)||0)>1||(((z=T==null?void 0:T.customCardPreferences)==null?void 0:z.maxInputs)||0)>1,Q=Oe(D,q);H({...l,cards:l.cards.map($=>$.id===Q.id?Q:$)}),Y(Q.id),W(Q),q||U("bar")}return e.jsxs(s.Button,{onClick:J,className:o,size:"xs",variant:a,children:[e.jsx(s.X,{className:"h-3.5 w-3.5"}),r]})}function we(r){const{control:a,onChange:o}=r;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:a.label,placeholder:"Control label",onChange:n=>o(n.target.value)})]})}function $e(r){const{currentStep:a,labels:o}=r;return e.jsx("div",{className:"sticky top-0 z-10 -mx-1 border-b border-border/60 bg-background/95 px-1 pb-2.5 pt-1 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:e.jsx("div",{className:"flex flex-wrap items-center gap-2 sm:gap-2.5",children:o.map((n,i)=>{const c=i+1,f=c===a,h=c<a;return e.jsxs(C.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:s.cn("flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",f?"border-foreground bg-foreground text-background":h?"border-foreground/30 bg-foreground/10 text-foreground":"border-border/60 bg-background text-muted-foreground"),children:c}),e.jsx("span",{className:s.cn("text-[12px]",f?"font-medium text-foreground":"text-muted-foreground"),children:n})]}),i<o.length-1?e.jsx("span",{className:"h-px w-4 bg-border/60 sm:w-6","aria-hidden":"true"}):null]},n)})})})}function re(r){const{secondary:a,tertiary:o,primary:n}=r;return e.jsxs("div",{className:"sticky bottom-0 z-10 -mx-1 flex justify-end gap-2 border-t bg-background/95 px-1 pb-1 pt-3 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:[a,o,n]})}function He(r){const{control:a,scope:o,detail:n}=r;return e.jsxs("div",{className:"flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5",children:[e.jsx(m.CircleCheck,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground"}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:a.label}),e.jsxs("div",{className:"text-[12px] text-muted-foreground",children:[s.getFriendlyTypeOption(a.type).label," ·"," ",s.getControlOptionPreview(a)," ·"," ",s.getPlacementLabel(o,a.placement)]}),n?e.jsx("div",{className:"text-[12px] text-muted-foreground",children:n}):null]})]})}function ye(r){const{control:a,defaultValue:o,availableFieldChoices:n,availableMetricChoices:i,previewControlDefinitions:c,previewControlValues:f,onControlChange:h,onLabelChange:p,onDefaultValueChange:v,onBack:g,onNext:x,nextDisabled:S}=r;return e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:a,onChange:p}),e.jsx(m.ControlDefinitionOptionsEditor,{control:a,availableFieldChoices:n,availableMetricChoices:i,previewControlDefinitions:c,previewControlValues:f,controlLifecycle:"create",onChange:h}),e.jsx(m.ControlDefaultValueEditor,{control:a,value:o,onChange:v,allowNoDefault:!0,allowCardDefault:!0,hint:"This is the value viewers will see first.",previewControlDefinitions:c,previewControlValues:f}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:g,children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:x,disabled:S,children:"Next"})})]})}const Ye=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function ve(r){const{text:a,ariaLabel:o}=r,[n,i]=C.useState(!1);return e.jsxs("button",{type:"button","aria-label":o,onClick:async()=>{try{await navigator.clipboard.writeText(a),i(!0),setTimeout(()=>i(!1),1200)}catch(c){console.error("Failed to copy",c)}},className:"group flex w-full items-center justify-between gap-2 rounded-control bg-muted/40 px-2 py-1 text-left transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",children:[e.jsx("code",{className:"min-w-0 truncate font-mono text-[12px] text-foreground",children:a}),e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:n?"Copied":"Click to copy"})]})}function Ce(r){const{control:a,scope:o,createdReference:n,explorerContent:i,sqlDescription:c,summaryDetail:f,onBack:h,onCancel:p,onDone:v}=r,g=Ye.has(a.type),x=n.match(/\[\[param\.(.+?)\]\]/),S=x?`{{ param('${x[1]}') }}`:"";return e.jsxs("div",{className:"space-y-4",children:[e.jsx(He,{control:a,scope:o,detail:f}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-foreground",children:"How cards use this control"}),e.jsxs("div",{className:"divide-y divide-border/60 overflow-hidden rounded-control border border-border/60",children:[g?e.jsxs("div",{className:"space-y-1 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Explorer cards"}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:i})]}):null,e.jsxs("div",{className:"space-y-1.5 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL cards"}),e.jsx(ve,{text:n,ariaLabel:"Copy SQL control reference"}),S?e.jsx(ve,{text:S,ariaLabel:"Copy Jinja control reference"}):null,e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[c," ",e.jsx("a",{href:"https://docs.semaphor.cloud/docs/concepts/template-expressions",target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:"Template expressions docs"}),"."]})]})]})]}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:h,children:"Back"}),tertiary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:p,children:"Cancel"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:v,children:"Done"})})]})}function Ke(r){const a=s.createBlankControl(r.scope,r.existingControls,r.reservedIds),o=r.type===a.type?{...a,label:s.DEFAULT_LABEL_BY_TYPE[r.type]}:{...s.applyControlTypeChange({controls:[{...a,label:s.DEFAULT_LABEL_BY_TYPE[r.type]}],controlId:a.id,nextType:r.type}).controls[0],label:s.DEFAULT_LABEL_BY_TYPE[r.type]};return{step:2,control:o,defaultValue:s.getDefaultValueForType(o,void 0)}}function We({scope:r,controls:a,reservedControlIds:o,defaultValues:n,onChange:i,emptyMessage:c,initialCreateFlow:f=!1,usageByControlId:h,availableFieldChoices:p,availableMetricChoices:v,structuralParticipants:g,structuralParticipantIdsByControlId:x,card:S,allowedControlTypes:w,onCreateFlowActiveChange:k,onCreateFlowComplete:E}){const V=C.useMemo(()=>new Set(o||[]),[o]),U=s.getPlacementOptionsForScope(r),H=s.getDefaultPlacement(r),[W,Y]=C.useState(null),[J,M]=C.useState(null),[l,D]=C.useState(()=>f?{step:1,control:s.createBlankControl(r,a,Array.from(V))}:null),T=C.useRef({}),q=C.useRef(void 0),Q=C.useRef(f),K=C.useMemo(()=>{const t=s.getFriendlyControlTypeOptions({scope:r,card:S});if(!w)return t;const u=new Set(w);return t.filter(d=>u.has(d.value))},[w,S,r]),G=C.useCallback(t=>{const u=s.getFriendlyControlTypeOptions({scope:r,card:S,includeType:w?void 0:t});if(!w)return u;const d=new Set(w);return u.filter(b=>d.has(b.value))},[w,S,r]),_=C.useCallback(t=>r==="dashboard"&&(t==="field_selector"||t==="metric_selector"),[r]),z=C.useMemo(()=>l?s.getEligibleParticipantsForStructuralControl(g||[],l.control.type):[],[l,g]),$=C.useMemo(()=>{if(!l)return{fields:p||[],metrics:v||[]};if(!_(l.control.type))return{fields:p||[],metrics:v||[]};const t=l.selectedCardIds||[],u=s.getCompatibleStructuralChoiceCatalog({controlType:l.control.type,participants:g||[],selectedCardIds:t});return{fields:l.control.type==="field_selector"?u.choices.map(d=>({option:d,target:u.fieldTargetMap[d.value]})):[],metrics:l.control.type==="metric_selector"?u.choices.map(d=>({option:d,target:u.metricTargetMap[d.value]})):[]}},[p,v,l,_,g]);C.useEffect(()=>{k==null||k(!!l)},[l,k]),C.useEffect(()=>{const t=f&&!Q.current;Q.current=f,t&&(D({step:1,control:s.createBlankControl(r,a,Array.from(V))}),M(null),Y(null))},[a,f,V,r]);const ae=t=>{if(!_(t.type))return{fields:p||[],metrics:v||[]};const u=(x==null?void 0:x[t.id])||[];if(u.length===0)return{fields:p||[],metrics:v||[]};const d=s.getCompatibleStructuralChoiceCatalog({controlType:t.type,participants:g||[],selectedCardIds:u});return{fields:t.type==="field_selector"?d.choices.map(b=>({option:b,target:d.fieldTargetMap[b.value]})):[],metrics:t.type==="metric_selector"?d.choices.map(b=>({option:b,target:d.metricTargetMap[b.value]})):[]}},A=t=>{if(!_(t.control.type))return{nextControl:t.control,cardBindingsById:void 0};const u=(x==null?void 0:x[t.control.id])||[],d=s.getCompatibleStructuralChoiceCatalog({controlType:t.control.type,participants:g||[],selectedCardIds:t.nextSelectedCardIds}),b=s.reconcileStructuralControlChoices({control:t.control,choices:d.choices}),j=Object.fromEntries(u.filter(N=>!t.nextSelectedCardIds.includes(N)).map(N=>[N,void 0]));return t.nextSelectedCardIds.length>0&&b.source.kind==="manual"&&b.source.options.length>0&&Object.assign(j,s.buildStructuralControlBindingsForParticipants({control:b,participants:g||[],selectedCardIds:t.nextSelectedCardIds})),{nextControl:b,cardBindingsById:j}},F=C.useCallback((t,u=n,d={type:"update"})=>{const b=t.map(j=>(s.resolveAuthoringControlDefaultValue({control:j,defaultValues:u}),s.syncSqlQueryControlExecutionRequirement(j)));i(b,u,d)},[n,i]),P=(t,u)=>{const d=a.find(L=>L.id===t);let b=a.map(L=>L.id!==t?L:u(L));const j=b.find(L=>L.id===t);let N,y;if(j&&r==="dashboard"&&(j.type==="field_selector"||j.type==="metric_selector")){const L=(x==null?void 0:x[j.id])||[],Z=A({control:j,nextSelectedCardIds:L});b=b.map(X=>X.id===t?Z.nextControl:X),N=Z.cardBindingsById,y=[j.id]}else if(d&&r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")){const L=(x==null?void 0:x[d.id])||[];N=Object.fromEntries(L.map(Z=>[Z,void 0])),y=[d.id]}const I=b.find(L=>L.id===t);let O=n;if(d&&I){const L=s.resolveAuthoringControlDefaultValue({control:d,defaultValues:n});d.source.kind==="manual"&&I.source.kind==="sql_query"&&(T.current[t]=L);const Z=L===void 0&&d.source.kind==="sql_query"&&I.source.kind==="manual"?T.current[t]:L,X=s.getNextEditedControlDefaultValue({previousControl:d,nextControl:I,currentDefaultValue:Z});I.source.kind==="manual"&&(T.current[t]=X),n&&(O={...n},X===void 0?delete O[t]:O[t]=X),b=b.map(ge=>ge.id===t?{...I,defaultValue:X}:ge)}F(b,O,{type:"update",cardBindingsById:N,affectedBindingControlIds:y})},B=(t,u)=>{if(!u.trim())return;const d=m.normalizeDashboardInputVariableName(u);if(d===t||V.has(d)||a.some(N=>N.id===d&&N.id!==t))return;const b=a.map(N=>N.id===t?{...N,id:d}:N);if(!n){F(b,void 0,{type:"rename",oldId:t,newId:d});return}const j={...n};Object.prototype.hasOwnProperty.call(j,t)&&(j[d]=j[t],delete j[t]),F(b,j,{type:"rename",oldId:t,newId:d})},ne=t=>{const u=a.filter(b=>b.id!==t);if(!n){F(u,void 0,{type:"remove",controlId:t});return}const d={...n};delete d[t],F(u,d,{type:"remove",controlId:t})},te=C.useCallback(()=>{q.current=void 0,D({step:1,control:s.createBlankControl(r,a,Array.from(V))}),M(null),Y(null)},[a,V,r]),R=t=>{D(u=>u&&(()=>{const d=t(u.control);u.control.source.kind==="manual"&&d.source.kind==="sql_query"&&(q.current=u.defaultValue);const b=u.defaultValue===void 0&&u.control.source.kind==="sql_query"&&d.source.kind==="manual"?q.current:u.defaultValue,j=s.getNextEditedControlDefaultValue({previousControl:u.control,nextControl:d,currentDefaultValue:b});return d.source.kind==="manual"&&(q.current=j),{...u,control:d,defaultValue:j}})())},ee=t=>{D(u=>u&&(u.control.source.kind==="manual"&&(q.current=t),{...u,defaultValue:t}))},oe=(()=>{if(!l)return!1;if(l.step===2&&_(l.control.type))return(l.selectedCardIds||[]).length>0;if(l.step!==2&&l.step!==3||!l.control.label.trim())return!1;const u=l.control.source.kind==="sql_query"?l.control:s.ensureManualSource(l.control);if(u.source.kind==="manual"&&(s.needsManualOptions(u)&&u.source.options.length===0||u.source.options.some(b=>b.label.trim().length===0||b.value.trim().length===0)))return!1;if(u.source.kind==="sql_query"){const{connectionId:d,sql:b,valueColumn:j}=u.source;return d.trim().length>0&&b.trim().length>0&&j.trim().length>0}return s.hasConcreteDefaultValue(s.getDefaultValueForType(u,l.defaultValue))})(),me=()=>{var N;if(!l)return;const t=s.ensureManualSource(l.control),u=s.deriveUniqueControlId({label:t.label,fallbackId:t.id,existingControls:a,reservedIds:Array.from(V)}),d={...t,id:u},b=r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")&&((N=l.selectedCardIds)!=null&&N.length)?s.buildStructuralControlBindingsForParticipants({control:d,participants:g||[],selectedCardIds:l.selectedCardIds}):void 0,j=s.getDefaultValueForType(d,l.defaultValue);D({step:r==="dashboard"&&(d.type==="field_selector"||d.type==="metric_selector")?4:3,control:d,defaultValue:j,createdControlId:u,selectedCardIds:l.selectedCardIds,cardBindingsById:b})},le=C.useCallback(()=>{D(null)},[]),fe=C.useCallback(()=>{if(!(l!=null&&l.createdControlId)){D(null);return}const t=l.control,u=l.createdControlId,d=s.getDefaultValueForType(t,l.defaultValue);if(n){const b={...n};d===void 0?delete b[u]:b[u]=d,F([...a,{...t,defaultValue:d}],b,{type:"add",cardBindingsById:l.cardBindingsById})}else F([...a,{...t,defaultValue:d}],void 0,{type:"add",cardBindingsById:l.cardBindingsById});M(u),D(null),E==null||E()},[a,l,n,F,E]),De=l?_(l.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],he=l!=null&&l.createdControlId?`[[param.${l.createdControlId}]]`:l?`[[param.${s.slugifyControlValue(l.control.label)||l.control.id}]]`:"",ie=s.buildAuthoringPreviewControlValues({controls:a,defaultValues:n}),de=l?[...a,l.control]:a,xe=l?s.buildAuthoringPreviewControlValues({controls:de,defaultValues:n,overrides:[{controlId:l.control.id,value:l.defaultValue}]}):ie;return e.jsxs("div",{className:"space-y-4",children:[l?e.jsxs("div",{className:"space-y-4 pb-1",children:[e.jsx($e,{currentStep:l.step,labels:De}),l.step===1&&(()=>{const t=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),u=new Set(["date","text"]),d=K.filter(N=>!t.has(N.value)&&!u.has(N.value)),b=K.filter(N=>t.has(N.value)),j=N=>e.jsxs("button",{type:"button",className:"rounded-control border border-border/60 bg-background px-3 py-2.5 text-left transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:outline-none",onClick:()=>D(Ke({scope:r,existingControls:a,reservedIds:Array.from(V),type:N.value})),children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:N.label}),e.jsx("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:N.description})]},N.value);return e.jsxs("div",{className:"space-y-4",children:[r==="card"&&(S==null?void 0:S.sql)==null?e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Explorer cards support displayed metric, group by field, aggregation, and time grain controls here."}):null,d.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Input controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:d.map(j)})]}),b.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data-driven controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:b.map(j)})]}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:le,children:"Back to controls"})})]})})(),l.step===2&&_(l.control.type)&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:l.control,onChange:t=>R(u=>({...u,label:t}))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),z.length===0?e.jsx("div",{className:"rounded-control border border-border/60 bg-muted/30 px-3 py-2.5 text-[12px] text-muted-foreground",children:"No eligible cards are available yet. Add compatible metrics or group-by fields to cards first."}):e.jsx("div",{className:"space-y-1 rounded-control border border-border/60 bg-background p-2",children:z.map(t=>{const u=(l.selectedCardIds||[]).includes(t.cardId);return e.jsxs("label",{className:"flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",children:[e.jsx(m.Checkbox,{checked:u,onCheckedChange:d=>D(b=>b&&{...b,selectedCardIds:d===!0?[...b.selectedCardIds||[],t.cardId]:(b.selectedCardIds||[]).filter(j=>j!==t.cardId)})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground",children:t.title}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:l.control.type==="field_selector"?`${t.fieldChoices.length} compatible group-by fields`:`${t.metricChoices.length} compatible metrics`})]})]},t.cardId)})}),e.jsx(re,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>D(t=>t&&{...t,step:1,selectedCardIds:[]}),children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:()=>D(t=>t&&{...t,step:3}),disabled:!oe,children:"Next"})})]}),l.step===2&&!_(l.control.type)&&e.jsx(ye,{control:l.control,defaultValue:l.defaultValue,availableFieldChoices:$.fields,availableMetricChoices:$.metrics,previewControlDefinitions:de,previewControlValues:xe,onControlChange:t=>R(()=>t),onLabelChange:t=>R(u=>({...u,label:t})),onDefaultValueChange:ee,onBack:()=>D(t=>t&&{...t,step:1}),onNext:me,nextDisabled:!oe}),l.step===3&&_(l.control.type)&&e.jsx(ye,{control:l.control,defaultValue:l.defaultValue,availableFieldChoices:$.fields,availableMetricChoices:$.metrics,previewControlDefinitions:de,previewControlValues:xe,onControlChange:t=>R(()=>t),onLabelChange:t=>R(u=>({...u,label:t})),onDefaultValueChange:ee,onBack:()=>D(t=>t&&{...t,step:2}),onNext:me,nextDisabled:!oe}),l.step===3&&!_(l.control.type)&&e.jsx(Ce,{control:l.control,scope:r,createdReference:he,explorerContent:e.jsxs(e.Fragment,{children:["Open the card and use"," ",e.jsx("span",{className:"font-medium text-foreground",children:"Settings → Controls"})," ","to choose what this control changes."]}),sqlDescription:"Reference this control directly in the SQL editor.",onBack:()=>D(t=>t&&{...t,step:2}),onCancel:le,onDone:fe}),l.step===4&&_(l.control.type)&&e.jsx(Ce,{control:l.control,scope:r,createdReference:he,summaryDetail:e.jsxs(e.Fragment,{children:["Used by ",(l.selectedCardIds||[]).length," selected card",(l.selectedCardIds||[]).length===1?"":"s"]}),explorerContent:e.jsx(e.Fragment,{children:"Selected cards have been set up to respond to this control automatically."}),sqlDescription:"SQL cards can still reference this control directly in the SQL editor.",onBack:()=>D(t=>t&&{...t,step:3}),onCancel:le,onDone:fe})]}):null,!l&&a.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:c}):null,!l&&a.map(t=>{const u=ae(t),d=h==null?void 0:h[t.id],b=s.resolveAuthoringControlDefaultValue({control:t,defaultValues:n}),j=J===t.id,N="inline-flex shrink-0 items-center rounded-[4px] border border-border/60 bg-muted/40 px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground";return e.jsxs("div",{className:"rounded-control border border-border/60",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-start gap-2 rounded-control text-left focus:outline-none focus-visible:bg-muted/40",onClick:()=>M(y=>y===t.id?null:t.id),children:[j?e.jsx(s.ChevronDown,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(m.ChevronRight,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-foreground",children:t.label||"Untitled control"}),e.jsx("span",{className:N,children:s.getFriendlyTypeOption(t.type).label}),e.jsx("span",{className:N,children:s.getPlacementLabel(r,t.placement)})]}),e.jsxs("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[s.getControlOptionPreview(t),d!=null&&d.status?` · ${d.status}`:""]})]})]}),e.jsx(s.Button,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>ne(t.id),"aria-label":`Remove ${t.label}`,children:e.jsx(m.Trash2,{className:"h-3.5 w-3.5"})})]}),j&&e.jsxs("div",{className:"space-y-4 border-t border-border/60 px-3 py-3",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:t.label,placeholder:"Control label",onChange:y=>P(t.id,I=>({...I,label:y.target.value}))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),e.jsxs(s.Select,{value:t.type,onValueChange:y=>{const I=s.applyControlTypeChange({controls:a,controlId:t.id,nextType:y,defaultValues:n});F(I.controls,I.defaultValues)},children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:G(t.type).map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),e.jsxs(s.Select,{value:t.placement||H,onValueChange:y=>P(t.id,I=>({...I,placement:y})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:U.map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]})]}),_(t.type)?e.jsx(m.StructuralParticipantSelector,{type:t.type,participants:s.getEligibleParticipantsForStructuralControl(g||[],t.type).map(y=>({cardId:y.cardId,title:y.title,choiceCount:t.type==="field_selector"?y.fieldChoices.length:y.metricChoices.length})),selectedCardIds:(x==null?void 0:x[t.id])||[],onChange:y=>{const I=A({control:t,nextSelectedCardIds:y}),O=a.map(L=>L.id===t.id?I.nextControl:L);F(O,n,{type:"update",cardBindingsById:I.cardBindingsById})}}):null,e.jsx(m.ControlDefinitionOptionsEditor,{control:t,availableFieldChoices:u.fields,availableMetricChoices:u.metrics,previewControlDefinitions:a,previewControlValues:ie,controlLifecycle:"edit",onChange:y=>P(t.id,()=>y)}),t.initialValueStrategy==="saved_default"&&e.jsx(m.ControlDefaultValueEditor,{control:t,value:b,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:a,previewControlValues:ie,onChange:y=>{const I=a.map(O=>O.id===t.id?{...O,defaultValue:y}:O);if(t.source.kind==="manual"&&(T.current[t.id]=y),n){const O={...n};y===void 0?delete O[t.id]:O[t.id]=y,F(I,O);return}F(I,void 0)}}),e.jsxs(m.Collapsible,{open:W===t.id,onOpenChange:y=>Y(y?t.id:null),children:[e.jsx(m.CollapsibleTrigger,{asChild:!0,children:e.jsxs(s.Button,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 gap-1 text-muted-foreground hover:text-foreground",children:[W===t.id?e.jsx(s.ChevronDown,{className:"h-3.5 w-3.5"}):e.jsx(m.ChevronRight,{className:"h-3.5 w-3.5"}),"Advanced"]})}),e.jsxs(m.CollapsibleContent,{className:"space-y-3 pt-2",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Variable name"}),e.jsx(m.ControlIdInput,{controlId:t.id,onCommit:y=>B(t.id,y)},t.id)]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),e.jsxs(s.Select,{value:t.initialValueStrategy,onValueChange:y=>P(t.id,I=>({...I,initialValueStrategy:y})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:s.INITIAL_VALUE_STRATEGY_OPTIONS.map(y=>e.jsx(s.SelectItem,{value:y.value,children:y.label},y.value))})]})]})]}),e.jsx(m.ControlVisibilitySettings,{control:t,onChange:y=>P(t.id,()=>y)})]})]})]})]},t.id)}),!l&&e.jsxs(s.Button,{type:"button",variant:"outline",size:"xs",onClick:te,children:[e.jsx(m.Plus,{className:"h-3.5 w-3.5"}),"Add control"]})]})}function Ge(r){const{open:a,onOpenChange:o,initialCreateFlowActive:n=!1,dismissMode:i="passive"}=r,c=a!==void 0,[f,h]=C.useState(!1),[p,v]=C.useState(n),g=c?a:f,x=C.useCallback(k=>{!k&&p&&i==="passive"||(c||h(k),k||v(!1),o==null||o(k))},[c,p,i,o]),S=C.useCallback(()=>{c||h(!1),v(!1),o==null||o(!1)},[c,o]);C.useEffect(()=>{g||v(!1)},[g]);const w=C.useCallback(k=>{p&&k.preventDefault()},[p]);return{forceClose:S,handleOpenChange:x,isCreateFlowActive:p,preventPassiveDismissDuringCreate:w,resolvedOpen:g,setIsCreateFlowActive:v}}exports.ControlDefinitionListEditor=We;exports.EditorAcceptButton=Ue;exports.EditorCancelButton=Qe;exports.EditorClearButton=Pe;exports.Library=je;exports.Link2=ke;exports.Rows3=Fe;exports.SendHorizontal=Ie;exports.VisualBadge=qe;exports.VisualSaveAndApplyButton=Re;exports.VisualSaveButton=ze;exports.flushPendingEditorDrafts=Ne;exports.registerPendingEditorDraftFlusher=Le;exports.useCreateFlowOverlayState=Ge;exports.useEffectiveEditorCardType=ue;exports.useSyncLegacyEditorState=Me;exports.useVisualUtils=se;