"use client" import { ColumnDef } from "@tanstack/react-table" import { Post } from "@/types/post" import { Button } from "@/components/ui/button" import { Edit, Trash, RotateCcw } from "lucide-react" interface PostColumnsProps { onEdit: (post: Post) => void onDelete: (id: number) => void onRestore: (id: number) => void statusFilter: string deletedIds: number[] } export const getPostColumns = ({ onEdit, onDelete, onRestore, statusFilter, deletedIds }: PostColumnsProps): ColumnDef[] => [ { accessorKey: "images", header: "Görsel", cell: ({ row }) => { const rawImages = row.original.images const apiUrl = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8080" // Backend tarafında "images" alanı virgülle ayrılmış birden fazla path içerebilir. // Liste görünümünde ilk path'i küçük görsel için kullanalım. const firstImage = rawImages ? rawImages .split(",") .map(p => p.trim()) .filter(Boolean)[0] : null const fullUrl = firstImage ? (firstImage.startsWith("http") ? firstImage : `${apiUrl}${firstImage}`) : null return (
{fullUrl ? ( // eslint-disable-next-line @next/next/no-img-element {row.original.title} ) : ( Yok )}
) }, }, { accessorKey: "title", header: "Başlık", }, { accessorKey: "categories", header: "Kategoriler", cell: ({ row }) => (
{row.original.categories?.map((cat, index) => ( {cat.title} ))}
), }, { accessorKey: "tags", header: "Etiketler", cell: ({ row }) => (
{row.original.tags?.map((tag, index) => ( {tag.name} ))}
), }, { accessorKey: "updated_at", header: "Son Güncelleme", cell: ({ row }) => { const updatedAt = row.original.updated_at || row.original.UpdatedAt return updatedAt ? new Date(updatedAt).toLocaleDateString("tr-TR") : "-" }, }, { id: "actions", cell: ({ row }) => { const id = row.original.id || row.original.ID const inDeletedList = typeof id === "number" && deletedIds.includes(id) // "Sadece Silinenler" filtresinde hepsi silinmiş kabul edilir. // "Tümü (Dahil)" filtresinde ise deletedIds listesine bakılır. const isDeleted = statusFilter === "only" || inDeletedList return (
{isDeleted ? ( ) : ( <> )}
) }, }, ]