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

نتایجِ بلیتِ اتوبوس

پیش‌نمایش تمام‌صفحه

نتایجِ اتوبوس با فیلترِ کنارِ فهرست: بازهٔ ساعتِ حرکت، شرکتِ مسافربری و نوعِ اتوبوس (VIP یا معمولی)؛ کارتِ فشرده با پایانهٔ مبدأ و مقصد، صندلیِ باقی‌مانده و تخفیف، و حالتِ «فیلتر نتیجه نداشت» با پاک‌کردنِ فیلترها.

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

این بلاک از ۱۶ آیتم دیگ استفاده می‌کند: badgebuttoncheckboxchoice-chipscontrol-sizeempty-statefare-date-stripiconslabeloperator-logopersianselectsheetswitchticket-cardtoast

پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/checkbox.json https://docs.digdesign.ir/r/choice-chips.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/empty-state.json https://docs.digdesign.ir/r/fare-date-strip.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/operator-logo.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/sheet.json https://docs.digdesign.ir/r/switch.json https://docs.digdesign.ir/r/ticket-card.json https://docs.digdesign.ir/r/toast.json
pnpm dlx digdesign@latest add https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/checkbox.json https://docs.digdesign.ir/r/choice-chips.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/empty-state.json https://docs.digdesign.ir/r/fare-date-strip.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/operator-logo.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/sheet.json https://docs.digdesign.ir/r/switch.json https://docs.digdesign.ir/r/ticket-card.json https://docs.digdesign.ir/r/toast.json
yarn dlx digdesign@latest add https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/checkbox.json https://docs.digdesign.ir/r/choice-chips.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/empty-state.json https://docs.digdesign.ir/r/fare-date-strip.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/operator-logo.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/sheet.json https://docs.digdesign.ir/r/switch.json https://docs.digdesign.ir/r/ticket-card.json https://docs.digdesign.ir/r/toast.json
bunx --bun digdesign@latest add https://docs.digdesign.ir/r/badge.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/checkbox.json https://docs.digdesign.ir/r/choice-chips.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/empty-state.json https://docs.digdesign.ir/r/fare-date-strip.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/operator-logo.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/sheet.json https://docs.digdesign.ir/r/switch.json https://docs.digdesign.ir/r/ticket-card.json https://docs.digdesign.ir/r/toast.json
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add badge button checkbox choice-chips control-size empty-state fare-date-strip label operator-logo persian select sheet switch ticket-card toast --framework vue
pnpm dlx digdesign@latest add badge button checkbox choice-chips control-size empty-state fare-date-strip label operator-logo persian select sheet switch ticket-card toast --framework vue
yarn dlx digdesign@latest add badge button checkbox choice-chips control-size empty-state fare-date-strip label operator-logo persian select sheet switch ticket-card toast --framework vue
bunx --bun digdesign@latest add badge button checkbox choice-chips control-size empty-state fare-date-strip label operator-logo persian select sheet switch ticket-card toast --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 badge button checkbox choice-chips control-size empty-state fare-date-strip icons label operator-logo persian select sheet switch ticket-card toast --framework angular
pnpm dlx digdesign@latest add badge button checkbox choice-chips control-size empty-state fare-date-strip icons label operator-logo persian select sheet switch ticket-card toast --framework angular
yarn dlx digdesign@latest add badge button checkbox choice-chips control-size empty-state fare-date-strip icons label operator-logo persian select sheet switch ticket-card toast --framework angular
bunx --bun digdesign@latest add badge button checkbox choice-chips control-size empty-state fare-date-strip icons label operator-logo persian select sheet switch ticket-card toast --framework angular
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add badge button checkbox choice-chips control-size empty-state fare-date-strip label persian select sheet switch ticket-card toast --framework android
pnpm dlx digdesign@latest add badge button checkbox choice-chips control-size empty-state fare-date-strip label persian select sheet switch ticket-card toast --framework android
yarn dlx digdesign@latest add badge button checkbox choice-chips control-size empty-state fare-date-strip label persian select sheet switch ticket-card toast --framework android
bunx --bun digdesign@latest add badge button checkbox choice-chips control-size empty-state fare-date-strip label persian select sheet switch ticket-card toast --framework android

۲. کد صفحه

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

ticket-results-bus.tsx
"use client"

import * as React from "react"

import { BusIcon, EditIcon, FilterIcon, LocationIcon } from "@/components/icons"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { ChoiceChip, ChoiceChips } from "@/components/ui/choice-chips"
import { Checkbox } from "@/components/ui/checkbox"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { EmptyState, EmptyStateActions, EmptyStateDescription, EmptyStateIcon, EmptyStateTitle } from "@/components/ui/empty-state"
import { FareDateStrip, type FareDay } from "@/components/ui/fare-date-strip"
import { Label } from "@/components/ui/label"
import { OperatorLogo } from "@/components/ui/operator-logo"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Sheet, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger } from "@/components/ui/sheet"
import { Switch } from "@/components/ui/switch"
import { TicketCard, TicketCardDetail } from "@/components/ui/ticket-card"
import { toast } from "@/components/ui/toast"
import { formatCurrency, toFaDigits } from "@/lib/persian"

type Bus = {
  id: string
  company: string
  depart: string
  arrive: string
  minutes: number
  from: string
  to: string
  kind: string
  vip: boolean
  price: number
  listPrice?: number
  seats: number
  logo: { color: "primary" | "success" | "warning" | "destructive" | "secondary"; icon?: boolean }
}

/** پاسخِ سرویسِ اتوبوس برای تهران به اصفهان؛ پایانه و نوعِ اتوبوس از خودِ شرکت می‌آید. */
const BUSES: Bus[] = [
  { id: "b1", company: "همسفر چابک‌سواران", depart: "06:30", arrive: "12:45", minutes: 375, from: "پایانهٔ جنوب", to: "پایانهٔ کاوه", kind: "VIP ۲۵ نفره", vip: true, price: 485000, listPrice: 540000, seats: 11, logo: { color: "primary", icon: true } },
  { id: "b2", company: "سیر و سفر", depart: "08:00", arrive: "14:30", minutes: 390, from: "پایانهٔ جنوب", to: "پایانهٔ صفه", kind: "معمولی ۴۴ نفره", vip: false, price: 290000, seats: 26, logo: { color: "success" } },
  { id: "b3", company: "رویال سفر ایرانیان", depart: "13:15", arrive: "19:20", minutes: 365, from: "پایانهٔ آرژانتین", to: "پایانهٔ کاوه", kind: "VIP ۲۵ نفره", vip: true, price: 510000, seats: 3, logo: { color: "warning" } },
  { id: "b4", company: "ایران‌پیما", depart: "16:45", arrive: "23:00", minutes: 375, from: "پایانهٔ غرب", to: "پایانهٔ کاوه", kind: "VIP ۳۰ نفره", vip: true, price: 455000, seats: 17, logo: { color: "destructive", icon: true } },
  { id: "b5", company: "سیر و سفر", depart: "22:30", arrive: "04:40", minutes: 370, from: "پایانهٔ جنوب", to: "پایانهٔ صفه", kind: "معمولی ۴۴ نفره", vip: false, price: 275000, seats: 32, logo: { color: "success" } },
]
const COMPANIES = [...new Set(BUSES.map((bus) => bus.company))]
const TIMES = [
  { value: "morning", label: "صبح", from: 0, to: 12 * 60 },
  { value: "noon", label: "ظهر", from: 12 * 60, to: 17 * 60 },
  { value: "night", label: "شب", from: 17 * 60, to: 24 * 60 },
]

