"use client";
// Read-only view of GET /timer/options — the option sets the app uses to build
// the meditation timer (durations, intervals, default bells, etc.). The exact
// shape is backend-defined, so we render it generically: primitive values as a
// definition list, arrays of objects as small tables.
import { useItem } from "@/lib/useResource";
import { Button, Card, PageHeader, Spinner, Badge, EmptyState } from "@/components/ui";
import { toFa } from "@/lib/utils";
function Primitive({ value }: { value: unknown }) {
if (typeof value === "boolean") {
return {value ? "بله" : "خیر"};
}
if (value === null || value === undefined) return —;
return {toFa(String(value))};
}
function ArrayBlock({ items }: { items: unknown[] }) {
if (!items.length) return ;
// Array of objects -> table of their union of keys.
if (items.every((it) => it && typeof it === "object" && !Array.isArray(it))) {
const keys = Array.from(
new Set(items.flatMap((it) => Object.keys(it as object))),
);
return (
{keys.map((k) => (
|
{k}
|
))}
{items.map((it, i) => (
{keys.map((k) => (
|
)[k]} />
|
))}
))}
);
}
// Array of primitives -> chips.
return (
{items.map((it, i) => (
{toFa(String(it))}
))}
);
}
export default function TimerOptionsPage() {
const { data, loading, error, reload } = useItem>(
"/timer/options",
);
return (
{loading ? (
) : error ? (
تلاش دوباره
}
/>
) : !data || typeof data !== "object" || !Object.keys(data).length ? (
) : (
{Object.entries(data).map(([key, value]) => (
{key}
{Array.isArray(value) ? (
) : value && typeof value === "object" ? (
{Object.entries(value as Record).map(
([k, v]) => (
),
)}
) : (
)}
))}
)}
);
}