import { has } from 'ramda';
import { isPlainObject, isString } from 'ramda-adjunct';
import "./refractor/registration.js";
import defaultNamespaceInstance from "./namespace.js";
import serializeValue from "./serializers/value/index.js";
import serializeJSON from "./serializers/json.js";
import serializeYAML from "./serializers/yaml-1-2.js";
export { dispatchPlugins as dispatchRefractorPlugins } from "./refractor/plugins/utils/index.js";
export { default as refractorPluginElementIdentity } from "./refractor/plugins/element-identity.js";
export { default as refractorPluginSemanticElementIdentity } from "./refractor/plugins/semantic-element-identity.js";
export { default as MediaTypes } from "./media-types.js";
export { Element, ObjectElement, MemberElement, ArrayElement, BooleanElement, StringElement, NullElement, NumberElement, RefElement, LinkElement, KeyValuePair, ObjectSlice, ArraySlice, refract } from 'minim';
export { default as namespace, Namespace, createNamespace } from "./namespace.js";
export { default as AnnotationElement } from "./elements/Annotation.js";
export { default as CommentElement } from "./elements/Comment.js";
export { default as ParseResultElement } from "./elements/ParseResult.js";
export { default as SourceMapElement } from "./elements/SourceMap.js";
export { isElement, isStringElement, isNumberElement, isNullElement, isBooleanElement, isArrayElement, isObjectElement, isMemberElement, isLinkElement, isRefElement, isAnnotationElement, isParseResultElement, isSourceMapElement, isPrimitiveElement, hasElementSourceMap, includesSymbols, includesClasses } from "./predicates/index.js";
export { default as createPredicate } from "./predicates/helpers.js";
export { filter, reject, find, findAtOffset, some, traverse, parents } from "./traversal/index.js";
export { visit, BREAK, mergeAllVisitors, getNodeType, keyMapDefault as keyMap } from "./traversal/visitor.js";
export { transclude, default as Transcluder } from "./transcluder/index.js";
export { dereference } from "./util.js";
/**
 * Transforms data to an Element from a particular namespace.
 */
export const from = (data, namespace = defaultNamespaceInstance) => {
  if (isString(data)) {
    // JSON serialized refract
    try {
      return namespace.fromRefract(JSON.parse(data));
    } catch {
      // noop
    }
  }
  if (isPlainObject(data) && has('element', data)) {
    // refract javascript structure
    return namespace.fromRefract(data);
  }
  return namespace.toElement(data);
};

/**
 * Transforms the ApiDOM into JavaScript POJO.
 * This POJO would be the result of interpreting the ApiDOM
 * into JavaScript structure.
 */
export const toValue = serializeValue;

/**
 * Transforms the ApiDOM into JSON string.
 */
export const toJSON = serializeJSON;

/**
 * Transforms the ApiDOM into YAML string.
 */
export const toYAML = serializeYAML;

/**
 * Creates a refract representation of an Element.
 * https://github.com/refractproject/refract-spec
 */
export const dehydrate = (element, namespace = defaultNamespaceInstance) => {
  return namespace.toRefract(element);
};

/**
 * Create a refracted string representation of an Element.
 */
export const toString = (element, namespace = defaultNamespaceInstance) => {
  const refractStructure = dehydrate(element, namespace);
  return JSON.stringify(refractStructure);
};
export { default as sexprs } from "./sexprs.js";
export { default as deepmerge } from "./deepmerge.js";