/** چهارشنبه ۲۹ مهر ۱۴۰۵؛ ثابت تا عکسِ گالری هر بار یکی باشد. */
const BASE = new Date(2026, 9, 21)
const DAYS: FareDay[] = [275000, 290000, 275000, 310000, 290000, 340000, 275000].map((price, index) => ({
  date: new Date(BASE.getFullYear(), BASE.getMonth(), BASE.getDate() + index - 2),
  price,
}))

const hm = (time: string) => Number(time.slice(0, 2)) * 60 + Number(time.slice(3))
const duration = (minutes: number) => `${toFaDigits(Math.floor(minutes / 60))} ساعت${minutes % 60 ? ` و ${toFaDigits(minutes % 60)} دقیقه` : ""}`
const dayLabel = new Intl.DateTimeFormat("fa-IR-u-ca-persian", { weekday: "long", day: "numeric", month: "long" })

type Filters = { times: string[]; companies: string[]; vip: boolean }
const EMPTY: Filters = { times: [], companies: [], vip: false }

const BUS_LOGOS: Record<string, string> = {
  "همسفر چابک‌سواران": "https://www.google.com/s2/favicons?domain=hamsafarco.com&sz=128",
  "سیر و سفر": "https://www.google.com/s2/favicons?domain=seirosafar.ir&sz=128",
  "رویال سفر ایرانیان": "https://www.google.com/s2/favicons?domain=royalsafar.com&sz=128",
  "ایران‌پیما": "https://www.google.com/s2/favicons?domain=iranpeyma.ir&sz=128",
}

/** فیلترها؛ همین در ستونِ کناریِ دسکتاپ و در Sheetِ گوشی. */
function FilterFields({ id, filters, onChange }: { id: string; filters: Filters; onChange: (next: Filters) => void }) {
  return (
    <div className="flex flex-col gap-6">
      <fieldset className="flex flex-col gap-3">
        <legend className="mb-3 text-sm font-bold">ساعتِ حرکت</legend>
        <ChoiceChips type="multiple" mobileSize="default" value={filters.times} onValueChange={(value) => onChange({ ...filters, times: value })} aria-label="ساعتِ حرکت">
          {TIMES.map((time) => (
            <ChoiceChip key={time.value} value={time.value}>
              {time.label}
            </ChoiceChip>
          ))}
        </ChoiceChips>
      </fieldset>
      <fieldset className="flex flex-col gap-3">
        <legend className="mb-3 text-sm font-bold">شرکتِ مسافربری</legend>
        {COMPANIES.map((company, index) => (
          <div key={company} className="flex items-center gap-2">
            <Checkbox
              id={`${id}-company-${index}`}
              checked={filters.companies.includes(company)}
              onCheckedChange={(checked) => onChange({ ...filters, companies: checked === true ? [...filters.companies, company] : filters.companies.filter((item) => item !== company) })}
            />
            <Label htmlFor={`${id}-company-${index}`} className="font-normal">
              {company}
            </Label>
          </div>
        ))}
      </fieldset>
      <div className="flex items-center justify-between gap-3">
        <Label htmlFor={`${id}-vip`}>فقط اتوبوسِ VIP</Label>
        <Switch id={`${id}-vip`} checked={filters.vip} onCheckedChange={(vip) => onChange({ ...filters, vip })} />
      </div>
    </div>
  )
}

/**
 * نتایجِ اتوبوس با فیلتر: ستونِ کناری در دسکتاپ (ساعتِ حرکت، شرکتِ مسافربری، فقط VIP) و همان فیلترها در
 * Sheet در گوشی با شمارِ فیلترِ فعال. کارت‌ها پایانهٔ مبدأ و مقصد، نوعِ اتوبوس، تخفیف و صندلیِ باقی‌مانده را
 * دارند؛ اگر فیلترها نتیجه‌ای نگذارند، حالتِ خالی با «پاک‌کردنِ فیلترها» می‌آید.
 */
