/* ============================================================ KODILA — Šifrant: Države ============================================================ */ const COUNTRY_STATUS_LABEL = { active: 'Aktivna', inactive: 'Nedejavna' }; function countryStatusRenderer(p) { const label = COUNTRY_STATUS_LABEL[p.value] || p.value; const cls = (window.STATUS_MAP[label] || 'default'); const c = cls === 'default' ? '' : cls; return `${label}`; } function countryEuRenderer(p) { return p.value ? `Da` : `Ne`; } const COUNTRY_COLS = [ { field: 'id', headerName: 'ID', width: 70, cellClass: 'cell-mono', pinned: 'left' }, { field: 'code', headerName: 'Oznaka', width: 100, cellClass: 'cell-mono cell-strong' }, { field: 'name', headerName: 'Ime', flex: 2, minWidth: 200 }, { field: 'currencyCode', headerName: 'Valuta', width: 160, valueFormatter: p => p.data.currencyCode ? `${p.data.currencyCode} — ${p.data.currencyName}` : '—', }, { field: 'isEu', headerName: 'Članica EU', width: 130, cellRenderer: countryEuRenderer }, { field: 'status', headerName: 'Status', width: 130, cellRenderer: countryStatusRenderer }, ]; const EMPTY_COUNTRY = { id: null, code: '', name: '', currencyId: '', isEu: false, status: 'active' }; const COUNTRY_ERROR_MESSAGES = { code: { required: 'Oznaka države je obvezna.', invalid: 'Oznaka mora biti sestavljena iz 2 črk (ISO 3166-1, npr. SI).', taken: 'Ta oznaka države že obstaja.', }, name: { required: 'Ime države je obvezno.' }, currencyId: { invalid: 'Izbrana valuta ne obstaja.' }, }; function DrzavaForm({ initial, currencies, onSave, onClose }) { const isEdit = !!(initial && initial.id); const [f, setF] = useState(initial && initial.id ? { ...EMPTY_COUNTRY, ...initial, currencyId: initial.currencyId != null ? String(initial.currencyId) : '' } : { ...EMPTY_COUNTRY }); const [errors, setErrors] = useState({}); const [saving, setSaving] = useState(false); const set = (k, v) => setF(s => ({ ...s, [k]: v })); const save = async () => { setSaving(true); const payload = { code: f.code.trim().toUpperCase(), name: f.name.trim(), currencyId: f.currencyId === '' ? null : Number(f.currencyId), isEu: !!f.isEu, status: f.status, }; const ok = await onSave(f.id, payload, isEdit, setErrors); setSaving(false); if (ok) onClose(); }; const fieldError = (field) => { const codes = errors[field]; if (!codes || !codes.length) return null; const map = COUNTRY_ERROR_MESSAGES[field] || {}; return codes.map(c => map[c] || c).join(' '); }; return (