import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2026 GoodData Corporation
import { useState } from "react";
import { yaml } from "@codemirror/lang-yaml";
import { lintGutter } from "@codemirror/lint";
import { lineNumbers } from "@codemirror/view";
import { SyntaxHighlightingInput } from "./SyntaxHighlightingInput.js";
import { createYamlSyntaxLinter } from "./yamlSyntaxLinter.js";
const noop = () => { };
/**
 * A YAML source editor: syntax highlighting, line numbers, a lint gutter, an optional syntax linter,
 * and optional schema-aware autocompletion. Generic YAML plumbing lives here; schema-specific policy
 * (the completion source, the syntax-error message, value handling) is injected by the caller.
 *
 * Uncontrolled: it seeds from `initialValue` and reports edits through `onChange`; the parent reads
 * the current value from `onChange`, never by re-driving `initialValue`.
 * @internal
 */
export function YamlEditor({ initialValue, onChange, disabled = false, label, completionSource, syntaxErrorMessage, extensions, placeholder, }) {
    const [seedValue] = useState(initialValue);
    const [allExtensions] = useState(() => [
        yaml(),
        lineNumbers(),
        lintGutter(),
        ...(syntaxErrorMessage ? [createYamlSyntaxLinter(syntaxErrorMessage)] : []),
        ...(extensions ?? []),
    ]);
    return (_jsx(SyntaxHighlightingInput, { label: label, value: seedValue, onChange: onChange ?? noop, extensions: allExtensions, onCompletion: completionSource, disabled: disabled, placeholder: placeholder }));
}