export default function TicketResultsBusBlock() {
  const [date, setDate] = React.useState(BASE)
  const [sort, setSort] = React.useState("early")
  const [filters, setFilters] = React.useState<Filters>(EMPTY)
  const active = filters.times.length + filters.companies.length + (filters.vip ? 1 : 0)

  const buses = BUSES.filter(
    (bus) =>
      (filters.times.length === 0 || filters.times.some((value) => TIMES.some((time) => time.value === value && hm(bus.depart) >= time.from && hm(bus.depart) < time.to))) &&
      (filters.companies.length === 0 || filters.companies.includes(bus.company)) &&
      (!filters.vip || bus.vip)
  ).sort((a, b) => (sort === "early" ? hm(a.depart) - hm(b.depart) : a.price - b.price))

  return (
    <ControlSizeProvider size="xl" asChild>
      <main className="mx-auto flex w-full max-w-6xl flex-col gap-6 p-4 sm:p-6">
        <header className="flex flex-col gap-4 rounded-xl border bg-card p-4 shadow-card sm:flex-row sm:items-center sm:p-5">
          <span aria-hidden className="hidden size-12 shrink-0 items-center justify-center rounded-lg bg-primary-subtle text-primary-subtle-foreground sm:flex [&>svg]:size-6">
            <BusIcon />
          </span>
          <div className="flex min-w-0 flex-1 flex-col gap-1">
            <h1 className="text-lg leading-snug font-black sm:text-xl">بلیتِ اتوبوسِ تهران به اصفهان</h1>
            <p className="text-sm text-muted-foreground">{dayLabel.format(date)} · ۲ صندلی</p>
          </div>
          <ControlSizeProvider size="lg" mobileSize="default" asChild>
            <div className="flex">
              <Button variant="outline" onClick={() => toast("فرمِ جست‌وجو با همین مسیر باز می‌شود.")} className="w-full sm:w-auto">
                <EditIcon />
                ویرایشِ جست‌وجو
              </Button>
            </div>
          </ControlSizeProvider>
        </header>

        <section aria-label="روزِ حرکت" className="flex flex-col gap-2">
          <p className="text-sm text-muted-foreground">کم‌ترین قیمتِ هر روز (هزار تومان)</p>
          <FareDateStrip days={DAYS} value={date} onValueChange={setDate} aria-label="روزِ حرکت" className="-m-1" />
        </section>

        <div className="grid gap-6 lg:grid-cols-[17rem_minmax(0,1fr)] lg:items-start">
          <aside aria-labelledby="bus-filters" className="hidden flex-col gap-5 rounded-xl border bg-card p-5 lg:flex">
            <div className="flex items-center justify-between gap-2">
              <h2 id="bus-filters" className="font-bold">
                فیلترها
              </h2>
              {active > 0 && (
                <ControlSizeProvider size="default" asChild>
                  <Button variant="ghost" onClick={() => setFilters(EMPTY)} className="-me-2">
                    پاک‌کردن
                  </Button>
                </ControlSizeProvider>
              )}
            </div>
            <FilterFields id="side" filters={filters} onChange={setFilters} />
          </aside>

          <section aria-labelledby="bus-results" className="flex min-w-0 flex-col gap-4">
            <div className="flex flex-wrap items-center justify-between gap-3">
              <h2 id="bus-results" className="font-bold" aria-live="polite">
                {toFaDigits(buses.length)} اتوبوسِ تهران به اصفهان
              </h2>
              <ControlSizeProvider size="lg" mobileSize="default" asChild>
                <div className="flex gap-2">
                  <Sheet>
                    <SheetTrigger asChild>
                      <Button variant="outline" className="lg:hidden">
                        <FilterIcon />
                        فیلترها
                        {active > 0 && (
                          <Badge size="sm" className="ms-1">
                            {toFaDigits(active)}
                          </Badge>
                        )}
                      </Button>
                    </SheetTrigger>
                    <ControlSizeProvider size="xl" asChild>
                      <SheetContent side="bottom" className="max-h-[85dvh] gap-0 overflow-y-auto rounded-t-xl p-0">
                        <SheetHeader className="border-b p-5">
                          <SheetTitle>فیلترها</SheetTitle>
                          <SheetDescription className="sr-only">ساعتِ حرکت، شرکت و نوعِ اتوبوس</SheetDescription>
                        </SheetHeader>
                        <div className="p-5">
                          <FilterFields id="sheet" filters={filters} onChange={setFilters} />
                        </div>
                        <SheetFooter className="flex-row gap-2 border-t p-5">
                          <Button variant="outline" onClick={() => setFilters(EMPTY)} className="flex-1">
                            پاک‌کردن
                          </Button>
                        </SheetFooter>
                      </SheetContent>
                    </ControlSizeProvider>
                  </Sheet>
                  <Select value={sort} onValueChange={setSort}>
                    <SelectTrigger aria-label="مرتب‌سازی" className="w-40">
                      <SelectValue />
                    </SelectTrigger>
                    <SelectContent>
                      <SelectItem value="early">زودترین حرکت</SelectItem>
                      <SelectItem value="cheap">ارزان‌ترین</SelectItem>
                    </SelectContent>
                  </Select>
                </div>
              </ControlSizeProvider>
            </div>

            {buses.length > 0 ? (
              <ul className="flex flex-col gap-4">
                {buses.map((bus) => (
                  <li key={bus.id}>
                    <TicketCard
                      departure={{ time: bus.depart, place: "تهران" }}
                      arrival={{ time: bus.arrive, place: "اصفهان", nextDay: hm(bus.arrive) < hm(bus.depart) }}
                      duration={duration(bus.minutes)}
                      icon={<BusIcon />}
                      logo={<OperatorLogo alt={bus.company} kind="bus" src={BUS_LOGOS[bus.company]} />}
                      operator={bus.company}
                      details={
                        <>
                          <TicketCardDetail icon={<LocationIcon />}>از {bus.from}</TicketCardDetail>
                          <TicketCardDetail icon={<LocationIcon />}>به {bus.to}</TicketCardDetail>
                        </>
                      }
                      tags={
                        <Badge variant="soft" size="lg" color={bus.vip ? "violet" : "default"}>
                          {bus.kind}
                        </Badge>
                      }
                      seatsLeft={bus.seats}
                      lowSeats={5}
                      price={formatCurrency(bus.price)}
                      originalPrice={bus.listPrice ? formatCurrency(bus.listPrice) : undefined}
                      priceLabel="قیمتِ هر صندلی"
                      action={<Button onClick={() => toast.success(`${bus.company}، ساعتِ ${toFaDigits(bus.depart)}؛ گامِ بعد انتخابِ صندلی.`)}>انتخابِ صندلی</Button>}
                    />
                  </li>
                ))}
              </ul>
            ) : (
              <EmptyState variant="bordered">
                <EmptyStateIcon>
                  <FilterIcon />
                </EmptyStateIcon>
                <EmptyStateTitle>با این فیلترها اتوبوسی نیست</EmptyStateTitle>
                <EmptyStateDescription>یکی از فیلترها را بردارید یا روزِ دیگری را ببینید.</EmptyStateDescription>
                <EmptyStateActions>
                  <Button variant="outline" onClick={() => setFilters(EMPTY)}>
                    پاک‌کردنِ فیلترها
                  </Button>
                </EmptyStateActions>
              </EmptyState>
            )}
          </section>
        </div>
      </main>
    </ControlSizeProvider>
  )
}
ticket-results-bus.vue
<script setup lang="ts">
import { computed, ref } from "vue"

import Badge from "@/components/ui/Badge.vue"
import Button from "@/components/ui/Button.vue"
import Checkbox from "@/components/ui/Checkbox.vue"
import ChoiceChip from "@/components/ui/ChoiceChip.vue"
import ChoiceChips from "@/components/ui/ChoiceChips.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import EmptyState from "@/components/ui/EmptyState.vue"
import EmptyStateActions from "@/components/ui/EmptyStateActions.vue"
import EmptyStateDescription from "@/components/ui/EmptyStateDescription.vue"
import EmptyStateIcon from "@/components/ui/EmptyStateIcon.vue"
import EmptyStateTitle from "@/components/ui/EmptyStateTitle.vue"
import FareDateStrip from "@/components/ui/FareDateStrip.vue"
import Label from "@/components/ui/Label.vue"
import OperatorLogo from "@/components/ui/OperatorLogo.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 Sheet from "@/components/ui/Sheet.vue"
import SheetContent from "@/components/ui/SheetContent.vue"
import SheetDescription from "@/components/ui/SheetDescription.vue"
import SheetFooter from "@/components/ui/SheetFooter.vue"
import SheetHeader from "@/components/ui/SheetHeader.vue"
import SheetTitle from "@/components/ui/SheetTitle.vue"
import SheetTrigger from "@/components/ui/SheetTrigger.vue"
import Switch from "@/components/ui/Switch.vue"
import TicketCard from "@/components/ui/TicketCard.vue"
import TicketCardDetail from "@/components/ui/TicketCardDetail.vue"
import { toast } from "@/components/ui/Toast.vue"
import { DigIcon } from "@/lib/icons"
import { formatCurrency, toFaDigits } from "@/lib/persian"

