بلاک‌ها · پنل مدیریت
ری‌اکت ۱۹ و Next.js با پیاده‌سازی دسترس‌پذیری داخلی دیگویو ۳ با Composition APISvelte ۵ با runesانگولار با signals و دایرکتیوهای standaloneجتپک کامپوز با KotliniOS — هنوز پورت نشده

منوی کناری، کارت‌های آمار، نمودار فروش ماهانه با بازهٔ تاریخ و آخرین سفارش‌ها.

۱. نصب کامپوننت‌ها

این بلاک از ۱۹ آیتم دیگ استفاده می‌کند: avatarbadgebuttoncardchart-presetscheckboxcollapsiblecontrol-sizedropdown-menuiconslabelpaginationpersiansearch-fieldselectsidebarstat-tiletabletoggle-group

پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add https://docs.digdesign.ir/r/avatar.json https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/card.json https://docs.digdesign.ir/r/chart-presets.json https://docs.digdesign.ir/r/checkbox.json https://docs.digdesign.ir/r/collapsible.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/dropdown-menu.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/pagination.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/search-field.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/sidebar.json https://docs.digdesign.ir/r/stat-tile.json https://docs.digdesign.ir/r/table.json https://docs.digdesign.ir/r/toggle-group.json
pnpm dlx digdesign@latest add https://docs.digdesign.ir/r/avatar.json https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/card.json https://docs.digdesign.ir/r/chart-presets.json https://docs.digdesign.ir/r/checkbox.json https://docs.digdesign.ir/r/collapsible.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/dropdown-menu.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/pagination.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/search-field.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/sidebar.json https://docs.digdesign.ir/r/stat-tile.json https://docs.digdesign.ir/r/table.json https://docs.digdesign.ir/r/toggle-group.json
yarn dlx digdesign@latest add https://docs.digdesign.ir/r/avatar.json https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/card.json https://docs.digdesign.ir/r/chart-presets.json https://docs.digdesign.ir/r/checkbox.json https://docs.digdesign.ir/r/collapsible.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/dropdown-menu.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/pagination.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/search-field.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/sidebar.json https://docs.digdesign.ir/r/stat-tile.json https://docs.digdesign.ir/r/table.json https://docs.digdesign.ir/r/toggle-group.json
bunx --bun digdesign@latest add https://docs.digdesign.ir/r/avatar.json https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/card.json https://docs.digdesign.ir/r/chart-presets.json https://docs.digdesign.ir/r/checkbox.json https://docs.digdesign.ir/r/collapsible.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/dropdown-menu.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/pagination.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/search-field.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/sidebar.json https://docs.digdesign.ir/r/stat-tile.json https://docs.digdesign.ir/r/table.json https://docs.digdesign.ir/r/toggle-group.json
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add avatar badge button card chart-presets checkbox collapsible control-size dropdown-menu label pagination persian search-field select sidebar stat-tile table toggle-group --framework vue
pnpm dlx digdesign@latest add avatar badge button card chart-presets checkbox collapsible control-size dropdown-menu label pagination persian search-field select sidebar stat-tile table toggle-group --framework vue
yarn dlx digdesign@latest add avatar badge button card chart-presets checkbox collapsible control-size dropdown-menu label pagination persian search-field select sidebar stat-tile table toggle-group --framework vue
bunx --bun digdesign@latest add avatar badge button card chart-presets checkbox collapsible control-size dropdown-menu label pagination persian search-field select sidebar stat-tile table toggle-group --framework vue
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add button --framework svelte
pnpm dlx digdesign@latest add button --framework svelte
yarn dlx digdesign@latest add button --framework svelte
bunx --bun digdesign@latest add button --framework svelte
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add avatar badge button card chart-presets checkbox collapsible control-size dropdown-menu icons label pagination persian search-field select sidebar stat-tile table toggle-group --framework angular
pnpm dlx digdesign@latest add avatar badge button card chart-presets checkbox collapsible control-size dropdown-menu icons label pagination persian search-field select sidebar stat-tile table toggle-group --framework angular
yarn dlx digdesign@latest add avatar badge button card chart-presets checkbox collapsible control-size dropdown-menu icons label pagination persian search-field select sidebar stat-tile table toggle-group --framework angular
bunx --bun digdesign@latest add avatar badge button card chart-presets checkbox collapsible control-size dropdown-menu icons label pagination persian search-field select sidebar stat-tile table toggle-group --framework angular
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add avatar badge button card chart-presets checkbox collapsible control-size dropdown-menu label pagination persian search-field select sidebar stat-tile table toggle-group --framework android
pnpm dlx digdesign@latest add avatar badge button card chart-presets checkbox collapsible control-size dropdown-menu label pagination persian search-field select sidebar stat-tile table toggle-group --framework android
yarn dlx digdesign@latest add avatar badge button card chart-presets checkbox collapsible control-size dropdown-menu label pagination persian search-field select sidebar stat-tile table toggle-group --framework android
bunx --bun digdesign@latest add avatar badge button card chart-presets checkbox collapsible control-size dropdown-menu label pagination persian search-field select sidebar stat-tile table toggle-group --framework android

۲. کد صفحه

کد را در صفحهٔ پروژه‌تان بگذارید (React: app/<route>/page.tsx) و متن‌ها، داده و هندلرها را با محصول خودتان عوض کنید. با سوییچر فریم‌ورک کدِ همین صفحه در فریم‌ورک دیگر را ببینید.

dashboard.tsx
"use client"

import * as React from "react"

import {
  AvatarGenderIcon,
  BadgeStarIcon,
  BarChartIcon,
  BellIcon,
  ChevronDownIcon,
  DashboardIcon,
  EnvelopeIcon,
  DigLogo,
  FilterIcon,
  GuideIcon,
  LogoutIcon,
  MoonIcon,
  SunIcon,
  PlusIcon,
  ReceiptIcon,
  SettingsIcon,
  ShieldCheckIcon,
  ShopIcon,
  TagIcon,
  TicketIcon,
  UsersIcon,
  XIcon,
} from "@/components/icons"
import { Avatar } from "@/components/ui/avatar"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Card, CardAction, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { ComboChart } from "@/components/ui/chart-presets"
import { Checkbox } from "@/components/ui/checkbox"
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible"
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Label } from "@/components/ui/label"
import {
  Pagination,
  PaginationContent,
  PaginationItem,
  PaginationLink,
  PaginationNext,
  PaginationPrevious,
} from "@/components/ui/pagination"
import { SearchField } from "@/components/ui/search-field"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import {
  Sidebar,
  SidebarContent,
  SidebarBrand,
  SidebarFooter,
  SidebarGroup,
  SidebarGroupContent,
  SidebarHeader,
  SidebarInset,
  SidebarMenu,
  SidebarMenuBadge,
  SidebarMenuButton,
  SidebarMenuItem,
  SidebarMenuSub,
  SidebarMenuSubButton,
  SidebarMenuSubItem,
  SidebarProvider,
  SidebarSearch,
  SidebarTrigger,
} from "@/components/ui/sidebar"
import {
  StatTile,
  StatTileAction,
  StatTileHeader,
  StatTileLabel,
  StatTileList,
} from "@/components/ui/stat-tile"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
import { formatCurrency, formatJalali, formatNumber, formatRelativeTime, toFaDigits, toSearchKey } from "@/lib/persian"
import { stockImages } from "@/lib/stock-images"

/* ------------------------------------------------------------------ داده */

/** دادهٔ نمونهٔ قطعی برای هر بازه؛ در پروژهٔ واقعی همین سه فراخوانی API است. */
function salesFor(period: string) {
  const wave = (index: number, base: number, amp: number) => Math.round(base + amp * Math.sin(index * 0.9) + index * (amp / 6))
  if (period === "7") {
    return Array.from({ length: 7 }, (_, index) => ({
      label: `${toFaDigits(3 + index)} مهر`,
      revenue: wave(index, 52, 12),
      orders: wave(index, 165, 28),
    }))
  }
  if (period === "30") {
    // ۳۰ روز در ۱۰ دستهٔ سه‌روزه، تا میله‌ها خوانا بمانند.
    return Array.from({ length: 10 }, (_, index) => ({
      label: `${toFaDigits(1 + index * 3)} ${index < 3 ? "شهریور" : "مهر"}`,
      revenue: wave(index, 150, 30),
      orders: wave(index, 480, 70),
    }))
  }
  return Array.from({ length: 12 }, (_, index) => ({
    label: `هفتهٔ ${toFaDigits(index + 1)}`,
    revenue: wave(index, 360, 70),
    orders: wave(index, 1150, 160),
  }))
}


const QUICK = [
  { title: "محصولِ تازه", hint: "افزودن به فروشگاه", icon: <PlusIcon />, tone: "bg-primary-subtle text-primary-subtle-foreground" },
  { title: "ثبتِ سفارش", hint: "فروشِ حضوری", icon: <ReceiptIcon />, tone: "bg-info-subtle text-info-subtle-foreground" },
  { title: "کدِ تخفیف", hint: "کمپینِ تازه", icon: <TagIcon />, tone: "bg-warning-subtle text-warning-subtle-foreground" },
  { title: "گزارشِ فروش", hint: "خروجی اکسل", icon: <BarChartIcon />, tone: "bg-success-subtle text-success-subtle-foreground" },
]

const CUSTOMERS = [
  { name: "مهسا توکلی", gender: "female" as const, orders: 24, spent: "۱۲٫۴ میلیون" },
  { name: "کیان مرادی", gender: "male" as const, orders: 18, spent: "۹٫۸ میلیون" },
  { name: "نیلوفر احمدی", gender: "female" as const, orders: 11, spent: "۶٫۱ میلیون" },
  { name: "پرهام نوری", gender: "male" as const, orders: 7, spent: "۳٫۹ میلیون" },
]

type Status = "shipped" | "processing" | "delivered" | "pending"
const STATUS: Record<Status, { text: string; color: "warning" | "info" | "success" | "destructive" }> = {
  shipped: { text: "ارسال شد", color: "warning" },
  processing: { text: "در حال آماده‌سازی", color: "info" },
  delivered: { text: "تحویل شد", color: "success" },
  pending: { text: "در انتظار پرداخت", color: "destructive" },
}
const ORDERS: { id: string; customer: string; date: string; total: number; status: Status }[] = [
  { id: "1098", customer: "آرمیتا رستگار", date: "2026-10-01", total: 2_450_000, status: "shipped" },
  { id: "1097", customer: "کیان مرادی", date: "2026-09-30", total: 1_265_000, status: "processing" },
  { id: "1096", customer: "نیلوفر احمدی", date: "2026-09-29", total: 5_100_000, status: "delivered" },
  { id: "1095", customer: "سارا محمدی", date: "2026-09-28", total: 789_000, status: "pending" },
  { id: "1094", customer: "علی کریمی", date: "2026-09-28", total: 3_320_000, status: "delivered" },
  { id: "1093", customer: "مهسا نوری", date: "2026-09-27", total: 1_980_000, status: "shipped" },
  { id: "1092", customer: "رضا امینی", date: "2026-09-27", total: 640_000, status: "delivered" },
  { id: "1091", customer: "پریسا کاظمی", date: "2026-09-26", total: 4_250_000, status: "processing" },
  { id: "1090", customer: "حامد یزدانی", date: "2026-09-25", total: 2_100_000, status: "delivered" },
  { id: "1089", customer: "الهام صادقی", date: "2026-09-25", total: 990_000, status: "pending" },
  { id: "1088", customer: "بهراد فرهی", date: "2026-09-24", total: 3_760_000, status: "delivered" },
  { id: "1087", customer: "شیما رحیمی", date: "2026-09-23", total: 1_430_000, status: "shipped" },
]
const PAGE_SIZE = 5

const NOTIFICATIONS = [
  { id: 1, title: "سفارش تازه", body: "سفارش ۱۰۹۹ ثبت شد", time: "2026-10-03T10:00:00", icon: <ReceiptIcon />, tone: "bg-info-subtle text-info" },
  { id: 2, title: "موجودی رو به اتمام", body: "فقط ۷ عدد از هدفون پرو مانده", time: "2026-10-03T09:00:00", icon: <ShopIcon />, tone: "bg-warning-subtle text-warning-subtle-foreground" },
  { id: 3, title: "نظر مثبت", body: "«ارسال سریع و بسته‌بندی عالی»", time: "2026-10-03T08:00:00", icon: <BadgeStarIcon />, tone: "bg-success-subtle text-success-subtle-foreground" },
]

