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

export interface TimestampOptions {
  mode: "timestamp-to-date" | "date-to-timestamp";
  unit: "seconds" | "milliseconds";
}

export const timestampConverterPlugin: PlimiPlugin<TimestampOptions> = {
  manifest: {
    id: "dev-timestamp",
    name: "Timestamp Converter",
    description: "Convert between Unix timestamps and human-readable dates.",
    category: "developer",
    version: "1.0.0",
    tags: ["timestamp", "unix", "date", "time", "epoch"],
    input: { type: "text", placeholder: "e.g. 1700000000 or 2024-01-15T12:00:00Z", multiline: false },
    output: { type: "json" },
    example: "1700000000",
    offlineReady: true,
  },

  optionsSchema: {
    fields: [
      {
        type: "select",
        key: "mode",
        label: "Mode",
        defaultValue: "timestamp-to-date",
        options: [
          { label: "Timestamp → Date", value: "timestamp-to-date" },
          { label: "Date → Timestamp", value: "date-to-timestamp" },
        ],
      },
      {
        type: "select",
        key: "unit",
        label: "Timestamp Unit",
        defaultValue: "seconds",
        options: [
          { label: "Seconds", value: "seconds" },
          { label: "Milliseconds", value: "milliseconds" },
        ],
      },
    ],
  },

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

  run: runTimestampConverter,
};
