import { s as __toESM } from "./chunk-BNovOVIE.js";
import { _ as Logger, a as OverridingHotkeyProvider, s as resolvePlatform } from "./button-Dj4BTre0.js";
import { t as require_react } from "./react-DA-nE2FX.js";
import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
import { A as looseObject, B as union, I as record, N as number, P as object, R as string, T as boolean, b as _enum, w as array } from "./zod-BWkcDORu.js";
import { t as merge_default } from "./merge-CHn7Yx0N.js";
var import_react = /* @__PURE__ */ __toESM(require_react()), useInsertionEffect = typeof window < "u" ? import_react.useInsertionEffect || import_react.useLayoutEffect : () => {
};
function useEvent(e) {
  let A = import_react.useRef(useEvent_shouldNotBeInvokedBeforeMount);
  useInsertionEffect(() => {
    A.current = e;
  }, [e]);
  let j = import_react.useRef(null);
  return j.current || (j.current = function() {
    return A.current.apply(this, arguments);
  }), j.current;
}
function useEvent_shouldNotBeInvokedBeforeMount() {
  throw Error("INVALID_USEEVENT_INVOCATION: the callback from useEvent cannot be invoked before the component has mounted.");
}
var useEvent_default = useEvent, has = Object.prototype.hasOwnProperty;
function find(e, A, j) {
  for (j of e.keys()) if (dequal(j, A)) return j;
}
function dequal(e, A) {
  var j, M, N;
  if (e === A) return true;
  if (e && A && (j = e.constructor) === A.constructor) {
    if (j === Date) return e.getTime() === A.getTime();
    if (j === RegExp) return e.toString() === A.toString();
    if (j === Array) {
      if ((M = e.length) === A.length) for (; M-- && dequal(e[M], A[M]); ) ;
      return M === -1;
    }
    if (j === Set) {
      if (e.size !== A.size) return false;
      for (M of e) if (N = M, N && typeof N == "object" && (N = find(A, N), !N) || !A.has(N)) return false;
      return true;
    }
    if (j === Map) {
      if (e.size !== A.size) return false;
      for (M of e) if (N = M[0], N && typeof N == "object" && (N = find(A, N), !N) || !dequal(M[1], A.get(N))) return false;
      return true;
    }
    if (j === ArrayBuffer) e = new Uint8Array(e), A = new Uint8Array(A);
    else if (j === DataView) {
      if ((M = e.byteLength) === A.byteLength) for (; M-- && e.getInt8(M) === A.getInt8(M); ) ;
      return M === -1;
    }
    if (ArrayBuffer.isView(e)) {
      if ((M = e.byteLength) === A.byteLength) for (; M-- && e[M] === A[M]; ) ;
      return M === -1;
    }
    if (!j || typeof e == "object") {
      for (j in M = 0, e) if (has.call(e, j) && ++M && !has.call(A, j) || !(j in A) || !dequal(e[j], A[j])) return false;
      return Object.keys(A).length === M;
    }
  }
  return e !== e && A !== A;
}
function hasInitialValue(e) {
  return "init" in e;
}
function isActuallyWritableAtom(e) {
  return !!e.write;
}
function isAtomStateInitialized(e) {
  return "v" in e || "e" in e;
}
function returnAtomValue(e) {
  if ("e" in e) throw e.e;
  return e.v;
}
var promiseStateMap = /* @__PURE__ */ new WeakMap();
function isPendingPromise(e) {
  var _a;
  return isPromiseLike$1(e) && !!((_a = promiseStateMap.get(e)) == null ? void 0 : _a[0]);
}
function abortPromise(e) {
  let A = promiseStateMap.get(e);
  (A == null ? void 0 : A[0]) && (A[0] = false, A[1].forEach((e2) => e2()));
}
function registerAbortHandler(e, A) {
  let j = promiseStateMap.get(e);
  if (!j) {
    j = [true, /* @__PURE__ */ new Set()], promiseStateMap.set(e, j);
    let A2 = () => {
      j[0] = false;
    };
    e.then(A2, A2);
  }
  j[1].add(A);
}
function isPromiseLike$1(e) {
  return typeof (e == null ? void 0 : e.then) == "function";
}
function addPendingPromiseToDependency(e, A, j) {
  if (!j.p.has(e)) {
    j.p.add(e);
    let M = () => j.p.delete(e);
    A.then(M, M);
  }
}
function getMountedOrPendingDependents(e, A, j) {
  var _a;
  let M = /* @__PURE__ */ new Set();
  for (let A2 of ((_a = j.get(e)) == null ? void 0 : _a.t) || []) M.add(A2);
  for (let e2 of A.p) M.add(e2);
  return M;
}
var BUILDING_BLOCK_atomRead = (e, A, ...j) => A.read(...j), BUILDING_BLOCK_atomWrite = (e, A, ...j) => A.write(...j), BUILDING_BLOCK_atomOnInit = (e, A) => {
  if (A.INTERNAL_onInit) return A.INTERNAL_onInit(e);
}, BUILDING_BLOCK_atomOnMount = (e, A, j) => {
  var _a;
  return (_a = A.onMount) == null ? void 0 : _a.call(A, j);
}, BUILDING_BLOCK_ensureAtomState = (e, A) => {
  var j;
  let M = getInternalBuildingBlocks(e), N = M[0], P = M[6], F = M[9], I = N.get(A);
  return I || (I = {
    d: /* @__PURE__ */ new Map(),
    p: /* @__PURE__ */ new Set(),
    n: 0
  }, N.set(A, I), (j = P.i) == null || j.call(P, A), F == null ? void 0 : F(e, A)), I;
}, BUILDING_BLOCK_flushCallbacks = (e) => {
  let A = getInternalBuildingBlocks(e), j = A[1], M = A[3], N = A[4], P = A[5], F = A[6], I = A[13], L = [], R = (e2) => {
    try {
      e2();
    } catch (e3) {
      L.push(e3);
    }
  };
  do {
    F.f && R(F.f);
    let A2 = /* @__PURE__ */ new Set(), L2 = A2.add.bind(A2);
    M.forEach((e2) => {
      var _a;
      return (_a = j.get(e2)) == null ? void 0 : _a.l.forEach(L2);
    }), M.clear(), P.forEach(L2), P.clear(), N.forEach(L2), N.clear(), A2.forEach(R), M.size && I(e);
  } while (M.size || P.size || N.size);
  if (L.length) throw AggregateError(L);
}, BUILDING_BLOCK_recomputeInvalidatedAtoms = (e) => {
  let A = getInternalBuildingBlocks(e), j = A[1], M = A[2], N = A[3], P = A[11], F = A[14], I = A[17], L = [], R = /* @__PURE__ */ new WeakSet(), z = /* @__PURE__ */ new WeakSet(), B = Array.from(N);
  for (; B.length; ) {
    let A2 = B[B.length - 1], N2 = P(e, A2);
    if (z.has(A2)) {
      B.pop();
      continue;
    }
    if (R.has(A2)) {
      M.get(A2) === N2.n && L.push([A2, N2]), z.add(A2), B.pop();
      continue;
    }
    R.add(A2);
    for (let e2 of getMountedOrPendingDependents(A2, N2, j)) R.has(e2) || B.push(e2);
  }
  for (let A2 = L.length - 1; A2 >= 0; --A2) {
    let [j2, P2] = L[A2], R2 = false;
    for (let e2 of P2.d.keys()) if (e2 !== j2 && N.has(e2)) {
      R2 = true;
      break;
    }
    R2 && (F(e, j2), I(e, j2)), M.delete(j2);
  }
}, BUILDING_BLOCK_readAtomState = (e, A) => {
  var j, M;
  let N = getInternalBuildingBlocks(e), P = N[1], F = N[2], I = N[3], L = N[6], R = N[7], z = N[11], B = N[12], V = N[13], H = N[14], U = N[16], W = N[17], G = N[20], K = z(e, A);
  if (isAtomStateInitialized(K)) {
    if (P.has(A) && F.get(A) !== K.n) return K;
    let j2 = false;
    for (let [A2, M2] of K.d) if (H(e, A2).n !== M2) {
      j2 = true;
      break;
    }
    if (!j2) return K;
  }
  K.d.clear();
  let q = true;
  function J() {
    P.has(A) && (W(e, A), V(e), B(e));
  }
  function Y(j2) {
    var M2;
    if (j2 === A) {
      let A2 = z(e, j2);
      if (!isAtomStateInitialized(A2)) if (hasInitialValue(j2)) G(e, j2, j2.init);
      else throw Error("no atom init");
      return returnAtomValue(A2);
    }
    let N2 = H(e, j2);
    try {
      return returnAtomValue(N2);
    } finally {
      K.d.set(j2, N2.n), isPendingPromise(K.v) && addPendingPromiseToDependency(A, K.v, N2), P.has(A) && ((M2 = P.get(j2)) == null || M2.t.add(A)), q || J();
    }
  }
  let X, Z, Q = {
    get signal() {
      return X || (X = new AbortController()), X.signal;
    },
    get setSelf() {
      return !Z && isActuallyWritableAtom(A) && (Z = (...j2) => {
        if (!q) try {
          return U(e, A, ...j2);
        } finally {
          V(e), B(e);
        }
      }), Z;
    }
  }, $ = K.n;
  try {
    let M2 = R(e, A, Y, Q);
    return G(e, A, M2), isPromiseLike$1(M2) && (registerAbortHandler(M2, () => X == null ? void 0 : X.abort()), M2.then(J, J)), (j = L.r) == null || j.call(L, A), K;
  } catch (e2) {
    return delete K.v, K.e = e2, ++K.n, K;
  } finally {
    q = false, $ !== K.n && F.get(A) === $ && (F.set(A, K.n), I.add(A), (M = L.c) == null || M.call(L, A));
  }
}, BUILDING_BLOCK_invalidateDependents = (e, A) => {
  let j = getInternalBuildingBlocks(e), M = j[1], N = j[2], P = j[11], F = [A];
  for (; F.length; ) {
    let A2 = F.pop(), j2 = P(e, A2);
    for (let I of getMountedOrPendingDependents(A2, j2, M)) {
      let A3 = P(e, I);
      N.set(I, A3.n), F.push(I);
    }
  }
}, BUILDING_BLOCK_writeAtomState = (e, A, ...j) => {
  let M = getInternalBuildingBlocks(e), N = M[3], P = M[6], F = M[8], I = M[11], L = M[12], R = M[13], z = M[14], B = M[15], V = M[16], H = M[17], U = M[20], W = true, G = (A2) => returnAtomValue(z(e, A2)), K = (j2, ...M2) => {
    var F2;
    let z2 = I(e, j2);
    try {
      if (j2 === A) {
        if (!hasInitialValue(j2)) throw Error("atom not writable");
        let A2 = z2.n, I2 = M2[0];
        U(e, j2, I2), H(e, j2), A2 !== z2.n && (N.add(j2), B(e, j2), (F2 = P.c) == null || F2.call(P, j2));
        return;
      } else return V(e, j2, ...M2);
    } finally {
      W || (R(e), L(e));
    }
  };
  try {
    return F(e, A, G, K, ...j);
  } finally {
    W = false;
  }
}, BUILDING_BLOCK_mountDependencies = (e, A) => {
  var _a;
  var j;
  let M = getInternalBuildingBlocks(e), N = M[1], P = M[3], F = M[6], I = M[11], L = M[15], R = M[18], z = M[19], B = I(e, A), V = N.get(A);
  if (V && !isPendingPromise(B.v)) {
    for (let [M2, N2] of B.d) if (!V.d.has(M2)) {
      let z2 = I(e, M2);
      R(e, M2).t.add(A), V.d.add(M2), N2 !== z2.n && (P.add(M2), L(e, M2), (j = F.c) == null || j.call(F, M2));
    }
    for (let j2 of V.d) B.d.has(j2) || (V.d.delete(j2), (_a = z(e, j2)) == null ? void 0 : _a.t.delete(A));
  }
}, BUILDING_BLOCK_mountAtom = (e, A) => {
  var j;
  let M = getInternalBuildingBlocks(e), N = M[1], P = M[4], F = M[6], I = M[10], L = M[11], R = M[12], z = M[13], B = M[14], V = M[16], H = M[18], U = L(e, A), W = N.get(A);
  if (!W) {
    B(e, A);
    for (let j2 of U.d.keys()) H(e, j2).t.add(A);
    W = {
      l: /* @__PURE__ */ new Set(),
      d: new Set(U.d.keys()),
      t: /* @__PURE__ */ new Set()
    }, N.set(A, W), isActuallyWritableAtom(A) && P.add(() => {
      let j2 = true, M2 = (...M3) => {
        try {
          return V(e, A, ...M3);
        } finally {
          j2 || (z(e), R(e));
        }
      };
      try {
        let N2 = I(e, A, M2);
        N2 && (W.u = () => {
          j2 = true;
          try {
            N2();
          } finally {
            j2 = false;
          }
        });
      } finally {
        j2 = false;
      }
    }), (j = F.m) == null || j.call(F, A);
  }
  return W;
}, BUILDING_BLOCK_unmountAtom = (e, A) => {
  var _a, _b;
  var j;
  let M = getInternalBuildingBlocks(e), N = M[1], P = M[5], F = M[6], I = M[11], L = M[19], R = I(e, A), z = N.get(A);
  if (!z || z.l.size) return z;
  let B = false;
  for (let e2 of z.t) if ((_a = N.get(e2)) == null ? void 0 : _a.d.has(A)) {
    B = true;
    break;
  }
  if (!B) {
    z.u && P.add(z.u), z = void 0, N.delete(A);
    for (let j2 of R.d.keys()) (_b = L(e, j2)) == null ? void 0 : _b.t.delete(A);
    (j = F.u) == null || j.call(F, A);
    return;
  }
  return z;
}, BUILDING_BLOCK_setAtomStateValueOrPromise = (e, A, j) => {
  let M = getInternalBuildingBlocks(e)[11], N = M(e, A), P = "v" in N, F = N.v;
  if (isPromiseLike$1(j)) for (let P2 of N.d.keys()) addPendingPromiseToDependency(A, j, M(e, P2));
  N.v = j, delete N.e, (!P || !Object.is(F, N.v)) && (++N.n, isPromiseLike$1(F) && abortPromise(F));
}, BUILDING_BLOCK_storeGet = (e, A) => {
  let j = getInternalBuildingBlocks(e)[14];
  return returnAtomValue(j(e, A));
}, BUILDING_BLOCK_storeSet = (e, A, ...j) => {
  let M = getInternalBuildingBlocks(e), N = M[12], P = M[13], F = M[16];
  try {
    return F(e, A, ...j);
  } finally {
    P(e), N(e);
  }
}, BUILDING_BLOCK_storeSub = (e, A, j) => {
  let M = getInternalBuildingBlocks(e), N = M[12], P = M[18], F = M[19], I = P(e, A).l;
  return I.add(j), N(e), () => {
    I.delete(j), F(e, A), N(e);
  };
}, buildingBlockMap = /* @__PURE__ */ new WeakMap(), getInternalBuildingBlocks = (e) => buildingBlockMap.get(e);
function getBuildingBlocks(e) {
  let A = getInternalBuildingBlocks(e), j = A[24];
  return j ? j(A) : A;
}
function buildStore(...e) {
  let A = {
    get(e2) {
      let j2 = getInternalBuildingBlocks(A)[21];
      return j2(A, e2);
    },
    set(e2, ...j2) {
      let M = getInternalBuildingBlocks(A)[22];
      return M(A, e2, ...j2);
    },
    sub(e2, j2) {
      let M = getInternalBuildingBlocks(A)[23];
      return M(A, e2, j2);
    }
  }, j = [
    /* @__PURE__ */ new WeakMap(),
    /* @__PURE__ */ new WeakMap(),
    /* @__PURE__ */ new WeakMap(),
    /* @__PURE__ */ new Set(),
    /* @__PURE__ */ new Set(),
    /* @__PURE__ */ new Set(),
    {},
    BUILDING_BLOCK_atomRead,
    BUILDING_BLOCK_atomWrite,
    BUILDING_BLOCK_atomOnInit,
    BUILDING_BLOCK_atomOnMount,
    BUILDING_BLOCK_ensureAtomState,
    BUILDING_BLOCK_flushCallbacks,
    BUILDING_BLOCK_recomputeInvalidatedAtoms,
    BUILDING_BLOCK_readAtomState,
    BUILDING_BLOCK_invalidateDependents,
    BUILDING_BLOCK_writeAtomState,
    BUILDING_BLOCK_mountDependencies,
    BUILDING_BLOCK_mountAtom,
    BUILDING_BLOCK_unmountAtom,
    BUILDING_BLOCK_setAtomStateValueOrPromise,
    BUILDING_BLOCK_storeGet,
    BUILDING_BLOCK_storeSet,
    BUILDING_BLOCK_storeSub,
    void 0
  ].map((A2, j2) => e[j2] || A2);
  return buildingBlockMap.set(A, Object.freeze(j)), A;
}
var keyCount = 0;
function atom(e, A) {
  let j = `atom${++keyCount}`, M = { toString() {
    return j;
  } };
  return typeof e == "function" ? M.read = e : (M.init = e, M.read = defaultRead, M.write = defaultWrite), A && (M.write = A), M;
}
function defaultRead(e) {
  return e(this);
}
function defaultWrite(e, A, j) {
  return A(this, typeof j == "function" ? j(e(this)) : j);
}
var overriddenCreateStore;
function createStore() {
  return overriddenCreateStore ? overriddenCreateStore() : buildStore();
}
var defaultStore;
function getDefaultStore() {
  return defaultStore || (defaultStore = createStore()), defaultStore;
}
var StoreContext = (0, import_react.createContext)(void 0);
function useStore(e) {
  let A = (0, import_react.useContext)(StoreContext);
  return (e == null ? void 0 : e.store) || A || getDefaultStore();
}
function Provider({ children: e, store: A }) {
  let j = (0, import_react.useRef)(null);
  return A ? (0, import_react.createElement)(StoreContext.Provider, { value: A }, e) : (j.current === null && (j.current = createStore()), (0, import_react.createElement)(StoreContext.Provider, { value: j.current }, e));
}
var isPromiseLike = (e) => typeof (e == null ? void 0 : e.then) == "function", attachPromiseStatus = (e) => {
  e.status || (e.status = "pending", e.then((A) => {
    e.status = "fulfilled", e.value = A;
  }, (A) => {
    e.status = "rejected", e.reason = A;
  }));
}, use = import_react.use || ((e) => {
  if (e.status === "pending") throw e;
  if (e.status === "fulfilled") return e.value;
  throw e.status === "rejected" ? e.reason : (attachPromiseStatus(e), e);
}), continuablePromiseMap = /* @__PURE__ */ new WeakMap(), createContinuablePromise = (e, A) => {
  let j = continuablePromiseMap.get(e);
  return j || (j = new Promise((M, N) => {
    let P = e, F = (e2) => (A2) => {
      P === e2 && M(A2);
    }, I = (e2) => (A2) => {
      P === e2 && N(A2);
    }, L = () => {
      try {
        let e2 = A();
        isPromiseLike(e2) ? (continuablePromiseMap.set(e2, j), P = e2, e2.then(F(e2), I(e2)), registerAbortHandler(e2, L)) : M(e2);
      } catch (e2) {
        N(e2);
      }
    };
    e.then(F(e), I(e)), registerAbortHandler(e, L);
  }), continuablePromiseMap.set(e, j)), j;
};
function useAtomValue(e, A) {
  let { delay: j, unstable_promiseStatus: M = !import_react.use } = A || {}, N = useStore(A), [[P, F, I], L] = (0, import_react.useReducer)((A2) => {
    let j2 = N.get(e);
    return Object.is(A2[0], j2) && A2[1] === N && A2[2] === e ? A2 : [
      j2,
      N,
      e
    ];
  }, void 0, () => [
    N.get(e),
    N,
    e
  ]), R = P;
  if ((F !== N || I !== e) && (L(), R = N.get(e)), (0, import_react.useEffect)(() => {
    let A2 = N.sub(e, () => {
      if (M) try {
        let A3 = N.get(e);
        isPromiseLike(A3) && attachPromiseStatus(createContinuablePromise(A3, () => N.get(e)));
      } catch {
      }
      if (typeof j == "number") {
        setTimeout(L, j);
        return;
      }
      L();
    });
    return L(), A2;
  }, [
    N,
    e,
    j,
    M
  ]), (0, import_react.useDebugValue)(R), isPromiseLike(R)) {
    let A2 = createContinuablePromise(R, () => N.get(e));
    return M && attachPromiseStatus(A2), use(A2);
  }
  return R;
}
function useSetAtom(e, A) {
  let j = useStore(A);
  return (0, import_react.useCallback)((...A2) => j.set(e, ...A2), [j, e]);
}
function useAtom(e, A) {
  return [useAtomValue(e, A), useSetAtom(e, A)];
}
function isIslands() {
  return true;
}
var import_compiler_runtime$2 = require_compiler_runtime();
const store = createStore();
async function waitFor(e, A) {
  return A(store.get(e)) ? store.get(e) : new Promise((j) => {
    let M = store.sub(e, () => {
      let N = store.get(e);
      A(N) && (M(), j(N));
    });
  });
}
function useJotaiEffect(e, A) {
  let j = (0, import_compiler_runtime$2.c)(5), M = useStore(), N, P;
  j[0] !== e || j[1] !== A || j[2] !== M ? (N = () => {
    let j2 = M.get(e);
    M.sub(e, () => {
      let N2 = M.get(e);
      A(N2, j2), j2 = N2;
    });
  }, P = [
    e,
    A,
    M
  ], j[0] = e, j[1] = A, j[2] = M, j[3] = N, j[4] = P) : (N = j[3], P = j[4]), (0, import_react.useEffect)(N, P);
}
var sentinel = /* @__PURE__ */ Symbol("sentinel");
function createDeepEqualAtom(e, A = dequal) {
  let j = sentinel;
  return atom((M) => {
    let N = M(e);
    return (j === sentinel || !A(j, N)) && (j = N), j;
  });
}
const PackageManagerNames = [
  "pip",
  "uv",
  "rye",
  "poetry",
  "pixi"
];
var VALID_APP_WIDTHS = [
  "normal",
  "compact",
  "medium",
  "full",
  "columns"
], VALID_SQL_OUTPUT_FORMATS = [
  "auto",
  "native",
  "polars",
  "lazy-polars",
  "pandas"
], AUTO_DOWNLOAD_FORMATS = [
  "html",
  "markdown",
  "ipynb"
];
const COPILOT_MODES = [
  "manual",
  "ask",
  "agent"
];
var AiConfigSchema = object({
  api_key: string().optional(),
  base_url: string().optional(),
  project: string().optional()
}).loose(), AiModelsSchema = object({
  chat_model: string().nullish(),
  edit_model: string().nullish(),
  autocomplete_model: string().nullish(),
  displayed_models: array(string()).default([]),
  custom_models: array(string()).default([])
});
const UserConfigSchema = looseObject({
  completion: object({
    activate_on_typing: boolean().prefault(true),
    signature_hint_on_typing: boolean().prefault(false),
    copilot: union([boolean(), _enum([
      "github",
      "codeium",
      "custom"
    ])]).prefault(false).transform((e) => e === true ? "github" : e),
    codeium_api_key: string().nullish()
  }).prefault({}),
  save: looseObject({
    autosave: _enum(["off", "after_delay"]).prefault("after_delay"),
    autosave_delay: number().nonnegative().transform((e) => Math.max(e, 1e3)).prefault(1e3),
    format_on_save: boolean().prefault(false)
  }).prefault({}),
  formatting: looseObject({ line_length: number().nonnegative().prefault(79).transform((e) => Math.min(e, 1e3)) }).prefault({}),
  keymap: looseObject({
    preset: _enum(["default", "vim"]).prefault("default"),
    overrides: record(string(), string()).prefault({}),
    destructive_delete: boolean().prefault(true)
  }).prefault({}),
  runtime: looseObject({
    auto_instantiate: boolean().prefault(true),
    on_cell_change: _enum(["lazy", "autorun"]).prefault("autorun"),
    auto_reload: _enum([
      "off",
      "lazy",
      "autorun"
    ]).prefault("off"),
    reactive_tests: boolean().prefault(true),
    watcher_on_save: _enum(["lazy", "autorun"]).prefault("lazy"),
    default_sql_output: _enum(VALID_SQL_OUTPUT_FORMATS).prefault("auto"),
    default_auto_download: array(_enum(AUTO_DOWNLOAD_FORMATS)).prefault([]),
    show_tracebacks: boolean().prefault(false)
  }).prefault({}),
  display: looseObject({
    theme: _enum([
      "light",
      "dark",
      "system"
    ]).prefault("light"),
    code_editor_font_size: number().nonnegative().prefault(14),
    cell_output: _enum(["above", "below"]).prefault("below"),
    dataframes: _enum(["rich", "plain"]).prefault("rich"),
    default_table_page_size: number().prefault(10),
    default_table_max_columns: number().prefault(50),
    default_width: _enum(VALID_APP_WIDTHS).prefault("medium").transform((e) => e === "normal" ? "compact" : e),
    locale: string().nullable().optional(),
    reference_highlighting: boolean().prefault(true)
  }).prefault({}),
  package_management: looseObject({ manager: _enum(PackageManagerNames).prefault("pip") }).prefault({}),
  ai: looseObject({
    rules: string().prefault(""),
    mode: _enum(COPILOT_MODES).prefault("manual"),
    inline_tooltip: boolean().prefault(false),
    open_ai: AiConfigSchema.optional(),
    anthropic: AiConfigSchema.optional(),
    google: AiConfigSchema.optional(),
    ollama: AiConfigSchema.optional(),
    openrouter: AiConfigSchema.optional(),
    wandb: AiConfigSchema.optional(),
    opencode_go: AiConfigSchema.optional(),
    open_ai_compatible: AiConfigSchema.optional(),
    azure: AiConfigSchema.optional(),
    bedrock: looseObject({
      region_name: string().optional(),
      profile_name: string().optional(),
      aws_access_key_id: string().optional(),
      aws_secret_access_key: string().optional()
    }).optional(),
    custom_providers: record(string(), AiConfigSchema).prefault({}),
    models: AiModelsSchema.prefault({
      displayed_models: [],
      custom_models: []
    })
  }).prefault({}),
  experimental: looseObject({
    markdown: boolean().optional(),
    rtc: boolean().optional()
  }).prefault(() => ({})),
  server: looseObject({ disable_file_downloads: boolean().optional() }).prefault(() => ({})),
  diagnostics: looseObject({
    enabled: boolean().optional(),
    sql_linter: boolean().optional()
  }).prefault(() => ({})),
  sharing: looseObject({
    html: boolean().optional(),
    wasm: boolean().optional()
  }).optional(),
  mcp: looseObject({ presets: array(_enum(["marimo", "context7"])).optional() }).optional().prefault({})
}).partial().prefault(() => ({
  completion: {},
  save: {},
  formatting: {},
  keymap: {},
  runtime: {},
  display: {},
  diagnostics: {},
  experimental: {},
  server: {},
  ai: {},
  package_management: {},
  mcp: {}
})), AppTitleSchema = string(), SqlOutputSchema = _enum(VALID_SQL_OUTPUT_FORMATS).prefault("auto"), AppConfigSchema = object({
  width: _enum(VALID_APP_WIDTHS).prefault("medium").transform((e) => e === "normal" ? "compact" : e),
  app_title: AppTitleSchema.nullish(),
  css_file: string().nullish(),
  html_head_file: string().nullish(),
  auto_download: array(_enum(AUTO_DOWNLOAD_FORMATS)).prefault([]),
  sql_output: SqlOutputSchema
}).prefault(() => ({
  width: "medium",
  auto_download: [],
  sql_output: "auto"
}));
function parseAppConfig(e) {
  try {
    return AppConfigSchema.parse(e);
  } catch (e2) {
    return Logger.error(`Marimo got an unexpected value in the configuration file: ${e2}`), AppConfigSchema.parse({});
  }
}
function defaultUserConfig() {
  return UserConfigSchema.parse({
    completion: {},
    save: {},
    formatting: {},
    keymap: {},
    runtime: {},
    display: {},
    diagnostics: {},
    experimental: {},
    server: {},
    ai: {},
    package_management: {},
    mcp: {}
  });
}
var import_compiler_runtime$1 = require_compiler_runtime();
const userConfigAtom = atom(defaultUserConfig()), configOverridesAtom = atom({}), resolvedMarimoConfigAtom = atom((e) => {
  let A = e(configOverridesAtom);
  return merge_default({}, e(userConfigAtom), A);
}), autoInstantiateAtom = atom((e) => e(resolvedMarimoConfigAtom).runtime.auto_instantiate), hotkeyOverridesAtom = atom((e) => e(resolvedMarimoConfigAtom).keymap.overrides ?? {}), platformAtom = atom(resolvePlatform());
atom((e) => new OverridingHotkeyProvider(e(hotkeyOverridesAtom), { platform: e(platformAtom) })), atom((e) => e(resolvedMarimoConfigAtom).save), atom((e) => e(resolvedMarimoConfigAtom).ai), atom((e) => e(resolvedMarimoConfigAtom).completion), atom((e) => e(resolvedMarimoConfigAtom).keymap.preset);
function useResolvedMarimoConfig() {
  let e = (0, import_compiler_runtime$1.c)(3), A = useAtomValue(resolvedMarimoConfigAtom), j = useSetAtom(userConfigAtom), M;
  return e[0] !== A || e[1] !== j ? (M = [A, j], e[0] = A, e[1] = j, e[2] = M) : M = e[2], M;
}
function getResolvedMarimoConfig() {
  return store.get(resolvedMarimoConfigAtom);
}
const aiEnabledAtom = atom((e) => isAiEnabled(e(resolvedMarimoConfigAtom)));
atom((e) => e(resolvedMarimoConfigAtom).display.code_editor_font_size);
const localeAtom = atom((e) => e(resolvedMarimoConfigAtom).display.locale);
function isAiEnabled(e) {
  var _a, _b, _c, _d, _e, _f;
  return !!((_b = (_a = e.ai) == null ? void 0 : _a.models) == null ? void 0 : _b.chat_model) || !!((_d = (_c = e.ai) == null ? void 0 : _c.models) == null ? void 0 : _d.edit_model) || !!((_f = (_e = e.ai) == null ? void 0 : _e.models) == null ? void 0 : _f.autocomplete_model);
}
const appConfigAtom = atom(parseAppConfig({}));
atom((e) => e(appConfigAtom).width), atom((e) => {
  var _a, _b;
  let A = e(resolvedMarimoConfigAtom), j = ((_a = A.snippets) == null ? void 0 : _a.custom_paths) ?? [], M = (_b = A.snippets) == null ? void 0 : _b.include_default_snippets;
  return j.length > 0 || M === true;
}), atom((e) => {
  var _a;
  return ((_a = e(resolvedMarimoConfigAtom).server) == null ? void 0 : _a.disable_file_downloads) ?? false;
});
var import_compiler_runtime = require_compiler_runtime(), themeAtom = atom((e) => {
  if (isIslands()) {
    if (document.body.classList.contains("dark-mode") || document.body.classList.contains("dark") || document.body.dataset.theme === "dark" || document.body.dataset.mode === "dark" || getVsCodeTheme() === "dark") return "dark";
    let e2 = window.getComputedStyle(document.body), A = e2.getPropertyValue("color-scheme").trim();
    if (A) return A.includes("dark") ? "dark" : "light";
    let j = e2.getPropertyValue("background-color").match(/\d+/g);
    if (j) {
      let [e3, A2, M] = j.map(Number);
      return (e3 * 299 + A2 * 587 + M * 114) / 1e3 < 128 ? "dark" : "light";
    }
    return "light";
  }
  return e(resolvedMarimoConfigAtom).display.theme;
}), prefersDarkModeAtom = atom(false);
function setupThemeListener() {
  if (typeof window > "u" || !window.matchMedia) return;
  let e = window.matchMedia("(prefers-color-scheme: dark)");
  store.set(prefersDarkModeAtom, e.matches), e.addEventListener("change", (e2) => {
    store.set(prefersDarkModeAtom, e2.matches);
  });
}
setupThemeListener();
function getVsCodeTheme() {
  switch (document.body.dataset.vscodeThemeKind) {
    case "vscode-dark":
      return "dark";
    case "vscode-high-contrast":
      return "dark";
    case "vscode-light":
      return "light";
  }
}
var codeThemeAtom = atom(getVsCodeTheme());
function setupVsCodeThemeListener() {
  let e = new MutationObserver(() => {
    let e2 = getVsCodeTheme();
    store.set(codeThemeAtom, e2);
  });
  return e.observe(document.body, {
    attributes: true,
    attributeFilter: ["data-vscode-theme-kind"]
  }), () => e.disconnect();
}
setupVsCodeThemeListener();
const resolvedThemeAtom = atom((e) => {
  let A = e(themeAtom), j = e(codeThemeAtom);
  if (j !== void 0) return j;
  let M = e(prefersDarkModeAtom);
  return A === "system" ? M ? "dark" : "light" : A;
});
function useTheme() {
  let e = (0, import_compiler_runtime.c)(3), A;
  e[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (A = { store }, e[0] = A) : A = e[0];
  let j = useAtomValue(resolvedThemeAtom, A), M;
  return e[1] === j ? M = e[2] : (M = { theme: j }, e[1] = j, e[2] = M), M;
}
export {
  dequal as C,
  getBuildingBlocks as S,
  useSetAtom as _,
  getResolvedMarimoConfig as a,
  createStore as b,
  AppConfigSchema as c,
  useJotaiEffect as d,
  waitFor as f,
  useAtomValue as g,
  useAtom as h,
  autoInstantiateAtom as i,
  createDeepEqualAtom as l,
  Provider as m,
  useTheme as n,
  localeAtom as o,
  isIslands as p,
  aiEnabledAtom as r,
  useResolvedMarimoConfig as s,
  resolvedThemeAtom as t,
  store as u,
  useStore as v,
  useEvent_default as w,
  buildStore as x,
  atom as y
};