/* ------------------------------------------------------------------ بلاک */

export default function DashboardBlock() {
  const [period, setPeriod] = React.useState("30")
  const [showRevenue, setShowRevenue] = React.useState(true)
  const [showOrders, setShowOrders] = React.useState(true)
  const [query, setQuery] = React.useState("")
  const [selected, setSelected] = React.useState<string[]>([])
  const [notifications, setNotifications] = React.useState(NOTIFICATIONS)
  const [page, setPage] = React.useState(1)

  const sales = React.useMemo(() => salesFor(period), [period])
  const filtered = ORDERS.filter((order) => toSearchKey(order.customer + order.id).includes(toSearchKey(query)))
  const pageCount = Math.max(1, Math.ceil(filtered.length / PAGE_SIZE))
  const currentPage = Math.min(page, pageCount)
  const orders = filtered.slice((currentPage - 1) * PAGE_SIZE, currentPage * PAGE_SIZE)
  const allSelected = orders.length > 0 && orders.every((order) => selected.includes(order.id))

  return (
    <ControlSizeProvider size="xl" asChild>
    <SidebarProvider>
      <DashboardSidebar />

      <SidebarInset className="flex min-w-0 flex-col gap-6 bg-muted p-4 sm:p-6">
        <header className="flex flex-wrap items-center gap-3">
          <SidebarTrigger />
          <div className="flex flex-col gap-0.5">
            <h1 className="text-xl font-bold">سلام آرمیتا</h1>
            <p className="text-sm text-muted-foreground">امروز ۱۲ سفارشِ تازه منتظرِ آماده‌سازی است.</p>
          </div>
          <SearchField
            aria-label="جست‌وجو"
            placeholder="جست‌وجوی محصول، مشتری یا سفارش…"
            className="order-last w-full sm:order-none sm:ms-auto sm:w-80 [&_input]:bg-card [&>div]:bg-card"
          />
          <div className="ms-auto flex items-center gap-2 sm:ms-0">
            <Button variant="outline" size="icon" aria-label="اعلان‌ها، ۳ مورد تازه" className="relative bg-card">
              <BellIcon />
              <span aria-hidden className="absolute end-2 top-2 size-2 rounded-full bg-destructive" />
            </Button>
            {/* پروفایل در نوارِ بالا؛ تنظیمات و خروج در منوی همین آواتار. */}
            <DropdownMenu>
              <DropdownMenuTrigger asChild>
                <Button variant="ghost" className="gap-2 px-1.5" aria-label="منوی حساب">
                  <Avatar size="sm" alt="آرمیتا رستگار" src={stockImages.personWoman1.src} icon={<AvatarGenderIcon gender="female" />} className="ring-1 ring-border" />
                  <span className="hidden flex-col items-start leading-snug md:flex">
                    <span className="text-sm font-semibold">آرمیتا رستگار</span>
                    <span className="text-xs text-muted-foreground">مدیر فروشگاه</span>
                  </span>
                  <ChevronDownIcon className="text-muted-foreground" />
                </Button>
              </DropdownMenuTrigger>
              <DropdownMenuContent align="end" className="w-56">
                <DropdownMenuItem>
                  <SettingsIcon />
                  تنظیمات حساب
                </DropdownMenuItem>
                <DropdownMenuSeparator />
                <DropdownMenuItem variant="destructive">
                  <LogoutIcon />
                  خروج
                </DropdownMenuItem>
              </DropdownMenuContent>
            </DropdownMenu>
          </div>
        </header>

        {/* دسترسی سریع: کارهای پرتکرار با یک کلیک، بالای همهٔ گزارش‌ها. */}
        <section aria-label="دسترسی سریع" className="grid grid-cols-2 gap-3 md:grid-cols-4">
          {QUICK.map((item) => (
            <Button
              key={item.title}
              variant="outline"
              className="h-auto justify-start gap-3 rounded-xl bg-card! p-4 text-start shadow-none hover:border-input"
            >
              <span aria-hidden className={`flex size-11 shrink-0 items-center justify-center rounded-xl [&_svg]:size-5 ${item.tone}`}>
                {item.icon}
              </span>
              <span className="flex min-w-0 flex-col gap-0.5">
                <span className="truncate text-sm font-semibold">{item.title}</span>
                <span className="truncate text-xs text-muted-foreground">{item.hint}</span>
              </span>
            </Button>
          ))}
        </section>


        <div className="grid grid-cols-1 gap-6 xl:grid-cols-[minmax(0,1fr)_22rem]">
          <Card>
            {/* کنترل‌ها روبه‌روی عنوان؛ در موبایل زیرِ آن می‌پیچند. */}
            <CardHeader className="flex flex-wrap items-center justify-between gap-3">
              <CardTitle>فروش و سفارش‌ها</CardTitle>
              <div className="flex flex-wrap items-center gap-4">
                <div className="flex items-center gap-2">
                  <Checkbox id="show-revenue" checked={showRevenue} onCheckedChange={(on) => setShowRevenue(on === true)} />
                  <Label htmlFor="show-revenue">فروش</Label>
                </div>
                <div className="flex items-center gap-2">
                  <Checkbox id="show-orders" checked={showOrders} onCheckedChange={(on) => setShowOrders(on === true)} />
                  <Label htmlFor="show-orders">سفارش</Label>
                </div>
                <Select value={period} onValueChange={(next) => setPeriod(next as string)}>
                  <SelectTrigger size="sm" aria-label="بازهٔ زمانی" className="w-28">
                    <SelectValue />
                  </SelectTrigger>
                  <SelectContent>
                    <SelectItem value="7">۷ روز</SelectItem>
                    <SelectItem value="30">۳۰ روز</SelectItem>
                    <SelectItem value="90">۹۰ روز</SelectItem>
                  </SelectContent>
                </Select>
              </div>
            </CardHeader>
            <CardContent>
              <ComboChart
                className="h-80"
                data={sales.map((row) => ({
                  ...row,
                  revenue: showRevenue ? row.revenue : null,
                  orders: showOrders ? row.orders : null,
                }))}
                categoryKey="label"
                bar={{ key: "revenue", label: "فروش (میلیون تومان)", color: "var(--chart-1)" }}
                barFormatter={(value) => formatNumber(value)}
                line={{ key: "orders", label: "سفارش", color: "var(--chart-4)" }}
              />
            </CardContent>
          </Card>

          <section className="flex flex-col gap-4" aria-label="خلاصه">
            <StatTile>
              <StatTileHeader>
                <StatTileLabel className="text-base text-foreground">قیفِ خرید</StatTileLabel>
                <StatTileAction aria-label="جزئیات قیف خرید" />
              </StatTileHeader>
              <StatTileList
                items={[
                  { label: "بازدید", value: 100, display: "٪۱۰۰" },
                  { label: "دیدنِ محصول", value: 74, display: "٪۷۴" },
                  { label: "افزودن به سبد", value: 62, display: "٪۶۲" },
                  { label: "خریدِ موفق", value: 21, display: "٪۲۱" },
                ]}
              />
            </StatTile>
            <StatTile className="gap-3">
              <StatTileHeader>
                <StatTileLabel className="text-base text-foreground">مشتریانِ تازه</StatTileLabel>
                <Button variant="ghost" className="ms-auto">
                  همه
                </Button>
              </StatTileHeader>
              <ul className="flex flex-col gap-1">
                {CUSTOMERS.map((customer) => (
                  <li key={customer.name} className="flex items-center gap-3 rounded-xl p-2 hover:bg-muted">
                    <Avatar size="sm" alt={customer.name} icon={<AvatarGenderIcon gender={customer.gender} />} className="ring-1 ring-border" />
                    <div className="flex min-w-0 flex-1 flex-col gap-1">
                      <span className="truncate text-sm font-medium">{customer.name}</span>
                      <span className="text-xs text-muted-foreground">
                        {toFaDigits(customer.orders)} سفارش · {customer.spent}
                      </span>
                    </div>
                    <Button variant="ghost" size="icon" aria-label={`پیام به ${customer.name}`}>
                      <EnvelopeIcon />
                    </Button>
                  </li>
                ))}
              </ul>
            </StatTile>
          </section>
        </div>

        <div className="grid grid-cols-1 gap-6 xl:grid-cols-[minmax(0,1fr)_22rem]">
          <Card>
            <CardHeader className="flex flex-wrap items-center justify-between gap-3">
              <CardTitle>سفارش‌ها</CardTitle>
              {/* جست‌وجو کنارِ فیلتر، روبه‌روی عنوان؛ ابزارهای جدول یک‌جا. */}
              <div className="flex w-full items-center gap-2 sm:w-auto">
                <SearchField
                  aria-label="جست‌وجوی سفارش"
                  placeholder="شماره سفارش یا نام مشتری"
                  value={query}
                  onValueChange={(value) => {
                    setQuery(value)
                    setPage(1)
                  }}
                  className="min-w-0 flex-1 sm:w-64"
                />
                <Button variant="outline" size="icon" aria-label="فیلتر سفارش‌ها">
                  <FilterIcon />
                </Button>
              </div>
            </CardHeader>
            <CardContent className="flex flex-col gap-4">
              <div className="overflow-hidden rounded-lg border border-border">
                <Table stackOnMobile className="min-w-[36rem]">
                  <TableHeader className="bg-muted">
                    <TableRow>
                      <TableHead className="w-10">
                        <Checkbox
                          aria-label="انتخاب همه"
                          checked={allSelected}
                          onCheckedChange={(on) => setSelected(on === true ? orders.map((order) => order.id) : [])}
                        />
                      </TableHead>
                      <TableHead>شماره</TableHead>
                      <TableHead>مشتری</TableHead>
                      <TableHead>تاریخ</TableHead>
                      <TableHead className="text-end">مبلغ</TableHead>
                      <TableHead>وضعیت</TableHead>
                    </TableRow>
                  </TableHeader>
                  <TableBody>
                    {orders.map((order) => (
                      <TableRow key={order.id} data-state={selected.includes(order.id) ? "selected" : undefined}>
                        <TableCell>
                          <Checkbox
                            aria-label={`انتخاب سفارش ${toFaDigits(order.id)}`}
                            checked={selected.includes(order.id)}
                            onCheckedChange={(on) =>
                              setSelected((list) => (on === true ? [...list, order.id] : list.filter((id) => id !== order.id)))
                            }
                          />
                        </TableCell>
                        <TableCell className="font-medium">
                          <bdi dir="ltr">#{toFaDigits(order.id)}</bdi>
                        </TableCell>
                        <TableCell>{order.customer}</TableCell>
                        <TableCell className="text-muted-foreground">{formatJalali(new Date(order.date))}</TableCell>
                        <TableCell className="text-end tabular-nums">{formatCurrency(order.total)}</TableCell>
                        <TableCell>
                          <Badge variant="soft" color={STATUS[order.status].color}>
                            {STATUS[order.status].text}
                          </Badge>
                        </TableCell>
                      </TableRow>
                    ))}
                  </TableBody>
                </Table>
              </div>
              <div className="flex flex-wrap items-center justify-between gap-3">
                <span className="text-sm text-muted-foreground">
                  {toFaDigits(filtered.length)} سفارش · صفحهٔ {toFaDigits(currentPage)} از {toFaDigits(pageCount)}
                </span>
                <Pagination className="mx-0 w-auto">
                  <PaginationContent>
                    <PaginationItem>
                      <PaginationPrevious
                        href="#"
                        aria-disabled={currentPage === 1}
                        onClick={(event) => {
                          event.preventDefault()
                          setPage(Math.max(1, currentPage - 1))
                        }}
                      />
                    </PaginationItem>
                    {Array.from({ length: pageCount }, (_, index) => index + 1).map((number) => (
                      <PaginationItem key={number}>
                        <PaginationLink
                          href="#"
                          isActive={number === currentPage}
                          onClick={(event) => {
                            event.preventDefault()
                            setPage(number)
                          }}
                        >
                          {toFaDigits(number)}
                        </PaginationLink>
                      </PaginationItem>
                    ))}
                    <PaginationItem>
                      <PaginationNext
                        href="#"
                        aria-disabled={currentPage === pageCount}
                        onClick={(event) => {
                          event.preventDefault()
                          setPage(Math.min(pageCount, currentPage + 1))
                        }}
                      />
                    </PaginationItem>
                  </PaginationContent>
                </Pagination>
              </div>
            </CardContent>
          </Card>

          <Card>
            <CardHeader>
              <CardTitle>اعلان‌ها</CardTitle>
              <CardAction>
                <Badge variant="soft" color="destructive">
                  {toFaDigits(notifications.length)} تازه
                </Badge>
              </CardAction>
            </CardHeader>
            <CardContent className="flex flex-col gap-3">
              {notifications.length === 0 && (
                <p className="py-6 text-center text-sm text-muted-foreground">اعلانِ تازه‌ای نیست.</p>
              )}
              {notifications.map((item) => (
                <div key={item.id} className="flex items-start gap-3 rounded-lg border border-border bg-card p-3">
                  <span aria-hidden className={`flex size-9 shrink-0 items-center justify-center rounded-full [&_svg]:size-4 ${item.tone}`}>
                    {item.icon}
                  </span>
                  <div className="flex min-w-0 flex-1 flex-col gap-1">
                    <span className="text-sm font-semibold">{item.title}</span>
                    <span className="truncate text-xs text-muted-foreground">{item.body}</span>
                    <span className="text-xs text-muted-foreground">{formatRelativeTime(item.time)}</span>
                  </div>
                  <Button
                    variant="ghost"
                    size="icon"
                    aria-label={`بستن اعلان ${item.title}`}
                    onClick={() => setNotifications((list) => list.filter((entry) => entry.id !== item.id))}
                  >
                    <XIcon />
                  </Button>
                </div>
              ))}
              <Button variant="outline" fullWidth>
                مشاهدهٔ همه
              </Button>
            </CardContent>
          </Card>
        </div>
      </SidebarInset>
    </SidebarProvider>
    </ControlSizeProvider>
  )
}

