import {Entity, EntityLocale, type Lang} from '@prisma/client'
import {useLocale} from 'next-intl'

import {getBlockEntity} from '@/actions/admin/entity'
import {
	Accordion,
	AccordionContent,
	AccordionItem,
	AccordionTrigger
} from '@/components/ui/accordion'
import {locales} from '@/i18n/routing'
import {EntityTerm} from '@/lib/schemas/admin/entity'
import {dump, thisLocale} from '@/lib/utils'

export default async function Terms() {
	const locale = useLocale()
	const terms = await getBlockEntity('terms')

	return (
		<section className='container mb-4 mt-12'>
			{/*<pre>{dump(terms)}</pre>*/}
			<div className='bw-terms-section mx-auto max-w-[1080px]'>
				<Accordion
					type='single'
					collapsible
					className='flex w-full flex-wrap justify-between gap-y-4'
				>
					{terms.map(async (term: any, index: number) => {
						const {locales} = term
						const locale: EntityLocale = await thisLocale(locales)

						const {title, body} = locale
						return (
							<AccordionItem
								key={index}
								value={`item-${index}`}
								className='bw-accordion-item'
							>
								<AccordionTrigger className='bw-accordion-trigger'>
									<div className='flex-grow'>{title}</div>
								</AccordionTrigger>
								<AccordionContent className='bw-accordion-content'>
									<span
										dangerouslySetInnerHTML={{__html: body as string}}
									></span>
								</AccordionContent>
							</AccordionItem>
						)
					})}
					{/*<div className='bw-accordion-item table-cell'></div>*/}
				</Accordion>
			</div>
		</section>
	)
}
