const SCENARIOS = {
  loan: [
    { selector: 'input[data-field="amount"]', placeholder: '25000' },
    { selector: 'input[data-field="apr"]', placeholder: '6.5' },
    { selector: 'input[data-field="term"]', placeholder: '5' },
    { selector: 'input[data-field="extra-payment"]', placeholder: '50' },
  ],
  mortgage: [
    { selector: '#home-price', placeholder: '350000' },
    { selector: '#down-payment', placeholder: '70000' },
    { selector: '#down-payment-percent', placeholder: '20' },
    { selector: '#interest-rate', placeholder: '6.5' },
    { selector: '#loan-term', placeholder: '30' },
    { selector: '#property-tax', placeholder: '3600' },
    { selector: '#home-insurance', placeholder: '1200' },
    { selector: '#hoa-fees', placeholder: '150' },
    { selector: '#pmi', placeholder: '0' },
    { selector: '#extra-monthly', placeholder: '200' },
    { selector: '#extra-yearly', placeholder: '0' },
    { selector: '#extra-one-time', placeholder: '0' },
  ],
  savings: [
    { selector: '#initial-deposit', placeholder: '10000' },
    { selector: '#monthly-contribution', placeholder: '300' },
    { selector: '#interest-rate', placeholder: '6' },
    { selector: '#time-period', placeholder: '10' },
    { selector: '#apy-input', placeholder: '6.17' },
    { selector: '#inflation-rate', placeholder: '2.5' },
    { selector: '#tax-rate', placeholder: '0' },
    { selector: '#contribution-increase', placeholder: '0' },
  ],
  'credit-card-payoff': [
    { selector: '#balance', placeholder: '5000' },
    { selector: '#apr', placeholder: '18.99' },
    { selector: '#payment', placeholder: '200' },
    { selector: '#months-goal', placeholder: '24' },
  ],
  roi: [
    { selector: '#initial-investment', placeholder: '10000' },
    { selector: '#final-value', placeholder: '15000' },
    { selector: '#duration', placeholder: '5' },
    { selector: '#additional-costs', placeholder: '500' },
    { selector: '#inflation-rate', placeholder: '2.5' },
  ],
  tip: [
    { selector: '#bill-amount', placeholder: '50' },
    { selector: '#num-people', placeholder: '2' },
    { selector: '#tip-percent', placeholder: '18' },
  ],
  discount: [
    { selector: '#original-price', placeholder: '100' },
    { selector: '#discount-value', placeholder: '20' },
    { selector: '#extra-discount-rate', placeholder: '10' },
    { selector: '#sales-tax', placeholder: '8.5' },
    { selector: '#quantity', placeholder: '1' },
  ],
  bmi: [
    { selector: '#h-cm', placeholder: '175' },
    { selector: '#h-ft', placeholder: '5' },
    { selector: '#h-in', placeholder: '11' },
    { selector: '#w', placeholder: '70' },
  ],
  'fuel-cost': [
    { selector: '#distance', placeholder: '250' },
    { selector: '#consumption', placeholder: '30' },
    { selector: '#fuel-price', placeholder: '3.5' },
  ],
  gpa: [
    { selector: '#current-gpa', placeholder: '3.5' },
    { selector: '#credits-earned', placeholder: '60' },
    { selector: '#target-gpa', placeholder: '3.8' },
    { selector: '#target-credits', placeholder: '15' },
  ],
  'grade-calc': [
    { selector: '#desired-grade', placeholder: '90' },
  ],
  'unit-converter': [
    { selector: '#unit-value', placeholder: '1' },
  ],
  percentage: [
    { selector: '#value-1', placeholder: '15' },
    { selector: '#value-2', placeholder: '100' },
  ],
  age: [
    { selector: '#birth-time', placeholder: '12:00' },
  ],
  'vat-tax': [
    { selector: '#tax-amount', placeholder: '100' },
    { selector: '#tax-rate', placeholder: '20' },
    { selector: '#tax-local-rate', placeholder: '1' },
  ],
  'debt-to-income': [
    { selector: '#gross-income', placeholder: '5000' },
    { selector: '#housing', placeholder: '1500' },
    { selector: '#car-loans', placeholder: '350' },
    { selector: '#student-loans', placeholder: '250' },
    { selector: '#credit-cards', placeholder: '150' },
    { selector: '#other-debts', placeholder: '100' },
    { selector: '#co-borrower-income', placeholder: '3000' },
  ],
  inflation: [
    { selector: '#amount-custom', placeholder: '10000' },
    { selector: '#inflation-rate', placeholder: '3' },
    { selector: '#years-custom', placeholder: '10' },
    { selector: '#investment-return', placeholder: '7' },
  ],
  'margin-break-even': [
    { selector: '#price', placeholder: '120' },
    { selector: '#variable-cost', placeholder: '70' },
    { selector: '#fixed-cost', placeholder: '1600' },
    { selector: '#target-profit', placeholder: '5000' },
    { selector: '#forecast-units', placeholder: '120' },
    { selector: '#sales-per-month', placeholder: '120' },
  ],
  pricing: [
    { selector: '#cogs', placeholder: '35' },
    { selector: '#packaging-cost', placeholder: '1.5' },
    { selector: '#shipping', placeholder: '4.25' },
    { selector: '#platform-pct', placeholder: '8' },
    { selector: '#payment-pct', placeholder: '2.9' },
    { selector: '#transaction-fixed-fee', placeholder: '0.3' },
    { selector: '#vat-pct', placeholder: '20' },
    { selector: '#target-value', placeholder: '40' },
    { selector: '#selling-price', placeholder: '60' },
  ],
  'ad-metrics': [
    { selector: '#ad-impressions', placeholder: '100000' },
    { selector: '#ad-clicks', placeholder: '2500' },
    { selector: '#ad-conversions', placeholder: '125' },
    { selector: '#ad-spend', placeholder: '1000' },
    { selector: '#ad-aov', placeholder: '60' },
    { selector: '#ad-cogs', placeholder: '25' },
    { selector: '#ad-revenue', placeholder: '7500' },
    { selector: '#ad-margin-input', placeholder: '20' },
  ],
  'discount-impact': [
    { selector: '#discount-price', placeholder: '100' },
    { selector: '#discount-cost', placeholder: '60' },
    { selector: '#discount-percent', placeholder: '20' },
    { selector: '#discount-amount', placeholder: '20' },
    { selector: '#discount-units', placeholder: '1000' },
    { selector: '#expected-lift', placeholder: '50' },
  ],
  'subscription-forecast': [
    { selector: '#start-subs', placeholder: '1000' },
    { selector: '#price', placeholder: '20' },
    { selector: '#new-subs-0', placeholder: '100' },
    { selector: '#signup-growth', placeholder: '5' },
    { selector: '#expansion', placeholder: '1' },
    { selector: '#months', placeholder: '12' },
    { selector: '#churn', placeholder: '3' },
  ],
  'investment-growth': [
    { selector: '#initial', placeholder: '10000' },
    { selector: '#contribution', placeholder: '300' },
    { selector: '#rate', placeholder: '7' },
    { selector: '#years', placeholder: '10' },
  ],
  'real-estate-roi': [
    { selector: '#price', placeholder: '300000' },
    { selector: '#downPct', placeholder: '20' },
    { selector: '#closing', placeholder: '5000' },
    { selector: '#initialRepairs', placeholder: '0' },
    { selector: '#rent', placeholder: '2200' },
    { selector: '#otherIncome', placeholder: '0' },
    { selector: '#vacancyPct', placeholder: '5' },
    { selector: '#taxes', placeholder: '3000' },
    { selector: '#insurance', placeholder: '1000' },
    { selector: '#hoa', placeholder: '0' },
    { selector: '#utilities', placeholder: '0' },
    { selector: '#pmFeePct', placeholder: '8' },
    { selector: '#maintPct', placeholder: '8' },
    { selector: '#apr', placeholder: '6.5' },
    { selector: '#termYears', placeholder: '30' },
    { selector: '#pointsPct', placeholder: '0' },
    { selector: '#pmiPct', placeholder: '0' },
  ],
  'mortgage-refi': [
    { selector: '#balance', placeholder: '300000' },
    { selector: '#rateCur', placeholder: '6.75' },
    { selector: '#termCur', placeholder: '300' },
    { selector: '#paymentCur', placeholder: '2072.73' },
    { selector: '#rateNew', placeholder: '5.75' },
    { selector: '#termNew', placeholder: '360' },
    { selector: '#closingCosts', placeholder: '5000' },
    { selector: '#cashOut', placeholder: '0' },
    { selector: '#pointsPct', placeholder: '0' },
    { selector: '#horizonMonths', placeholder: '60' },
    { selector: '#discountRatePct', placeholder: '3' },
  ],
  'rent-vs-buy': [
    { selector: '#price', placeholder: '400000' },
    { selector: '#rent', placeholder: '1900' },
    { selector: '#downPct', placeholder: '20' },
    { selector: '#downAmt', placeholder: '80000' },
    { selector: '#apr', placeholder: '6.5' },
    { selector: '#termYears', placeholder: '30' },
    { selector: '#taxes', placeholder: '4000' },
    { selector: '#insurance', placeholder: '1200' },
    { selector: '#maintPct', placeholder: '1.5' },
    { selector: '#hoa', placeholder: '0' },
    { selector: '#renovationBudget', placeholder: '20000' },
    { selector: '#closingBuy', placeholder: '8000' },
    { selector: '#sellCostPct', placeholder: '6' },
    { selector: '#rentUpfrontCost', placeholder: '6000' },
    { selector: '#rentUpfrontMonths', placeholder: '3' },
    { selector: '#appreciationPct', placeholder: '3' },
    { selector: '#rentGrowthPct', placeholder: '3' },
    { selector: '#investReturnPct', placeholder: '7' },
    { selector: '#horizonYears', placeholder: '7' },
    { selector: '#pmiPct', placeholder: '0.5' },
    { selector: '#taxRatePct', placeholder: '22' },
    { selector: '#taxCap', placeholder: '10000' },
    { selector: '#inflationPct', placeholder: '2.5' },
    { selector: '#taxGrowthPct', placeholder: '2.5' },
    { selector: '#insuranceGrowthPct', placeholder: '2.5' },
    { selector: '#capGainsRatePct', placeholder: '15' },
  ],
  'time-efficiency': [
    { selector: '#time-before', placeholder: '10' },
    { selector: '#time-after', placeholder: '5' },
    { selector: '#tasks-per-person', placeholder: '20' },
    { selector: '#people', placeholder: '10' },
    { selector: '#hourly-rate', placeholder: '40' },
    { selector: '#workdays', placeholder: '220' },
    { selector: '#adoption', placeholder: '80' },
    { selector: '#utilization', placeholder: '90' },
    { selector: '#ramp-months', placeholder: '0' },
    { selector: '#one-time-cost', placeholder: '5000' },
    { selector: '#monthly-cost', placeholder: '200' },
  ],
  'overtime-pay': [
    { selector: '#hourly-rate', placeholder: '30' },
    { selector: '#ot-threshold', placeholder: '40' },
    { selector: '#ot-multiplier', placeholder: '1.5' },
    { selector: '#hours-worked', placeholder: '50' },
    { selector: '#tax-pct', placeholder: '20' },
  ],
  'project-cost': [
    { selector: '#materials-cost', placeholder: '1800' },
    { selector: '#materials-markup', placeholder: '0' },
    { selector: '#overhead-pct', placeholder: '15' },
    { selector: '#contingency-pct', placeholder: '10' },
    { selector: '#profit-pct', placeholder: '20' },
    { selector: '#tax-pct', placeholder: '0' },
  ],
  'energy-usage': [
    { selector: '#device-power', placeholder: '1500' },
    { selector: '#device-quantity', placeholder: '1' },
    { selector: '#device-hours', placeholder: '4' },
    { selector: '#device-days', placeholder: '7' },
    { selector: '#device-duty', placeholder: '100' },
    { selector: '#device-standby', placeholder: '0' },
    { selector: '#energy-rate', placeholder: '0.15' },
  ],
};

function applySelectorPlaceholder(root, selector, placeholder) {
  if (!root || !selector) {
    return;
  }
  root.querySelectorAll(selector).forEach((input) => {
    if (input && typeof input.setAttribute === 'function') {
      input.setAttribute('placeholder', String(placeholder));
    }
  });
}

export function getPlaceholderScenario(calcType) {
  return Array.isArray(SCENARIOS[calcType]) ? SCENARIOS[calcType] : [];
}

export function applyPlaceholderScenario(root, calcType) {
  const scenario = getPlaceholderScenario(calcType);
  if (!scenario.length) {
    return;
  }

  scenario.forEach((entry) => {
    applySelectorPlaceholder(root, entry.selector, entry.placeholder);
  });
}