/* ------------------------------------------------------------------ اجزا */

function DashboardSidebar() {
  return (
    <Sidebar collapsible="icon">
      <SidebarHeader className="gap-3 p-3 group-data-[collapsible=icon]:p-2">
        <SidebarBrand logo={<DigLogo />} title="فروشگاه دیگ" subtitle="پنل مدیریت" />
        <SidebarSearch placeholder="جست‌وجو در منو…" aria-label="جست‌وجو در منو" />
      </SidebarHeader>
      <SidebarContent className="gap-0 pt-4">
        <SidebarGroup>
          <SidebarGroupContent>
            <SidebarMenu>
              <NavItem icon={<DashboardIcon />} active>
                پیشخوان
              </NavItem>
              <NavItem icon={<ReceiptIcon />} badge={toFaDigits(12)}>
                سفارش‌ها
              </NavItem>
              <NavItem icon={<ShopIcon />}>محصولات</NavItem>
              <NavItem icon={<UsersIcon />}>مشتریان</NavItem>
              {/* زیرمنو جمع‌شونده و پیش‌فرض بسته؛ همیشه‌باز منو را شلوغ می‌کرد. */}
              <SidebarMenuItem>
                <Collapsible>
                  <CollapsibleTrigger asChild>
                    <SidebarMenuButton className="group/collapsible">
                      <BarChartIcon />
                      <span>تحلیل‌ها</span>
                      <Badge variant="soft" color="violet" size="sm" className="ms-auto">
                        ویژه
                      </Badge>
                      <ChevronDownIcon className="size-4! transition-transform group-data-[state=open]/collapsible:rotate-180" />
                    </SidebarMenuButton>
                  </CollapsibleTrigger>
                  <CollapsibleContent>
                    <SidebarMenuSub>
                      {["گزارش فروش", "عملکرد محصولات", "رفتار مشتریان"].map((title) => (
                        <SidebarMenuSubItem key={title}>
                          <SidebarMenuSubButton href="#">{title}</SidebarMenuSubButton>
                        </SidebarMenuSubItem>
                      ))}
                    </SidebarMenuSub>
                  </CollapsibleContent>
                </Collapsible>
              </SidebarMenuItem>
            </SidebarMenu>
          </SidebarGroupContent>
        </SidebarGroup>
        <SidebarGroup>
          <SidebarGroupContent>
            <SidebarMenu>
              <NavItem icon={<BellIcon />} badge={toFaDigits(6)} badgeTone="destructive">
                هشدار موجودی
              </NavItem>
              <NavItem icon={<ShieldCheckIcon />}>نقش‌ها و دسترسی‌ها</NavItem>
              <NavItem icon={<TicketIcon />}>پشتیبانی</NavItem>
              <NavItem icon={<GuideIcon />}>راهنما</NavItem>
            </SidebarMenu>
          </SidebarGroupContent>
        </SidebarGroup>
      </SidebarContent>
      <SidebarFooter className="gap-4 px-3 pt-3 pb-9 group-data-[collapsible=icon]:p-2">
        <ThemeSwitch />
        <p className="text-center text-xs text-muted-foreground group-data-[collapsible=icon]:hidden">نسخهٔ ۲٫۴٫۰ · به‌روزرسانی ۱۲ مهر</p>
      </SidebarFooter>
    </Sidebar>
  )
}

/**
 * سوییچِ روشن/تیره در پایینِ نوار. کلاسِ dark روی <html> را عوض می‌کند؛ در پروژه‌ای
 * که next-themes دارد، به‌جایش setTheme را صدا بزنید.
 */
function ThemeSwitch() {
  return (
    <>
      <ThemeSegmented />
      {/* حالتِ جمع: یک دکمهٔ آیکونی که بینِ دو پوسته جابه‌جا می‌کند. */}
      <ThemeIconToggle />
    </>
  )
}

function useHtmlTheme() {
  return React.useSyncExternalStore(
    (notify) => {
      const observer = new MutationObserver(notify)
      observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] })
      return () => observer.disconnect()
    },
    () => (document.documentElement.classList.contains("dark") ? "dark" : "light"),
    () => "light"
  )
}

function applyTheme(next: "light" | "dark") {
  document.documentElement.classList.toggle("dark", next === "dark")
  document.documentElement.classList.toggle("light", next === "light")
}

function ThemeIconToggle() {
  const theme = useHtmlTheme()
  return (
    <SidebarMenu className="hidden group-data-[collapsible=icon]:flex">
      <SidebarMenuItem>
        <SidebarMenuButton
          tooltip={theme === "dark" ? "پوستهٔ روشن" : "پوستهٔ تیره"}
          onClick={() => applyTheme(theme === "dark" ? "light" : "dark")}
        >
          {theme === "dark" ? <SunIcon /> : <MoonIcon />}
          <span>{theme === "dark" ? "پوستهٔ روشن" : "پوستهٔ تیره"}</span>
        </SidebarMenuButton>
      </SidebarMenuItem>
    </SidebarMenu>
  )
}

function ThemeSegmented() {
  const theme = useHtmlTheme()
  return (
    // کنترلِ ریزِ پایینِ نوارِ کناری؛ هم‌اندازهٔ آیتم‌های منو (۳۶)، نه فیلترِ صفحه.
    <ControlSizeProvider size="default" mobileSize="sm" asChild>
      <ToggleGroup
        type="single"
        variant="segmented"
        fullWidth
        value={theme}
        onValueChange={(value) => {
          if (!value) return
          applyTheme(value as "light" | "dark")
        }}
        aria-label="پوستهٔ رنگی"
        className="group-data-[collapsible=icon]:hidden"
      >
        <ToggleGroupItem value="light" aria-label="پوستهٔ روشن">
          <SunIcon />
        </ToggleGroupItem>
        <ToggleGroupItem value="dark" aria-label="پوستهٔ تیره">
          <MoonIcon />
        </ToggleGroupItem>
      </ToggleGroup>
    </ControlSizeProvider>
  )
}

function NavItem({
  icon,
  active = false,
  badge,
  badgeTone,
  children,
}: {
  icon: React.ReactNode
  active?: boolean
  badge?: string
  badgeTone?: "destructive"
  children: React.ReactNode
}) {
  return (
    <SidebarMenuItem>
      <SidebarMenuButton asChild isActive={active} tooltip={typeof children === "string" ? children : undefined}>
        <a href="#">
          {icon}
          <span>{children}</span>
        </a>
      </SidebarMenuButton>
      {badge && (
        <SidebarMenuBadge tone={badgeTone === "destructive" ? "destructive" : "default"}>
          {badge}
        </SidebarMenuBadge>
      )}
    </SidebarMenuItem>
  )
}

/** نمودارِ خطی کوچک برای کارتِ آمار؛ SVGِ سبک به‌جای یک نمونهٔ کاملِ نمودار. */
dashboard.vue
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref } from "vue"

import Avatar from "@/components/ui/Avatar.vue"
import Badge from "@/components/ui/Badge.vue"
import Button from "@/components/ui/Button.vue"
import Card from "@/components/ui/Card.vue"
import CardAction from "@/components/ui/CardAction.vue"
import CardContent from "@/components/ui/CardContent.vue"
import CardHeader from "@/components/ui/CardHeader.vue"
import CardTitle from "@/components/ui/CardTitle.vue"
import Checkbox from "@/components/ui/Checkbox.vue"
import Collapsible from "@/components/ui/Collapsible.vue"
import CollapsibleContent from "@/components/ui/CollapsibleContent.vue"
import CollapsibleTrigger from "@/components/ui/CollapsibleTrigger.vue"
import ComboChart from "@/components/ui/ComboChart.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import DropdownMenu from "@/components/ui/DropdownMenu.vue"
import DropdownMenuContent from "@/components/ui/DropdownMenuContent.vue"
import DropdownMenuItem from "@/components/ui/DropdownMenuItem.vue"
import DropdownMenuSeparator from "@/components/ui/DropdownMenuSeparator.vue"
import DropdownMenuTrigger from "@/components/ui/DropdownMenuTrigger.vue"
import Label from "@/components/ui/Label.vue"
import Pagination from "@/components/ui/Pagination.vue"
import PaginationContent from "@/components/ui/PaginationContent.vue"
import PaginationItem from "@/components/ui/PaginationItem.vue"
import PaginationLink from "@/components/ui/PaginationLink.vue"
import PaginationNext from "@/components/ui/PaginationNext.vue"
import PaginationPrevious from "@/components/ui/PaginationPrevious.vue"
import SearchField from "@/components/ui/SearchField.vue"
import Select from "@/components/ui/Select.vue"
import SelectContent from "@/components/ui/SelectContent.vue"
import SelectItem from "@/components/ui/SelectItem.vue"
import SelectTrigger from "@/components/ui/SelectTrigger.vue"
import SelectValue from "@/components/ui/SelectValue.vue"
import Sidebar from "@/components/ui/Sidebar.vue"
import SidebarBrand from "@/components/ui/SidebarBrand.vue"
import SidebarContent from "@/components/ui/SidebarContent.vue"
import SidebarFooter from "@/components/ui/SidebarFooter.vue"
import SidebarGroup from "@/components/ui/SidebarGroup.vue"
import SidebarGroupContent from "@/components/ui/SidebarGroupContent.vue"
import SidebarHeader from "@/components/ui/SidebarHeader.vue"
import SidebarInset from "@/components/ui/SidebarInset.vue"
import SidebarMenu from "@/components/ui/SidebarMenu.vue"
import SidebarMenuBadge from "@/components/ui/SidebarMenuBadge.vue"
import SidebarMenuButton from "@/components/ui/SidebarMenuButton.vue"
import SidebarMenuItem from "@/components/ui/SidebarMenuItem.vue"
import SidebarMenuSub from "@/components/ui/SidebarMenuSub.vue"
import SidebarMenuSubButton from "@/components/ui/SidebarMenuSubButton.vue"
import SidebarMenuSubItem from "@/components/ui/SidebarMenuSubItem.vue"
import SidebarProvider from "@/components/ui/SidebarProvider.vue"
import SidebarSearch from "@/components/ui/SidebarSearch.vue"
import SidebarTrigger from "@/components/ui/SidebarTrigger.vue"
import StatTile from "@/components/ui/StatTile.vue"
import StatTileAction from "@/components/ui/StatTileAction.vue"
import StatTileHeader from "@/components/ui/StatTileHeader.vue"
import StatTileLabel from "@/components/ui/StatTileLabel.vue"
import StatTileList from "@/components/ui/StatTileList.vue"
import Table from "@/components/ui/Table.vue"
import TableBody from "@/components/ui/TableBody.vue"
import TableCell from "@/components/ui/TableCell.vue"
import TableHead from "@/components/ui/TableHead.vue"
import TableHeader from "@/components/ui/TableHeader.vue"
import TableRow from "@/components/ui/TableRow.vue"
import ToggleGroup from "@/components/ui/ToggleGroup.vue"
import ToggleGroupItem from "@/components/ui/ToggleGroupItem.vue"
import { DigIcon, type DigIconName } from "@/lib/icons"
import { formatCurrency, formatJalali, formatNumber, formatRelativeTime, toFaDigits, toSearchKey } from "@/lib/persian"

