import {
  FileJson,
  QrCode,
  KeyRound,
  FileText,
  Braces,
  Type,
  Ruler,
  Palette,
  AlignLeft,
  Image as ImageIcon,
  Link2,
  FileCode,
  FileSpreadsheet,
  GitCompare,
  Hash as HashIcon,
  Clock,
  Dices,
  Tags,
  Percent,
  HeartPulse,
  Cake,
  ListOrdered,
  FileImage,
  AppWindow,
  type LucideIcon,
} from "lucide-react";

export type Tier = "free" | "pro";

export type Tool = {
  slug: string;
  name: string;
  shortDesc: string;
  category: "Convert" | "Generate" | "Check" | "Develop";
  icon: LucideIcon;
  tier: Tier;
  // One-time unlock price in USD. Only meaningful for tier "pro" — every
  // Pro tool has its own price instead of one flat plan.
  price?: number;
  // Present only on tools added from the admin panel (see lib/dynamicTools.ts).
  // Built-in tools below never set this.
  dynamic?: boolean;
};

export const tools: Tool[] = [
  // --- original 10 ---
  {
    slug: "image-to-pdf",
    name: "Image to PDF Converter",
    shortDesc: "Combine JPG or PNG images into a single downloadable PDF.",
    category: "Convert",
    icon: ImageIcon,
    tier: "pro",
    price: 5,
  },
  {
    slug: "word-counter",
    name: "Word & Character Counter",
    shortDesc: "Live word, character, sentence and reading-time counts.",
    category: "Check",
    icon: AlignLeft,
    tier: "free",
  },
  {
    slug: "qr-code-generator",
    name: "QR Code Generator",
    shortDesc: "Turn any link or text into a downloadable QR code.",
    category: "Generate",
    icon: QrCode,
    tier: "pro",
    price: 5,
  },
  {
    slug: "password-generator",
    name: "Password Generator",
    shortDesc: "Create strong, random passwords with custom rules.",
    category: "Generate",
    icon: KeyRound,
    tier: "free",
  },
  {
    slug: "json-formatter",
    name: "JSON Formatter & Validator",
    shortDesc: "Format, validate and minify JSON instantly.",
    category: "Develop",
    icon: FileJson,
    tier: "free",
  },
  {
    slug: "base64-converter",
    name: "Base64 Encoder / Decoder",
    shortDesc: "Encode text to Base64 or decode it back, both ways.",
    category: "Develop",
    icon: Braces,
    tier: "free",
  },
  {
    slug: "case-converter",
    name: "Text Case Converter",
    shortDesc: "Switch text between UPPER, lower, Title and Sentence case.",
    category: "Convert",
    icon: Type,
    tier: "free",
  },
  {
    slug: "unit-converter",
    name: "Unit Converter",
    shortDesc: "Convert length, weight and temperature between common units.",
    category: "Convert",
    icon: Ruler,
    tier: "pro",
    price: 5,
  },
  {
    slug: "color-converter",
    name: "Color Converter",
    shortDesc: "Convert colors between HEX, RGB and HSL with a live preview.",
    category: "Develop",
    icon: Palette,
    tier: "free",
  },
  {
    slug: "lorem-ipsum-generator",
    name: "Lorem Ipsum Generator",
    shortDesc: "Generate placeholder paragraphs, sentences or words.",
    category: "Generate",
    icon: FileText,
    tier: "free",
  },
  // --- 15 new tools ---
  {
    slug: "url-encoder-decoder",
    name: "URL Encoder / Decoder",
    shortDesc: "Encode or decode URLs and query strings instantly.",
    category: "Develop",
    icon: Link2,
    tier: "free",
  },
  {
    slug: "markdown-previewer",
    name: "Markdown Previewer",
    shortDesc: "Write Markdown and see the rendered preview live.",
    category: "Develop",
    icon: FileCode,
    tier: "free",
  },
  {
    slug: "slug-generator",
    name: "Slug Generator",
    shortDesc: "Turn any title into a clean, URL-safe slug.",
    category: "Convert",
    icon: Tags,
    tier: "free",
  },
  {
    slug: "timestamp-converter",
    name: "Timestamp Converter",
    shortDesc: "Convert between Unix timestamps and readable dates.",
    category: "Convert",
    icon: Clock,
    tier: "free",
  },
  {
    slug: "random-number-generator",
    name: "Random Number Generator",
    shortDesc: "Generate random numbers in a custom range.",
    category: "Generate",
    icon: Dices,
    tier: "free",
  },
  {
    slug: "meta-tag-generator",
    name: "Meta Tag Generator",
    shortDesc: "Build SEO-ready title, description and meta tags.",
    category: "Generate",
    icon: Tags,
    tier: "pro",
    price: 5,
  },
  {
    slug: "percentage-calculator",
    name: "Percentage Calculator",
    shortDesc: "Work out percentages, increases and decreases.",
    category: "Check",
    icon: Percent,
    tier: "free",
  },
  {
    slug: "bmi-calculator",
    name: "BMI Calculator",
    shortDesc: "Calculate Body Mass Index from height and weight.",
    category: "Check",
    icon: HeartPulse,
    tier: "free",
  },
  {
    slug: "age-calculator",
    name: "Age Calculator",
    shortDesc: "Find exact age in years, months and days from a birth date.",
    category: "Check",
    icon: Cake,
    tier: "free",
  },
  {
    slug: "csv-to-json",
    name: "CSV to JSON Converter",
    shortDesc: "Convert CSV data into clean, structured JSON.",
    category: "Convert",
    icon: FileSpreadsheet,
    tier: "pro",
    price: 5,
  },
  {
    slug: "text-diff-checker",
    name: "Text Diff Checker",
    shortDesc: "Compare two blocks of text and highlight the differences.",
    category: "Check",
    icon: GitCompare,
    tier: "pro",
    price: 5,
  },
  {
    slug: "sha256-hash-generator",
    name: "SHA-256 Hash Generator",
    shortDesc: "Generate a secure SHA-256 hash from any text.",
    category: "Develop",
    icon: HashIcon,
    tier: "pro",
    price: 5,
  },
  {
    slug: "word-frequency-counter",
    name: "Word Frequency Counter",
    shortDesc: "See which words appear most often in your text.",
    category: "Check",
    icon: ListOrdered,
    tier: "pro",
    price: 5,
  },
  {
    slug: "image-compressor",
    name: "Image Compressor",
    shortDesc: "Shrink image file size in your browser before uploading.",
    category: "Convert",
    icon: FileImage,
    tier: "pro",
    price: 5,
  },
  {
    slug: "favicon-generator",
    name: "Favicon Generator",
    shortDesc: "Turn any image into ready-to-use favicon sizes.",
    category: "Generate",
    icon: AppWindow,
    tier: "pro",
    price: 5,
  },
];

export function getTool(slug: string) {
  return tools.find((t) => t.slug === slug);
}

/** Every Pro tool has its own price; free tools have none. */
export function getToolPrice(tool: Pick<Tool, "tier" | "price">): number {
  if (tool.tier !== "pro") return 0;
  return typeof tool.price === "number" ? tool.price : 5; // 5 = PAID_TOOL_PRICE fallback, kept local to avoid a circular import
}
