import markdown from 'highlight.js/lib/languages/markdown';
import typescript from 'highlight.js/lib/languages/typescript';
import javascript from 'highlight.js/lib/languages/javascript';
import json from 'highlight.js/lib/languages/json';
import yaml from 'highlight.js/lib/languages/yaml';
import css from 'highlight.js/lib/languages/css';

export { default as ExampleWrapper } from './ExampleWrapper.svelte';
export { default as Highlight } from './Highlight.svelte';
export { default as HighlightAuto } from './HighlightAuto.svelte';
export { default as HighlightSvelte } from './HighlightSvelte.svelte';
export { default as LangTag } from './LangTag.svelte';
export { default as HighlightTable } from './HighlightTable.svelte';
export { default as LineNumberTable } from './LineNumberTable.svelte';
export { default as HighlightCompo } from './HighlightCompo.svelte';
export { transformComponents, transformModules, defaultPathToName, pathExtractors } from './moduleHelpers';
export { HIGHLIGHT_CONSTANTS, createHighlightedLinesSet, calculateLineNumberWidth, escapeHtml, replaceLibImport } from './highlightUtils';

export function copyToClipboard(text: string): Promise<void> {
  if (typeof navigator === 'undefined' || !navigator.clipboard) {
    return Promise.reject(new Error('Clipboard API not available'));
  }
  return navigator.clipboard.writeText(text).catch((err) => {
    console.error('Failed to copy: ', err);
    throw err; // Re-throw the error so the caller can handle it if needed
  });
}

// Language configurations
export const languages = {
  css: { name: 'css', register: css },
  md: { name: 'markdown', register: markdown },
  ts: { name: 'typescript', register: typescript },
  js: { name: 'javascript', register: javascript },
  javascript: { name: 'javascript', register: javascript },
  json: { name: 'json', register: json },
  yaml: { name: 'yaml', register: yaml }
} as const;

export * from './types';
