function renderText(text) {
  if (!text.includes('**')) return text
  const parts = text.split(/(\*\*[^*]+\*\*)/)
  return parts.map((part, i) => {
    if (part.startsWith('**') && part.endsWith('**')) {
      return <strong key={i}>{part.slice(2, -2)}</strong>
    }
    return part
  })
}

export default function ServiceContentBlocks({ blocks }) {
  return (
    <>
      {blocks.map((block, i) => {
        switch (block.type) {
          case 'paragraph':
            return <p key={i}>{renderText(block.text)}</p>
          case 'heading':
            const Tag = `h${block.level}`
            return <Tag key={i}><strong>{block.text}</strong></Tag>
          case 'list':
            return (
              <ul key={i}>
                {block.items.map((item, j) => <li key={j}>{item}</li>)}
              </ul>
            )
          default:
            return null
        }
      })}
    </>
  )
}
