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

export interface UrlEncoderOptions {
  mode: "encode" | "decode";
  component: "full" | "component";
}

export const urlEncoderPlugin: PlimiPlugin<UrlEncoderOptions> = {
  manifest: {
    id: "dev-url",
    name: "URL Encoder",
    description: "Encode or decode URLs and URI components.",
    category: "developer",
    version: "1.0.0",
    tags: ["url", "encode", "decode", "uri"],
    input: { type: "text" },
    output: { type: "text" },
    example: "https://plimi.app/search?q=hello world&lang=en",
    offlineReady: true,
  },

  optionsSchema: {
    fields: [
      {
        type: "select",
        key: "mode",
        label: "Mode",
        defaultValue: "encode",
        options: [
          { label: "Encode", value: "encode" },
          { label: "Decode", value: "decode" },
        ],
      },
      {
        type: "select",
        key: "component",
        label: "Target",
        defaultValue: "component",
        options: [
          { label: "Full URL", value: "full" },
          { label: "URI Component", value: "component" },
        ],
      },
    ],
  },

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

  run: runUrlEncoder,
};