// stock-images:begin
/** تصویرهای کتابخانهٔ دیگ (همان آدرس‌های `stockImages` نسخهٔ React). */
const stockImages: Record<string, { src: string; alt: string }> = {
  personWoman1: { src: "https://docs.digdesign.ir/images/person-woman-1.webp", alt: "پرترهٔ زنی با روسری" },
}
// stock-images:end

const AVATAR_ICON = "size-[95%] translate-y-1 text-[color-mix(in_oklab,var(--muted-foreground)_55%,var(--muted))]"

/* ------------------------------------------------------------------ داده */

/** دادهٔ نمونهٔ قطعی برای هر بازه؛ در پروژهٔ واقعی همین سه فراخوانی API است. */
function salesFor(period: string) {
  const wave = (index: number, base: number, amp: number) => Math.round(base + amp * Math.sin(index * 0.9) + index * (amp / 6))
  if (period === "7") {
    return Array.from({ length: 7 }, (_, index) => ({
      label: `${toFaDigits(3 + index)} مهر`,
      revenue: wave(index, 52, 12),
      orders: wave(index, 165, 28),
    }))
  }
  if (period === "30") {
    // ۳۰ روز در ۱۰ دستهٔ سه‌روزه، تا میله‌ها خوانا بمانند.
    return Array.from({ length: 10 }, (_, index) => ({
      label: `${toFaDigits(1 + index * 3)} ${index < 3 ? "شهریور" : "مهر"}`,
      revenue: wave(index, 150, 30),
      orders: wave(index, 480, 70),
    }))
  }
  return Array.from({ length: 12 }, (_, index) => ({
    label: `هفتهٔ ${toFaDigits(index + 1)}`,
    revenue: wave(index, 360, 70),
    orders: wave(index, 1150, 160),
  }))
}

const QUICK: { title: string; hint: string; icon: DigIconName; tone: string }[] = [
  { title: "محصولِ تازه", hint: "افزودن به فروشگاه", icon: "plus", tone: "bg-primary-subtle text-primary-subtle-foreground" },
  { title: "ثبتِ سفارش", hint: "فروشِ حضوری", icon: "receipt", tone: "bg-info-subtle text-info-subtle-foreground" },
  { title: "کدِ تخفیف", hint: "کمپینِ تازه", icon: "tag", tone: "bg-warning-subtle text-warning-subtle-foreground" },
  { title: "گزارشِ فروش", hint: "خروجی اکسل", icon: "bar-chart", tone: "bg-success-subtle text-success-subtle-foreground" },
]

const CUSTOMERS: { name: string; gender: "male" | "female"; orders: number; spent: string }[] = [
  { name: "مهسا توکلی", gender: "female", orders: 24, spent: "۱۲٫۴ میلیون" },
  { name: "کیان مرادی", gender: "male", orders: 18, spent: "۹٫۸ میلیون" },
  { name: "نیلوفر احمدی", gender: "female", orders: 11, spent: "۶٫۱ میلیون" },
  { name: "پرهام نوری", gender: "male", orders: 7, spent: "۳٫۹ میلیون" },
]

type Status = "shipped" | "processing" | "delivered" | "pending"
const STATUS: Record<Status, { text: string; color: "warning" | "info" | "success" | "destructive" }> = {
  shipped: { text: "ارسال شد", color: "warning" },
  processing: { text: "در حال آماده‌سازی", color: "info" },
  delivered: { text: "تحویل شد", color: "success" },
  pending: { text: "در انتظار پرداخت", color: "destructive" },
}
const ORDERS: { id: string; customer: string; date: string; total: number; status: Status }[] = [
  { id: "1098", customer: "آرمیتا رستگار", date: "2026-10-01", total: 2_450_000, status: "shipped" },
  { id: "1097", customer: "کیان مرادی", date: "2026-09-30", total: 1_265_000, status: "processing" },
  { id: "1096", customer: "نیلوفر احمدی", date: "2026-09-29", total: 5_100_000, status: "delivered" },
  { id: "1095", customer: "سارا محمدی", date: "2026-09-28", total: 789_000, status: "pending" },
  { id: "1094", customer: "علی کریمی", date: "2026-09-28", total: 3_320_000, status: "delivered" },
  { id: "1093", customer: "مهسا نوری", date: "2026-09-27", total: 1_980_000, status: "shipped" },
  { id: "1092", customer: "رضا امینی", date: "2026-09-27", total: 640_000, status: "delivered" },
  { id: "1091", customer: "پریسا کاظمی", date: "2026-09-26", total: 4_250_000, status: "processing" },
  { id: "1090", customer: "حامد یزدانی", date: "2026-09-25", total: 2_100_000, status: "delivered" },
  { id: "1089", customer: "الهام صادقی", date: "2026-09-25", total: 990_000, status: "pending" },
  { id: "1088", customer: "بهراد فرهی", date: "2026-09-24", total: 3_760_000, status: "delivered" },
  { id: "1087", customer: "شیما رحیمی", date: "2026-09-23", total: 1_430_000, status: "shipped" },
]
const PAGE_SIZE = 5

const NOTIFICATIONS: { id: number; title: string; body: string; time: string; icon: DigIconName; tone: string }[] = [
  { id: 1, title: "سفارش تازه", body: "سفارش ۱۰۹۹ ثبت شد", time: "2026-10-03T10:00:00", icon: "receipt", tone: "bg-info-subtle text-info" },
  { id: 2, title: "موجودی رو به اتمام", body: "فقط ۷ عدد از هدفون پرو مانده", time: "2026-10-03T09:00:00", icon: "shop", tone: "bg-warning-subtle text-warning-subtle-foreground" },
  { id: 3, title: "نظر مثبت", body: "«ارسال سریع و بسته‌بندی عالی»", time: "2026-10-03T08:00:00", icon: "badge-star", tone: "bg-success-subtle text-success-subtle-foreground" },
]

/** آیتم‌های منوی کناری؛ همان NavItemهای نسخهٔ React. */
const NAV_MAIN: { icon: DigIconName; title: string; active?: boolean; badge?: string }[] = [
  { icon: "dashboard", title: "پیشخوان", active: true },
  { icon: "receipt", title: "سفارش‌ها", badge: toFaDigits(12) },
  { icon: "shop", title: "محصولات" },
  { icon: "users", title: "مشتریان" },
]
const NAV_ANALYTICS = ["گزارش فروش", "عملکرد محصولات", "رفتار مشتریان"]
const NAV_SUPPORT: { icon: DigIconName; title: string; badge?: string; destructive?: boolean }[] = [
  { icon: "bell", title: "هشدار موجودی", badge: toFaDigits(6), destructive: true },
  { icon: "shield-check", title: "نقش‌ها و دسترسی‌ها" },
  { icon: "ticket", title: "پشتیبانی" },
  { icon: "guide", title: "راهنما" },
]

/**
 * سوییچِ روشن/تیره در پایینِ نوار. کلاسِ dark روی <html> را عوض می‌کند؛ در پروژه‌ای
 * که حالتِ رنگی را جای دیگری نگه می‌دارد، به‌جایش همان را صدا بزنید.
 */
const theme = ref<"light" | "dark">("light")
let themeObserver: MutationObserver | undefined
const readTheme = () => (document.documentElement.classList.contains("dark") ? "dark" : "light")
onMounted(() => {
  theme.value = readTheme()
  themeObserver = new MutationObserver(() => (theme.value = readTheme()))
  themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] })
})
onBeforeUnmount(() => themeObserver?.disconnect())
function applyTheme(next: "light" | "dark") {
  document.documentElement.classList.toggle("dark", next === "dark")
  document.documentElement.classList.toggle("light", next === "light")
}
function onThemeChange(value: string | string[] | undefined) {
  if (!value) return
  applyTheme(value as "light" | "dark")
}

/* ------------------------------------------------------------------ بلاک */

const period = ref("30")
const showRevenue = ref(true)
const showOrders = ref(true)
const query = ref("")
const selected = ref<string[]>([])
const notifications = ref([...NOTIFICATIONS])
const page = ref(1)

const sales = computed(() => salesFor(period.value))
const chartData = computed(() =>
  sales.value.map((row) => ({
    ...row,
    revenue: showRevenue.value ? row.revenue : null,
    orders: showOrders.value ? row.orders : null,
  }))
)
const filtered = computed(() => ORDERS.filter((order) => toSearchKey(order.customer + order.id).includes(toSearchKey(query.value))))
const pageCount = computed(() => Math.max(1, Math.ceil(filtered.value.length / PAGE_SIZE)))
const currentPage = computed(() => Math.min(page.value, pageCount.value))
const orders = computed(() => filtered.value.slice((currentPage.value - 1) * PAGE_SIZE, currentPage.value * PAGE_SIZE))
const allSelected = computed(() => orders.value.length > 0 && orders.value.every((order) => selected.value.includes(order.id)))

function onOrderSearch(value: string) {
  query.value = value
  page.value = 1
}
function setSelected(id: string, on: boolean) {
  selected.value = on ? [...selected.value, id] : selected.value.filter((item) => item !== id)
}
</script>

