import React from "react";
import dayjs from "dayjs";
import { FlexWidget, OverlapWidget, SvgWidget, TextWidget } from "react-native-android-widget";
import { AS } from "../../storageControl";
import { STORAGE_KEYS } from "../../constants";
import { WidgetColors, widgetLightColors } from "./widget-theme";
type LastFelicaSnapshot = {
balance: number;
idm: string;
systemCode?: string;
scannedAt: string;
};
export async function getFelicaQuickAccessData() {
const nowText = dayjs().format("HH:mm");
const snapshot = (await AS.getItem(STORAGE_KEYS.FELICA_LAST_SNAPSHOT).catch(
() => null
)) as LastFelicaSnapshot | null;
const hasBalance =
snapshot != null && typeof snapshot.balance === "number" && snapshot.balance >= 0;
return {
nowText,
amountText: hasBalance ? `\u00A5${snapshot.balance.toLocaleString()}` : "未読取",
detailText:
snapshot?.scannedAt != null
? `最終読取: ${snapshot.scannedAt}`
: "カードをタップして読取開始",
};
}
// IC card + NFC arcs, -22° rotated, as widget background
const IC_CARD_BG_SVG_LIGHT = ``;
const IC_CARD_BG_SVG_DARK = ``;
export function FelicaQuickAccessWidget({
amountText,
detailText,
colors = widgetLightColors,
}: {
amountText: string;
nowText: string;
detailText: string;
colors?: WidgetColors;
}) {
const hasValue = amountText !== "未読取";
const isDark = colors.background !== "#ffffff" && colors.background !== "#DDF2FF";
return (
{/* Background: IC card + NFC icons, rotated */}
{/* Foreground: balance only */}
{/* Bottom-right: scan timestamp */}
{hasValue && (
)}
);
}