// Council: manage award EVENTS and their CATEGORIES (add / amend / remove).
const AWARD_SETUP = (function () {
const COLORS = [
['var(--navy)', 'var(--navy)', 'Navy'],
['var(--ocean)', 'var(--navy)', 'Ocean'],
['var(--gold)', 'var(--gold-d)', 'Red'],
['var(--ok)', 'var(--ok)', 'Green'],
['var(--warn)', '#9c6a16', 'Amber'],
['var(--navy2)', 'var(--navy)', 'Royal'],
];
const ICONS = ['♛', '★', '◈', '♦', '✦', '◎', '✎', '❦', '◆', '▲'];
const uid = () => 'c_' + Math.random().toString(36).slice(2, 8);
function EventEditor({ item, onClose }) {
const { actions } = CTSCStore.useStore();
const [v, setV] = React.useState(item ? JSON.parse(JSON.stringify(item)) : { name: '', eyebrow: '', blurb: '', explainer: false, categories: [] });
const set = (k, val) => setV(s => ({ ...s, [k]: val }));
const setCat = (id, patch) => setV(s => ({ ...s, categories: s.categories.map(c => c.id === id ? { ...c, ...patch } : c) }));
const addCat = () => setV(s => ({ ...s, categories: [...s.categories, { id: uid(), name: '', desc: '', ic: '★', acc: 'var(--navy)', accD: 'var(--navy)' }] }));
const delCat = (id) => setV(s => ({ ...s, categories: s.categories.filter(c => c.id !== id) }));
const save = () => {
const payload = { ...v, categories: v.categories.filter(c => c.name.trim()) };
if (item) actions.updateItem('awardEvents', item.id, payload); else actions.addItem('awardEvents', payload);
onClose();
};
const valid = v.name.trim() && v.categories.some(c => c.name.trim());
return (
e.stopPropagation()} className="fade-in" style={{ background: '#fff', borderRadius: 14, width: 'min(640px,100%)', maxHeight: '90vh', overflow: 'auto', boxShadow: 'var(--shadow-lg)' }}>
{item ? 'Edit award event' : 'New award event'}
set('name', e.target.value)} placeholder="e.g. CTSC Sport Awards" />
{v.categories.length === 0 &&
No categories yet — add one.
}
{v.categories.map(c => (
{c.ic}
setCat(c.id, { name: e.target.value })} placeholder="Category name" style={{ flex: 1, fontFamily: 'inherit', fontSize: 14, fontWeight: 700, padding: '9px 12px', border: '1.5px solid var(--line)', borderRadius: 6, color: 'var(--navy)' }} />
))}
);
}
function AwardSetup() {
const { data, actions } = CTSCStore.useStore();
const events = data.awardEvents || [];
const [editing, setEditing] = React.useState(null);
const recCount = (evName, catName) => (data.awards || []).filter(a => a.event === evName && a.category === catName).length;
return (
Award setup
Add or amend award events and their categories. Changes appear on the public Awards page and in nomination forms.
{events.map(ev => (
{ev.name}
{ev.eyebrow} · {ev.categories.length} categories
{events.length > 1 && }
{ev.categories.map(c => (
{c.ic}
{c.name}
{recCount(ev.name, c.name)}
))}
))}
{editing &&
setEditing(null)} />}
);
}
return { AwardSetup };
})();
window.AwardSetup = AWARD_SETUP.AwardSetup;