/**
 * Available placeholders for custom HTML templates
 *
 * These placeholders are replaced with actual product data at render time.
 * Both SSR (Server-Side Rendering) and Web Component modes support these placeholders.
 *
 * This is the SINGLE SOURCE OF TRUTH for all placeholders in the application.
 * Import from here instead of defining placeholders elsewhere.
 */

export interface PlaceholderInfo {
  key: string;
  description: string;
}

/**
 * Available placeholders for custom HTML
 */
export const availablePlaceholders: PlaceholderInfo[] = [
  // Product info
  { key: "{productName}", description: "Product name" },
  { key: "{productId}", description: "Product ID" },
  { key: "{productID}", description: "Product ID (alias)" },

  // Regular price
  { key: "{regularPrice}", description: "Full regular price" },
  { key: "{regularPriceMain}", description: "Regular price integer part" },
  { key: "{regularPriceDecimal}", description: "Regular price decimal part" },
  { key: "{regularPriceSeparator}", description: "Regular price decimal separator" },

  // Sale price
  { key: "{salePrice}", description: "Full sale price" },
  { key: "{salePriceMain}", description: "Sale price integer part" },
  { key: "{salePriceDecimal}", description: "Sale price decimal part" },
  { key: "{salePriceSeparator}", description: "Sale price decimal separator" },

  // Variable price range - min/max current prices
  { key: "{minPrice}", description: "Minimum variation price (variable products)" },
  { key: "{minPriceMain}", description: "Min price integer part" },
  { key: "{minPriceDecimal}", description: "Min price decimal part" },
  { key: "{maxPrice}", description: "Maximum variation price (variable products)" },
  { key: "{maxPriceMain}", description: "Max price integer part" },
  { key: "{maxPriceDecimal}", description: "Max price decimal part" },

  // Variable price range - min/max regular prices (before sale)
  { key: "{minRegularPrice}", description: "Min regular price (before sale)" },
  { key: "{minRegularPriceMain}", description: "Min regular price integer part" },
  { key: "{minRegularPriceDecimal}", description: "Min regular price decimal part" },
  { key: "{maxRegularPrice}", description: "Max regular price (before sale)" },
  { key: "{maxRegularPriceMain}", description: "Max regular price integer part" },
  { key: "{maxRegularPriceDecimal}", description: "Max regular price decimal part" },

  // Variable price range - min/max sale prices
  { key: "{minSalePrice}", description: "Min sale price (variable products)" },
  { key: "{minSalePriceMain}", description: "Min sale price integer part" },
  { key: "{minSalePriceDecimal}", description: "Min sale price decimal part" },
  { key: "{maxSalePrice}", description: "Max sale price (variable products)" },
  { key: "{maxSalePriceMain}", description: "Max sale price integer part" },
  { key: "{maxSalePriceDecimal}", description: "Max sale price decimal part" },

  // Currency
  { key: "{currencySymbol}", description: "Currency symbol" },

  // Discount info
  { key: "{discount}", description: "Discount percentage number (e.g., 20)" },
  { key: "{discountPercentage}", description: "Discount percentage (alias)" },
  { key: "{discountAmount}", description: "Discount amount with currency" },
  { key: "{discountAmountRaw}", description: "Discount amount number only" },
  { key: "{savedAmount}", description: "Amount saved with currency" },

  // Additional info
  { key: "{taxLabel}", description: "Tax label (ex. incl. VAT)" },
  { key: "{stockStatus}", description: "Stock status text" },
];

/**
 * Canvas-derived placeholders (applied in LayoutRenderer before price replacement).
 *
 * Built from element `name` as camelCase slug:
 * - text element "Badge" → `{badge}`
 * - variablePriceRange "Price Range" → `{priceRangePrefix}`
 *
 * Use `describeCanvasPlaceholders(elements)` for the current layout's dynamic list.
 */
export const CANVAS_PLACEHOLDER_NOTE =
  "Canvas placeholders are derived from element names at render time (see canvasPlaceholders.ts).";

/**
 * Get just the placeholder keys as an array of strings
 * For use in components that only need the keys
 */
export const PLACEHOLDER_KEYS: string[] = availablePlaceholders.map((p) => p.key);

/**
 * Get placeholder descriptions as a map for quick lookup
 */
export const PLACEHOLDER_DESCRIPTIONS: Record<string, string> = availablePlaceholders.reduce((acc, p) => {
  acc[p.key] = p.description;
  return acc;
}, {} as Record<string, string>);

/**
 * Type for placeholder keys (union of all valid placeholder strings)
 */
export type PlaceholderKey = (typeof availablePlaceholders)[number]["key"];
