const { SectionHead, Button, Field, ChipGroup, FormAlert, Icon } = window.CoolZoneSolutionDesignSystem_12e696; const PC_YEAR_KWH = { old: 140, mid: 100, new: 70 }; const PC_CURRENCY_BY_LANG = { it: 'EUR', de: 'EUR', 'de-ch': 'CHF', pl: 'PLN' }; const PC_FUEL_PRICES = { CHF: { oil: 0.135, gas: 0.115, electric: 0.29, pellet: 0.095 }, EUR: { oil: 0.12, gas: 0.11, electric: 0.32, pellet: 0.07 }, PLN: { oil: 0.60, gas: 0.40, electric: 0.90, pellet: 0.35 }, }; const PC_ELECTRICITY_PRICE = { CHF: 0.29, EUR: 0.32, PLN: 0.90 }; const PC_COP = 3.6; function ProjectCheck({ t, lang }) { const [building, setBuilding] = React.useState(null); const [area, setArea] = React.useState(140); const [year, setYear] = React.useState(null); const [fuel, setFuel] = React.useState(null); const [goal, setGoal] = React.useState(null); const [photo, setPhoto] = React.useState(null); const [contact, setContact] = React.useState({ name: '', email: '', phone: '', city: '' }); const [tried, setTried] = React.useState(false); const [status, setStatus] = React.useState('idle'); // idle | sending | sent | error const currency = PC_CURRENCY_BY_LANG[lang.toLowerCase()] || 'EUR'; const prices = PC_FUEL_PRICES[currency]; const fmt = (n) => n.toLocaleString('de-CH', { maximumFractionDigits: 0 }); const showSaving = goal && goal !== 'repair' && fuel && year; const demand = area * (PC_YEAR_KWH[year] || 100); const nowCost = fuel ? demand * prices[fuel] : 0; const pumpCost = (demand / PC_COP) * PC_ELECTRICITY_PRICE[currency]; const saving = Math.max(0, Math.round((nowCost - pumpCost) / 10) * 10); const bad = { name: !contact.name.trim(), email: !/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(contact.email), phone: contact.phone.trim().length < 6, }; const setC = (k) => (e) => setContact({ ...contact, [k]: e.target.value }); const onPhoto = (e) => { const f = e.target.files && e.target.files[0]; if (f) setPhoto(f); }; const submit = async (e) => { e.preventDefault(); setTried(true); if (Object.values(bad).some(Boolean)) return; setStatus('sending'); const fd = new FormData(); fd.append('name', contact.name); fd.append('email', contact.email); fd.append('phone', contact.phone); fd.append('objectType', building || ''); fd.append('area', String(area)); fd.append('currentSystem', fuel || ''); fd.append('timeline', goal || ''); fd.append('problems', '[]'); const noteParts = [`${t.pcCityLabel}: ${contact.city || '—'}`]; if (showSaving) noteParts.push(`${t.pcLiveSavingLabel}: ${currency} ${fmt(saving)} ${t.pcLivePerYear}`); fd.append('notes', noteParts.join(' — ')); if (photo) fd.append('photo', photo); try { const res = await fetch('/api/leads-api.php', { method: 'POST', body: fd }); setStatus(res.ok ? 'sent' : 'error'); } catch (err) { setStatus('error'); } }; if (status === 'sent') { return (
); } return (
({ value: b, label: b }))} value={building} onChange={setBuilding} /> ({ value: f.id, label: f.label }))} />
{t.pcPhotoTitle}

{t.pcPhotoNote}

{photo ? (
📷 {photo.name}
) : ( )}
{t.pcContactTitle}

{t.pcContactLead}

{status === 'error' &&

{t.pcErrorNote}

}

{t.pcLiveTitle}

{showSaving ? ( <>

{currency} {fmt(saving)}{t.pcLivePerYear}

) : goal === 'repair' ? (

{t.pcLiveRepairNote}

) : (

{t.pcLiveWaiting}

)}

{t.savDisclaimer}

); } Object.assign(window, { ProjectCheck });