type FareDay = { date: Date; price: number | null; soldOut?: boolean }

type Bus = {
  id: string
  company: string
  depart: string
  arrive: string
  minutes: number
  from: string
  to: string
  kind: string
  vip: boolean
  price: number
  listPrice?: number
  seats: number
  logo: { color: "primary" | "success" | "warning" | "destructive" | "secondary"; icon?: boolean }
}

/** پاسخِ سرویسِ اتوبوس برای تهران به اصفهان؛ پایانه و نوعِ اتوبوس از خودِ شرکت می‌آید. */
const BUSES: Bus[] = [
  { id: "b1", company: "همسفر چابک‌سواران", depart: "06:30", arrive: "12:45", minutes: 375, from: "پایانهٔ جنوب", to: "پایانهٔ کاوه", kind: "VIP ۲۵ نفره", vip: true, price: 485000, listPrice: 540000, seats: 11, logo: { color: "primary", icon: true } },
  { id: "b2", company: "سیر و سفر", depart: "08:00", arrive: "14:30", minutes: 390, from: "پایانهٔ جنوب", to: "پایانهٔ صفه", kind: "معمولی ۴۴ نفره", vip: false, price: 290000, seats: 26, logo: { color: "success" } },
  { id: "b3", company: "رویال سفر ایرانیان", depart: "13:15", arrive: "19:20", minutes: 365, from: "پایانهٔ آرژانتین", to: "پایانهٔ کاوه", kind: "VIP ۲۵ نفره", vip: true, price: 510000, seats: 3, logo: { color: "warning" } },
  { id: "b4", company: "ایران‌پیما", depart: "16:45", arrive: "23:00", minutes: 375, from: "پایانهٔ غرب", to: "پایانهٔ کاوه", kind: "VIP ۳۰ نفره", vip: true, price: 455000, seats: 17, logo: { color: "destructive", icon: true } },
  { id: "b5", company: "سیر و سفر", depart: "22:30", arrive: "04:40", minutes: 370, from: "پایانهٔ جنوب", to: "پایانهٔ صفه", kind: "معمولی ۴۴ نفره", vip: false, price: 275000, seats: 32, logo: { color: "success" } },
]
const COMPANIES = [...new Set(BUSES.map((bus) => bus.company))]
const TIMES = [
  { value: "morning", label: "صبح", from: 0, to: 12 * 60 },
  { value: "noon", label: "ظهر", from: 12 * 60, to: 17 * 60 },
  { value: "night", label: "شب", from: 17 * 60, to: 24 * 60 },
]

/** چهارشنبه ۲۹ مهر ۱۴۰۵؛ ثابت تا عکسِ گالری هر بار یکی باشد. */
const BASE = new Date(2026, 9, 21)
const DAYS: FareDay[] = [275000, 290000, 275000, 310000, 290000, 340000, 275000].map((price, index) => ({
  date: new Date(BASE.getFullYear(), BASE.getMonth(), BASE.getDate() + index - 2),
  price,
}))

const hm = (time: string) => Number(time.slice(0, 2)) * 60 + Number(time.slice(3))
const duration = (minutes: number) => `${toFaDigits(Math.floor(minutes / 60))} ساعت${minutes % 60 ? ` و ${toFaDigits(minutes % 60)} دقیقه` : ""}`
const dayLabel = new Intl.DateTimeFormat("fa-IR-u-ca-persian", { weekday: "long", day: "numeric", month: "long" })

type Filters = { times: string[]; companies: string[]; vip: boolean }
const EMPTY: Filters = { times: [], companies: [], vip: false }

const BUS_LOGOS: Record<string, string> = {
  "همسفر چابک‌سواران": "https://www.google.com/s2/favicons?domain=hamsafarco.com&sz=128",
  "سیر و سفر": "https://www.google.com/s2/favicons?domain=seirosafar.ir&sz=128",
  "رویال سفر ایرانیان": "https://www.google.com/s2/favicons?domain=royalsafar.com&sz=128",
  "ایران‌پیما": "https://www.google.com/s2/favicons?domain=iranpeyma.ir&sz=128",
}


/**
 * نتایجِ اتوبوس با فیلتر: ستونِ کناری در دسکتاپ (ساعتِ حرکت، شرکتِ مسافربری، فقط VIP) و همان فیلترها در
 * Sheet در گوشی با شمارِ فیلترِ فعال. کارت‌ها پایانهٔ مبدأ و مقصد، نوعِ اتوبوس، تخفیف و صندلیِ باقی‌مانده را
 * دارند؛ اگر فیلترها نتیجه‌ای نگذارند، حالتِ خالی با «پاک‌کردنِ فیلترها» می‌آید.
 */
const date = ref(BASE)
const sort = ref("early")
const filters = ref<Filters>({ ...EMPTY, times: [], companies: [] })
const active = computed(() => filters.value.times.length + filters.value.companies.length + (filters.value.vip ? 1 : 0))

const buses = computed(() =>
  BUSES.filter(
    (bus) =>
      (filters.value.times.length === 0 || filters.value.times.some((value) => TIMES.some((time) => time.value === value && hm(bus.depart) >= time.from && hm(bus.depart) < time.to))) &&
      (filters.value.companies.length === 0 || filters.value.companies.includes(bus.company)) &&
      (!filters.value.vip || bus.vip)
  ).sort((a, b) => (sort.value === "early" ? hm(a.depart) - hm(b.depart) : a.price - b.price))
)

function clearFilters() {
  filters.value = { times: [], companies: [], vip: false }
}
function onTimes(value: string | string[] | undefined) {
  filters.value = { ...filters.value, times: (value as string[] | undefined) ?? [] }
}
function toggleCompany(company: string, checked: boolean | "indeterminate") {
  filters.value = {
    ...filters.value,
    companies: checked === true ? [...filters.value.companies, company] : filters.value.companies.filter((item) => item !== company),
  }
}
function onDate(next: Date | undefined) {
  if (next) date.value = next
}
</script>

