import { useEffect, useMemo, useState } from 'react' const J = { 'Content-Type': 'application/json' } const slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/^_+|_+$/g, '').slice(0, 40) // What can be edited: fields per entry and the columns of the list const defs = (saved, attrs) => { const cats = (saved.equipment_categories || []).map((c) => [c.id, c.name]) const groups = (saved.skill_groups || []).map((g) => [g.id, g.name]) const skills = (saved.skills || []).map((s) => [s.id, s.name]) const name = (list, id) => (list.find(([k]) => k === id) || [])[1] || id return { equipment: { label: 'Items', noun: 'item', fields: [['name', 'Name', 'text'], ['cat', 'Category', 'select', cats], ['stat', 'Stat (damage, armor ...)', 'text'], ['tier', 'Tier (optional, e.g. light)', 'text'], ['kg', 'Weight (kg)', 'number'], ['note', 'Note', 'text'], ['placeholder', 'Placeholder (still open in the brainstorm)', 'bool']], blank: { cat: cats[0]?.[0] || '', stat: '', kg: 1, note: '' }, cols: [['Name', (e) => e.name], ['Category', (e) => name(cats, e.cat)], ['Stat', (e) => `${e.stat}${e.tier ? ` (${e.tier})` : ''}`], ['kg', (e) => e.kg]], }, equipment_categories: { label: 'Item categories', noun: 'category', fields: [['name', 'Name', 'text'], ['stat', 'Name of the stat column', 'text']], blank: { stat: '' }, cols: [['Name', (e) => e.name], ['Stat column', (e) => e.stat]], }, skills: { label: 'Skills', noun: 'skill', fields: [['name', 'Name', 'text'], ['group', 'Group', 'select', groups], ['type', 'Type', 'select', [['basic', 'Basic'], ['advanced', 'Advanced']]], ['attrs', 'Attributes (the higher one counts)', 'multi', attrs], ['desc', 'Description', 'textarea'], ['placeholder', 'Placeholder (still open in the brainstorm)', 'bool']], blank: { group: groups[0]?.[0] || '', type: 'basic', attrs: [], desc: '' }, cols: [['Name', (e) => e.name], ['Group', (e) => name(groups, e.group)], ['Type', (e) => e.type], ['Attributes', (e) => e.attrs.map((a) => name(attrs, a)).join(' / ')]], }, skill_groups: { label: 'Skill groups', noun: 'group', fields: [['name', 'Name', 'text']], blank: {}, cols: [['Name', (e) => e.name]], }, professions: { label: 'Professions', noun: 'profession', fields: [['name', 'Name', 'text'], ['desc', 'Description', 'textarea'], ['bonus_attrs', 'Attributes that can get the profession bonus', 'multi', attrs], ['proficiencies', 'Skills with fixed proficiency', 'multi', skills], ['picks', 'Free proficiency picks', 'number'], ['note', 'Note', 'text'], ['placeholder', 'Placeholder (still open in the brainstorm)', 'bool']], blank: { desc: '', bonus_attrs: [], proficiencies: [], picks: 0 }, cols: [['Name', (e) => e.name], ['Bonus', (e) => e.bonus_attrs.map((a) => name(attrs, a)).join(', ')], ['Proficiencies', (e) => e.proficiencies.map((s) => name(skills, s)).join(', ')], ['Picks', (e) => e.picks]], }, } } function Field({ f, value, onChange }) { const [key, label, type, opts] = f if (type === 'bool') return return (