KSA-ORACLE/resources/js/utils/resolveCardImage.ts
2026-05-28 13:28:13 +03:00

24 lines
685 B
TypeScript

import type { Card } from '@/types/cart';
export function resolveCardImage(card: Pick<Card, 'id' | 'asset_id' | 'image_url'>, fallbackIndex?: number): string {
if (card.image_url) {
return card.image_url;
}
if (typeof card.asset_id === 'number' && Number.isInteger(card.asset_id) && card.asset_id > 0) {
return `/cards/${card.asset_id + 1}.png`;
}
const numericId = Number(card.id);
if (Number.isInteger(numericId) && numericId > 0) {
return `/cards/${numericId + 1}.png`;
}
if (typeof fallbackIndex === 'number' && fallbackIndex >= 0) {
return `/cards/${fallbackIndex + 2}.png`;
}
return '/cards/2.png';
}