import React from 'react';

import { Card, CardPostData } from '@/components/Card';
import { cn } from '@/utilities/ui';

export type Props = {
  posts: CardPostData[];
  showImage?: boolean;
};

export const CollectionArchive: React.FC<Props> = (props) => {
  const { posts, showImage } = props;

  return (
    <div className={cn('container')}>
      <div>
        <div className='grid grid-cols-4 gap-x-4 gap-y-4 sm:grid-cols-8 lg:grid-cols-12 lg:gap-x-8 lg:gap-y-8 xl:gap-x-8'>
          {posts?.map((result, index) => {
            if (typeof result === 'object' && result !== null) {
              return (
                <div className='col-span-4' key={index}>
                  <Card className='h-full' doc={result} showCategories showImage={showImage} />
                </div>
              );
            }

            return null;
          })}
        </div>
      </div>
    </div>
  );
};
