Files
tripz-llc/marketing/js/calculator.js
T
Hamza-AyedandClaude Opus 5 75b80bd299 refactor(marketing): تفكيك الموقع إلى وحدات + توحيد الباقات الثلاث
- marketing: index.html من 2274 إلى 775 سطراً، والباقي إلى
  styles/ (tokens·base·components·sections·responsive) و
  js/ (app·i18n·calculator·analytics) و i18n/ بخمس لغات
  (ar·en·fr·es·tr) عبر سمة data-i18n.
- docs/05 + docs/33 + لوحة السوبر-أدمن: الباقات صارت ثلاثاً
  (إطلاق · نمو · سيادة) بدل الأربع، وتحديث docs/31 بما يطابقها.
- docs/36: توثيق سيرو إكسبرس للتوصيل.
- تنظيف استيرادات غير مستعملة في apps/rider و apps/driver.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 04:53:19 +03:00

76 lines
2.9 KiB
JavaScript

/* ============ CALCULATOR (docs/05 formula) ============ */
function fmt(n){return "$"+Math.round(n).toLocaleString("en-US");}
const CURS=[
{val:"JOD:1.41",key:"calc.opt.jod"},
{val:"EGP:0.021",key:"calc.opt.egp"},
{val:"SYP:0.00007",key:"calc.opt.syp"},
{val:"USD:1",key:"calc.opt.usd"},
{val:"EUR:1.08",key:"calc.opt.eur"},
{val:"MAD:0.10",key:"calc.opt.mad"},
{val:"XOF:0.0017",key:"calc.opt.xof"}
];
const PLANS=[
{val:"349:0.025:0.04:launch",key:"calc.opt.launch"},
{val:"599:0.02:0.03:growth",key:"calc.opt.growth"},
{val:"879:0.01:0.02:sov",key:"calc.opt.sov"}
];
function buildCalcDropdowns(){
const d=I18N[LANG];
const curSel=$("#cur"),planSel=$("#plan");
const curVal=curSel.value,planVal=planSel.value;
curSel.innerHTML="";planSel.innerHTML="";
CURS.forEach(c=>{const o=document.createElement("option");o.value=c.val;o.textContent=d[c.key]||c.val;curSel.appendChild(o);});
PLANS.forEach(p=>{const o=document.createElement("option");o.value=p.val;o.textContent=d[p.key]||p.val;planSel.appendChild(o);});
curSel.value=curVal;planSel.value=planVal;
}
function calc(){
const trips=+$("#trips").value;
const fare=+$("#fare").value||0;
const [curCode, rate]=$("#cur").value.split(":");
const [baseVal, gmvVal, minVal, pKey]=$("#plan").value.split(":");
const base = +baseVal, minRate = +minVal;
const usd = fare * (+rate);
const monthlyTrips = trips * 30;
const gmv = monthlyTrips * usd;
let gmvFee;
if(pKey === "launch"){
if(gmv <= 50000) gmvFee = gmv * 0.025;
else if(gmv <= 200000) gmvFee = 50000 * 0.025 + (gmv - 50000) * 0.02;
else gmvFee = 50000 * 0.025 + 150000 * 0.02 + (gmv - 200000) * 0.015;
} else if(pKey === "growth"){
if(gmv <= 50000) gmvFee = gmv * 0.02;
else if(gmv <= 200000) gmvFee = 50000 * 0.02 + (gmv - 50000) * 0.015;
else gmvFee = 50000 * 0.02 + 150000 * 0.015 + (gmv - 200000) * 0.01;
} else {
gmvFee = gmv * 0.01;
}
const minMonthly = monthlyTrips * minRate;
const tripz = base + Math.max(minMonthly, gmvFee);
const commission = monthlyTrips * 0.10;
const floor = monthlyTrips * 0.05;
$("#rTripz").textContent = fmt(tripz);
$("#rComm").textContent = fmt(commission);
$("#rFloor").textContent = fmt(floor);
const save = Math.max(commission, floor) - tripz;
const bigEl = $("#saveBig");
bigEl.textContent = (save > 0 ? fmt(save * 12) : "$0") + "/yr";
const sv = $("#savings"); sv.classList.remove("bump"); void sv.offsetWidth; sv.classList.add("bump");
const pct = ((trips - 50) / (5000 - 50)) * 100;
$("#trips").style.setProperty("--p", pct + "%");
$("#tripsVal").textContent = trips.toLocaleString("en-US") + " / day";
const msg = encodeURIComponent(`Tripz — ${I18N[LANG]["calc.r.savecap"]}: ${bigEl.textContent} | ${trips}/day @ ${fare} ${curCode}`);
$("#waCalc").href = "https://wa.me/201023248456?text=" + msg;
}
/* ============ CALC INPUTS ============ */
["trips","fare","cur","plan"].forEach(id=>$("#"+id).addEventListener("input",calc));