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

export interface TextDiffOptions {
  ignoreWhitespace: boolean;
}

export const textDiffPlugin: PlimiPlugin<TextDiffOptions> = {
  manifest: {
    id: "txt-diff",
    name: "Text Diff",
    description: "Compare two texts and see the differences line by line.",
    category: "text",
    version: "1.0.0",
    tags: ["diff", "compare", "text"],
    input: {
      type: "group",
      fields: [
        {
          key: "original",
          label: "original",
          type: "text",
          placeholder: "Paste the original text…",
          example: "function greet(name) {\n  return 'Hello ' + name;\n}",
        },
        {
          key: "modified",
          label: "modified",
          type: "text",
          placeholder: "Paste the modified text…",
          example: "function greet(name) {\n  return `Hello, ${name}!`;\n}\n\nfunction farewell(name) {\n  return `Bye, ${name}!`;\n}",
        },
      ],
    },
    output: { type: "text" },
    offlineReady: true,
  },

  optionsSchema: {
    fields: [
      {
        type: "boolean",
        key: "ignoreWhitespace",
        label: "Ignore whitespace",
        defaultValue: false,
      },
    ],
  },

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

  run: runTextDiff,
};
