2026-02-17 15:49:33 -05:00
|
|
|
---
|
2026-02-20 09:11:36 -05:00
|
|
|
import ebay from "/vendors/ebay.svg?raw";
|
2026-02-21 16:26:34 -05:00
|
|
|
import SetIcon from '../../components/SetIcon.astro';
|
|
|
|
|
import EnergyIcon from '../../components/EnergyIcon.astro';
|
|
|
|
|
import RarityIcon from '../../components/RarityIcon.astro';
|
2026-02-20 11:54:05 -05:00
|
|
|
import { db } from '../../db/index.ts';
|
2026-02-21 16:26:34 -05:00
|
|
|
import { privateDecrypt } from "node:crypto";
|
|
|
|
|
|
|
|
|
|
import latestSales from '../../sampleData/latestsales.json';
|
|
|
|
|
import chartdata from '../../sampleData/chartdata.json';
|
|
|
|
|
|
|
|
|
|
const priceData = chartdata;
|
2026-02-20 11:54:05 -05:00
|
|
|
|
|
|
|
|
export const partial = true;
|
|
|
|
|
export const prerender = false;
|
|
|
|
|
|
|
|
|
|
const searchParams = Astro.url.searchParams;
|
2026-02-23 19:05:55 -05:00
|
|
|
const cardId = Number(searchParams.get('cardId')) || 0;
|
2026-02-20 11:54:05 -05:00
|
|
|
|
2026-02-20 09:11:36 -05:00
|
|
|
|
2026-02-20 11:54:05 -05:00
|
|
|
// query the database for the card with the given productId and return the card data as json
|
|
|
|
|
const card = await db.query.cards.findFirst({
|
2026-02-23 19:05:55 -05:00
|
|
|
where: { cardId: Number(cardId) },
|
2026-02-20 11:54:05 -05:00
|
|
|
with: {
|
|
|
|
|
prices: true,
|
|
|
|
|
set: true,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-23 23:17:19 -05:00
|
|
|
const nearMint = card?.prices.find(price => price.condition === "Near Mint") || null;
|
2026-02-22 11:00:30 -05:00
|
|
|
const calculatedAt = new Date(nearMint?.calculatedAt || 0);
|
|
|
|
|
|
|
|
|
|
function timeAgo(date: any) {
|
|
|
|
|
if (date==0) return "never";
|
2026-02-21 16:26:34 -05:00
|
|
|
|
|
|
|
|
const seconds = Math.floor((Date.now() - date) / 1000);
|
|
|
|
|
|
|
|
|
|
const intervals = {
|
|
|
|
|
year: 31536000,
|
|
|
|
|
month: 2592000,
|
|
|
|
|
day: 86400,
|
|
|
|
|
hour: 3600,
|
|
|
|
|
minute: 60
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (const [unit, value] of Object.entries(intervals)) {
|
|
|
|
|
const count = Math.floor(seconds / value);
|
|
|
|
|
if (count >= 1) return `${count} ${unit}${count > 1 ? "s" : ""} ago`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "just now";
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 23:17:19 -05:00
|
|
|
const conditionOrder = ["Near Mint", "Lightly Played", "Moderately Played", "Heavily Played", "Damaged"];
|
|
|
|
|
|
|
|
|
|
const conditionAttributes = (price: any) => {
|
|
|
|
|
const volatility = (() => {
|
2026-02-24 09:14:06 -05:00
|
|
|
const current = price?.marketPrice;
|
2026-02-23 23:17:19 -05:00
|
|
|
const low = price?.lowestPrice;
|
|
|
|
|
const high = price?.highestPrice;
|
|
|
|
|
|
|
|
|
|
if (current === null || low === null || high === null) return "—";
|
|
|
|
|
|
|
|
|
|
const range = Number(high) - Number(low);
|
|
|
|
|
if (range <= 0) return "Low";
|
|
|
|
|
|
|
|
|
|
const position = (Number(current) - Number(low)) / range;
|
|
|
|
|
if (position > 0.75) return "High";
|
|
|
|
|
if (position > 0.46) return "Medium";
|
|
|
|
|
return "Low";
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
const volatilityClass =
|
|
|
|
|
volatility === "High" ? "alert-danger" :
|
|
|
|
|
volatility === "Medium" ? "alert-warning" :
|
|
|
|
|
volatility === "Low" ? "alert-success" :
|
|
|
|
|
"";
|
|
|
|
|
|
|
|
|
|
const condition: string = price?.condition || "Near Mint";
|
|
|
|
|
return {
|
|
|
|
|
"Near Mint": { label: "nav-nm", volatility: volatility, volatilityClass: volatilityClass, class:"show active" },
|
|
|
|
|
"Lightly Played": { label: "nav-lp", volatility: volatility, volatilityClass: volatilityClass },
|
|
|
|
|
"Moderately Played": { label: "nav-mp", volatility: volatility, volatilityClass: volatilityClass },
|
|
|
|
|
"Heavily Played": { label: "nav-hp", volatility: volatility, volatilityClass: volatilityClass },
|
|
|
|
|
"Damaged": { label: "nav-dmg", volatility: volatility, volatilityClass: volatilityClass},
|
|
|
|
|
}[condition];
|
|
|
|
|
};
|
2026-02-23 17:04:45 -05:00
|
|
|
|
2026-02-24 09:59:45 -05:00
|
|
|
const ebaySearchUrl = (card: any) => {
|
|
|
|
|
return `https://www.ebay.com/sch/i.html?_nkw=${encodeURIComponent(card?.productUrlName)}+${encodeURIComponent(card?.set?.setUrlName)}+${card?.number}&LH_Sold=1&Graded=No&_dcat=183454${card?.productId}`;
|
|
|
|
|
};
|
2026-02-20 11:54:05 -05:00
|
|
|
---
|
|
|
|
|
<div class="modal-dialog modal-dialog-centered modal-fullscreen-md-down modal-xl">
|
2026-02-20 09:11:36 -05:00
|
|
|
<div class="modal-dialog modal-dialog-centered modal-fullscreen-md-down modal-xl">
|
|
|
|
|
<div class="modal-content">
|
|
|
|
|
<div class="modal-header border-0">
|
2026-02-21 16:26:34 -05:00
|
|
|
<div class="container-fluid">
|
2026-02-23 23:17:19 -05:00
|
|
|
<span class="h4 card-title pe-2">{card?.productName}</span><span class="text-secondary ps-2 border-start">{card?.number}</span><span class="text-secondary ps-2">{card?.variant}</span>
|
2026-02-21 16:26:34 -05:00
|
|
|
</div>
|
2026-02-20 09:11:36 -05:00
|
|
|
<button type="button" class="btn-close" aria-label="Close" data-bs-dismiss="modal"></button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="modal-body pt-0">
|
|
|
|
|
<div class="container-fluid">
|
|
|
|
|
<div class="card mb-2 border-0">
|
|
|
|
|
<div class="row g-4">
|
|
|
|
|
<div class="col-sm-12 col-md-3">
|
2026-02-21 16:26:34 -05:00
|
|
|
<p class="text-secondary">{card?.set?.setName}</p>
|
2026-02-23 07:53:57 -05:00
|
|
|
<div class="position-relative d-inline-block"><img src={`/cards/${card?.productId}.jpg`} class="card-image img-fluid rounded" alt={card?.productName} onerror="this.onerror=null;this.src='/cards/noImage.webp'"><span class="position-absolute bottom-0 start-0 d-inline"><SetIcon set={card?.set?.setCode} /></span><span class="position-absolute top-0 end-0 d-inline"><EnergyIcon energy={card?.energyType} /></span><span class="rarity-icon-large position-absolute bottom-0 end-0 d-inline"><RarityIcon rarity={card?.rarityName} /></span></div>
|
2026-02-20 09:11:36 -05:00
|
|
|
<div class="d-flex flex-row justify-content-between mt-2">
|
2026-02-21 16:26:34 -05:00
|
|
|
<div class="p text-secondary">{card?.Artist}</div>
|
2026-02-20 09:11:36 -05:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-sm-12 col-md-7">
|
2026-02-24 12:36:19 -05:00
|
|
|
<ul class="nav nav-tabs nav-fill border-0 me-3" id="myTab" role="tablist">
|
2026-02-23 17:04:45 -05:00
|
|
|
<li class="nav-item" role="presentation">
|
|
|
|
|
<button class="nav-link nm active" id="nm-tab" data-bs-toggle="tab" data-bs-target="#nav-nm" type="button" role="tab" aria-controls="nav-nm" aria-selected="true"><span class="d-none d-md-inline">Near Mint</span><span class="d-md-none">NM</span></button>
|
|
|
|
|
</li>
|
|
|
|
|
<li class="nav-item" role="presentation">
|
|
|
|
|
<button class="nav-link lp" id="lp-tab" data-bs-toggle="tab" data-bs-target="#nav-lp" type="button" role="tab" aria-controls="nav-lp" aria-selected="false"><span class="d-none d-md-inline">Lightly Played</span><span class="d-md-none">LP</span></button>
|
|
|
|
|
</li>
|
|
|
|
|
<li class="nav-item" role="presentation">
|
|
|
|
|
<button class="nav-link mp" id="mp-tab" data-bs-toggle="tab" data-bs-target="#nav-mp" type="button" role="tab" aria-controls="nav-mp" aria-selected="false"><span class="d-none d-md-inline">Moderately Played</span><span class="d-md-none">MP</span></button>
|
|
|
|
|
</li>
|
|
|
|
|
<li class="nav-item" role="presentation">
|
|
|
|
|
<button class="nav-link hp" id="hp-tab" data-bs-toggle="tab" data-bs-target="#nav-hp" type="button" role="tab" aria-controls="nav-hp" aria-selected="false"><span class="d-none d-md-inline">Heavily Played</span><span class="d-md-none">HP</span></button>
|
|
|
|
|
</li>
|
|
|
|
|
<li class="nav-item" role="presentation">
|
|
|
|
|
<button class="nav-link dmg" id="dmg-tab" data-bs-toggle="tab" data-bs-target="#nav-dmg" type="button" role="tab" aria-controls="nav-dmg" aria-selected="false"><span class="d-none d-md-inline">Damaged</span><span class="d-md-none">DMG</span></button>
|
|
|
|
|
</li>
|
|
|
|
|
<li class="nav-item" role="presentation">
|
|
|
|
|
<button class="nav-link vendor" id="vendor-tab" data-bs-toggle="tab" data-bs-target="#nav-vendor" type="button" role="tab" aria-controls="nav-vendor" aria-selected="false"><span class="d-none d-md-inline">Inventory</span><span class="d-md-none">+/-</span></button>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<div class="tab-content" id="myTabContent">
|
2026-02-23 23:17:19 -05:00
|
|
|
{card?.prices.slice().sort((a, b) => conditionOrder.indexOf(a.condition) - conditionOrder.indexOf(b.condition)).map((price) => {
|
|
|
|
|
const attributes = conditionAttributes(price);
|
|
|
|
|
return (
|
|
|
|
|
<div class={`tab-pane fade ${attributes?.label} ${attributes?.class}`} id={`${attributes?.label}`} role="tabpanel" tabindex="0">
|
|
|
|
|
<div class="row g-2 mt-2">
|
2026-02-24 12:36:19 -05:00
|
|
|
<div class="row row-cols-4 row-cols-md-1 mt-2 col-12 col-md-2">
|
|
|
|
|
<div class="col alert alert-secondary rounded p-2 mb-2">
|
2026-02-23 23:17:19 -05:00
|
|
|
<h6>Market Price</h6>
|
|
|
|
|
<p>${price.marketPrice}</p>
|
|
|
|
|
</div>
|
2026-02-24 12:36:19 -05:00
|
|
|
<div class="col alert alert-secondary rounded p-2 mb-2">
|
2026-02-23 23:17:19 -05:00
|
|
|
<h6>Lowest Price</h6>
|
|
|
|
|
<p>${price.lowestPrice}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="alert alert-secondary rounded p-2 mb-2">
|
|
|
|
|
<h6>Highest Price</h6>
|
|
|
|
|
<p>${price.highestPrice}</p>
|
|
|
|
|
</div>
|
2026-02-24 12:36:19 -05:00
|
|
|
<div class={`col alert alert-secondary rounded p-2 mb-2 ${attributes?.volatilityClass}`}>
|
2026-02-23 23:17:19 -05:00
|
|
|
<h6>Volatility</h6>
|
|
|
|
|
<p>{attributes?.volatility}</p>
|
|
|
|
|
</div>
|
2026-02-24 12:36:19 -05:00
|
|
|
</div>
|
|
|
|
|
<div class="mt-2 col-12 col-md-10">
|
|
|
|
|
<div class="col-12 alert alert-secondary rounded p-2 mb-2">
|
2026-02-23 23:17:19 -05:00
|
|
|
<h6>Latest Sales</h6>
|
|
|
|
|
</div>
|
2026-02-24 12:36:19 -05:00
|
|
|
<div class="col-12 alert alert-secondary rounded mb-1 py-2 ">
|
2026-02-23 23:17:19 -05:00
|
|
|
<p class="h6">Placeholder for graph</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-24 12:36:19 -05:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-23 23:17:19 -05:00
|
|
|
);
|
|
|
|
|
})}
|
2026-02-23 17:04:45 -05:00
|
|
|
<div class="tab-pane fade" id="nav-vendor" role="tabpanel" aria-labelledby="nav-vendor" tabindex="0">
|
|
|
|
|
<div class="row g-2 mt-2">
|
2026-02-24 12:36:19 -05:00
|
|
|
|
2026-02-23 17:04:45 -05:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-20 09:11:36 -05:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-sm-12 col-md-2 mt-0 mt-md-5">
|
2026-02-21 16:26:34 -05:00
|
|
|
<a class="btn btn-secondary mb-2 w-100" href={`https://www.tcgplayer.com/product/${card?.productId}`} target="_blank"><img src="/vendors/tcgplayer.webp"> TCGPlayer</a>
|
2026-02-24 09:59:45 -05:00
|
|
|
<a class="btn btn-secondary mb-2 w-100" href={`${ebaySearchUrl(card)}`} target="_blank"><span set:html={ebay} /></a>
|
2026-02-20 09:11:36 -05:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-21 16:26:34 -05:00
|
|
|
<div class="text-end my-0"><small class="text-body-secondary">Prices last updated: {timeAgo(calculatedAt)}</small></div>
|
2026-02-20 09:11:36 -05:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|