'use client';

import { Database } from '@prisma/client';
import { ColumnDef } from '@tanstack/react-table';
import Image from 'next/image';
import { databaseProviders } from '@/lib/deploy/database-config';
import { cn } from '@/lib/utils';

interface IDatabase extends Pick<Database, 'id' | 'name' | 'provider' | 'createdAt'> {
	status: any;
}

export const columns: ColumnDef<IDatabase>[] = [
	{
		accessorKey: 'provider',
		header: 'Provider',
		cell(props) {
			return (
				<div className="flex items-center relative">
					<Image src={databaseProviders.filter((pro) => pro.id.toUpperCase() === props.getValue())[0]?.image?.src} alt={databaseProviders.filter((pro) => pro.id.toUpperCase() === props.getValue())[0]?.image?.alt} width={32} height={32} />
					<span className={cn('absolute bottom-0 left-8 w-2 h-2 rounded-full', props.row.original.status.status.phase == 'Running' ? 'bg-emerald-400' : 'bg-red-400')}></span>
				</div>
			);
		},
	},
	{
		accessorKey: 'name',
		header: 'Name',
	},
	{
		accessorKey: 'createdAt',
		header: 'Created',
		cell(props) {
			return <span>{new Date(props.getValue() as string).toLocaleDateString('en-US', { hour: '2-digit', minute: '2-digit' })}</span>;
		},
	},
];