<template>
  <ControlSize size="xl" as-child>
    <SidebarProvider>
      <Sidebar collapsible="icon">
        <SidebarHeader class="gap-3 p-3 group-data-[collapsible=icon]:p-2">
          <SidebarBrand title="فروشگاه دیگ" subtitle="پنل مدیریت">
            <template #logo><DigIcon name="dig-logo" /></template>
          </SidebarBrand>
          <SidebarSearch placeholder="جست‌وجو در منو…" aria-label="جست‌وجو در منو" />
        </SidebarHeader>
        <SidebarContent class="gap-0 pt-4">
          <SidebarGroup>
            <SidebarGroupContent>
              <SidebarMenu>
                <SidebarMenuItem v-for="item in NAV_MAIN" :key="item.title">
                  <SidebarMenuButton as-child :is-active="item.active" :tooltip="item.title">
                    <a href="#">
                      <DigIcon :name="item.icon" />
                      <span>{{ item.title }}</span>
                    </a>
                  </SidebarMenuButton>
                  <SidebarMenuBadge v-if="item.badge">{{ item.badge }}</SidebarMenuBadge>
                </SidebarMenuItem>
                <!-- زیرمنو جمع‌شونده و پیش‌فرض بسته؛ همیشه‌باز منو را شلوغ می‌کرد. -->
                <SidebarMenuItem>
                  <Collapsible>
                    <CollapsibleTrigger as-child>
                      <SidebarMenuButton class="group/collapsible">
                        <DigIcon name="bar-chart" />
                        <span>تحلیل‌ها</span>
                        <Badge variant="soft" color="violet" size="sm" class="ms-auto">ویژه</Badge>
                        <DigIcon name="chevron-down" class="size-4! transition-transform group-data-[state=open]/collapsible:rotate-180" />
                      </SidebarMenuButton>
                    </CollapsibleTrigger>
                    <CollapsibleContent>
                      <SidebarMenuSub>
                        <SidebarMenuSubItem v-for="title in NAV_ANALYTICS" :key="title">
                          <SidebarMenuSubButton href="#">{{ title }}</SidebarMenuSubButton>
                        </SidebarMenuSubItem>
                      </SidebarMenuSub>
                    </CollapsibleContent>
                  </Collapsible>
                </SidebarMenuItem>
              </SidebarMenu>
            </SidebarGroupContent>
          </SidebarGroup>
          <SidebarGroup>
            <SidebarGroupContent>
              <SidebarMenu>
                <SidebarMenuItem v-for="item in NAV_SUPPORT" :key="item.title">
                  <SidebarMenuButton as-child :tooltip="item.title">
                    <a href="#">
                      <DigIcon :name="item.icon" />
                      <span>{{ item.title }}</span>
                    </a>
                  </SidebarMenuButton>
                  <SidebarMenuBadge v-if="item.badge" :tone="item.destructive ? 'destructive' : 'default'">{{ item.badge }}</SidebarMenuBadge>
                </SidebarMenuItem>
              </SidebarMenu>
            </SidebarGroupContent>
          </SidebarGroup>
        </SidebarContent>
        <SidebarFooter class="gap-4 px-3 pt-3 pb-9 group-data-[collapsible=icon]:p-2">
          <!-- کنترلِ ریزِ پایینِ نوارِ کناری؛ هم‌اندازهٔ آیتم‌های منو (۳۶)، نه فیلترِ صفحه. -->
          <ControlSize size="default" mobile-size="sm" as-child>
            <ToggleGroup type="single" variant="segmented" full-width :value="theme" aria-label="پوستهٔ رنگی" class="group-data-[collapsible=icon]:hidden" @update:value="onThemeChange">
              <ToggleGroupItem value="light" aria-label="پوستهٔ روشن">
                <DigIcon name="sun" />
              </ToggleGroupItem>
              <ToggleGroupItem value="dark" aria-label="پوستهٔ تیره">
                <DigIcon name="moon" />
              </ToggleGroupItem>
            </ToggleGroup>
          </ControlSize>
          <!-- حالتِ جمع: یک دکمهٔ آیکونی که بینِ دو پوسته جابه‌جا می‌کند. -->
          <SidebarMenu class="hidden group-data-[collapsible=icon]:flex">
            <SidebarMenuItem>
              <SidebarMenuButton :tooltip="theme === 'dark' ? 'پوستهٔ روشن' : 'پوستهٔ تیره'" @click="applyTheme(theme === 'dark' ? 'light' : 'dark')">
                <DigIcon :name="theme === 'dark' ? 'sun' : 'moon'" />
                <span>{{ theme === "dark" ? "پوستهٔ روشن" : "پوستهٔ تیره" }}</span>
              </SidebarMenuButton>
            </SidebarMenuItem>
          </SidebarMenu>
          <p class="text-center text-xs text-muted-foreground group-data-[collapsible=icon]:hidden">نسخهٔ ۲٫۴٫۰ · به‌روزرسانی ۱۲ مهر</p>
        </SidebarFooter>
      </Sidebar>

      <SidebarInset class="flex min-w-0 flex-col gap-6 bg-muted p-4 sm:p-6">
        <header class="flex flex-wrap items-center gap-3">
          <SidebarTrigger />
          <div class="flex flex-col gap-0.5">
            <h1 class="text-xl font-bold">سلام آرمیتا</h1>
            <p class="text-sm text-muted-foreground">امروز ۱۲ سفارشِ تازه منتظرِ آماده‌سازی است.</p>
          </div>
          <SearchField aria-label="جست‌وجو" placeholder="جست‌وجوی محصول، مشتری یا سفارش…" class="order-last w-full sm:order-none sm:ms-auto sm:w-80 [&_input]:bg-card [&>div]:bg-card" />
          <div class="ms-auto flex items-center gap-2 sm:ms-0">
            <Button variant="outline" size="icon" aria-label="اعلان‌ها، ۳ مورد تازه" class="relative bg-card">
              <DigIcon name="bell" />
              <span aria-hidden="true" class="absolute end-2 top-2 size-2 rounded-full bg-destructive" />
            </Button>
            <!-- پروفایل در نوارِ بالا؛ تنظیمات و خروج در منوی همین آواتار. -->
            <DropdownMenu>
              <DropdownMenuTrigger as-child>
                <Button variant="ghost" class="gap-2 px-1.5" aria-label="منوی حساب">
                  <Avatar size="sm" alt="آرمیتا رستگار" :src="stockImages.personWoman1.src" class="ring-1 ring-border">
                    <template #icon><DigIcon name="avatar-female" :class="AVATAR_ICON" /></template>
                  </Avatar>
                  <span class="hidden flex-col items-start leading-snug md:flex">
                    <span class="text-sm font-semibold">آرمیتا رستگار</span>
                    <span class="text-xs text-muted-foreground">مدیر فروشگاه</span>
                  </span>
                  <DigIcon name="chevron-down" class="text-muted-foreground" />
                </Button>
              </DropdownMenuTrigger>
              <DropdownMenuContent align="end" class="w-56">
                <DropdownMenuItem>
                  <DigIcon name="settings" />
                  تنظیمات حساب
                </DropdownMenuItem>
                <DropdownMenuSeparator />
                <DropdownMenuItem variant="destructive">
                  <DigIcon name="logout" />
                  خروج
                </DropdownMenuItem>
              </DropdownMenuContent>
            </DropdownMenu>
          </div>
        </header>

        <!-- دسترسی سریع: کارهای پرتکرار با یک کلیک، بالای همهٔ گزارش‌ها. -->
        <section aria-label="دسترسی سریع" class="grid grid-cols-2 gap-3 md:grid-cols-4">
          <Button v-for="item in QUICK" :key="item.title" variant="outline" class="h-auto justify-start gap-3 rounded-xl bg-card! p-4 text-start shadow-none hover:border-input">
            <span aria-hidden="true" :class="`flex size-11 shrink-0 items-center justify-center rounded-xl [&_svg]:size-5 ${item.tone}`">
              <DigIcon :name="item.icon" />
            </span>
            <span class="flex min-w-0 flex-col gap-0.5">
              <span class="truncate text-sm font-semibold">{{ item.title }}</span>
              <span class="truncate text-xs text-muted-foreground">{{ item.hint }}</span>
            </span>
          </Button>
        </section>

        <div class="grid grid-cols-1 gap-6 xl:grid-cols-[minmax(0,1fr)_22rem]">
          <Card>
            <!-- کنترل‌ها روبه‌روی عنوان؛ در موبایل زیرِ آن می‌پیچند. -->
            <CardHeader class="flex flex-wrap items-center justify-between gap-3">
              <CardTitle>فروش و سفارش‌ها</CardTitle>
              <div class="flex flex-wrap items-center gap-4">
                <div class="flex items-center gap-2">
                  <Checkbox id="show-revenue" :checked="showRevenue" @update:checked="(on) => (showRevenue = on === true)" />
                  <Label for="show-revenue">فروش</Label>
                </div>
                <div class="flex items-center gap-2">
                  <Checkbox id="show-orders" :checked="showOrders" @update:checked="(on) => (showOrders = on === true)" />
                  <Label for="show-orders">سفارش</Label>
                </div>
                <Select :value="period" @update:value="(next) => (period = next as string)">
                  <SelectTrigger size="sm" aria-label="بازهٔ زمانی" class="w-28">
                    <SelectValue />
                  </SelectTrigger>
                  <SelectContent>
                    <SelectItem value="7">۷ روز</SelectItem>
                    <SelectItem value="30">۳۰ روز</SelectItem>
                    <SelectItem value="90">۹۰ روز</SelectItem>
                  </SelectContent>
                </Select>
              </div>
            </CardHeader>
            <CardContent>
              <ComboChart
                class="h-80"
                :data="chartData"
                category-key="label"
                :bar="{ key: 'revenue', label: 'فروش (میلیون تومان)', color: 'var(--chart-1)' }"
                :bar-formatter="(value: number) => formatNumber(value)"
                :line="{ key: 'orders', label: 'سفارش', color: 'var(--chart-4)' }"
              />
            </CardContent>
          </Card>

          <section class="flex flex-col gap-4" aria-label="خلاصه">
            <StatTile>
              <StatTileHeader>
                <StatTileLabel class="text-base text-foreground">قیفِ خرید</StatTileLabel>
                <StatTileAction aria-label="جزئیات قیف خرید" />
              </StatTileHeader>
              <StatTileList
                :items="[
                  { label: 'بازدید', value: 100, display: '٪۱۰۰' },
                  { label: 'دیدنِ محصول', value: 74, display: '٪۷۴' },
                  { label: 'افزودن به سبد', value: 62, display: '٪۶۲' },
                  { label: 'خریدِ موفق', value: 21, display: '٪۲۱' },
                ]"
              />
            </StatTile>
            <StatTile class="gap-3">
              <StatTileHeader>
                <StatTileLabel class="text-base text-foreground">مشتریانِ تازه</StatTileLabel>
                <Button variant="ghost" class="ms-auto">همه</Button>
              </StatTileHeader>
              <ul class="flex flex-col gap-1">
                <li v-for="customer in CUSTOMERS" :key="customer.name" class="flex items-center gap-3 rounded-xl p-2 hover:bg-muted">
                  <Avatar size="sm" :alt="customer.name" class="ring-1 ring-border">
                    <template #icon><DigIcon :name="customer.gender === 'male' ? 'avatar-male' : 'avatar-female'" :class="AVATAR_ICON" /></template>
                  </Avatar>
                  <div class="flex min-w-0 flex-1 flex-col gap-1">
                    <span class="truncate text-sm font-medium">{{ customer.name }}</span>
                    <span class="text-xs text-muted-foreground">{{ toFaDigits(customer.orders) }} سفارش · {{ customer.spent }}</span>
                  </div>
                  <Button variant="ghost" size="icon" :aria-label="`پیام به ${customer.name}`">
                    <DigIcon name="envelope" />
                  </Button>
                </li>
              </ul>
            </StatTile>
          </section>
        </div>

        <div class="grid grid-cols-1 gap-6 xl:grid-cols-[minmax(0,1fr)_22rem]">
          <Card>
            <CardHeader class="flex flex-wrap items-center justify-between gap-3">
              <CardTitle>سفارش‌ها</CardTitle>
              <!-- جست‌وجو کنارِ فیلتر، روبه‌روی عنوان؛ ابزارهای جدول یک‌جا. -->
              <div class="flex w-full items-center gap-2 sm:w-auto">
                <SearchField aria-label="جست‌وجوی سفارش" placeholder="شماره سفارش یا نام مشتری" :model-value="query" class="min-w-0 flex-1 sm:w-64" @update:model-value="onOrderSearch" />
                <Button variant="outline" size="icon" aria-label="فیلتر سفارش‌ها">
                  <DigIcon name="filter" />
                </Button>
              </div>
            </CardHeader>
            <CardContent class="flex flex-col gap-4">
              <div class="overflow-hidden rounded-lg border border-border">
                <Table stack-on-mobile class="min-w-[36rem]">
                  <TableHeader class="bg-muted">
                    <TableRow>
                      <TableHead class="w-10">
                        <Checkbox aria-label="انتخاب همه" :checked="allSelected" @update:checked="(on) => (selected = on === true ? orders.map((order) => order.id) : [])" />
                      </TableHead>
                      <TableHead>شماره</TableHead>
                      <TableHead>مشتری</TableHead>
                      <TableHead>تاریخ</TableHead>
                      <TableHead class="text-end">مبلغ</TableHead>
                      <TableHead>وضعیت</TableHead>
                    </TableRow>
                  </TableHeader>
                  <TableBody>
                    <TableRow v-for="order in orders" :key="order.id" :data-state="selected.includes(order.id) ? 'selected' : undefined">
                      <TableCell>
                        <Checkbox :aria-label="`انتخاب سفارش ${toFaDigits(order.id)}`" :checked="selected.includes(order.id)" @update:checked="(on) => setSelected(order.id, on === true)" />
                      </TableCell>
                      <TableCell class="font-medium">
                        <bdi dir="ltr">#{{ toFaDigits(order.id) }}</bdi>
                      </TableCell>
                      <TableCell>{{ order.customer }}</TableCell>
                      <TableCell class="text-muted-foreground">{{ formatJalali(new Date(order.date)) }}</TableCell>
                      <TableCell class="text-end tabular-nums">{{ formatCurrency(order.total) }}</TableCell>
                      <TableCell>
                        <Badge variant="soft" :color="STATUS[order.status].color">{{ STATUS[order.status].text }}</Badge>
                      </TableCell>
                    </TableRow>
                  </TableBody>
                </Table>
              </div>
              <div class="flex flex-wrap items-center justify-between gap-3">
                <span class="text-sm text-muted-foreground">{{ toFaDigits(filtered.length) }} سفارش · صفحهٔ {{ toFaDigits(currentPage) }} از {{ toFaDigits(pageCount) }}</span>
                <Pagination class="mx-0 w-auto">
                  <PaginationContent>
                    <PaginationItem>
                      <PaginationPrevious href="#" :aria-disabled="currentPage === 1" @click.prevent="page = Math.max(1, currentPage - 1)" />
                    </PaginationItem>
                    <PaginationItem v-for="number in pageCount" :key="number">
                      <PaginationLink href="#" :is-active="number === currentPage" @click.prevent="page = number">{{ toFaDigits(number) }}</PaginationLink>
                    </PaginationItem>
                    <PaginationItem>
                      <PaginationNext href="#" :aria-disabled="currentPage === pageCount" @click.prevent="page = Math.min(pageCount, currentPage + 1)" />
                    </PaginationItem>
                  </PaginationContent>
                </Pagination>
              </div>
            </CardContent>
          </Card>

          <Card>
            <CardHeader>
              <CardTitle>اعلان‌ها</CardTitle>
              <CardAction>
                <Badge variant="soft" color="destructive">{{ toFaDigits(notifications.length) }} تازه</Badge>
              </CardAction>
            </CardHeader>
            <CardContent class="flex flex-col gap-3">
              <p v-if="notifications.length === 0" class="py-6 text-center text-sm text-muted-foreground">اعلانِ تازه‌ای نیست.</p>
              <div v-for="item in notifications" :key="item.id" class="flex items-start gap-3 rounded-lg border border-border bg-card p-3">
                <span aria-hidden="true" :class="`flex size-9 shrink-0 items-center justify-center rounded-full [&_svg]:size-4 ${item.tone}`">
                  <DigIcon :name="item.icon" />
                </span>
                <div class="flex min-w-0 flex-1 flex-col gap-1">
                  <span class="text-sm font-semibold">{{ item.title }}</span>
                  <span class="truncate text-xs text-muted-foreground">{{ item.body }}</span>
                  <span class="text-xs text-muted-foreground">{{ formatRelativeTime(item.time) }}</span>
                </div>
                <Button variant="ghost" size="icon" :aria-label="`بستن اعلان ${item.title}`" @click="notifications = notifications.filter((entry) => entry.id !== item.id)">
                  <DigIcon name="x" />
                </Button>
              </div>
              <Button variant="outline" full-width>مشاهدهٔ همه</Button>
            </CardContent>
          </Card>
        </div>
      </SidebarInset>
    </SidebarProvider>
  </ControlSize>
