// WealthIntelligence — Dashboard page
const HomePage = ({state, t, setRoute, openCassettaEditor, openItemDetail, openPersonDetail}) => {
const unassignedItems = state.inventory.filter(it => !state.cassette.some(c => c.itemIds.includes(it.id)));
const activeTemporary = state.temporaryIllness?.active;
// Total wealth
const valuedItems = state.inventory.filter(it => typeof it.valueEur === 'number' && it.valueEur > 0);
const totalEur = valuedItems.reduce((s, it) => s + it.valueEur, 0);
const byCategory = {};
valuedItems.forEach(it => { byCategory[it.category] = (byCategory[it.category] || 0) + it.valueEur; });
const sortedCats = Object.entries(byCategory).sort((a,b) => b[1] - a[1]);
const topCats = sortedCats.slice(0, 4);
const otherSum = sortedCats.slice(4).reduce((s, [,v]) => s + v, 0);
const suggestions = [
{
id:'cassetta', icon:'vault', tone:'accent',
title: t.home.action_create_cassetta, desc: t.home.action_create_cassetta_desc,
action: () => openCassettaEditor(),
},
{
id:'person', icon:'people', tone:'paper',
title: t.home.action_add_person, desc: t.home.action_add_person_desc,
action: () => setRoute('trustworthy'),
},
{
id:'inventory', icon:'inventory', tone:'paper',
title: t.home.action_complete_inventory, desc: t.home.action_complete_inventory_desc,
action: () => setRoute('inventory'),
},
];
const recentCassette = state.cassette.slice(0, 3);
const peopleTop = state.people.slice(0, 5);
return
{/* Hero: greeting + total-wealth card */}
{t.home.greeting_day}, {state.user.name.split(' ')[0]}
{t.home.hero_title_1}
{t.home.hero_title_2}
{t.home.hero_sub}
{/* Total wealth card */}
{t.home.total_wealth}
{fmtEur(totalEur)}
{t.home.total_wealth_sub
.replace('{valued}', valuedItems.length)
.replace('{total}', state.inventory.length)}
{t.home.breakdown}
{topCats.map(([cat, sum]) => {
const pct = Math.round((sum / totalEur) * 100);
return
{t.inventory.cat[cat] || cat}
{fmtEur(sum)} · {pct}%
;
})}
{otherSum > 0 && (
Altre categorie
{fmtEur(otherSum)} · {Math.round((otherSum/totalEur)*100)}%
)}
{/* KPI strip */}
{/* Active temporary illness banner */}
{activeTemporary && (
Modalità infermità temporanea attiva
Le cassette con trigger "infermità temporanea" sono accessibili alle persone fidate. Disattiva quando torni operativo.
)}
{/* Suggestions */}
{suggestions.map(s => (
{s.title}
{s.desc}
{t.common.continue}
))}
{/* Recent cassette */}
{recentCassette.length > 0 && (
setRoute('vault')}>{t.home.see_all}}
/>
{recentCassette.map(c => {
const assigned = c.assignees.map(id => state.people.find(p=>p.id===id)).filter(Boolean);
return
openCassettaEditor(c)}>
{c.name}
{c.itemIds.length} {c.itemIds.length===1?t.vault.item_count_one:t.vault.items_count}
;
})}
)}
{/* Trustworthy people preview */}
setRoute('trustworthy')}>{t.home.see_all}}
/>
{peopleTop.map(p => {
const cassetteCount = state.cassette.filter(c => c.assignees.includes(p.id)).length;
return
openPersonDetail && openPersonDetail(p)}>
{p.name.split(' ')[0]}
{p.rel}
{cassetteCount} {cassetteCount===1 ? t.trustworthy.cassetta_assigned_one : t.trustworthy.cassette_assigned}
;
})}
;
};
Object.assign(window, { HomePage });