import React, { useState } from 'react'
import ImageList from '@mui/material/ImageList'
import ImageListItem from '@mui/material/ImageListItem'
import { LmComponentRender } from '@LmComponentRender'
import { LmCoreComponents } from '@CONFIG'
import dynamic from 'next/dynamic'
import { useImageListStyles } from './useImageListStyles'
import { getLinkAttrs, LinkType } from '../../utils/linkHandler'
import { LmImageListProps } from './imageListTypes'
import { COLUMN_COUNT } from '../card/cardListStyles'
const ImageListLightbox = dynamic(() => import('./ImageListLightbox'))
export default function LmImageList({
content
}: LmImageListProps): JSX.Element {
const { classes, cx } = useImageListStyles()
const [lightbox, setLightbox] = useState('')
const gutterSize = content.column_gap ? Number(content.column_gap) : 2
const onImageClick = (element: any) => {
content.enable_lightbox && setLightbox(element._uid)
}
const body = content.body || []
const isMasonry = content.variant === 'masonry' || content.masonry
return (
span': {
height: '100%!important',
width: '100%!important'
}
},
...(!isMasonry
? {
gridTemplateColumns: {
xs: `repeat(${
content.column_count_phone ||
content.column_count ||
COLUMN_COUNT.PHONE
}, 1fr)!important`,
sm: `repeat(${
content.column_count_tablet ||
content.column_count ||
COLUMN_COUNT.TABLET
}, 1fr)!important`,
lg: `repeat(${
content.column_count || COLUMN_COUNT.DESKTOP
}, 1fr)!important`
}
}
: {
columnCount: {
xs: `${
content.column_count_phone ||
content.column_count ||
COLUMN_COUNT.PHONE_MASONRY
}!important`,
sm: `${
content.column_count_tablet ||
content.column_count ||
COLUMN_COUNT.TABLET
}!important`,
lg: `${
content.column_count || COLUMN_COUNT.DESKTOP
}!important`
}
})
}}
>
{body.map((item, i) => {
const btnProps: any =
item.link?.cached_url && !content.enable_lightbox
? {
...getLinkAttrs(item.link as LinkType, {
openExternal: !!item.open_external
}),
naked: true,
component: LmCoreComponents.lm_link_render
}
: {}
return (
onImageClick({ _uid: item._uid, count: i, ...ev })
}
>
)
})}
{lightbox && (
)}
)
}