"use client";

import * as React from "react";
import dynamic from "next/dynamic";

/**
 * Lazy entry point for the code editor.
 *
 * CodeMirror 6 plus its language packs weigh ~540 KB, and only the coding lab,
 * the simulator, and the project form ever need it. Loading it through
 * `next/dynamic` keeps that weight out of the initial bundle for every other
 * route while leaving the call sites unchanged.
 *
 * The placeholder keeps the editor's height reserved so the surrounding layout
 * does not jump when the real component arrives.
 */
const CodeEditorClient = dynamic(
  () => import("@/components/coding/code-editor-client").then((m) => m.CodeEditor),
  {
    ssr: false,
    loading: () => (
      <div className="grid h-80 place-items-center rounded-lg border border-line bg-surface-sunken">
        <span className="ws-label">Memuat editor…</span>
      </div>
    ),
  }
);

export function CodeEditor(props: React.ComponentProps<typeof CodeEditorClient>) {
  return <CodeEditorClient {...props} />;
}
