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-28 10:19:40 -05:00
|
|
|
import { db } from '../../db/index';
|
2026-03-16 11:05:10 -04:00
|
|
|
import { priceHistory, skus } from '../../db/schema';
|
|
|
|
|
import { eq, inArray } from 'drizzle-orm';
|
2026-03-09 12:00:29 -04:00
|
|
|
import FirstEditionIcon from "../../components/FirstEditionIcon.astro";
|
2026-02-21 16:26:34 -05:00
|
|
|
|
2026-03-16 14:07:37 -04:00
|
|
|
import { Tooltip } from "bootstrap";
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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: {
|
2026-03-16 11:05:10 -04:00
|
|
|
prices: true,
|
2026-02-20 11:54:05 -05:00
|
|
|
set: true,
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-25 14:12:11 -05:00
|
|
|
function timeAgo(date: Date | null) {
|
|
|
|
|
if (!date) return "Not applicable";
|
|
|
|
|
const seconds = Math.floor((Date.now() - date.getTime()) / 1000);
|
|
|
|
|
const intervals: Record<string, number> = {
|
2026-02-21 16:26:34 -05:00
|
|
|
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-25 14:12:11 -05:00
|
|
|
const calculatedAt = (() => {
|
|
|
|
|
if (!card?.prices?.length) return null;
|
|
|
|
|
const dates = card.prices
|
|
|
|
|
.map(p => p.calculatedAt)
|
2026-03-16 08:39:06 -04:00
|
|
|
.filter(d => d)
|
2026-02-25 14:12:11 -05:00
|
|
|
.map(d => new Date(d));
|
|
|
|
|
if (!dates.length) return null;
|
|
|
|
|
return new Date(Math.max(...dates.map(d => d.getTime())));
|
|
|
|
|
})();
|
|
|
|
|
|
2026-03-16 11:05:10 -04:00
|
|
|
// ── Fetch price history + compute volatility ──────────────────────────────
|
|
|
|
|
const cardSkus = card?.prices?.length
|
|
|
|
|
? await db.select().from(skus).where(eq(skus.cardId, cardId))
|
|
|
|
|
: [];
|
|
|
|
|
|
|
|
|
|
const skuIds = cardSkus.map(s => s.skuId);
|
|
|
|
|
|
|
|
|
|
const historyRows = skuIds.length
|
|
|
|
|
? await db
|
|
|
|
|
.select({
|
|
|
|
|
skuId: priceHistory.skuId,
|
|
|
|
|
calculatedAt: priceHistory.calculatedAt,
|
|
|
|
|
marketPrice: priceHistory.marketPrice,
|
|
|
|
|
condition: skus.condition,
|
|
|
|
|
})
|
|
|
|
|
.from(priceHistory)
|
|
|
|
|
.innerJoin(skus, eq(priceHistory.skuId, skus.skuId))
|
|
|
|
|
.where(inArray(priceHistory.skuId, skuIds))
|
|
|
|
|
.orderBy(priceHistory.calculatedAt)
|
|
|
|
|
: [];
|
|
|
|
|
|
|
|
|
|
// Rolling 30-day cutoff for volatility calculation
|
|
|
|
|
const thirtyDaysAgo = new Date(Date.now() - 30 * 86_400_000);
|
|
|
|
|
|
|
|
|
|
const byCondition: Record<string, number[]> = {};
|
|
|
|
|
for (const row of historyRows) {
|
|
|
|
|
if (row.marketPrice == null) continue;
|
|
|
|
|
if (!row.calculatedAt) continue;
|
|
|
|
|
if (new Date(row.calculatedAt) < thirtyDaysAgo) continue;
|
|
|
|
|
const price = Number(row.marketPrice);
|
|
|
|
|
if (price <= 0) continue;
|
|
|
|
|
if (!byCondition[row.condition]) byCondition[row.condition] = [];
|
|
|
|
|
byCondition[row.condition].push(price);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function computeVolatility(prices: number[]): { label: string; monthlyVol: number } {
|
|
|
|
|
if (prices.length < 2) return { label: '—', monthlyVol: 0 };
|
|
|
|
|
const returns: number[] = [];
|
|
|
|
|
for (let i = 1; i < prices.length; i++) {
|
|
|
|
|
returns.push(Math.log(prices[i] / prices[i - 1]));
|
|
|
|
|
}
|
|
|
|
|
const mean = returns.reduce((a, b) => a + b, 0) / returns.length;
|
|
|
|
|
const variance = returns.reduce((sum, r) => sum + (r - mean) ** 2, 0) / (returns.length - 1);
|
|
|
|
|
const monthlyVol = Math.sqrt(variance) * Math.sqrt(30);
|
|
|
|
|
const label = monthlyVol >= 0.30 ? 'High'
|
|
|
|
|
: monthlyVol >= 0.15 ? 'Medium'
|
|
|
|
|
: 'Low';
|
|
|
|
|
return { label, monthlyVol: Math.round(monthlyVol * 100) / 100 };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const volatilityByCondition: Record<string, { label: string; monthlyVol: number }> = {};
|
|
|
|
|
for (const [condition, prices] of Object.entries(byCondition)) {
|
|
|
|
|
volatilityByCondition[condition] = computeVolatility(prices);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ── Price history for chart (full history, not windowed) ──────────────────
|
|
|
|
|
const priceHistoryForChart = historyRows.map(row => ({
|
|
|
|
|
condition: row.condition,
|
|
|
|
|
calculatedAt: row.calculatedAt
|
|
|
|
|
? new Date(row.calculatedAt).toISOString().split('T')[0]
|
|
|
|
|
: null,
|
|
|
|
|
marketPrice: row.marketPrice,
|
|
|
|
|
})).filter(r => r.calculatedAt !== null);
|
|
|
|
|
|
|
|
|
|
// ── Determine which range buttons to show ────────────────────────────────
|
|
|
|
|
const now = Date.now();
|
|
|
|
|
const oldestDate = historyRows.length
|
|
|
|
|
? Math.min(...historyRows
|
|
|
|
|
.filter(r => r.calculatedAt)
|
|
|
|
|
.map(r => new Date(r.calculatedAt!).getTime()))
|
|
|
|
|
: now;
|
|
|
|
|
|
|
|
|
|
const dataSpanDays = (now - oldestDate) / 86_400_000;
|
|
|
|
|
|
|
|
|
|
const showRanges = {
|
|
|
|
|
'1m': dataSpanDays >= 1,
|
2026-03-16 14:07:37 -04:00
|
|
|
'3m': dataSpanDays >= 60,
|
|
|
|
|
'6m': dataSpanDays >= 180,
|
|
|
|
|
'1y': dataSpanDays >= 365,
|
|
|
|
|
'all': dataSpanDays >= 400,
|
2026-03-16 11:05:10 -04:00
|
|
|
};
|
2026-03-16 08:39:06 -04:00
|
|
|
|
2026-02-23 23:17:19 -05:00
|
|
|
const conditionOrder = ["Near Mint", "Lightly Played", "Moderately Played", "Heavily Played", "Damaged"];
|
|
|
|
|
|
|
|
|
|
const conditionAttributes = (price: any) => {
|
2026-03-16 11:05:10 -04:00
|
|
|
const condition: string = price?.condition || "Near Mint";
|
|
|
|
|
const vol = volatilityByCondition[condition] ?? { label: '—', monthlyVol: 0 };
|
2026-02-23 23:17:19 -05:00
|
|
|
|
2026-03-09 12:00:29 -04:00
|
|
|
const volatilityClass = (() => {
|
2026-03-16 11:05:10 -04:00
|
|
|
switch (vol.label) {
|
|
|
|
|
case "High": return "alert-danger";
|
|
|
|
|
case "Medium": return "alert-warning";
|
|
|
|
|
case "Low": return "alert-success";
|
|
|
|
|
default: return "alert-dark";
|
2026-03-09 12:00:29 -04:00
|
|
|
}
|
|
|
|
|
})();
|
2026-02-23 23:17:19 -05:00
|
|
|
|
2026-03-16 11:05:10 -04:00
|
|
|
const volatilityDisplay = vol.label === '—'
|
|
|
|
|
? '—'
|
|
|
|
|
: `${vol.label} (${(vol.monthlyVol * 100).toFixed(0)}%)`;
|
2026-03-09 12:00:29 -04:00
|
|
|
|
2026-02-23 23:17:19 -05:00
|
|
|
return {
|
2026-03-16 11:05:10 -04:00
|
|
|
"Near Mint": { label: "nav-nm", volatility: volatilityDisplay, volatilityClass, class: "show active" },
|
|
|
|
|
"Lightly Played": { label: "nav-lp", volatility: volatilityDisplay, volatilityClass },
|
|
|
|
|
"Moderately Played":{ label: "nav-mp", volatility: volatilityDisplay, volatilityClass },
|
|
|
|
|
"Heavily Played": { label: "nav-hp", volatility: volatilityDisplay, volatilityClass },
|
|
|
|
|
"Damaged": { label: "nav-dmg", volatility: volatilityDisplay, volatilityClass }
|
2026-02-23 23:17:19 -05:00
|
|
|
}[condition];
|
|
|
|
|
};
|
2026-02-23 17:04:45 -05:00
|
|
|
|
2026-02-24 09:59:45 -05:00
|
|
|
const ebaySearchUrl = (card: any) => {
|
2026-03-02 14:09:59 -05:00
|
|
|
return `https://www.ebay.com/sch/i.html?_nkw=${encodeURIComponent(card?.productUrlName)}+${encodeURIComponent(card?.set?.setUrlName)}+${encodeURIComponent(card?.number)}&LH_Sold=1&Graded=No&_dcat=183454`;
|
2026-02-24 09:59:45 -05:00
|
|
|
};
|
2026-03-11 15:21:43 -04:00
|
|
|
|
|
|
|
|
const altSearchUrl = (card: any) => {
|
|
|
|
|
return `https://alt.xyz/browse?query=${encodeURIComponent(card?.productUrlName)}+${encodeURIComponent(card?.set?.setUrlName)}+${encodeURIComponent(card?.number)}&sortBy=newest_first`;
|
|
|
|
|
};
|
2026-02-20 11:54:05 -05:00
|
|
|
---
|
2026-02-25 14:12:11 -05:00
|
|
|
|
2026-02-20 09:11:36 -05:00
|
|
|
<div class="modal-dialog modal-dialog-centered modal-fullscreen-md-down modal-xl">
|
2026-03-06 13:53:15 -05:00
|
|
|
<div class="modal-content" data-card-id={card?.cardId}>
|
2026-02-20 09:11:36 -05:00
|
|
|
<div class="modal-header border-0">
|
2026-02-28 20:47:32 -05:00
|
|
|
<div class="container-fluid row align-items-center">
|
2026-03-16 08:39:06 -04:00
|
|
|
<div class="h4 card-title pe-2 col-sm-12 col-md-auto mb-sm-1">{card?.productName}</div>
|
|
|
|
|
<div class="text-secondary col-auto">{card?.number}</div>
|
|
|
|
|
<div class="text-light col-auto">{card?.variant}</div>
|
2026-02-21 16:26:34 -05:00
|
|
|
</div>
|
2026-03-06 13:53:15 -05:00
|
|
|
<div class="d-flex gap-2 align-items-center">
|
|
|
|
|
<button type="button" class="btn-close" aria-label="Close" data-bs-dismiss="modal"></button>
|
|
|
|
|
</div>
|
2026-03-16 08:39:06 -04:00
|
|
|
</div>
|
|
|
|
|
<div class="modal-body pt-0">
|
2026-02-20 09:11:36 -05:00
|
|
|
<div class="container-fluid">
|
2026-03-16 08:39:06 -04:00
|
|
|
<div class="card mb-2 border-0">
|
2026-02-20 09:11:36 -05:00
|
|
|
<div class="row g-4">
|
2026-03-16 08:39:06 -04:00
|
|
|
|
|
|
|
|
<!-- Card image column -->
|
|
|
|
|
<div class="col-sm-12 col-md-3">
|
|
|
|
|
<div class="position-relative mt-1">
|
2026-03-18 13:31:56 -04:00
|
|
|
|
|
|
|
|
<!-- card-image-wrap gives the modal image shimmer effects
|
|
|
|
|
without the hover lift/scale that image-grow has in main.scss -->
|
|
|
|
|
<div
|
|
|
|
|
class="card-image-wrap rounded-4"
|
|
|
|
|
data-energy={card?.energyType}
|
|
|
|
|
data-rarity={card?.rarityName}
|
|
|
|
|
data-variant={card?.variant}
|
|
|
|
|
data-name={card?.productName}
|
|
|
|
|
>
|
|
|
|
|
<img
|
|
|
|
|
src={`/cards/${card?.productId}.jpg`}
|
|
|
|
|
class="card-image w-100 img-fluid rounded-4"
|
|
|
|
|
alt={card?.productName}
|
|
|
|
|
crossorigin="anonymous"
|
|
|
|
|
onerror="this.onerror=null; this.src='/cards/default.jpg'; this.closest('.image-grow, .card-image-wrap')?.setAttribute('data-default','true')"
|
|
|
|
|
onclick="copyImage(this); dataLayer.push({'event': 'copiedImage'});"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-03-16 08:39:06 -04:00
|
|
|
<span class="position-absolute top-50 start-0 d-inline"><FirstEditionIcon edition={card?.variant} /></span>
|
|
|
|
|
<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>
|
|
|
|
|
<div class="d-flex flex-column flex-lg-row justify-content-between mt-2">
|
|
|
|
|
<div class="text-secondary">{card?.set?.setCode}</div>
|
|
|
|
|
<div class="text-secondary">Illus<span class="d-none d-lg-inline">trator</span>: {card?.artist}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- Tabs + price data column -->
|
|
|
|
|
<div class="col-sm-12 col-md-7">
|
|
|
|
|
<ul class="nav nav-tabs nav-fill border-0 me-3 mb-2" id="myTab" role="tablist">
|
|
|
|
|
<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">
|
2026-03-25 08:41:21 -04:00
|
|
|
<span class="d-none">Near Mint</span><span class="d-inline">NM</span>
|
2026-03-16 08:39:06 -04:00
|
|
|
</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">
|
2026-03-25 08:41:21 -04:00
|
|
|
<span class="d-none">Lightly Played</span><span class="d-inline">LP</span>
|
2026-03-16 08:39:06 -04:00
|
|
|
</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">
|
2026-03-25 08:41:21 -04:00
|
|
|
<span class="d-none">Moderately Played</span><span class="d-inline">MP</span>
|
2026-03-16 08:39:06 -04:00
|
|
|
</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">
|
2026-03-25 08:41:21 -04:00
|
|
|
<span class="d-none">Heavily Played</span><span class="d-inline">HP</span>
|
2026-03-16 08:39:06 -04:00
|
|
|
</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">
|
2026-03-25 08:41:21 -04:00
|
|
|
<span class="d-none">Damaged</span><span class="d-inline">DMG</span>
|
2026-03-16 08:39:06 -04:00
|
|
|
</button>
|
|
|
|
|
</li>
|
|
|
|
|
<li class="nav-item" role="presentation">
|
2026-03-25 08:41:21 -04:00
|
|
|
<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">
|
2026-03-16 11:05:10 -04:00
|
|
|
<span class="d-none d-xxl-inline">Inventory</span><span class="d-xxl-none">+/-</span>
|
2026-03-16 08:39:06 -04:00
|
|
|
</button>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
<div class="tab-content" id="myTabContent">
|
|
|
|
|
{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">
|
2026-03-16 11:05:10 -04:00
|
|
|
<div class="d-flex flex-column gap-1">
|
|
|
|
|
|
|
|
|
|
<!-- Stat cards -->
|
2026-03-16 14:07:37 -04:00
|
|
|
<div class="d-flex flex-fill flex-row gap-1">
|
|
|
|
|
<div class="alert alert-dark rounded p-2 flex-fill d-flex flex-column mb-0">
|
|
|
|
|
<h6 class="mb-auto">Market Price</h6>
|
|
|
|
|
<p class="mb-0 mt-1">${price.marketPrice}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="alert alert-dark rounded p-2 flex-fill d-flex flex-column mb-0">
|
|
|
|
|
<h6 class="mb-auto">Lowest Price</h6>
|
|
|
|
|
<p class="mb-0 mt-1">${price.lowestPrice}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="alert alert-dark rounded p-2 flex-fill d-flex flex-column mb-0">
|
|
|
|
|
<h6 class="mb-auto">Highest Price</h6>
|
|
|
|
|
<p class="mb-0 mt-1">${price.highestPrice}</p>
|
2026-03-16 11:05:10 -04:00
|
|
|
</div>
|
2026-03-16 14:07:37 -04:00
|
|
|
<div class={`alert rounded p-2 flex-fill d-flex flex-column mb-0 ${attributes?.volatilityClass}`}>
|
|
|
|
|
<h6 class="mb-auto d-flex justify-content-between align-items-start">
|
2026-03-18 13:31:56 -04:00
|
|
|
<span class="me-1">Volatility</span>
|
2026-03-16 14:07:37 -04:00
|
|
|
<span
|
2026-03-18 13:31:56 -04:00
|
|
|
class="volatility-info float-end mt-0"
|
2026-03-16 14:07:37 -04:00
|
|
|
data-bs-toggle="tooltip"
|
|
|
|
|
data-bs-placement="top"
|
|
|
|
|
data-bs-container="body"
|
|
|
|
|
data-bs-custom-class="volatility-popover"
|
|
|
|
|
data-bs-trigger="hover focus click"
|
|
|
|
|
data-bs-html="true"
|
|
|
|
|
data-bs-title={`
|
|
|
|
|
<div class='tooltip-heading fw-bold mb-1'>Monthly Volatility</div>
|
|
|
|
|
<div class='small'>
|
|
|
|
|
<p class="mb-1">
|
|
|
|
|
<strong>What this measures:</strong> how much the market price tends to move day-to-day,
|
|
|
|
|
scaled up to a monthly expectation.
|
|
|
|
|
</p>
|
|
|
|
|
<p class="mb-0">
|
|
|
|
|
A card with <strong>30% volatility</strong> typically swings ±30% over a month.
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
`}
|
|
|
|
|
>
|
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="13" height="13" fill="currentColor" viewBox="0 0 16 16"> <path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z"/> <path d="m8.93 6.588-2.29.287-.082.38.45.083c.294.07.352.176.288.469l-.738 3.468c-.194.897.105 1.319.808 1.319.545 0 1.178-.252 1.465-.598l.088-.416c-.2.176-.492.246-.686.246-.275 0-.375-.193-.304-.533L8.93 6.588zM9 4.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0z"/> </svg>
|
|
|
|
|
</span>
|
|
|
|
|
</h6>
|
|
|
|
|
<p class="mb-0 mt-1">{attributes?.volatility}</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-16 11:05:10 -04:00
|
|
|
|
|
|
|
|
<!-- Table only — chart is outside the tab panes -->
|
|
|
|
|
<div class="w-100">
|
|
|
|
|
<div class="alert alert-dark rounded p-2 mb-0 table-responsive">
|
|
|
|
|
<h6>Latest Verified Sales</h6>
|
|
|
|
|
<table class="table table-sm mb-0">
|
|
|
|
|
<caption class="small">Filtered to remove mismatched language variants</caption>
|
|
|
|
|
<thead class="table-dark">
|
|
|
|
|
<tr>
|
|
|
|
|
<th scope="col">Date</th>
|
|
|
|
|
<th scope="col">Title</th>
|
|
|
|
|
<th scope="col">Price</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
<tr><td> </td><td> </td><td> </td></tr>
|
|
|
|
|
<tr><td> </td><td> </td><td> </td></tr>
|
|
|
|
|
<tr><td> </td><td> </td><td> </td></tr>
|
|
|
|
|
<tr><td> </td><td> </td><td> </td></tr>
|
|
|
|
|
<tr><td> </td><td> </td><td> </td></tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
2026-03-16 08:39:06 -04:00
|
|
|
</div>
|
2026-03-16 11:05:10 -04:00
|
|
|
|
2026-03-16 08:39:06 -04:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
|
2026-03-25 08:41:21 -04:00
|
|
|
<div class="tab-pane fade" id="nav-vendor" role="tabpanel" aria-labelledby="nav-vendor" tabindex="0">
|
|
|
|
|
<style>
|
|
|
|
|
:root {
|
|
|
|
|
--c-nm: 156, 204, 102;
|
|
|
|
|
--c-lp: 211, 225, 86;
|
|
|
|
|
--c-mp: 255, 238, 87;
|
|
|
|
|
--c-hp: 255, 201, 41;
|
|
|
|
|
--c-dmg: 255, 167, 36;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.btn-check:checked + .btn-cond-nm { background: rgba(var(--c-nm), 1); border-color: rgba(var(--c-nm), 1); color: #2d4a10; }
|
|
|
|
|
.btn-check:checked + .btn-cond-lp { background: rgba(var(--c-lp), 1); border-color: rgba(var(--c-lp), 1); color: #3a4310; }
|
|
|
|
|
.btn-check:checked + .btn-cond-mp { background: rgba(var(--c-mp), 1); border-color: rgba(var(--c-mp), 1); color: #44420a; }
|
|
|
|
|
.btn-check:checked + .btn-cond-hp { background: rgba(var(--c-hp), 1); border-color: rgba(var(--c-hp), 1); color: #4a3608; }
|
|
|
|
|
.btn-check:checked + .btn-cond-dmg { background: rgba(var(--c-dmg), 1); border-color: rgba(var(--c-dmg), 1); color: #4a2c08; }
|
|
|
|
|
|
|
|
|
|
.btn-cond-nm, .btn-cond-lp, .btn-cond-mp, .btn-cond-hp, .btn-cond-dmg {
|
|
|
|
|
border: 1px solid rgba(255,255,255,0.15);
|
|
|
|
|
color: var(--bs-body-color);
|
|
|
|
|
background: transparent;
|
|
|
|
|
font-size: 0.8rem;
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
transition: background 0.1s, border-color 0.1s;
|
|
|
|
|
}
|
|
|
|
|
.btn-cond-nm:hover { background: rgba(var(--c-nm), 0.2); border-color: rgba(var(--c-nm), 0.6); }
|
|
|
|
|
.btn-cond-lp:hover { background: rgba(var(--c-lp), 0.2); border-color: rgba(var(--c-lp), 0.6); }
|
|
|
|
|
.btn-cond-mp:hover { background: rgba(var(--c-mp), 0.2); border-color: rgba(var(--c-mp), 0.6); }
|
|
|
|
|
.btn-cond-hp:hover { background: rgba(var(--c-hp), 0.2); border-color: rgba(var(--c-hp), 0.6); }
|
|
|
|
|
.btn-cond-dmg:hover { background: rgba(var(--c-dmg), 0.2); border-color: rgba(var(--c-dmg), 0.6); }
|
|
|
|
|
|
|
|
|
|
.price-toggle .btn { font-size: 0.75rem; padding: 0.25rem 0.6rem; line-height: 1; }
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<form id="inventoryForm" novalidate>
|
|
|
|
|
|
|
|
|
|
<div class="row g-3 mb-3">
|
|
|
|
|
<div class="col-4">
|
|
|
|
|
<label for="quantity" class="form-label fw-medium">Quantity</label>
|
|
|
|
|
<input type="number" class="form-control" id="quantity" name="quantity"
|
|
|
|
|
min="1" step="1" value="1" required>
|
|
|
|
|
<div class="invalid-feedback">Required.</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="col-8">
|
|
|
|
|
<label class="form-label fw-medium">Condition</label>
|
|
|
|
|
<div class="btn-group w-100" role="group" aria-label="Condition">
|
|
|
|
|
<input type="radio" class="btn-check" name="condition" id="cond-nm" value="Near Mint" autocomplete="off" checked>
|
|
|
|
|
<label class="btn btn-cond-nm" for="cond-nm">NM</label>
|
|
|
|
|
|
|
|
|
|
<input type="radio" class="btn-check" name="condition" id="cond-lp" value="Lightly Played" autocomplete="off">
|
|
|
|
|
<label class="btn btn-cond-lp" for="cond-lp">LP</label>
|
|
|
|
|
|
|
|
|
|
<input type="radio" class="btn-check" name="condition" id="cond-mp" value="Moderately Played" autocomplete="off">
|
|
|
|
|
<label class="btn btn-cond-mp" for="cond-mp">MP</label>
|
|
|
|
|
|
|
|
|
|
<input type="radio" class="btn-check" name="condition" id="cond-hp" value="Heavily Played" autocomplete="off">
|
|
|
|
|
<label class="btn btn-cond-hp" for="cond-hp">HP</label>
|
|
|
|
|
|
|
|
|
|
<input type="radio" class="btn-check" name="condition" id="cond-dmg" value="Damaged" autocomplete="off">
|
|
|
|
|
<label class="btn btn-cond-dmg" for="cond-dmg">DMG</label>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="mb-3">
|
|
|
|
|
<div class="d-flex justify-content-between align-items-center mb-1">
|
|
|
|
|
<label for="purchasePrice" class="form-label fw-medium mb-0">Purchase price</label>
|
|
|
|
|
<div class="btn-group btn-group-sm price-toggle" role="group" aria-label="Price mode">
|
|
|
|
|
<input type="radio" class="btn-check" name="priceMode" id="mode-dollar" value="dollar" autocomplete="off" checked>
|
|
|
|
|
<label class="btn btn-outline-secondary" for="mode-dollar">$ amount</label>
|
|
|
|
|
<input type="radio" class="btn-check" name="priceMode" id="mode-percent" value="percent" autocomplete="off">
|
|
|
|
|
<label class="btn btn-outline-secondary" for="mode-percent">% of market</label>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="input-group">
|
|
|
|
|
<span class="input-group-text" id="pricePrefix">$</span>
|
|
|
|
|
<input type="number" class="form-control" id="purchasePrice" name="purchasePrice"
|
|
|
|
|
min="0" step="0.01" placeholder="0.00"
|
|
|
|
|
aria-describedby="pricePrefix priceSuffix priceHint" required>
|
|
|
|
|
<span class="input-group-text d-none" id="priceSuffix">%</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-text" id="priceHint">Enter the amount you paid.</div>
|
|
|
|
|
<div class="invalid-feedback">Enter a purchase price.</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="mb-4">
|
|
|
|
|
<label for="note" class="form-label fw-medium">
|
|
|
|
|
Note
|
|
|
|
|
<span class="text-body-tertiary fw-normal ms-1 small">optional</span>
|
|
|
|
|
</label>
|
|
|
|
|
<textarea class="form-control" id="note" name="note"
|
|
|
|
|
rows="2" maxlength="255"
|
|
|
|
|
placeholder="e.g. bought at local shop, gift, graded copy…"></textarea>
|
|
|
|
|
<div class="form-text text-end" id="noteCount">0 / 255</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="d-flex gap-2">
|
|
|
|
|
<button type="submit" class="btn btn-success flex-fill">Save to inventory</button>
|
|
|
|
|
<button type="reset" class="btn btn-outline-secondary">Reset</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
(function () {
|
|
|
|
|
const priceInput = document.getElementById('purchasePrice');
|
|
|
|
|
const pricePrefix = document.getElementById('pricePrefix');
|
|
|
|
|
const priceSuffix = document.getElementById('priceSuffix');
|
|
|
|
|
const priceHint = document.getElementById('priceHint');
|
|
|
|
|
const note = document.getElementById('note');
|
|
|
|
|
const noteCount = document.getElementById('noteCount');
|
|
|
|
|
|
|
|
|
|
document.querySelectorAll('input[name="priceMode"]').forEach(radio => {
|
|
|
|
|
radio.addEventListener('change', () => {
|
|
|
|
|
const isPct = radio.value === 'percent';
|
|
|
|
|
pricePrefix.classList.toggle('d-none', isPct);
|
|
|
|
|
priceSuffix.classList.toggle('d-none', !isPct);
|
|
|
|
|
priceInput.step = isPct ? '1' : '0.01';
|
|
|
|
|
priceInput.max = isPct ? '100' : '';
|
|
|
|
|
priceInput.placeholder = isPct ? '100' : '0.00';
|
|
|
|
|
priceInput.value = '';
|
|
|
|
|
priceHint.textContent = isPct
|
|
|
|
|
? 'Percentage of the current market price you paid (e.g. 80 = 80%).'
|
|
|
|
|
: 'Enter the amount you paid.';
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
note.addEventListener('input', () => {
|
|
|
|
|
noteCount.textContent = `${note.value.length} / 255`;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
document.getElementById('inventoryForm').addEventListener('submit', e => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
const form = e.currentTarget;
|
|
|
|
|
if (!form.checkValidity()) { form.classList.add('was-validated'); return; }
|
|
|
|
|
form.classList.remove('was-validated');
|
|
|
|
|
// your save logic here — form data available via new FormData(form)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
document.getElementById('inventoryForm').addEventListener('reset', () => {
|
|
|
|
|
document.getElementById('inventoryForm').classList.remove('was-validated');
|
|
|
|
|
noteCount.textContent = '0 / 255';
|
|
|
|
|
pricePrefix.classList.remove('d-none');
|
|
|
|
|
priceSuffix.classList.add('d-none');
|
|
|
|
|
priceInput.step = '0.01';
|
|
|
|
|
priceInput.max = '';
|
|
|
|
|
priceInput.placeholder = '0.00';
|
|
|
|
|
priceHint.textContent = 'Enter the amount you paid.';
|
|
|
|
|
document.getElementById('mode-dollar').checked = true;
|
|
|
|
|
});
|
|
|
|
|
})();
|
|
|
|
|
</script>
|
|
|
|
|
</div>
|
2026-03-16 08:39:06 -04:00
|
|
|
</div>
|
|
|
|
|
|
2026-03-16 11:05:10 -04:00
|
|
|
<!-- Chart lives permanently outside tab-content so Bootstrap never hides it. -->
|
|
|
|
|
<div class="d-block d-lg-flex gap-1 mt-1">
|
|
|
|
|
<div class="col-12">
|
|
|
|
|
<div class="alert alert-dark rounded p-2 mb-0">
|
|
|
|
|
<h6>Market Price History</h6>
|
|
|
|
|
<div id="priceHistoryEmpty" class="d-none text-secondary text-center py-4">
|
|
|
|
|
No sales data for the selected period/condition
|
|
|
|
|
</div>
|
|
|
|
|
<div class="position-relative" style="height: 200px;">
|
|
|
|
|
<canvas
|
|
|
|
|
id="priceHistoryChart"
|
|
|
|
|
class="price-history-chart"
|
|
|
|
|
data-card-id={card?.cardId}
|
|
|
|
|
data-history={JSON.stringify(priceHistoryForChart)}>
|
|
|
|
|
</canvas>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="btn-group btn-group-sm d-flex flex-row gap-1 justify-content-end mt-2" role="group" aria-label="Time range">
|
|
|
|
|
{showRanges['1m'] && <button type="button" class="btn btn-dark price-range-btn active" data-range="1m">1M</button>}
|
|
|
|
|
{showRanges['3m'] && <button type="button" class="btn btn-dark price-range-btn" data-range="3m">3M</button>}
|
2026-03-16 14:07:37 -04:00
|
|
|
{showRanges['6m'] && <button type="button" class="btn btn-dark price-range-btn" data-range="6m">6M</button>}
|
|
|
|
|
{showRanges['1y'] && <button type="button" class="btn btn-dark price-range-btn" data-range="1y">1Y</button>}
|
|
|
|
|
{showRanges['all'] && <button type="button" class="btn btn-dark price-range-btn" data-range="all">All</button>}
|
2026-03-16 11:05:10 -04:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-16 08:39:06 -04:00
|
|
|
</div>
|
2026-02-20 09:11:36 -05:00
|
|
|
</div>
|
2026-03-16 11:05:10 -04:00
|
|
|
|
2026-03-16 08:39:06 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- External links column -->
|
|
|
|
|
<div class="col-sm-12 col-md-2 mt-0 mt-md-5 d-flex flex-row flex-md-column">
|
2026-03-11 15:21:43 -04:00
|
|
|
<a class="btn btn-dark mb-2 w-100 p-2" href={`https://www.tcgplayer.com/product/${card?.productId}`} target="_blank" onclick="dataLayer.push({'event': 'tcgplayerClick', 'tcgplayerUrl': this.getAttribute('href')});"><img src="/vendors/tcgplayer.webp"> <span class="d-none d-lg-inline">TCGPlayer</span></a>
|
|
|
|
|
<a class="btn btn-dark mb-2 w-100 p-2" href={`${ebaySearchUrl(card)}`} target="_blank" onclick="dataLayer.push({'event': 'ebayClick', 'ebayUrl': this.getAttribute('href')});"><span set:html={ebay} /></a>
|
|
|
|
|
<a class="btn btn-dark mb-2 w-100 p-2" href={`${altSearchUrl(card)}`} target="_blank" onclick="dataLayer.push({'event': 'altClick', 'altUrl': this.getAttribute('href')});"><svg width="48" height="20.16" viewBox="0 0 48 20" fill="none"><path d="M14.2761 19.9996H18.5308L11.6934 0.0712891H7.76953L14.2761 19.9996Z" fill="#ffffff"></path><path d="M6.17778 19.9986H6.14536L3.19643 11.2305L0 19.9988L6.17768 19.9989L6.17778 19.9986Z" fill="#ffffff"></path><path d="M24.7842 0H20.6759V19.9661H34.3427V16.5426H24.7842V0Z" fill="#ffffff"></path><path d="M41.6644 3.42355H47.4981V0H31.5033V3.42355H37.5561V19.9661H41.6644V3.42355Z" fill="#ffffff"></path></svg></a>
|
2026-03-16 08:39:06 -04:00
|
|
|
</div>
|
|
|
|
|
|
2026-02-20 09:11:36 -05:00
|
|
|
</div>
|
2026-03-09 14:25:18 -04:00
|
|
|
<div class="text-end my-0"><small class="text-body-tertiary">Prices last changed: {timeAgo(calculatedAt)}</small></div>
|
2026-03-16 08:39:06 -04:00
|
|
|
</div>
|
2026-02-20 09:11:36 -05:00
|
|
|
</div>
|
2026-03-16 08:39:06 -04:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-16 11:05:10 -04:00
|
|
|
</div>
|