</template>

کدِ این بلاک هنوز برای Svelte نوشته نشده است.

این موارد هنوز برای Svelte آماده نیستند: avatarbadgecardchart-presetscheckboxcollapsiblecontrol-sizedropdown-menulabelpaginationpersiansearch-fieldselectsidebarstat-tiletabletoggle-groupآیکون avatar-genderآیکون badge-starآیکون bar-chartآیکون bellآیکون chevron-downآیکون dashboardآیکون dig-logoآیکون envelopeآیکون filterآیکون guideآیکون logoutآیکون moonآیکون plusآیکون receiptآیکون settingsآیکون shield-checkآیکون shopآیکون sunآیکون tagآیکون ticketآیکون usersآیکون x

کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="svelte" ایجنت آن را با کامپوننت‌های Svelte می‌سازد.

dashboard.ts
import {
  Component,
  ChangeDetectionStrategy,
  signal,
  afterNextRender,
  DestroyRef,
  inject,
  computed,
} from "@angular/core"

import { DigControlSize } from "@/components/ui/control-size"
import {
  DigSidebarProvider,
  DigSidebar,
  DigSidebarHeader,
  DigSidebarBrand,
  DigSidebarBrandLogo,
  DigSidebarSearch,
  DigSidebarContent,
  DigSidebarGroup,
  DigSidebarGroupContent,
  DigSidebarMenu,
  DigSidebarMenuItem,
  DigSidebarMenuButton,
  DigSidebarMenuBadge,
  DigSidebarMenuSub,
  DigSidebarMenuSubItem,
  DigSidebarMenuSubButton,
  DigSidebarFooter,
  DigSidebarInset,
  DigSidebarTrigger,
} from "@/components/ui/sidebar"
import { DigIcon, type DigIconName } from "@/lib/icons"
import {
  DigCollapsible,
  DigCollapsibleTrigger,
  DigCollapsibleContent,
} from "@/components/ui/collapsible"
import { DigBadge } from "@/components/ui/badge"
import {
  DigToggleGroup,
  DigToggleGroupItem,
} from "@/components/ui/toggle-group"
import { DigSearchField } from "@/components/ui/search-field"
import { DigButton } from "@/components/ui/button"
import {
  DigDropdownMenu,
  DigDropdownMenuTrigger,
  DigDropdownMenuContent,
  DigDropdownMenuItem,
  DigDropdownMenuSeparator,
} from "@/components/ui/dropdown-menu"
import { DigAvatar } from "@/components/ui/avatar"
import {
  DigCard,
  DigCardHeader,
  DigCardTitle,
  DigCardContent,
  DigCardAction,
} from "@/components/ui/card"
import { DigCheckbox } from "@/components/ui/checkbox"
import { DigLabel } from "@/components/ui/label"
import {
  DigSelect,
  DigSelectTrigger,
  DigSelectValue,
  DigSelectContent,
  DigSelectItem,
} from "@/components/ui/select"
import { DigComboChart } from "@/components/ui/chart-presets"
import {
  DigStatTile,
  DigStatTileHeader,
  DigStatTileLabel,
  DigStatTileAction,
  DigStatTileList,
} from "@/components/ui/stat-tile"
import {
  DigTable,
  DigTableHeader,
  DigTableRow,
  DigTableHead,
  DigTableBody,
  DigTableCell,
} from "@/components/ui/table"
import {
  DigPagination,
  DigPaginationContent,
  DigPaginationItem,
  DigPaginationPrevious,
  DigPaginationLink,
  DigPaginationNext,
} from "@/components/ui/pagination"
import {
  formatCurrency,
  formatJalali,
  formatNumber,
  formatRelativeTime,
  toFaDigits,
  toSearchKey,
} from "@/lib/persian"

const stockImages: Record<string, { src: string; alt: string }> = {
  personWoman1: {
    src: "https://docs.digdesign.ir/images/person-woman-1.webp",
    alt: "پرترهٔ زنی با روسری",
  },
}

const QUICK: {
  title: string
  hint: string
  icon: DigIconName
  tone: string
}[] = [
  {
    title: "محصولِ تازه",
    hint: "افزودن به فروشگاه",
    icon: "plus",
    tone: "bg-primary-subtle text-primary-subtle-foreground",
  },
  {
    title: "ثبتِ سفارش",
    hint: "فروشِ حضوری",
    icon: "receipt",
    tone: "bg-info-subtle text-info-subtle-foreground",
  },
  {
    title: "کدِ تخفیف",
    hint: "کمپینِ تازه",
    icon: "tag",
    tone: "bg-warning-subtle text-warning-subtle-foreground",
  },
  {
    title: "گزارشِ فروش",
    hint: "خروجی اکسل",
    icon: "bar-chart",
    tone: "bg-success-subtle text-success-subtle-foreground",
  },
]

const CUSTOMERS: {
  name: string
  gender: "male" | "female"
  orders: number
  spent: string
}[] = [
  { name: "مهسا توکلی", gender: "female", orders: 24, spent: "۱۲٫۴ میلیون" },
  { name: "کیان مرادی", gender: "male", orders: 18, spent: "۹٫۸ میلیون" },
  { name: "نیلوفر احمدی", gender: "female", orders: 11, spent: "۶٫۱ میلیون" },
  { name: "پرهام نوری", gender: "male", orders: 7, spent: "۳٫۹ میلیون" },
]

type Status = "shipped" | "processing" | "delivered" | "pending"

const STATUS: Record<
  Status,
  { text: string; color: "warning" | "info" | "success" | "destructive" }
> = {
  shipped: { text: "ارسال شد", color: "warning" },
  processing: { text: "در حال آماده‌سازی", color: "info" },
  delivered: { text: "تحویل شد", color: "success" },
  pending: { text: "در انتظار پرداخت", color: "destructive" },
}

const ORDERS: {
  id: string
  customer: string
  date: string
  total: number
  status: Status
}[] = [
  {
    id: "1098",
    customer: "آرمیتا رستگار",
    date: "2026-10-01",
    total: 2_450_000,
    status: "shipped",
  },
  {
    id: "1097",
    customer: "کیان مرادی",
    date: "2026-09-30",
    total: 1_265_000,
    status: "processing",
  },
  {
    id: "1096",
    customer: "نیلوفر احمدی",
    date: "2026-09-29",
    total: 5_100_000,
    status: "delivered",
  },
  {
    id: "1095",
    customer: "سارا محمدی",
    date: "2026-09-28",
    total: 789_000,
    status: "pending",
  },
  {
    id: "1094",
    customer: "علی کریمی",
    date: "2026-09-28",
    total: 3_320_000,
    status: "delivered",
  },
  {
    id: "1093",
    customer: "مهسا نوری",
    date: "2026-09-27",
    total: 1_980_000,
    status: "shipped",
  },
  {
    id: "1092",
    customer: "رضا امینی",
    date: "2026-09-27",
    total: 640_000,
    status: "delivered",
  },
  {
    id: "1091",
    customer: "پریسا کاظمی",
    date: "2026-09-26",
    total: 4_250_000,
    status: "processing",
  },
  {
    id: "1090",
    customer: "حامد یزدانی",
    date: "2026-09-25",
    total: 2_100_000,
    status: "delivered",
  },
  {
    id: "1089",
    customer: "الهام صادقی",
    date: "2026-09-25",
    total: 990_000,
    status: "pending",
  },
  {
    id: "1088",
    customer: "بهراد فرهی",
    date: "2026-09-24",
    total: 3_760_000,
    status: "delivered",
  },
  {
    id: "1087",
    customer: "شیما رحیمی",
    date: "2026-09-23",
    total: 1_430_000,
    status: "shipped",
  },
]

const PAGE_SIZE = 5

const NOTIFICATIONS: {
  id: number
  title: string
  body: string
  time: string
  icon: DigIconName
  tone: string
}[] = [
  {
    id: 1,
    title: "سفارش تازه",
    body: "سفارش ۱۰۹۹ ثبت شد",
    time: "2026-10-03T10:00:00",
    icon: "receipt",
    tone: "bg-info-subtle text-info",
  },
  {
    id: 2,
    title: "موجودی رو به اتمام",
    body: "فقط ۷ عدد از هدفون پرو مانده",
    time: "2026-10-03T09:00:00",
    icon: "shop",
    tone: "bg-warning-subtle text-warning-subtle-foreground",
  },
  {
    id: 3,
    title: "نظر مثبت",
    body: "«ارسال سریع و بسته‌بندی عالی»",
    time: "2026-10-03T08:00:00",
    icon: "badge-star",
    tone: "bg-success-subtle text-success-subtle-foreground",
  },
]

const NAV_MAIN: {
  icon: DigIconName
  title: string
  active?: boolean
  badge?: string
}[] = [
  { icon: "dashboard", title: "پیشخوان", active: true },
  { icon: "receipt", title: "سفارش‌ها", badge: toFaDigits(12) },
  { icon: "shop", title: "محصولات" },
  { icon: "users", title: "مشتریان" },
]

const NAV_ANALYTICS = ["گزارش فروش", "عملکرد محصولات", "رفتار مشتریان"]

const NAV_SUPPORT: {
  icon: DigIconName
  title: string
  badge?: string
  destructive?: boolean
}[] = [
  {
    icon: "bell",
    title: "هشدار موجودی",
    badge: toFaDigits(6),
    destructive: true,
  },
  { icon: "shield-check", title: "نقش‌ها و دسترسی‌ها" },
  { icon: "ticket", title: "پشتیبانی" },
  { icon: "guide", title: "راهنما" },
]

const readTheme = () =>
  document.documentElement.classList.contains("dark") ? "dark" : "light"