<template>
  <ControlSize size="xl" as-child>
    <main class="mx-auto flex w-full max-w-6xl flex-col gap-6 p-4 sm:p-6">
      <header class="flex flex-col gap-4 rounded-xl border bg-card p-4 shadow-card sm:flex-row sm:items-center sm:p-5">
        <span aria-hidden="true" class="hidden size-12 shrink-0 items-center justify-center rounded-lg bg-primary-subtle text-primary-subtle-foreground sm:flex [&>svg]:size-6">
          <DigIcon name="bus" />
        </span>
        <div class="flex min-w-0 flex-1 flex-col gap-1">
          <h1 class="text-lg leading-snug font-black sm:text-xl">بلیتِ اتوبوسِ تهران به اصفهان</h1>
          <p class="text-sm text-muted-foreground">{{ dayLabel.format(date) }} · ۲ صندلی</p>
        </div>
        <ControlSize size="lg" mobile-size="default" as-child>
          <div class="flex">
            <Button variant="outline" class="w-full sm:w-auto" @click="toast('فرمِ جست‌وجو با همین مسیر باز می‌شود.')">
              <DigIcon name="edit" />
              ویرایشِ جست‌وجو
            </Button>
          </div>
        </ControlSize>
      </header>

      <section aria-label="روزِ حرکت" class="flex flex-col gap-2">
        <p class="text-sm text-muted-foreground">کم‌ترین قیمتِ هر روز (هزار تومان)</p>
        <FareDateStrip :days="DAYS" :model-value="date" aria-label="روزِ حرکت" class="-m-1" @update:model-value="onDate" />
      </section>

      <div class="grid gap-6 lg:grid-cols-[17rem_minmax(0,1fr)] lg:items-start">
        <aside aria-labelledby="bus-filters" class="hidden flex-col gap-5 rounded-xl border bg-card p-5 lg:flex">
          <div class="flex items-center justify-between gap-2">
            <h2 id="bus-filters" class="font-bold">فیلترها</h2>
            <ControlSize v-if="active > 0" size="default" as-child>
              <Button variant="ghost" class="-me-2" @click="clearFilters">پاک‌کردن</Button>
            </ControlSize>
          </div>
          <!-- فیلترها؛ همین در ستونِ کناریِ دسکتاپ و در Sheetِ گوشی. -->
          <div class="flex flex-col gap-6">
            <fieldset class="flex flex-col gap-3">
              <legend class="mb-3 text-sm font-bold">ساعتِ حرکت</legend>
              <ChoiceChips type="multiple" mobile-size="default" :value="filters.times" aria-label="ساعتِ حرکت" @update:value="onTimes">
                <ChoiceChip v-for="time in TIMES" :key="time.value" :value="time.value">{{ time.label }}</ChoiceChip>
              </ChoiceChips>
            </fieldset>
            <fieldset class="flex flex-col gap-3">
              <legend class="mb-3 text-sm font-bold">شرکتِ مسافربری</legend>
              <div v-for="(company, index) in COMPANIES" :key="company" class="flex items-center gap-2">
                <Checkbox :id="`side-company-${index}`" :checked="filters.companies.includes(company)" @update:checked="(checked) => toggleCompany(company, checked)" />
                <Label :for="`side-company-${index}`" class="font-normal">{{ company }}</Label>
              </div>
            </fieldset>
            <div class="flex items-center justify-between gap-3">
              <Label for="side-vip">فقط اتوبوسِ VIP</Label>
              <Switch id="side-vip" :checked="filters.vip" @update:checked="(vip) => (filters = { ...filters, vip })" />
            </div>
          </div>
        </aside>

        <section aria-labelledby="bus-results" class="flex min-w-0 flex-col gap-4">
          <div class="flex flex-wrap items-center justify-between gap-3">
            <h2 id="bus-results" class="font-bold" aria-live="polite">{{ toFaDigits(buses.length) }} اتوبوسِ تهران به اصفهان</h2>
            <ControlSize size="lg" mobile-size="default" as-child>
              <div class="flex gap-2">
                <Sheet>
                  <SheetTrigger as-child>
                    <Button variant="outline" class="lg:hidden">
                      <DigIcon name="filter" />
                      فیلترها
                      <Badge v-if="active > 0" size="sm" class="ms-1">{{ toFaDigits(active) }}</Badge>
                    </Button>
                  </SheetTrigger>
                  <ControlSize size="xl" as-child>
                    <SheetContent side="bottom" class="max-h-[85dvh] gap-0 overflow-y-auto rounded-t-xl p-0">
                      <SheetHeader class="border-b p-5">
                        <SheetTitle>فیلترها</SheetTitle>
                        <SheetDescription class="sr-only">ساعتِ حرکت، شرکت و نوعِ اتوبوس</SheetDescription>
                      </SheetHeader>
                      <div class="p-5">
                        <div class="flex flex-col gap-6">
                          <fieldset class="flex flex-col gap-3">
                            <legend class="mb-3 text-sm font-bold">ساعتِ حرکت</legend>
                            <ChoiceChips type="multiple" mobile-size="default" :value="filters.times" aria-label="ساعتِ حرکت" @update:value="onTimes">
                              <ChoiceChip v-for="time in TIMES" :key="time.value" :value="time.value">{{ time.label }}</ChoiceChip>
                            </ChoiceChips>
                          </fieldset>
                          <fieldset class="flex flex-col gap-3">
                            <legend class="mb-3 text-sm font-bold">شرکتِ مسافربری</legend>
                            <div v-for="(company, index) in COMPANIES" :key="company" class="flex items-center gap-2">
                              <Checkbox :id="`sheet-company-${index}`" :checked="filters.companies.includes(company)" @update:checked="(checked) => toggleCompany(company, checked)" />
                              <Label :for="`sheet-company-${index}`" class="font-normal">{{ company }}</Label>
                            </div>
                          </fieldset>
                          <div class="flex items-center justify-between gap-3">
                            <Label for="sheet-vip">فقط اتوبوسِ VIP</Label>
                            <Switch id="sheet-vip" :checked="filters.vip" @update:checked="(vip) => (filters = { ...filters, vip })" />
                          </div>
                        </div>
                      </div>
                      <SheetFooter class="flex-row gap-2 border-t p-5">
                        <Button variant="outline" class="flex-1" @click="clearFilters">پاک‌کردن</Button>
                      </SheetFooter>
                    </SheetContent>
                  </ControlSize>
                </Sheet>
                <Select :value="sort" @update:value="(value) => (sort = value as string)">
                  <SelectTrigger aria-label="مرتب‌سازی" class="w-40">
                    <SelectValue />
                  </SelectTrigger>
                  <SelectContent>
                    <SelectItem value="early">زودترین حرکت</SelectItem>
                    <SelectItem value="cheap">ارزان‌ترین</SelectItem>
                  </SelectContent>
                </Select>
              </div>
            </ControlSize>
          </div>

          <ul v-if="buses.length > 0" class="flex flex-col gap-4">
            <li v-for="bus in buses" :key="bus.id">
              <TicketCard
                :departure="{ time: bus.depart, place: 'تهران' }"
                :arrival="{ time: bus.arrive, place: 'اصفهان', nextDay: hm(bus.arrive) < hm(bus.depart) }"
                :duration="duration(bus.minutes)"
                :operator="bus.company"
                :seats-left="bus.seats"
                :low-seats="5"
                :price="formatCurrency(bus.price)"
                :original-price="bus.listPrice ? formatCurrency(bus.listPrice) : undefined"
                price-label="قیمتِ هر صندلی"
              >
                <template #icon><DigIcon name="bus" /></template>
                <template #logo><OperatorLogo :alt="bus.company" kind="bus" :src="BUS_LOGOS[bus.company]" /></template>
                <template #details>
                  <TicketCardDetail>
                    <template #icon><DigIcon name="location" /></template>
                    از {{ bus.from }}
                  </TicketCardDetail>
                  <TicketCardDetail>
                    <template #icon><DigIcon name="location" /></template>
                    به {{ bus.to }}
                  </TicketCardDetail>
                </template>
                <template #tags><Badge variant="soft" size="lg" :color="bus.vip ? 'violet' : 'default'">{{ bus.kind }}</Badge></template>
                <template #action>
                  <Button @click="toast.success(`${bus.company}، ساعتِ ${toFaDigits(bus.depart)}؛ گامِ بعد انتخابِ صندلی.`)">انتخابِ صندلی</Button>
                </template>
              </TicketCard>
            </li>
          </ul>
          <EmptyState v-else variant="bordered">
            <EmptyStateIcon>
              <DigIcon name="filter" />
            </EmptyStateIcon>
            <EmptyStateTitle>با این فیلترها اتوبوسی نیست</EmptyStateTitle>
            <EmptyStateDescription>یکی از فیلترها را بردارید یا روزِ دیگری را ببینید.</EmptyStateDescription>
            <EmptyStateActions>
              <Button variant="outline" @click="clearFilters">پاک‌کردنِ فیلترها</Button>
            </EmptyStateActions>
          </EmptyState>
        </section>
      </div>
    </main>
  </ControlSize>
