import type { PlimiPlugin } from "../../core/plugins/plugin-types";
import { runPdfSplitter } from "./run";

export interface PdfSplitterOptions {
  splitMode: "extract" | "burst";
  pageRange: string;
}

export const pdfSplitterPlugin: PlimiPlugin<PdfSplitterOptions> = {
  manifest: {
    id: "pdf-splitter",
    name: "PDF Splitter",
    description: "Extract page ranges or split a PDF document into individual pages safely in your browser.",
    category: "pdf",
    version: "1.0.0",
    tags: ["pdf", "split", "extract", "pages"],
    input: {
      type: "files",
      accept: ["application/pdf"],
      multiple: false,
    },
    output: { type: "files" },
    offlineReady: true,
  },

  optionsSchema: {
    fields: [
      {
        type: "select",
        key: "splitMode",
        label: "Split Mode",
        defaultValue: "extract",
        options: [
          { label: "Extract Range", value: "extract" },
          { label: "Split Every Page", value: "burst" },
        ],
      },
      {
        type: "text",
        key: "pageRange",
        label: "Page Range",
        defaultValue: "1",
        placeholder: "e.g. 1-3, 5 (for Extract mode)",
      },
    ],
  },

  capabilities: {
    cancelable: true,
    worker: false,
  },

  run: runPdfSplitter,
};