@Component({
  selector: "dig-block-dashboard",
  imports: [
    DigControlSize,
    DigSidebarProvider,
    DigSidebar,
    DigSidebarHeader,
    DigSidebarBrand,
    DigSidebarBrandLogo,
    DigSidebarSearch,
    DigSidebarContent,
    DigSidebarGroup,
    DigSidebarGroupContent,
    DigSidebarMenu,
    DigSidebarMenuItem,
    DigSidebarMenuButton,
    DigSidebarMenuBadge,
    DigSidebarMenuSub,
    DigSidebarMenuSubItem,
    DigSidebarMenuSubButton,
    DigSidebarFooter,
    DigSidebarInset,
    DigSidebarTrigger,
    DigIcon,
    DigCollapsible,
    DigCollapsibleTrigger,
    DigCollapsibleContent,
    DigBadge,
    DigToggleGroup,
    DigToggleGroupItem,
    DigSearchField,
    DigButton,
    DigDropdownMenu,
    DigDropdownMenuTrigger,
    DigDropdownMenuContent,
    DigDropdownMenuItem,
    DigDropdownMenuSeparator,
    DigAvatar,
    DigCard,
    DigCardHeader,
    DigCardTitle,
    DigCardContent,
    DigCardAction,
    DigCheckbox,
    DigLabel,
    DigSelect,
    DigSelectTrigger,
    DigSelectValue,
    DigSelectContent,
    DigSelectItem,
    DigComboChart,
    DigStatTile,
    DigStatTileHeader,
    DigStatTileLabel,
    DigStatTileAction,
    DigStatTileList,
    DigTable,
    DigTableHeader,
    DigTableRow,
    DigTableHead,
    DigTableBody,
    DigTableCell,
    DigPagination,
    DigPaginationContent,
    DigPaginationItem,
    DigPaginationPrevious,
    DigPaginationLink,
    DigPaginationNext,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <div digControlSize="xl">
      <div digSidebarProvider>
        <div digSidebar collapsible="icon">
          <div
            digSidebarHeader
            class="gap-3 p-3 group-data-[collapsible=icon]:p-2"
          >
            <div digSidebarBrand title="فروشگاه دیگ" subtitle="پنل مدیریت">
              <span digSidebarBrandLogo><svg digIcon="dig-logo"></svg></span>
            </div>
            <label
              digSidebarSearch
              placeholder="جست‌وجو در منو…"
              aria-label="جست‌وجو در منو"
            ></label>
          </div>
          <div digSidebarContent class="gap-0 pt-4">
            <div digSidebarGroup>
              <div digSidebarGroupContent>
                <ul digSidebarMenu>
                  @for (item of NAV_MAIN; track item.title) {
                    <li digSidebarMenuItem>
                      <a
                        digSidebarMenuButton
                        [isActive]="item.active"
                        [tooltip]="item.title"
                        href="#"
                        ><svg [digIcon]="item.icon"></svg>
                        <span>{{ item.title }}</span></a
                      >
                      @if (item.badge) {
                        <div digSidebarMenuBadge>{{ item.badge }}</div>
                      }
                    </li>
                  }
                  <!-- زیرمنو جمع‌شونده و پیش‌فرض بسته؛ همیشه‌باز منو را شلوغ می‌کرد. -->
                  <li digSidebarMenuItem>
                    <div digCollapsible>
                      <button
                        digCollapsibleTrigger
                        digSidebarMenuButton
                        class="group/collapsible"
                      >
                        <svg digIcon="bar-chart"></svg>
                        <span>تحلیل‌ها</span>
                        <span
                          digBadge
                          variant="soft"
                          color="violet"
                          size="sm"
                          class="ms-auto"
                          >ویژه</span
                        >
                        <svg
                          digIcon="chevron-down"
                          class="size-4! transition-transform group-data-[state=open]/collapsible:rotate-180"
                        ></svg>
                      </button>
                      <div digCollapsibleContent>
                        <ul digSidebarMenuSub>
                          @for (title of NAV_ANALYTICS; track title) {
                            <li digSidebarMenuSubItem>
                              <a digSidebarMenuSubButton href="#">{{
                                title
                              }}</a>
                            </li>
                          }
                        </ul>
                      </div>
                    </div>
                  </li>
                </ul>
              </div>
            </div>
            <div digSidebarGroup>
              <div digSidebarGroupContent>
                <ul digSidebarMenu>
                  @for (item of NAV_SUPPORT; track item.title) {
                    <li digSidebarMenuItem>
                      <a digSidebarMenuButton [tooltip]="item.title" href="#"
                        ><svg [digIcon]="item.icon"></svg>
                        <span>{{ item.title }}</span></a
                      >
                      @if (item.badge) {
                        <div
                          digSidebarMenuBadge
                          [tone]="item.destructive ? 'destructive' : 'default'"
                        >
                          {{ item.badge }}
                        </div>
                      }
                    </li>
                  }
                </ul>
              </div>
            </div>
          </div>
          <div
            digSidebarFooter
            class="gap-4 px-3 pt-3 pb-9 group-data-[collapsible=icon]:p-2"
          >
            <!-- کنترلِ ریزِ پایینِ نوارِ کناری؛ هم‌اندازهٔ آیتم‌های منو (۳۶)، نه فیلترِ صفحه. -->
            <div digControlSize="default" mobileSize="sm">
              <div
                digToggleGroup
                type="single"
                variant="segmented"
                fullWidth
                [value]="theme()"
                aria-label="پوستهٔ رنگی"
                class="group-data-[collapsible=icon]:hidden"
                (valueChange)="onThemeChange($event)"
              >
                <button
                  digToggleGroupItem
                  value="light"
                  aria-label="پوستهٔ روشن"
                >
                  <svg digIcon="sun"></svg>
                </button>
                <button
                  digToggleGroupItem
                  value="dark"
                  aria-label="پوستهٔ تیره"
                >
                  <svg digIcon="moon"></svg>
                </button>
              </div>
            </div>
            <!-- حالتِ جمع: یک دکمهٔ آیکونی که بینِ دو پوسته جابه‌جا می‌کند. -->
            <ul
              digSidebarMenu
              class="hidden group-data-[collapsible=icon]:flex"
            >
              <li digSidebarMenuItem>
                <button
                  digSidebarMenuButton
                  [tooltip]="theme() === 'dark' ? 'پوستهٔ روشن' : 'پوستهٔ تیره'"
                  (click)="applyTheme(theme() === 'dark' ? 'light' : 'dark')"
                >
                  <svg [digIcon]="theme() === 'dark' ? 'sun' : 'moon'"></svg>
                  <span>{{
                    theme() === "dark" ? "پوستهٔ روشن" : "پوستهٔ تیره"
                  }}</span>
                </button>
              </li>
            </ul>
            <p
              class="text-center text-xs text-muted-foreground group-data-[collapsible=icon]:hidden"
            >
              نسخهٔ ۲٫۴٫۰ · به‌روزرسانی ۱۲ مهر
            </p>
          </div>
        </div>

        <main
          digSidebarInset
          class="flex min-w-0 flex-col gap-6 bg-muted p-4 sm:p-6"
        >
          <header class="flex flex-wrap items-center gap-3">
            <button digSidebarTrigger></button>
            <div class="flex flex-col gap-0.5">
              <h1 class="text-xl font-bold">سلام آرمیتا</h1>
              <p class="text-sm text-muted-foreground">
                امروز ۱۲ سفارشِ تازه منتظرِ آماده‌سازی است.
              </p>
            </div>
            <div
              digSearchField
              aria-label="جست‌وجو"
              placeholder="جست‌وجوی محصول، مشتری یا سفارش…"
              class="order-last w-full sm:order-none sm:ms-auto sm:w-80 [&_input]:bg-card [&>div]:bg-card"
            ></div>
            <div class="ms-auto flex items-center gap-2 sm:ms-0">
              <button
                digButton
                type="button"
                variant="outline"
                size="icon"
                aria-label="اعلان‌ها، ۳ مورد تازه"
                class="relative bg-card"
              >
                <svg digIcon="bell"></svg>
                <span
                  aria-hidden="true"
                  class="absolute end-2 top-2 size-2 rounded-full bg-destructive"
                ></span>
              </button>
              <!-- پروفایل در نوارِ بالا؛ تنظیمات و خروج در منوی همین آواتار. -->
              <ng-container digDropdownMenu
                ><button
                  digDropdownMenuTrigger
                  digButton
                  type="button"
                  variant="ghost"
                  class="gap-2 px-1.5"
                  aria-label="منوی حساب"
                >
                  <span
                    digAvatar
                    size="sm"
                    alt="آرمیتا رستگار"
                    [src]="stockImages.personWoman1.src"
                    class="ring-1 ring-border"
                    iconName="avatar-female"
                  ></span>
                  <span class="hidden flex-col items-start leading-snug md:flex"
                    ><span class="text-sm font-semibold">آرمیتا رستگار</span>
                    <span class="text-xs text-muted-foreground"
                      >مدیر فروشگاه</span
                    ></span
                  >
                  <svg
                    digIcon="chevron-down"
                    class="text-muted-foreground"
                  ></svg>
                </button>
                <div digDropdownMenuContent align="end" class="w-56">
                  <div digDropdownMenuItem>
                    <svg digIcon="settings"></svg>
                    تنظیمات حساب
                  </div>
                  <div digDropdownMenuSeparator></div>
                  <div digDropdownMenuItem variant="destructive">
                    <svg digIcon="logout"></svg>
                    خروج
                  </div>
                </div></ng-container
              >
            </div>
          </header>

          <!-- دسترسی سریع: کارهای پرتکرار با یک کلیک، بالای همهٔ گزارش‌ها. -->
          <section
            aria-label="دسترسی سریع"
            class="grid grid-cols-2 gap-3 md:grid-cols-4"
          >
            @for (item of QUICK; track item.title) {
              <button
                digButton
                type="button"
                variant="outline"
                class="h-auto justify-start gap-3 rounded-xl bg-card! p-4 text-start shadow-none hover:border-input"
              >
                <span
                  aria-hidden="true"
                  [class]="
                    \`flex size-11 shrink-0 items-center justify-center rounded-xl [&_svg]:size-5 \${item.tone}\`
                  "
                  ><svg [digIcon]="item.icon"></svg
                ></span>
                <span class="flex min-w-0 flex-col gap-0.5"
                  ><span class="truncate text-sm font-semibold">{{
                    item.title
                  }}</span>
                  <span class="truncate text-xs text-muted-foreground">{{
                    item.hint
                  }}</span></span
                >
              </button>
            }
          </section>

          <div
            class="grid grid-cols-1 gap-6 xl:grid-cols-[minmax(0,1fr)_22rem]"
          >
            <div digCard>
              <!-- کنترل‌ها روبه‌روی عنوان؛ در موبایل زیرِ آن می‌پیچند. -->
              <div
                digCardHeader
                class="flex flex-wrap items-center justify-between gap-3"
              >
                <div digCardTitle>فروش و سفارش‌ها</div>
                <div class="flex flex-wrap items-center gap-4">
                  <div class="flex items-center gap-2">
                    <button
                      digCheckbox
                      id="show-revenue"
                      [checked]="showRevenue()"
                      (checkedChange)="showRevenue.set($event === true)"
                    ></button>
                    <label digLabel for="show-revenue">فروش</label>
                  </div>
                  <div class="flex items-center gap-2">
                    <button
                      digCheckbox
                      id="show-orders"
                      [checked]="showOrders()"
                      (checkedChange)="showOrders.set($event === true)"
                    ></button>
                    <label digLabel for="show-orders">سفارش</label>
                  </div>
                  <ng-container
                    digSelect
                    [value]="period()"
                    (valueChange)="setPeriod($event)"
                    ><button
                      digSelectTrigger
                      size="sm"
                      aria-label="بازهٔ زمانی"
                      class="w-28"
                    >
                      <span digSelectValue></span>
                    </button>
                    <div digSelectContent>
                      <div digSelectItem value="7">۷ روز</div>
                      <div digSelectItem value="30">۳۰ روز</div>
                      <div digSelectItem value="90">۹۰ روز</div>
                    </div></ng-container
                  >
                </div>
              </div>
              <div digCardContent>
                <div
                  digComboChart
                  class="h-80"
                  [data]="chartData()"
                  categoryKey="label"
                  [bar]="{
                    key: 'revenue',
                    label: 'فروش (میلیون تومان)',
                    color: 'var(--chart-1)',
                  }"
                  [barFormatter]="(value) => formatNumber(value)"
                  [line]="{
                    key: 'orders',
                    label: 'سفارش',
                    color: 'var(--chart-4)',
                  }"
                ></div>
              </div>
            </div>

            <section class="flex flex-col gap-4" aria-label="خلاصه">
              <div digStatTile>
                <div digStatTileHeader>
                  <div digStatTileLabel class="text-base text-foreground">
                    قیفِ خرید
                  </div>
                  <button
                    digStatTileAction
                    aria-label="جزئیات قیف خرید"
                  ></button>
                </div>
                <ul
                  digStatTileList
                  [items]="[
                    { label: 'بازدید', value: 100, display: '٪۱۰۰' },
                    { label: 'دیدنِ محصول', value: 74, display: '٪۷۴' },
                    { label: 'افزودن به سبد', value: 62, display: '٪۶۲' },
                    { label: 'خریدِ موفق', value: 21, display: '٪۲۱' },
                  ]"
                ></ul>
              </div>
              <div digStatTile class="gap-3">
                <div digStatTileHeader>
                  <div digStatTileLabel class="text-base text-foreground">
                    مشتریانِ تازه
                  </div>
                  <button
                    digButton
                    type="button"
                    variant="ghost"
                    class="ms-auto"
                  >
                    همه
                  </button>
                </div>
                <ul class="flex flex-col gap-1">
                  @for (customer of CUSTOMERS; track customer.name) {
                    <li
                      class="flex items-center gap-3 rounded-xl p-2 hover:bg-muted"
                    >
                      <span
                        digAvatar
                        size="sm"
                        [alt]="customer.name"
                        class="ring-1 ring-border"
                        [iconName]="
                          customer.gender === 'male'
                            ? 'avatar-male'
                            : 'avatar-female'
                        "
                      ></span>
                      <div class="flex min-w-0 flex-1 flex-col gap-1">
                        <span class="truncate text-sm font-medium">{{
                          customer.name
                        }}</span>
                        <span class="text-xs text-muted-foreground"
                          >{{ toFaDigits(customer.orders) }} سفارش ·
                          {{ customer.spent }}</span
                        >
                      </div>
                      <button
                        digButton
                        type="button"
                        variant="ghost"
                        size="icon"
                        [attr.aria-label]="\`پیام به \${customer.name}\`"
                      >
                        <svg digIcon="envelope"></svg>
                      </button>
                    </li>
                  }
                </ul>
              </div>
            </section>
          </div>

          <div
            class="grid grid-cols-1 gap-6 xl:grid-cols-[minmax(0,1fr)_22rem]"
          >
            <div digCard>
              <div
                digCardHeader
                class="flex flex-wrap items-center justify-between gap-3"
              >
                <div digCardTitle>سفارش‌ها</div>
                <!-- جست‌وجو کنارِ فیلتر، روبه‌روی عنوان؛ ابزارهای جدول یک‌جا. -->
                <div class="flex w-full items-center gap-2 sm:w-auto">
                  <div
                    digSearchField
                    aria-label="جست‌وجوی سفارش"
                    placeholder="شماره سفارش یا نام مشتری"
                    [value]="query()"
                    class="min-w-0 flex-1 sm:w-64"
                    (valueChange)="onOrderSearch($event)"
                  ></div>
                  <button
                    digButton
                    type="button"
                    variant="outline"
                    size="icon"
                    aria-label="فیلتر سفارش‌ها"
                  >
                    <svg digIcon="filter"></svg>
                  </button>
                </div>
              </div>
              <div digCardContent class="flex flex-col gap-4">
                <div class="overflow-hidden rounded-lg border border-border">
                  <dig-table stackOnMobile class="min-w-[36rem]"
                    ><thead digTableHeader class="bg-muted">
                      <tr digTableRow>
                        <th digTableHead class="w-10">
                          <button
                            digCheckbox
                            aria-label="انتخاب همه"
                            [checked]="allSelected()"
                            (checkedChange)="selected.set($event === true ? orders().map((order) => order.id) : [])"
                          ></button>
                        </th>
                        <th digTableHead>شماره</th>
                        <th digTableHead>مشتری</th>
                        <th digTableHead>تاریخ</th>
                        <th digTableHead class="text-end">مبلغ</th>
                        <th digTableHead>وضعیت</th>
                      </tr>
                    </thead>
                    <tbody digTableBody>
                      @for (order of orders(); track order.id) {
                        <tr
                          digTableRow
                          [attr.data-state]="
                            selected().includes(order.id)
                              ? 'selected'
                              : undefined
                          "
                        >
                          <td digTableCell>
                            <button
                              digCheckbox
                              [attr.aria-label]="
                                \`انتخاب سفارش \${toFaDigits(order.id)}\`
                              "
                              [checked]="selected().includes(order.id)"
                              (checkedChange)="
                                setSelected(order.id, $event === true)
                              "
                            ></button>
                          </td>
                          <td digTableCell class="font-medium">
                            <bdi dir="ltr">#{{ toFaDigits(order.id) }}</bdi>
                          </td>
                          <td digTableCell>{{ order.customer }}</td>
                          <td digTableCell class="text-muted-foreground">
                            {{ formatJalali(order.date) }}
                          </td>
                          <td digTableCell class="text-end tabular-nums">
                            {{ formatCurrency(order.total) }}
                          </td>
                          <td digTableCell>
                            <span
                              digBadge
                              variant="soft"
                              [color]="STATUS[order.status].color"
                              >{{ STATUS[order.status].text }}</span
                            >
                          </td>
                        </tr>
                      }
                    </tbody></dig-table
                  >
                </div>
                <div class="flex flex-wrap items-center justify-between gap-3">
                  <span class="text-sm text-muted-foreground"
                    >{{ toFaDigits(filtered().length) }} سفارش · صفحهٔ
                    {{ toFaDigits(currentPage()) }} از
                    {{ toFaDigits(pageCount()) }}</span
                  >
                  <nav digPagination class="mx-0 w-auto">
                    <ul digPaginationContent>
                      <li digPaginationItem>
                        <a
                          digPaginationPrevious
                          href="#"
                          [attr.aria-disabled]="currentPage() === 1"
                          (click)="
                            $event.preventDefault();
                            page.set(math.max(1, currentPage() - 1))
                          "
                        ></a>
                      </li>
                      @for (number of range(pageCount()); track number) {
                        <li digPaginationItem>
                          <a
                            digPaginationLink
                            href="#"
                            [isActive]="number === currentPage()"
                            (click)="$event.preventDefault(); page.set(number)"
                            >{{ toFaDigits(number) }}</a
                          >
                        </li>
                      }
                      <li digPaginationItem>
                        <a
                          digPaginationNext
                          href="#"
                          [attr.aria-disabled]="currentPage() === pageCount()"
                          (click)="
                            $event.preventDefault();
                            page.set(math.min(pageCount(), currentPage() + 1))
                          "
                        ></a>
                      </li>
                    </ul>
                  </nav>
                </div>
              </div>
            </div>

            <div digCard>
              <div digCardHeader>
                <div digCardTitle>اعلان‌ها</div>
                <div digCardAction>
                  <span digBadge variant="soft" color="destructive"
                    >{{ toFaDigits(notifications().length) }} تازه</span
                  >
                </div>
              </div>
              <div digCardContent class="flex flex-col gap-3">
                @if (notifications().length === 0) {
                  <p class="py-6 text-center text-sm text-muted-foreground">
                    اعلانِ تازه‌ای نیست.
                  </p>
                }
                @for (item of notifications(); track item.id) {
                  <div
                    class="flex items-start gap-3 rounded-lg border border-border bg-card p-3"
                  >
                    <span
                      aria-hidden="true"
                      [class]="
                        \`flex size-9 shrink-0 items-center justify-center rounded-full [&_svg]:size-4 \${item.tone}\`
                      "
                      ><svg [digIcon]="item.icon"></svg
                    ></span>
                    <div class="flex min-w-0 flex-1 flex-col gap-1">
                      <span class="text-sm font-semibold">{{
                        item.title
                      }}</span>
                      <span class="truncate text-xs text-muted-foreground">{{
                        item.body
                      }}</span>
                      <span class="text-xs text-muted-foreground">{{
                        formatRelativeTime(item.time)
                      }}</span>
                    </div>
                    <button
                      digButton
                      type="button"
                      variant="ghost"
                      size="icon"
                      [attr.aria-label]="\`بستن اعلان \${item.title}\`"
                      (click)="notifications.set(notifications().filter((entry) => entry.id !== item.id))"
                    >
                      <svg digIcon="x"></svg>
                    </button>
                  </div>
                }
                <button digButton type="button" variant="outline" fullWidth>
                  مشاهدهٔ همه
                </button>
              </div>
            </div>
          </div>
        </main>
      </div>
    </div>
  `,
})
export class DashboardBlock {
  range(count: number) {
    return Array.from({ length: count }, (_, index) => index + 1)
  }

  readonly math = Math

  readonly toFaDigits = toFaDigits

  readonly formatRelativeTime = formatRelativeTime

  readonly formatNumber = formatNumber

  readonly formatJalali = formatJalali

  readonly formatCurrency = formatCurrency

  readonly NAV_SUPPORT = NAV_SUPPORT

  readonly NAV_ANALYTICS = NAV_ANALYTICS

  readonly NAV_MAIN = NAV_MAIN

  readonly STATUS = STATUS

  readonly CUSTOMERS = CUSTOMERS

  readonly QUICK = QUICK

  readonly stockImages = stockImages

  salesFor(period: string) {
    const wave = (index: number, base: number, amp: number) =>
      Math.round(base + amp * Math.sin(index * 0.9) + index * (amp / 6))
    if (period === "7") {
      return Array.from({ length: 7 }, (_, index) => ({
        label: `${toFaDigits(3 + index)} مهر`,
        revenue: wave(index, 52, 12),
        orders: wave(index, 165, 28),
      }))
    }
    if (period === "30") {
      // ۳۰ روز در ۱۰ دستهٔ سه‌روزه، تا میله‌ها خوانا بمانند.
      return Array.from({ length: 10 }, (_, index) => ({
        label: `${toFaDigits(1 + index * 3)} ${index < 3 ? "شهریور" : "مهر"}`,
        revenue: wave(index, 150, 30),
        orders: wave(index, 480, 70),
      }))
    }
    return Array.from({ length: 12 }, (_, index) => ({
      label: `هفتهٔ ${toFaDigits(index + 1)}`,
      revenue: wave(index, 360, 70),
      orders: wave(index, 1150, 160),
    }))
  }

  readonly theme = signal<"light" | "dark">("light")

  themeObserver: MutationObserver | undefined

  applyTheme(next: "light" | "dark") {
    this.theme.set(next)
    document.documentElement.classList.toggle("dark", next === "dark")
    document.documentElement.classList.toggle("light", next === "light")
  }

  onThemeChange(value: string | string[] | undefined) {
    if (!value) return
    this.applyTheme(value as "light" | "dark")
  }

  readonly period = signal("30")

  readonly showRevenue = signal(true)

  readonly showOrders = signal(true)

  readonly query = signal("")

  readonly selected = signal<string[]>([])

  readonly notifications = signal([...NOTIFICATIONS])

  readonly page = signal(1)

  readonly sales = computed(() => this.salesFor(this.period()))

  readonly chartData = computed(() =>
    this.sales().map((row) => ({
      ...row,
      revenue: this.showRevenue() ? row.revenue : null,
      orders: this.showOrders() ? row.orders : null,
    }))
  )

  readonly filtered = computed(() =>
    ORDERS.filter((order) =>
      toSearchKey(order.customer + order.id).includes(toSearchKey(this.query()))
    )
  )

  readonly pageCount = computed(() =>
    Math.max(1, Math.ceil(this.filtered().length / PAGE_SIZE))
  )

  readonly currentPage = computed(() => Math.min(this.page(), this.pageCount()))

  readonly orders = computed(() =>
    this.filtered().slice(
      (this.currentPage() - 1) * PAGE_SIZE,
      this.currentPage() * PAGE_SIZE
    )
  )

  readonly allSelected = computed(
    () =>
      this.orders().length > 0 &&
      this.orders().every((order) => this.selected().includes(order.id))
  )

  onOrderSearch(value: string) {
    this.query.set(value)
    this.page.set(1)
  }

  setSelected(id: string, on: boolean) {
    this.selected.set(
      on
        ? [...this.selected(), id]
        : this.selected().filter((item) => item !== id)
    )
  }

  constructor() {
    afterNextRender(() => {
      this.theme.set(readTheme())
      this.themeObserver = new MutationObserver(() =>
        this.theme.set(readTheme())
      )
      this.themeObserver.observe(document.documentElement, {
        attributes: true,
        attributeFilter: ["class"],
      })
    })
    inject(DestroyRef).onDestroy(() => this.themeObserver?.disconnect())
  }

  setPeriod(value: string | string[] | undefined) {
    if (typeof value === "string") this.period.set(value)
  }
}

کدِ این بلاک هنوز برای Android نوشته نشده است.

همهٔ کامپوننت‌های لازم برای Android آماده‌اند؛ با MCP می‌توانید همین صفحه را از روی نسخهٔ React بسازید.

کدِ React همین بلاک مرجع است. با MCP دیگ و get_block با framework="android" ایجنت آن را با کامپوننت‌های Android می‌سازد.