</template>

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

این موارد هنوز برای Svelte آماده نیستند: badgecheckboxchoice-chipscontrol-sizeempty-statefare-date-striplabeloperator-logopersianselectsheetswitchticket-cardtoastآیکون busآیکون editآیکون filterآیکون location

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

ticket-results-bus.ts
import { Component, ChangeDetectionStrategy, signal, computed } from "@angular/core"

import { DigControlSize } from "@/components/ui/control-size"
import { DigIcon } from "@/lib/icons"
import { DigButton } from "@/components/ui/button"
import { DigFareDateStrip } from "@/components/ui/fare-date-strip"
import { DigChoiceChips, DigChoiceChip } from "@/components/ui/choice-chips"
import { DigCheckbox } from "@/components/ui/checkbox"
import { DigLabel } from "@/components/ui/label"
import { DigSwitch } from "@/components/ui/switch"
import {
  DigSheet,
  DigSheetTrigger,
  DigSheetContent,
  DigSheetHeader,
  DigSheetTitle,
  DigSheetDescription,
  DigSheetFooter,
} from "@/components/ui/sheet"
import { DigBadge } from "@/components/ui/badge"
import { DigSelect, DigSelectTrigger, DigSelectValue, DigSelectContent, DigSelectItem } from "@/components/ui/select"
import {
  DigTicketCard,
  DigTicketCardIcon,
  DigTicketCardLogo,
  DigTicketCardDetail,
  DigTicketCardDetailIcon,
  DigTicketCardTag,
  DigTicketCardAction,
} from "@/components/ui/ticket-card"
import { DigOperatorLogo } from "@/components/ui/operator-logo"
import {
  DigEmptyState,
  DigEmptyStateIcon,
  DigEmptyStateTitle,
  DigEmptyStateDescription,
  DigEmptyStateActions,
} from "@/components/ui/empty-state"
import { toast } from "@/components/ui/toast"
import { formatCurrency, toFaDigits } from "@/lib/persian"

type FareDay = { date: Date; price: number | null; soldOut?: boolean }

type Bus = {
  id: string
  company: string
  depart: string
  arrive: string
  minutes: number
  from: string
  to: string
  kind: string
  vip: boolean
  price: number
  listPrice?: number
  seats: number
  logo: { color: "primary" | "success" | "warning" | "destructive" | "secondary"; icon?: boolean }
}

const BUSES: Bus[] = [
  {
    id: "b1",
    company: "همسفر چابک‌سواران",
    depart: "06:30",
    arrive: "12:45",
    minutes: 375,
    from: "پایانهٔ جنوب",
    to: "پایانهٔ کاوه",
    kind: "VIP ۲۵ نفره",
    vip: true,
    price: 485000,
    listPrice: 540000,
    seats: 11,
    logo: { color: "primary", icon: true },
  },
  {
    id: "b2",
    company: "سیر و سفر",
    depart: "08:00",
    arrive: "14:30",
    minutes: 390,
    from: "پایانهٔ جنوب",
    to: "پایانهٔ صفه",
    kind: "معمولی ۴۴ نفره",
    vip: false,
    price: 290000,
    seats: 26,
    logo: { color: "success" },
  },
  {
    id: "b3",
    company: "رویال سفر ایرانیان",
    depart: "13:15",
    arrive: "19:20",
    minutes: 365,
    from: "پایانهٔ آرژانتین",
    to: "پایانهٔ کاوه",
    kind: "VIP ۲۵ نفره",
    vip: true,
    price: 510000,
    seats: 3,
    logo: { color: "warning" },
  },
  {
    id: "b4",
    company: "ایران‌پیما",
    depart: "16:45",
    arrive: "23:00",
    minutes: 375,
    from: "پایانهٔ غرب",
    to: "پایانهٔ کاوه",
    kind: "VIP ۳۰ نفره",
    vip: true,
    price: 455000,
    seats: 17,
    logo: { color: "destructive", icon: true },
  },
  {
    id: "b5",
    company: "سیر و سفر",
    depart: "22:30",
    arrive: "04:40",
    minutes: 370,
    from: "پایانهٔ جنوب",
    to: "پایانهٔ صفه",
    kind: "معمولی ۴۴ نفره",
    vip: false,
    price: 275000,
    seats: 32,
    logo: { color: "success" },
  },
]

const COMPANIES = [...new Set(BUSES.map((bus) => bus.company))]

const TIMES = [
  { value: "morning", label: "صبح", from: 0, to: 12 * 60 },
  { value: "noon", label: "ظهر", from: 12 * 60, to: 17 * 60 },
  { value: "night", label: "شب", from: 17 * 60, to: 24 * 60 },
]

const BASE = new Date(2026, 9, 21)

const DAYS: FareDay[] = [275000, 290000, 275000, 310000, 290000, 340000, 275000].map((price, index) => ({
  date: new Date(BASE.getFullYear(), BASE.getMonth(), BASE.getDate() + index - 2),
  price,
}))

const hm = (time: string) => Number(time.slice(0, 2)) * 60 + Number(time.slice(3))

const duration = (minutes: number) =>
  `${toFaDigits(Math.floor(minutes / 60))} ساعت${minutes % 60 ? ` و ${toFaDigits(minutes % 60)} دقیقه` : ""}`

