import { defineConfig } from 'tsup';

export default defineConfig([
  {
    entry: {
      core: 'src/core.ts',
      headless: 'src/headless.ts',
      'core-plugins': 'src/core-plugins/index.ts',
      mcp: 'src/mcp/index.ts',
      // Subpath entries — stable public surface at directory-boundary
      // granularity, so framework adapters outside packages/{react,vue}
      // can consume internals without reaching into src/.
      'prosemirror/index': 'src/prosemirror/index.ts',
      'prosemirror/extensions/index': 'src/prosemirror/extensions/index.ts',
      'prosemirror/conversion/index': 'src/prosemirror/conversion/index.ts',
      'prosemirror/commands/index': 'src/prosemirror/commands/index.ts',
      'prosemirror/plugins/index': 'src/prosemirror/plugins/index.ts',
      'prosemirror/utils/ClickPositionResolver': 'src/prosemirror/utils/ClickPositionResolver.ts',
      'prosemirror/utils/extractTrackedChanges': 'src/prosemirror/utils/extractTrackedChanges.ts',
      'prosemirror/utils/LayoutSelectionGate': 'src/prosemirror/utils/LayoutSelectionGate.ts',
      'prosemirror/utils/PointerEventHandler': 'src/prosemirror/utils/PointerEventHandler.ts',
      'prosemirror/utils/visualLineNavigation': 'src/prosemirror/utils/visualLineNavigation.ts',
      'prosemirror/extensions/nodes/TableExtension':
        'src/prosemirror/extensions/nodes/TableExtension/index.ts',
      'prosemirror/template/prosemirror-plugin': 'src/prosemirror/template/prosemirror-plugin.ts',
      'docx/index': 'src/docx/index.ts',
      'docx/wrapTypes': 'src/docx/wrapTypes.ts',
      'docx/serializer/index': 'src/docx/serializer/index.ts',
      'agent/index': 'src/agent/index.ts',
      'utils/index': 'src/utils/index.ts',
      'utils/cardStyles': 'src/utils/cardStyles.ts',
      'types/document': 'src/types/document.ts',
      'types/content': 'src/types/content.ts',
      'types/agentApi': 'src/types/agentApi.ts',
      'layout-engine/index': 'src/layout-engine/index.ts',
      'layout-engine/types': 'src/layout-engine/types.ts',
      'layout-painter/index': 'src/layout-painter/index.ts',
      'layout-painter/renderPage': 'src/layout-painter/renderPage.ts',
      'layout-bridge/index': 'src/layout-bridge/index.ts',
      'layout-bridge/clickToPositionDom': 'src/layout-bridge/clickToPositionDom.ts',
      'layout-bridge/measuring/index': 'src/layout-bridge/measuring/index.ts',
      'layout-bridge/tableInsertHover': 'src/layout-bridge/tableInsertHover.ts',
      'layout-bridge/toFlowBlocks': 'src/layout-bridge/toFlowBlocks.ts',
      'plugin-api/index': 'src/plugin-api/index.ts',
      'plugin-api/RenderedDomContext': 'src/plugin-api/RenderedDomContext.ts',
      'plugin-api/resolveItemPositions': 'src/plugin-api/resolveItemPositions.ts',
      'plugin-api/types': 'src/plugin-api/types.ts',
      'docx/parser': 'src/docx/parser.ts',
      'docx/rezip': 'src/docx/rezip.ts',
      'utils/headingCollector': 'src/utils/headingCollector.ts',
      'utils/highlightColors': 'src/utils/highlightColors.ts',
      'utils/textSelection': 'src/utils/textSelection.ts',
      'utils/comments': 'src/utils/comments.ts',
      'utils/findReplace': 'src/utils/findReplace.ts',
      'utils/findVerticalScrollParent': 'src/utils/findVerticalScrollParent.ts',
      'utils/fontOptions': 'src/utils/fontOptions.ts',
      'utils/stylePreview': 'src/utils/stylePreview.ts',
      'utils/listState': 'src/utils/listState.ts',
      'utils/reportIssue': 'src/utils/reportIssue.ts',
      'utils/sidebarConstants': 'src/utils/sidebarConstants.ts',
      'utils/units': 'src/utils/units.ts',
      'managers/AutoSaveManager': 'src/managers/AutoSaveManager.ts',
      'managers/TableSelectionManager': 'src/managers/TableSelectionManager.ts',
      'managers/types': 'src/managers/types.ts',
      'prosemirror/commands/formatting': 'src/prosemirror/commands/formatting.ts',
      'prosemirror/commands/pageBreak': 'src/prosemirror/commands/pageBreak.ts',
      'prosemirror/commands/sectionBreak': 'src/prosemirror/commands/sectionBreak.ts',
      'prosemirror/commands/paragraph': 'src/prosemirror/commands/paragraph.ts',
      'prosemirror/conversion/fromProseDoc': 'src/prosemirror/conversion/fromProseDoc.ts',
      'prosemirror/plugins/selectionTracker': 'src/prosemirror/plugins/selectionTracker.ts',
      'prosemirror/schema/index': 'src/prosemirror/schema/index.ts',
      'prosemirror/styles/index': 'src/prosemirror/styles/index.ts',
      // Tier-1 shared orchestration modules (lifted from the React/Vue adapters).
      'prosemirror/paraText': 'src/prosemirror/paraText.ts',
      'prosemirror/queries': 'src/prosemirror/queries.ts',
      'prosemirror/applyFormatting': 'src/prosemirror/applyFormatting.ts',
      'prosemirror/tableResize': 'src/prosemirror/tableResize.ts',
      'prosemirror/cellDragSelection': 'src/prosemirror/cellDragSelection.ts',
      'prosemirror/imageCommit': 'src/prosemirror/imageCommit.ts',
      'prosemirror/commentOps': 'src/prosemirror/commentOps.ts',
      'prosemirror/commentIdAllocator': 'src/prosemirror/commentIdAllocator.ts',
      'editor/index': 'src/editor/index.ts',
      'utils/autoScroll': 'src/utils/autoScroll.ts',
    },
    format: ['cjs', 'esm'],
    dts: true,
    splitting: true,
    sourcemap: false,
    clean: true,
    treeshake: true,
    minify: true,
    external: [
      'prosemirror-commands',
      'prosemirror-dropcursor',
      'prosemirror-history',
      'prosemirror-keymap',
      'prosemirror-model',
      'prosemirror-state',
      'prosemirror-tables',
      'prosemirror-transform',
      'prosemirror-view',
    ],
    injectStyle: false,
  },
  // CLI build (with shebang) - bundles all deps for standalone use
  {
    entry: {
      'mcp-cli': 'src/mcp/cli.ts',
    },
    format: ['esm'],
    dts: true,
    splitting: false,
    sourcemap: false,
    clean: false,
    treeshake: true,
    minify: true,
    injectStyle: false,
    banner: {
      js: '#!/usr/bin/env node',
    },
  },
]);
