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

export interface ImageEditorOptions {
  format: "image/png" | "image/jpeg" | "image/webp";
  quality: number;
  dataUrl?: string;
}

const ImageEditorUi = lazy(() => import("./ImageEditorUi"));

export const imageEditorPlugin: PlimiPlugin<ImageEditorOptions> = {
  manifest: {
    id: "image-editor",
    name: "Image Editor",
    description:
      "Edit images with text, drawing, shapes, colors, layers, and export locally.",
    category: "image",
    version: "1.0.0",
    tags: ["image", "editor", "text", "draw", "shapes", "fabric"],
    input: {
      type: "files",
      accept: ["image/jpeg", "image/png", "image/webp"],
      multiple: false,
      maxSizeMb: 25,
    },
    output: { type: "files" },
    offlineReady: true,
  },

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

  permissions: {
    network: "none",
    fileSystem: "read-write",
    clipboard: "none",
  },

  run: runImageEditor,
  customUi: ImageEditorUi,
};
