---
import type { ConditionalWrapperProps } from './conditionalwrapper'

export type Props = ConditionalWrapperProps

const { condition } = Astro.props

const wrapper = await Astro.slots.render('wrapper')
const children = await Astro.slots.render('default')
const wrapped = wrapper?.replace('children', children)

if (!Astro.slots.has('wrapper')) {
    // eslint-disable-next-line no-console
    console.error('Missing wrapper. Add slot="wrapper" to one of the elements.')
}
---

<Fragment set:html={condition ? wrapped : children} />
