// Copyright 2018-2026 the Deno authors. MIT license.

import { core, primordials } from "ext:core/mod.js";
import { windowOrWorkerGlobalScope } from "ext:runtime/98_global_scope_shared.js";
const { Console } = core.loadExtScript("ext:deno_node/console.ts");

// Don't rely on global `console` because during bootstrapping, it is pointing
// to the native `console` object provided by V8. Read via the property
// descriptor from `windowOrWorkerGlobalScope` so this works whether the
// install used a data descriptor (`propNonEnumerable`) or an accessor
// descriptor (`propNonEnumerableLazyLoaded`).
// deno-lint-ignore no-explicit-any
const _consoleDesc = windowOrWorkerGlobalScope.console as any;
const console = typeof _consoleDesc.get === "function"
  ? _consoleDesc.get()
  : _consoleDesc.value;

const { ObjectAssign } = primordials;

ObjectAssign(console, { Console });

export default console;

export { Console };
export const {
  assert,
  clear,
  count,
  countReset,
  debug,
  dir,
  dirxml,
  error,
  group,
  groupCollapsed,
  groupEnd,
  info,
  log,
  profile,
  profileEnd,
  table,
  time,
  timeEnd,
  timeLog,
  timeStamp,
  trace,
  warn,
} = console;
// deno-lint-ignore no-explicit-any
export const indentLevel = (console as any)?.indentLevel;
