// heading — a section heading. `level` picks the tag (h1–h4), `text` is plain
// text (the renderer escapes it; no HTML here — use rich_text for markup).
const { registerBlock } = require('../registry')
const { oneOf, requiredText, onlyKeys } = require('../propHelpers')

const LEVELS = ['h1', 'h2', 'h3', 'h4']
const MAX_TEXT = 200

registerBlock({
  type: 'heading',
  version: 1,
  cacheTTL: null,
  schema(props) {
    const errors = onlyKeys(props, ['level', 'text'])
    const level = oneOf('level', LEVELS)(props.level)
    if (level) errors.push(level)
    const text = requiredText('text', props.text, MAX_TEXT)
    if (text) errors.push(text)
    return errors
  },
})
