import { ArrowUpDown, Info, LogIn, Trash2 } from 'lucide-vue-next'; import DisplayName from '../../DisplayName.vue'; import Location from '../../Location.vue'; import LocationWorld from '../../LocationWorld.vue'; import { Button } from '../../ui/button'; import { i18n } from '../../../plugins'; import { formatDateFilter } from '../../../shared/utils'; const { t } = i18n.global; const sortButton = ({ column, label, descFirst = false }) => ( ); const resolveBool = (maybeRef) => { if (maybeRef && typeof maybeRef === 'object' && 'value' in maybeRef) { return !!maybeRef.value; } return !!maybeRef; }; const baseDateColumn = () => ({ id: 'created_at', accessorFn: (row) => (row?.created_at ? Date.parse(row.created_at) : 0), size: 170, header: ({ column }) => sortButton({ column, label: t('table.previous_instances.date'), descFirst: true }), cell: ({ row }) => {formatDateFilter(row.original?.created_at, 'long')} }); const timeColumn = () => ({ id: 'time', accessorFn: (row) => row?.time ?? 0, size: 100, header: ({ column }) => sortButton({ column, label: t('table.previous_instances.time') }), cell: ({ row }) => {row.original?.timer ?? ''} }); const actionsColumn = ({ shiftHeld, onShowInfo, onDelete, onDeletePrompt, onLaunch }) => ({ id: 'actions', enableSorting: false, size: onLaunch ? 140 : 120, header: () => t('table.previous_instances.action'), meta: { thClass: 'text-right', tdClass: 'text-right' }, cell: ({ row }) => { const original = row.original; const isShiftHeld = resolveBool(shiftHeld); return (
{onLaunch ? ( ) : null}
); } }); export const createPreviousInstancesColumns = (variant, config) => { if (variant === 'user') { return [ baseDateColumn(), { id: 'world', accessorFn: (row) => row?.worldName ?? row?.name ?? '', header: ({ column }) => sortButton({ column, label: t('table.previous_instances.world') }), meta: { stretch: true }, cell: ({ row }) => ( ) }, { id: 'creator', accessorFn: (row) => row?.$location?.userId ?? '', size: 170, header: () => t('table.previous_instances.instance_creator'), cell: ({ row }) => ( ) }, timeColumn(), actionsColumn({ shiftHeld: config.shiftHeld, onLaunch: config.onLaunch, onShowInfo: config.onShowInfo, onDelete: config.onDelete, onDeletePrompt: config.onDeletePrompt }) ]; } if (variant === 'world') { return [ baseDateColumn(), { id: 'instance', accessorFn: (row) => row?.$location?.tag ?? row?.location ?? '', header: () => t('table.previous_instances.instance_name'), meta: { stretch: true }, cell: ({ row }) => ( ) }, { id: 'creator', accessorFn: (row) => row?.$location?.userId ?? '', size: 170, header: () => t('table.previous_instances.instance_creator'), cell: ({ row }) => ( ) }, timeColumn(), actionsColumn({ shiftHeld: config.shiftHeld, onShowInfo: config.onShowInfo, onDelete: config.onDelete, onDeletePrompt: config.onDeletePrompt }) ]; } return [ baseDateColumn(), { id: 'instance', accessorFn: (row) => row?.worldName ?? row?.name ?? '', header: () => t('table.previous_instances.instance_name'), meta: { stretch: true }, cell: ({ row }) => ( ) }, timeColumn(), actionsColumn({ shiftHeld: config.shiftHeld, onShowInfo: config.onShowInfo, onDelete: config.onDelete, onDeletePrompt: config.onDeletePrompt }) ]; };