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

export interface QrCodeGeneratorOptions {
  size: number;
  margin: number;
  errorCorrection: "L" | "M" | "Q" | "H";
  format: "svg" | "png";
}

export const qrCodeGeneratorPlugin: PlimiPlugin<QrCodeGeneratorOptions> = {
  manifest: {
    id: "qr-code-generator",
    name: "QR Code Generator",
    description: "Generate high-performance, offline-ready QR codes locally in the browser using WebAssembly.",
    category: "image",
    version: "1.0.0",
    tags: ["qr", "qrcode", "generator", "wasm", "barcode"],
    input: {
      type: "text",
      label: "Text / URL",
      placeholder: "Enter text or URL to encode...",
      multiline: true,
      rows: 4,
    },
    output: { type: "files" },
    example: "https://plimi.app",
    offlineReady: true,
  },

  optionsSchema: {
    fields: [
      {
        type: "slider",
        key: "size",
        label: "Size (pixels)",
        defaultValue: 256,
        min: 128,
        max: 1024,
        step: 32,
      },
      {
        type: "slider",
        key: "margin",
        label: "Margin (modules)",
        defaultValue: 4,
        min: 0,
        max: 10,
        step: 1,
      },
      {
        type: "select",
        key: "errorCorrection",
        label: "Error Correction Level",
        defaultValue: "M",
        options: [
          { label: "Low (7% recovery)", value: "L" },
          { label: "Medium (15% recovery)", value: "M" },
          { label: "Quartile (25% recovery)", value: "Q" },
          { label: "High (30% recovery)", value: "H" },
        ],
      },
      {
        type: "select",
        key: "format",
        label: "Output Format",
        defaultValue: "svg",
        options: [
          { label: "SVG Vector File", value: "svg" },
          { label: "PNG Image File", value: "png" },
        ],
      },
    ],
  },

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

  run: runQrCodeGenerator,
};
