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

export interface RedactRect {
  x: number; // Absolute X coordinate in image natural pixels
  y: number; // Absolute Y coordinate in image natural pixels
  w: number; // Absolute width in image natural pixels
  h: number; // Absolute height in image natural pixels
}

export interface ImageRedactorOptions {
  rects: RedactRect[];
  color: string;
}

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

export const imageRedactorPlugin: PlimiPlugin<ImageRedactorOptions> = {
  manifest: {
    id: "image-redactor",
    name: "Image Redactor",
    description: "Safely paint black boxes over sensitive data like addresses or credit cards entirely in your browser.",
    category: "privacy",
    version: "1.0.0",
    tags: ["privacy", "redact", "hide", "censor", "blur", "image"],
    input: {
      type: "files",
      accept: ["image/jpeg", "image/png", "image/webp"],
      multiple: false,
    },
    output: { type: "files" },
    offlineReady: true,
  },

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

  run: runImageRedactor,

  customUi: ImageRedactorUi,
};