const dayLabel = new Intl.DateTimeFormat("fa-IR-u-ca-persian", { weekday: "long", day: "numeric", month: "long" })

type Filters = { times: string[]; companies: string[]; vip: boolean }

const EMPTY: Filters = { times: [], companies: [], vip: false }

const BUS_LOGOS: Record<string, string> = {
  "همسفر چابک‌سواران": "https://www.google.com/s2/favicons?domain=hamsafarco.com&sz=128",
  "سیر و سفر": "https://www.google.com/s2/favicons?domain=seirosafar.ir&sz=128",
  "رویال سفر ایرانیان": "https://www.google.com/s2/favicons?domain=royalsafar.com&sz=128",
  ایران‌پیما: "https://www.google.com/s2/favicons?domain=iranpeyma.ir&sz=128",
}

@Component({
  selector: "dig-block-ticket-results-bus",
  imports: [
    DigControlSize,
    DigIcon,
    DigButton,
    DigFareDateStrip,
    DigChoiceChips,
    DigChoiceChip,
    DigCheckbox,
    DigLabel,
    DigSwitch,
    DigSheet,
    DigSheetTrigger,
    DigSheetContent,
    DigSheetHeader,
    DigSheetTitle,
    DigSheetDescription,
    DigSheetFooter,
    DigBadge,
    DigSelect,
    DigSelectTrigger,
    DigSelectValue,
    DigSelectContent,
    DigSelectItem,
    DigTicketCard,
    DigTicketCardIcon,
    DigTicketCardLogo,
    DigTicketCardDetail,
    DigTicketCardDetailIcon,
    DigTicketCardTag,
    DigTicketCardAction,
    DigOperatorLogo,
    DigEmptyState,
    DigEmptyStateIcon,
    DigEmptyStateTitle,
    DigEmptyStateDescription,
    DigEmptyStateActions,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <main digControlSize="xl" class="mx-auto flex w-full max-w-6xl flex-col gap-6 p-4 sm:p-6">
      <header class="flex flex-col gap-4 rounded-xl border bg-card p-4 shadow-card sm:flex-row sm:items-center sm:p-5">
        <span
          aria-hidden="true"
          class="hidden size-12 shrink-0 items-center justify-center rounded-lg bg-primary-subtle text-primary-subtle-foreground sm:flex [&>svg]:size-6"
          ><svg digIcon="bus"></svg
        ></span>
        <div class="flex min-w-0 flex-1 flex-col gap-1">
          <h1 class="text-lg leading-snug font-black sm:text-xl">بلیتِ اتوبوسِ تهران به اصفهان</h1>
          <p class="text-sm text-muted-foreground">{{ dayLabel.format(date()) }} · ۲ صندلی</p>
        </div>
        <div digControlSize="lg" mobileSize="default" class="flex">
          <button
            digButton
            type="button"
            variant="outline"
            class="w-full sm:w-auto"
            (click)="notify('فرمِ جست‌وجو با همین مسیر باز می‌شود.')"
          >
            <svg digIcon="edit"></svg>
            ویرایشِ جست‌وجو
          </button>
        </div>
      </header>

      <section aria-label="روزِ حرکت" class="flex flex-col gap-2">
        <p class="text-sm text-muted-foreground">کم‌ترین قیمتِ هر روز (هزار تومان)</p>
        <div
          digFareDateStrip
          [days]="DAYS"
          [value]="date()"
          aria-label="روزِ حرکت"
          class="-m-1"
          (valueChange)="onDate($event)"
        ></div>
      </section>

      <div class="grid gap-6 lg:grid-cols-[17rem_minmax(0,1fr)] lg:items-start">
        <aside aria-labelledby="bus-filters" class="hidden flex-col gap-5 rounded-xl border bg-card p-5 lg:flex">
          <div class="flex items-center justify-between gap-2">
            <h2 id="bus-filters" class="font-bold">فیلترها</h2>
            @if (active() > 0) {
              <button
                digControlSize="default"
                digButton
                type="button"
                variant="ghost"
                class="-me-2"
                (click)="clearFilters()"
              >
                پاک‌کردن
              </button>
            }
          </div>
          <!-- فیلترها؛ همین در ستونِ کناریِ دسکتاپ و در Sheetِ گوشی. -->
          <div class="flex flex-col gap-6">
            <fieldset class="flex flex-col gap-3">
              <legend class="mb-3 text-sm font-bold">ساعتِ حرکت</legend>
              <div
                digChoiceChips
                type="multiple"
                mobileSize="default"
                [value]="filters().times"
                aria-label="ساعتِ حرکت"
                (valueChange)="onTimes($event)"
              >
                @for (time of TIMES; track time.value) {
                  <button digChoiceChip [value]="time.value">{{ time.label }}</button>
                }
              </div>
            </fieldset>
            <fieldset class="flex flex-col gap-3">
              <legend class="mb-3 text-sm font-bold">شرکتِ مسافربری</legend>
              @for (company of COMPANIES; track company; let index = $index) {
                <div class="flex items-center gap-2">
                  <button
                    digCheckbox
                    [id]="\`side-company-\${index}\`"
                    [checked]="filters().companies.includes(company)"
                    (checkedChange)="toggleCompany(company, $event)"
                  ></button>
                  <label digLabel [htmlFor]="\`side-company-\${index}\`" class="font-normal">{{ company }}</label>
                </div>
              }
            </fieldset>
            <div class="flex items-center justify-between gap-3">
              <label digLabel for="side-vip">فقط اتوبوسِ VIP</label>
              <button
                digSwitch
                id="side-vip"
                [checked]="filters().vip"
                (checkedChange)="filters.set({ ...filters(), vip: $event })"
              ></button>
            </div>
          </div>
        </aside>

        <section aria-labelledby="bus-results" class="flex min-w-0 flex-col gap-4">
          <div class="flex flex-wrap items-center justify-between gap-3">
            <h2 id="bus-results" class="font-bold" aria-live="polite">
              {{ toFaDigits(buses().length) }} اتوبوسِ تهران به اصفهان
            </h2>
            <div digControlSize="lg" mobileSize="default" class="flex gap-2">
              <ng-container digSheet
                ><button digSheetTrigger digButton type="button" variant="outline" class="lg:hidden">
                  <svg digIcon="filter"></svg>
                  فیلترها
                  @if (active() > 0) {
                    <span digBadge size="sm" class="ms-1">{{ toFaDigits(active()) }}</span>
                  }
                </button>
                <div digControlSize="xl">
                  <div digSheetContent side="bottom" class="max-h-[85dvh] gap-0 overflow-y-auto rounded-t-xl p-0">
                    <div digSheetHeader class="border-b p-5">
                      <h2 digSheetTitle>فیلترها</h2>
                      <p digSheetDescription class="sr-only">ساعتِ حرکت، شرکت و نوعِ اتوبوس</p>
                    </div>
                    <div class="p-5">
                      <div class="flex flex-col gap-6">
                        <fieldset class="flex flex-col gap-3">
                          <legend class="mb-3 text-sm font-bold">ساعتِ حرکت</legend>
                          <div
                            digChoiceChips
                            type="multiple"
                            mobileSize="default"
                            [value]="filters().times"
                            aria-label="ساعتِ حرکت"
                            (valueChange)="onTimes($event)"
                          >
                            @for (time of TIMES; track time.value) {
                              <button digChoiceChip [value]="time.value">{{ time.label }}</button>
                            }
                          </div>
                        </fieldset>
                        <fieldset class="flex flex-col gap-3">
                          <legend class="mb-3 text-sm font-bold">شرکتِ مسافربری</legend>
                          @for (company of COMPANIES; track company; let index = $index) {
                            <div class="flex items-center gap-2">
                              <button
                                digCheckbox
                                [id]="\`sheet-company-\${index}\`"
                                [checked]="filters().companies.includes(company)"
                                (checkedChange)="toggleCompany(company, $event)"
                              ></button>
                              <label digLabel [htmlFor]="\`sheet-company-\${index}\`" class="font-normal">{{
                                company
                              }}</label>
                            </div>
                          }
                        </fieldset>
                        <div class="flex items-center justify-between gap-3">
                          <label digLabel for="sheet-vip">فقط اتوبوسِ VIP</label>
                          <button
                            digSwitch
                            id="sheet-vip"
                            [checked]="filters().vip"
                            (checkedChange)="filters.set({ ...filters(), vip: $event })"
                          ></button>
                        </div>
                      </div>
                    </div>
                    <div digSheetFooter class="flex-row gap-2 border-t p-5">
                      <button digButton type="button" variant="outline" class="flex-1" (click)="clearFilters()">
                        پاک‌کردن
                      </button>
                    </div>
                  </div>
                </div></ng-container
              >
              <ng-container digSelect [value]="sort()" (valueChange)="setSort($event)"
                ><button digSelectTrigger aria-label="مرتب‌سازی" class="w-40"><span digSelectValue></span></button>
                <div digSelectContent>
                  <div digSelectItem value="early">زودترین حرکت</div>
                  <div digSelectItem value="cheap">ارزان‌ترین</div>
                </div></ng-container
              >
            </div>
          </div>

          @if (buses().length > 0) {
            <ul class="flex flex-col gap-4">
              @for (bus of buses(); track bus.id) {
                <li>
                  <article
                    digTicketCard
                    [departure]="{ time: bus.depart, place: 'تهران' }"
                    [arrival]="{ time: bus.arrive, place: 'اصفهان', nextDay: hm(bus.arrive) < hm(bus.depart) }"
                    [duration]="duration(bus.minutes)"
                    [operator]="bus.company"
                    [seatsLeft]="bus.seats"
                    [lowSeats]="5"
                    [price]="formatCurrency(bus.price)"
                    [originalPrice]="bus.listPrice ? formatCurrency(bus.listPrice) : undefined"
                    priceLabel="قیمتِ هر صندلی"
                  >
                    <span digTicketCardIcon><svg digIcon="bus"></svg></span
                    ><span digTicketCardLogo
                      ><span digOperatorLogo [alt]="bus.company" kind="bus" [src]="BUS_LOGOS[bus.company]"></span
                    ></span>
                    <li digTicketCardDetail>
                      <span digTicketCardDetailIcon><svg digIcon="location"></svg></span> از {{ bus.from }}
                    </li>
                    <li digTicketCardDetail>
                      <span digTicketCardDetailIcon><svg digIcon="location"></svg></span> به {{ bus.to }}
                    </li>
                    <span digTicketCardTag
                      ><span digBadge variant="soft" size="lg" [color]="bus.vip ? 'violet' : 'default'">{{
                        bus.kind
                      }}</span></span
                    ><span digTicketCardAction
                      ><button
                        digButton
                        type="button"
                        (click)="notify(\`\${bus.company}، ساعتِ \${toFaDigits(bus.depart)}؛ گامِ بعد انتخابِ صندلی.\`)"
                      >
                        انتخابِ صندلی
                      </button></span
                    >
                  </article>
                </li>
              }
            </ul>
          } @else {
            <div digEmptyState variant="bordered">
              <span digEmptyStateIcon><svg digIcon="filter"></svg></span>
              <h3 digEmptyStateTitle>با این فیلترها اتوبوسی نیست</h3>
              <p digEmptyStateDescription>یکی از فیلترها را بردارید یا روزِ دیگری را ببینید.</p>
              <div digEmptyStateActions>
                <button digButton type="button" variant="outline" (click)="clearFilters()">پاک‌کردنِ فیلترها</button>
              </div>
            </div>
          }
        </section>
      </div>
    </main>
  `,
})
export class TicketResultsBusBlock {
  readonly toFaDigits = toFaDigits

  readonly formatCurrency = formatCurrency

  readonly BUS_LOGOS = BUS_LOGOS

  readonly dayLabel = dayLabel

  readonly duration = duration

  readonly hm = hm

  readonly DAYS = DAYS

  readonly TIMES = TIMES

  readonly COMPANIES = COMPANIES

  readonly date = signal(BASE)

  readonly sort = signal("early")

  readonly filters = signal<Filters>({ ...EMPTY, times: [], companies: [] })

  readonly active = computed(
    () => this.filters().times.length + this.filters().companies.length + (this.filters().vip ? 1 : 0)
  )

  readonly buses = computed(() =>
    BUSES.filter(
      (bus) =>
        (this.filters().times.length === 0 ||
          this.filters().times.some((value) =>
            TIMES.some((time) => time.value === value && hm(bus.depart) >= time.from && hm(bus.depart) < time.to)
          )) &&
        (this.filters().companies.length === 0 || this.filters().companies.includes(bus.company)) &&
        (!this.filters().vip || bus.vip)
    ).sort((a, b) => (this.sort() === "early" ? hm(a.depart) - hm(b.depart) : a.price - b.price))
  )

  clearFilters() {
    this.filters.set({ times: [], companies: [], vip: false })
  }

  onTimes(value: string | string[] | undefined) {
    this.filters.set({ ...this.filters(), times: (value as string[] | undefined) ?? [] })
  }

  toggleCompany(company: string, checked: boolean | "indeterminate") {
    this.filters.set({
      ...this.filters(),
      companies:
        checked === true
          ? [...this.filters().companies, company]
          : this.filters().companies.filter((item) => item !== company),
    })
  }

  onDate(next: Date | undefined) {
    if (next) this.date.set(next)
  }

  setSort(value: string | string[] | undefined) {
    if (typeof value === "string") this.sort.set(value)
  }
  notify(message: string) {
    toast.success(message)
  }
}

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

این موارد هنوز برای Android آماده نیستند: operator-logo

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