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

شش نوعِ سفر در برگه‌های آیکون‌دار (پرواز، قطار، اتوبوس، هتل، ویلا، تور)، بنری که با هر برگه عکس و تیترش عوض می‌شود، و فرمِ مخصوصِ هر کدام: پرواز داخلی/خارجی با کلاس، قطار با نوعِ واگن، هتل با اتاق، تور با «بلیت + اقامت».

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

این بلاک از ۱۴ آیتم دیگ استفاده می‌کند: autocompletebuttoncontrol-sizedate-pickerdate-range-pickericonslabelnumber-fieldpersianpopoverselecttabstoasttoggle-group

پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add https://docs.digdesign.ir/r/autocomplete.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/date-picker.json https://docs.digdesign.ir/r/date-range-picker.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/number-field.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/popover.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/tabs.json https://docs.digdesign.ir/r/toast.json https://docs.digdesign.ir/r/toggle-group.json
pnpm dlx digdesign@latest add https://docs.digdesign.ir/r/autocomplete.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/date-picker.json https://docs.digdesign.ir/r/date-range-picker.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/number-field.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/popover.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/tabs.json https://docs.digdesign.ir/r/toast.json https://docs.digdesign.ir/r/toggle-group.json
yarn dlx digdesign@latest add https://docs.digdesign.ir/r/autocomplete.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/date-picker.json https://docs.digdesign.ir/r/date-range-picker.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/number-field.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/popover.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/tabs.json https://docs.digdesign.ir/r/toast.json https://docs.digdesign.ir/r/toggle-group.json
bunx --bun digdesign@latest add https://docs.digdesign.ir/r/autocomplete.json https://docs.digdesign.ir/r/button.json https://docs.digdesign.ir/r/control-size.json https://docs.digdesign.ir/r/date-picker.json https://docs.digdesign.ir/r/date-range-picker.json https://docs.digdesign.ir/r/icons.json https://docs.digdesign.ir/r/label.json https://docs.digdesign.ir/r/number-field.json https://docs.digdesign.ir/r/persian.json https://docs.digdesign.ir/r/popover.json https://docs.digdesign.ir/r/select.json https://docs.digdesign.ir/r/tabs.json https://docs.digdesign.ir/r/toast.json https://docs.digdesign.ir/r/toggle-group.json
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add autocomplete button control-size date-picker date-range-picker label number-field persian popover select tabs toast toggle-group --framework vue
pnpm dlx digdesign@latest add autocomplete button control-size date-picker date-range-picker label number-field persian popover select tabs toast toggle-group --framework vue
yarn dlx digdesign@latest add autocomplete button control-size date-picker date-range-picker label number-field persian popover select tabs toast toggle-group --framework vue
bunx --bun digdesign@latest add autocomplete button control-size date-picker date-range-picker label number-field persian popover select tabs toast 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 autocomplete button control-size date-picker date-range-picker icons label number-field persian popover select tabs toast toggle-group --framework angular
pnpm dlx digdesign@latest add autocomplete button control-size date-picker date-range-picker icons label number-field persian popover select tabs toast toggle-group --framework angular
yarn dlx digdesign@latest add autocomplete button control-size date-picker date-range-picker icons label number-field persian popover select tabs toast toggle-group --framework angular
bunx --bun digdesign@latest add autocomplete button control-size date-picker date-range-picker icons label number-field persian popover select tabs toast toggle-group --framework angular
پکیج‌منیجر پیش‌فرض Node.jsنصب سریع با لینک سخت و دیسک مشترکYarn نسخهٔ ۲ به بالا (Berry)رانتایم و پکیج‌منیجر Bun
npx digdesign@latest add autocomplete button control-size date-picker date-range-picker label number-field persian popover select tabs toast toggle-group --framework android
pnpm dlx digdesign@latest add autocomplete button control-size date-picker date-range-picker label number-field persian popover select tabs toast toggle-group --framework android
yarn dlx digdesign@latest add autocomplete button control-size date-picker date-range-picker label number-field persian popover select tabs toast toggle-group --framework android
bunx --bun digdesign@latest add autocomplete button control-size date-picker date-range-picker label number-field persian popover select tabs toast toggle-group --framework android

۲. کد صفحه

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

travel-search.tsx
"use client"

import * as React from "react"
import type { DateRange } from "react-day-picker"

import { BusIcon, ChevronDownIcon, HomeIcon, HotelIcon, PlaneIcon, SuitcaseIcon, SwapIcon, TrainIcon } from "@/components/icons"
import { Autocomplete } from "@/components/ui/autocomplete"
import { Button } from "@/components/ui/button"
import { ControlSizeProvider } from "@/components/ui/control-size"
import { DatePicker } from "@/components/ui/date-picker"
import { DateRangePicker } from "@/components/ui/date-range-picker"
import { Label } from "@/components/ui/label"
import { NumberField } from "@/components/ui/number-field"
import { Popover, PopoverClose, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
import { toast } from "@/components/ui/toast"
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
import { toFaDigits } from "@/lib/persian"
import { stockImages, type StockImageName } from "@/lib/stock-images"

type Option = { value: string; label: string }
type ServiceId = "flight" | "train" | "bus" | "hotel" | "villa" | "tour"

const SERVICES: { value: ServiceId; label: string; icon: React.ComponentType<{ className?: string }>; image: StockImageName; title: string; subtitle: string }[] = [
  { value: "flight", label: "پرواز", icon: PlaneIcon, image: "travelPlane", title: "کجا پرواز کنیم؟", subtitle: "پروازهای داخلی و خارجی از ۲۰ ایرلاین، با قیمتِ نهایی." },
  { value: "train", label: "قطار", icon: TrainIcon, image: "travelTrain", title: "سفر با قطار، راحت و به‌صرفه", subtitle: "همهٔ قطارهای رجا، فدک و سیر با انتخابِ کوپه." },
  { value: "bus", label: "اتوبوس", icon: BusIcon, image: "travelBus", title: "بلیتِ اتوبوس از هر پایانه", subtitle: "بیش از ۸۰۰ مسیرِ بین‌شهری با صندلیِ انتخابی." },
  { value: "hotel", label: "هتل", icon: HotelIcon, image: "travelHotel", title: "هتلی که دنبالش هستی", subtitle: "رزروِ قطعی با بهترین قیمت و لغوِ رایگان در بیشترِ هتل‌ها." },
  { value: "villa", label: "ویلا", icon: HomeIcon, image: "travelVilla", title: "ویلا و اقامتگاهِ بومی", subtitle: "از کلبهٔ جنگلی تا ویلای ساحلی، با عکس و نظرِ مهمان‌ها." },
  { value: "tour", label: "تور", icon: SuitcaseIcon, image: "travelTour", title: "تورهای داخلی و خارجی", subtitle: "بلیت و اقامت در یک بسته، یا تورِ گردشگری با راهنما." },
]

const DOMESTIC: Option[] = [
  { value: "THR", label: "تهران" },
  { value: "MHD", label: "مشهد" },
  { value: "IFN", label: "اصفهان" },
  { value: "SYZ", label: "شیراز" },
  { value: "TBZ", label: "تبریز" },
  { value: "KIH", label: "کیش" },
  { value: "AWZ", label: "اهواز" },
  { value: "RAS", label: "رشت" },
]
const FOREIGN: Option[] = [
  { value: "IST", label: "استانبول" },
  { value: "DXB", label: "دبی" },
  { value: "NJF", label: "نجف" },
  { value: "TBS", label: "تفلیس" },
  { value: "EVN", label: "ایروان" },
  { value: "KUL", label: "کوالالامپور" },
]
const VILLA_PLACES: Option[] = [
  { value: "ramsar", label: "رامسر" },
  { value: "chalus", label: "چالوس" },
  { value: "kordan", label: "کردان" },
  { value: "masuleh", label: "ماسوله" },
  { value: "kashan", label: "کاشان، اقامتگاهِ سنتی" },
  { value: "qeshm", label: "قشم" },
]
const ALL_CITIES = [...DOMESTIC, ...FOREIGN, ...VILLA_PLACES]
const cityName = (code: string) => ALL_CITIES.find((city) => city.value === code)?.label ?? ""

/** پیشنهادهای زیرِ کارت برای هر نوعِ سفر؛ مسیر برای حمل‌ونقل، شهر برای اقامت. */
const POPULAR: Record<ServiceId, { from?: string; to: string }[]> = {
  flight: [{ from: "THR", to: "MHD" }, { from: "THR", to: "KIH" }, { from: "IFN", to: "MHD" }, { from: "THR", to: "IST" }],
  train: [{ from: "THR", to: "MHD" }, { from: "THR", to: "TBZ" }, { from: "THR", to: "IFN" }, { from: "MHD", to: "SYZ" }],
  bus: [{ from: "THR", to: "RAS" }, { from: "THR", to: "IFN" }, { from: "SYZ", to: "IFN" }, { from: "THR", to: "TBZ" }],
  hotel: [{ to: "KIH" }, { to: "MHD" }, { to: "IST" }, { to: "SYZ" }],
  villa: [{ to: "ramsar" }, { to: "kordan" }, { to: "masuleh" }, { to: "kashan" }],
  tour: [{ from: "THR", to: "IST" }, { from: "THR", to: "KIH" }, { from: "THR", to: "DXB" }, { from: "THR", to: "TBS" }],
}

/** داده و رفتارِ مشترکِ هر فرم: مبدأ، مقصد، خطای مقصد، تاریخ و مسافر. */
function useTripState(defaults: { origin?: string } = {}) {
  const [origin, setOrigin] = React.useState(defaults.origin ?? "")
  const [destination, setDestinationRaw] = React.useState("")
  const [missing, setMissing] = React.useState(false)
  const [date, setDate] = React.useState<Date>()
  const [range, setRange] = React.useState<DateRange>()
  const setDestination = (value: string) => {
    setDestinationRaw(value)
    setMissing(false)
  }
  return { origin, setOrigin, destination, setDestination, missing, setMissing, date, setDate, range, setRange }
}
type TripState = ReturnType<typeof useTripState>

/** گزینه‌های کوچکِ بالای فیلدها (یک‌طرفه، نوعِ کوپه، کلاسِ پرواز)؛ Select با اندازهٔ کنترلِ ثانویه. */
function OptionSelect({ label, value, onValueChange, options }: { label: string; value: string; onValueChange: (value: string) => void; options: Option[] }) {
  return (
    <Select value={value} onValueChange={onValueChange}>
      <SelectTrigger aria-label={label} className="w-auto min-w-28 gap-2 rounded-full">
        <SelectValue />
      </SelectTrigger>
      <ControlSizeProvider size="xl" asChild>
        <SelectContent>
          {options.map((option) => (
            <SelectItem key={option.value} value={option.value}>
              {option.label}
            </SelectItem>
          ))}
        </SelectContent>
      </ControlSizeProvider>
    </Select>
  )
}

/** ردیفِ گزینه‌ها: سگمنتِ داخلی/خارجی و Selectهای کوچک، ۴۰ در دسکتاپ و ۳۶ در گوشی. */
function OptionsRow({ children }: { children: React.ReactNode }) {
  return (
    <ControlSizeProvider size="lg" mobileSize="default" asChild>
      <div className="flex flex-wrap items-center gap-2">{children}</div>
    </ControlSizeProvider>
  )
}

function Scope({ value, onValueChange, options, label }: { value: string; onValueChange: (value: string) => void; options: Option[]; label: string }) {
  return (
    <ToggleGroup type="single" variant="segmented" value={value} onValueChange={(next) => next && onValueChange(next as string)} aria-label={label}>
      {options.map((option) => (
        <ToggleGroupItem key={option.value} value={option.value}>
          {option.label}
        </ToggleGroupItem>
      ))}
    </ToggleGroup>
  )
}

/** مبدأ و مقصد با دکمهٔ جابه‌جایی؛ در دسکتاپ دکمه میانِ دو فیلد، در موبایل کنارِ برچسبِ مقصد. */
function RouteFields({ id, trip, cities, originLabel, destinationLabel, noun }: { id: string; trip: TripState; cities: Option[]; originLabel: string; destinationLabel: string; noun: string }) {
  const swap = () => {
    trip.setOrigin(trip.destination)
    trip.setDestination(trip.origin)
  }
  return (
    <div className="grid grid-cols-1 gap-4 sm:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] sm:items-start sm:gap-2">
      <div className="flex flex-col gap-2">
        <Label htmlFor={`${id}-origin`}>{originLabel}</Label>
        <Autocomplete id={`${id}-origin`} items={cities.filter((city) => city.value !== trip.destination)} value={trip.origin} onValueChange={trip.setOrigin} placeholder={`${noun}ِ مبدأ`} emptyText="پیدا نشد" className="w-full" />
      </div>
      <Button type="button" variant="ghost" size="icon" aria-label="جابه‌جاییِ مبدأ و مقصد" disabled={!trip.origin || !trip.destination} onClick={swap} className="hidden rounded-full sm:mt-7 sm:flex">
        <SwapIcon />
      </Button>
      <div className="flex flex-col gap-2">
        <div className="flex h-5 items-center justify-between gap-2">
          <Label htmlFor={`${id}-destination`}>{destinationLabel}</Label>
          <ControlSizeProvider size="lg" asChild>
            <Button type="button" variant="ghost" aria-label="جابه‌جاییِ مبدأ و مقصد" disabled={!trip.origin || !trip.destination} onClick={swap} className="-me-2 gap-1.5 px-2 sm:hidden">
              <SwapIcon className="rotate-90" />
              جابه‌جایی
            </Button>
          </ControlSizeProvider>
        </div>
        <DestinationInput id={id} trip={trip} cities={cities.filter((city) => city.value !== trip.origin)} placeholder={`${noun}ِ مقصد`} />
      </div>
    </div>
  )
}

function DestinationInput({ id, trip, cities, placeholder }: { id: string; trip: TripState; cities: Option[]; placeholder: string }) {
  return (
    <>
      <Autocomplete
        id={`${id}-destination`}
        items={cities}
        value={trip.destination}
        onValueChange={trip.setDestination}
        placeholder={placeholder}
        emptyText="پیدا نشد"
        aria-invalid={trip.missing || undefined}
        aria-describedby={trip.missing ? `${id}-destination-error` : undefined}
        className="w-full"
      />
      {trip.missing && (
        <p id={`${id}-destination-error`} className="text-sm text-destructive">
          مقصد را انتخاب کن.
        </p>
      )}
    </>
  )
}

function DateFields({ id, trip, round, labels }: { id: string; trip: TripState; round: boolean; labels: [string, string] }) {
  return round ? (
    <div className="flex flex-col gap-2">
      <Label id={`${id}-range`}>{labels[1]}</Label>
      <DateRangePicker calendar="jalali" value={trip.range} onChange={trip.setRange} aria-label={labels[1]} placeholder="انتخابِ دو تاریخ" className="w-full" />
    </div>
  ) : (
    <DatePicker id={`${id}-date`} label={labels[0]} calendar="jalali" value={trip.date} onChange={trip.setDate} minDate={new Date()} className="w-full" />
  )
}

type PeopleRow = { label: string; hint?: string; value: number; onChange: (value: number) => void; min: number; max: number }

/**
 * شمارندهٔ مسافر و اتاق در پاپ‌اوور؛ متنِ دکمه خلاصهٔ انتخاب است و با هر تغییر به‌روز می‌شود.
 * هر ردیف عنوان و بازهٔ سنی دارد و «تأیید» پاپ‌اوور را می‌بندد و فوکوس را به همین دکمه برمی‌گرداند.
 */
function PeopleField({ id, label, rows, summary }: { id: string; label: string; rows: PeopleRow[]; summary: string }) {
  return (
    <div className="flex flex-col gap-2">
      <Label id={`${id}-people`}>{label}</Label>
      <Popover>
        <PopoverTrigger asChild>
          <Button id={`${id}-people-trigger`} variant="outline" aria-labelledby={`${id}-people ${id}-people-trigger`} className="justify-between font-normal">
            <span className="truncate">{summary}</span>
            <ChevronDownIcon className="text-muted-foreground" />
          </Button>
        </PopoverTrigger>
        <ControlSizeProvider size="xl" asChild>
          <PopoverContent align="end" aria-label={label} className="flex w-80 max-w-[calc(100vw-2rem)] flex-col gap-4">
            {rows.map((row, index) => (
              <div key={row.label} className="flex items-center justify-between gap-3">
                <div className="flex min-w-0 flex-col gap-0.5">
                  <Label id={`${id}-row-${index}`}>{row.label}</Label>
                  {row.hint && <span className="text-xs text-muted-foreground">{row.hint}</span>}
                </div>
                <NumberField aria-labelledby={`${id}-row-${index}`} value={row.value} onValueChange={row.onChange} min={row.min} max={row.max} className="w-32 shrink-0" />
              </div>
            ))}
            <PopoverClose asChild>
              <Button className="mt-2">تأیید</Button>
            </PopoverClose>
          </PopoverContent>
        </ControlSizeProvider>
      </Popover>
    </div>
  )
}

/** خلاصهٔ مسافران برای متنِ دکمه: فقط بزرگسال «۲ بزرگسال»، گروهِ مختلط «۳ مسافر» تا در ستونِ باریکِ دسکتاپ بریده نشود. */
function passengerSummary(adults: number, others: number) {
  return others > 0 ? `${toFaDigits(adults + others)} مسافر` : `${toFaDigits(adults)} بزرگسال`
}

function usePassengers() {
  const [adults, setAdults] = React.useState(1)
  const [children, setChildren] = React.useState(0)
  const [infants, setInfants] = React.useState(0)
  return { adults, setAdults, children, setChildren, infants, setInfants }
}

/** فرمِ هر برگه: ارسال بدونِ غیرفعال‌کردنِ دکمه؛ مقصدِ خالی خطا را کنارِ همان فیلد نشان می‌دهد و فوکوس می‌گیرد. */
function SearchForm({ id, trip, onSearch, options, children }: { id: string; trip: TripState; onSearch: () => void; options?: React.ReactNode; children: React.ReactNode }) {
  return (
    <form
      noValidate
      className="flex flex-col gap-5"
      onSubmit={(event) => {
        event.preventDefault()
        if (!trip.destination) {
          trip.setMissing(true)
          document.getElementById(`${id}-destination`)?.focus()
          return
        }
        onSearch()
      }}
    >
      {options && <OptionsRow>{options}</OptionsRow>}
      <div className="grid grid-cols-1 gap-4 lg:grid-cols-[minmax(0,1.7fr)_minmax(0,1fr)_minmax(0,0.85fr)_auto] lg:items-start">
        {children}
        <Button type="submit" className="lg:mt-7 lg:min-w-32">
          جست‌وجو
        </Button>
      </div>
    </form>
  )
}

const TRIP_TYPES: Option[] = [
  { value: "oneway", label: "یک‌طرفه" },
  { value: "round", label: "رفت و برگشت" },
]

function FlightForm({ trip }: { trip: TripState }) {
  const [scope, setScope] = React.useState("domestic")
  const [tripType, setTripType] = React.useState("oneway")
  const [cabin, setCabin] = React.useState("economy")
  const people = usePassengers()
  const cities = scope === "domestic" ? DOMESTIC : [...DOMESTIC.slice(0, 4), ...FOREIGN]
  return (
    <SearchForm
      id="flight"
      trip={trip}
      onSearch={() => toast.success(`پروازهای ${cityName(trip.origin)} به ${cityName(trip.destination)}…`)}
      options={
        <>
          <Scope label="نوعِ پرواز" value={scope} onValueChange={setScope} options={[{ value: "domestic", label: "داخلی" }, { value: "foreign", label: "خارجی" }]} />
          <OptionSelect label="نوعِ سفر" value={tripType} onValueChange={setTripType} options={TRIP_TYPES} />
          {scope === "foreign" && (
            <OptionSelect label="کلاسِ پرواز" value={cabin} onValueChange={setCabin} options={[{ value: "economy", label: "اکونومی" }, { value: "business", label: "بیزینس" }, { value: "first", label: "فرست" }]} />
          )}
        </>
      }
    >
      <RouteFields id="flight" trip={trip} cities={cities} originLabel="مبدأ" destinationLabel="مقصد" noun={scope === "domestic" ? "شهر" : "شهر یا فرودگاه"} />
      <DateFields id="flight" trip={trip} round={tripType === "round"} labels={["تاریخِ رفت", "تاریخِ رفت و برگشت"]} />
      <PeopleField
        id="flight"
        label="مسافران"
        summary={passengerSummary(people.adults, people.children + people.infants)}
        rows={[
          { label: "بزرگسال", hint: "۱۲ سال به بالا", value: people.adults, onChange: people.setAdults, min: 1, max: 9 },
          { label: "کودک", hint: "۲ تا ۱۲ سال", value: people.children, onChange: people.setChildren, min: 0, max: 8 },
          { label: "نوزاد", hint: "زیرِ ۲ سال، یکی برای هر بزرگسال", value: people.infants, onChange: people.setInfants, min: 0, max: people.adults },
        ]}
      />
    </SearchForm>
  )
}

function TrainForm({ trip }: { trip: TripState }) {
  const [tripType, setTripType] = React.useState("oneway")
  const [wagon, setWagon] = React.useState("compartment")
  const [group, setGroup] = React.useState("regular")
  const people = usePassengers()
  return (
    <SearchForm
      id="train"
      trip={trip}
      onSearch={() => toast.success(`قطارهای ${cityName(trip.origin)} به ${cityName(trip.destination)}…`)}
      options={
        <>
          <OptionSelect label="نوعِ سفر" value={tripType} onValueChange={setTripType} options={TRIP_TYPES} />
          <OptionSelect label="نوعِ واگن" value={wagon} onValueChange={setWagon} options={[{ value: "compartment", label: "کوپهٔ عادی" }, { value: "private", label: "کوپهٔ دربست" }, { value: "salon", label: "سالنی" }]} />
          <OptionSelect label="نوعِ مسافر" value={group} onValueChange={setGroup} options={[{ value: "regular", label: "مسافرانِ عادی" }, { value: "women", label: "ویژهٔ بانوان" }, { value: "men", label: "ویژهٔ آقایان" }]} />
        </>
      }
    >
      <RouteFields id="train" trip={trip} cities={DOMESTIC.filter((city) => city.value !== "KIH")} originLabel="ایستگاهِ مبدأ" destinationLabel="ایستگاهِ مقصد" noun="شهر" />
      <DateFields id="train" trip={trip} round={tripType === "round"} labels={["تاریخِ حرکت", "تاریخِ رفت و برگشت"]} />
      <PeopleField
        id="train"
        label="مسافران"
        summary={passengerSummary(people.adults, people.children + people.infants)}
        rows={[
          { label: "بزرگسال", hint: "۱۲ سال به بالا", value: people.adults, onChange: people.setAdults, min: 1, max: wagon === "private" ? 4 : 9 },
          { label: "کودک", hint: "۲ تا ۱۲ سال، نیم‌بها", value: people.children, onChange: people.setChildren, min: 0, max: 6 },
          { label: "نوزاد", hint: "زیرِ ۲ سال، بدونِ صندلی", value: people.infants, onChange: people.setInfants, min: 0, max: people.adults },
        ]}
      />
    </SearchForm>
  )
}

function BusForm({ trip }: { trip: TripState }) {
  const [seats, setSeats] = React.useState(1)
  return (
    <SearchForm id="bus" trip={trip} onSearch={() => toast.success(`اتوبوس‌های ${cityName(trip.origin)} به ${cityName(trip.destination)}…`)}>
      <RouteFields id="bus" trip={trip} cities={DOMESTIC.filter((city) => city.value !== "KIH")} originLabel="مبدأ" destinationLabel="مقصد" noun="شهر یا پایانه" />
      <DateFields id="bus" trip={trip} round={false} labels={["تاریخِ حرکت", ""]} />
      <PeopleField id="bus" label="صندلی" summary={`${toFaDigits(seats)} صندلی`} rows={[{ label: "تعدادِ صندلی", value: seats, onChange: setSeats, min: 1, max: 6 }]} />
    </SearchForm>
  )
}

function StayForm({ id, trip, cities, foreignCities, label, placeholder, onSearch }: { id: "hotel" | "villa"; trip: TripState; cities: Option[]; foreignCities?: Option[]; label: string; placeholder: string; onSearch: () => void }) {
  const [scope, setScope] = React.useState("domestic")
  const [adults, setAdults] = React.useState(2)
  const [children, setChildren] = React.useState(0)
  const [rooms, setRooms] = React.useState(1)
  const guests = adults + children
  return (
    <SearchForm
      id={id}
      trip={trip}
      onSearch={onSearch}
      options={
        foreignCities && (
          <Scope
            label="داخلی یا خارجی"
            value={scope}
            onValueChange={(next) => {
              setScope(next)
              trip.setDestination("")
            }}
            options={[{ value: "domestic", label: "داخلی" }, { value: "foreign", label: "خارجی" }]}
          />
        )
      }
    >
      <div className="flex flex-col gap-2">
        <Label htmlFor={`${id}-destination`}>{label}</Label>
        <DestinationInput id={id} trip={trip} cities={scope === "foreign" && foreignCities ? foreignCities : cities} placeholder={placeholder} />
      </div>
      <DateFields id={id} trip={trip} round labels={["", "تاریخِ ورود و خروج"]} />
      <PeopleField
        id={id}
        label={id === "hotel" ? "مسافران و اتاق" : "تعدادِ مهمان"}
        summary={id === "hotel" ? `${toFaDigits(guests)} مسافر، ${toFaDigits(rooms)} اتاق` : `${toFaDigits(guests)} مهمان`}
        rows={[
          { label: "بزرگسال", hint: "۱۲ سال به بالا", value: adults, onChange: setAdults, min: 1, max: 12 },
          { label: "کودک", hint: "زیرِ ۱۲ سال", value: children, onChange: setChildren, min: 0, max: 6 },
          ...(id === "hotel" ? [{ label: "اتاق", value: rooms, onChange: setRooms, min: 1, max: Math.max(1, adults) }] : []),
        ]}
      />
    </SearchForm>
  )
}

function TourForm({ trip }: { trip: TripState }) {
  const [kind, setKind] = React.useState("package")
  const [adults, setAdults] = React.useState(2)
  const [rooms, setRooms] = React.useState(1)
  const cities = [...DOMESTIC, ...FOREIGN]
  return (
    <SearchForm
      id="tour"
      trip={trip}
      onSearch={() => toast.success(`تورهای ${cityName(trip.destination)}…`)}
      options={<Scope label="نوعِ تور" value={kind} onValueChange={setKind} options={[{ value: "package", label: "بلیت + اقامت" }, { value: "sightseeing", label: "تورِ گردشگری" }]} />}
    >
      <RouteFields id="tour" trip={trip} cities={cities} originLabel="مبدأ" destinationLabel="مقصد" noun={kind === "package" ? "شهر" : "شهر یا کشور"} />
      {kind === "package" ? (
        <>
          <DateFields id="tour" trip={trip} round labels={["", "تاریخِ رفت و برگشت"]} />
          <PeopleField
            id="tour"
            label="مسافران و اتاق"
            summary={`${toFaDigits(adults)} مسافر، ${toFaDigits(rooms)} اتاق`}
            rows={[
              { label: "مسافر", value: adults, onChange: setAdults, min: 1, max: 12 },
              { label: "اتاق", value: rooms, onChange: setRooms, min: 1, max: adults },
            ]}
          />
        </>
      ) : (
        <DateFields id="tour" trip={trip} round={false} labels={["از تاریخ", ""]} />
      )}
    </SearchForm>
  )
}

/**
 * جست‌وجوی سفر: شش نوعِ سفر (پرواز، قطار، اتوبوس، هتل، ویلا، تور) در برگه‌های خطیِ آیکون‌دار بالای کارت.
 * بنر با هر برگه عکس و تیترِ خودش را می‌گیرد و فرم فقط فیلدهایی را دارد که آن سفر لازم دارد: پرواز داخلی
 * یا خارجی با کلاسِ پرواز، قطار با نوعِ واگن و مسافر، اتوبوس با صندلی، هتل با اتاق، تور با «بلیت + اقامت»
 * یا گردشگری. هر برگه وضعیتِ خودش را نگه می‌دارد تا رفت‌وبرگشت بینِ برگه‌ها چیزی را پاک نکند. پیشنهادهای
 * زیرِ کارت هم با برگه عوض می‌شوند و با یک لمس فرم را پر می‌کنند.
 */
export default function TravelSearchBlock() {
  const [service, setService] = React.useState<ServiceId>("flight")
  const current = SERVICES.find((item) => item.value === service) ?? SERVICES[0]
  const trips: Record<ServiceId, TripState> = {
    flight: useTripState({ origin: "THR" }),
    train: useTripState({ origin: "THR" }),
    bus: useTripState({ origin: "THR" }),
    hotel: useTripState(),
    villa: useTripState(),
    tour: useTripState({ origin: "THR" }),
  }
  const trip = trips[service]
  const image = stockImages[current.image]
  const isStay = service === "hotel" || service === "villa"

  return (
    <ControlSizeProvider size="xl" asChild>
      <main className="mx-auto flex w-full max-w-5xl flex-col gap-8 p-4 sm:p-6">
        <div className="flex flex-col">
          {/* بنر: عکسِ همان نوعِ سفر؛ گرادیانِ تیره از سمتِ متن (در موبایل از بالا) تا تیتر روی هر عکسی خوانا بماند. */}
          <header className="relative isolate overflow-hidden rounded-xl bg-inverse px-5 pt-6 pb-24 text-[var(--dig-white)] sm:px-10 sm:pt-10 sm:pb-28">
            {/* eslint-disable-next-line @next/next/no-img-element -- عکس از کتابخانهٔ تصویرِ دیگ */}
            <img key={current.image} src={image.src} alt="" aria-hidden className="absolute inset-0 -z-20 size-full animate-in object-cover duration-500 fade-in" />
            <span aria-hidden className="pointer-events-none absolute inset-0 -z-10 bg-[linear-gradient(to_bottom,var(--inverse)_15%,color-mix(in_oklab,var(--inverse)_60%,transparent))] sm:bg-[linear-gradient(to_left,var(--inverse)_5%,color-mix(in_oklab,var(--inverse)_70%,transparent)_45%,color-mix(in_oklab,var(--inverse)_10%,transparent))]" />
            <div className="flex max-w-md flex-col gap-2" aria-live="polite">
              <h1 className="text-2xl leading-snug font-black sm:text-4xl">{current.title}</h1>
              <p className="text-sm text-[var(--dig-slate-200)] sm:text-base">{current.subtitle}</p>
            </div>
          </header>

          {/* کارتِ جست‌وجو روی لبهٔ بنر؛ برگه‌ها لبه‌به‌لبهٔ کارت، فرم با فاصله. */}
          <Tabs variant="line" value={service} onValueChange={(value) => setService(value as ServiceId)} className="relative mx-3 -mt-14 gap-0 rounded-xl border border-border bg-card shadow-card sm:mx-6">
            <TabsList aria-label="نوعِ سفر" className="px-1 sm:px-4">
              {SERVICES.map(({ value, label, icon: Icon }) => (
                <TabsTrigger key={value} value={value} className="px-1 text-xs sm:px-4 sm:text-sm">
                  <Icon className="size-5 sm:size-6" />
                  {label}
                </TabsTrigger>
              ))}
            </TabsList>
            <div className="p-4 sm:p-6">
              <TabsContent value="flight" forceMount>
                <FlightForm trip={trips.flight} />
              </TabsContent>
              <TabsContent value="train" forceMount>
                <TrainForm trip={trips.train} />
              </TabsContent>
              <TabsContent value="bus" forceMount>
                <BusForm trip={trips.bus} />
              </TabsContent>
              <TabsContent value="hotel" forceMount>
                <StayForm
                  id="hotel"
                  trip={trips.hotel}
                  cities={DOMESTIC}
                  foreignCities={FOREIGN}
                  label="شهر یا هتل"
                  placeholder="مثلاً کیش یا هتلِ داریوش"
                  onSearch={() => toast.success(`هتل‌های ${cityName(trips.hotel.destination)}…`)}
                />
              </TabsContent>
              <TabsContent value="villa" forceMount>
                <StayForm id="villa" trip={trips.villa} cities={VILLA_PLACES} label="مقصد یا نوعِ اقامتگاه" placeholder="مثلاً رامسر یا کلبهٔ جنگلی" onSearch={() => toast.success(`اقامتگاه‌های ${cityName(trips.villa.destination)}…`)} />
              </TabsContent>
              <TabsContent value="tour" forceMount>
                <TourForm trip={trips.tour} />
              </TabsContent>
            </div>
          </Tabs>
        </div>

        {/* پیشنهادهای همان نوعِ سفر: یک لمس، فرم پر می‌شود. */}
        <section aria-labelledby="popular-title" className="flex flex-col gap-3">
          <h2 id="popular-title" className="font-bold">
            {isStay ? "مقصدهای پرطرفدار" : "مسیرهای پرطرفدار"}
          </h2>
          <ControlSizeProvider size="lg" mobileSize="default" asChild>
            <div className="flex flex-wrap gap-2">
              {POPULAR[service].map((route) => (
                <Button
                  key={`${route.from}-${route.to}`}
                  type="button"
                  variant="outline"
                  className="shrink-0"
                  onClick={() => {
                    if (route.from) trip.setOrigin(route.from)
                    trip.setDestination(route.to)
                  }}
                >
                  {route.from && (
                    <>
                      {cityName(route.from)}
                      <span aria-label="به" className="text-muted-foreground">
                        ←
                      </span>
                    </>
                  )}
                  {cityName(route.to)}
                </Button>
              ))}
            </div>
          </ControlSizeProvider>
        </section>
      </main>
    </ControlSizeProvider>
  )
}
travel-search.vue
<script setup lang="ts">
import { computed, reactive, ref } from "vue"

import Autocomplete from "@/components/ui/Autocomplete.vue"
import Button from "@/components/ui/Button.vue"
import ControlSize from "@/components/ui/ControlSize.vue"
import DatePicker from "@/components/ui/DatePicker.vue"
import DateRangePicker from "@/components/ui/DateRangePicker.vue"
import Label from "@/components/ui/Label.vue"
import NumberField from "@/components/ui/NumberField.vue"
import Popover from "@/components/ui/Popover.vue"
import PopoverClose from "@/components/ui/PopoverClose.vue"
import PopoverContent from "@/components/ui/PopoverContent.vue"
import PopoverTrigger from "@/components/ui/PopoverTrigger.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 Tabs from "@/components/ui/Tabs.vue"
import TabsContent from "@/components/ui/TabsContent.vue"
import TabsList from "@/components/ui/TabsList.vue"
import TabsTrigger from "@/components/ui/TabsTrigger.vue"
import { toast } from "@/components/ui/Toast.vue"
import ToggleGroup from "@/components/ui/ToggleGroup.vue"
import ToggleGroupItem from "@/components/ui/ToggleGroupItem.vue"
import { DigIcon } from "@/lib/icons"
import { toFaDigits } from "@/lib/persian"

const IMAGES = "https://docs.digdesign.ir/images"

type Option = { value: string; label: string }
type ServiceId = "flight" | "train" | "bus" | "hotel" | "villa" | "tour"
type DateRange = { from?: Date; to?: Date }

const SERVICES: { value: ServiceId; label: string; icon: string; image: string; title: string; subtitle: string }[] = [
  { value: "flight", label: "پرواز", icon: "plane", image: `${IMAGES}/travel-plane.webp`, title: "کجا پرواز کنیم؟", subtitle: "پروازهای داخلی و خارجی از ۲۰ ایرلاین، با قیمتِ نهایی." },
  { value: "train", label: "قطار", icon: "train", image: `${IMAGES}/travel-train.webp`, title: "سفر با قطار، راحت و به‌صرفه", subtitle: "همهٔ قطارهای رجا، فدک و سیر با انتخابِ کوپه." },
  { value: "bus", label: "اتوبوس", icon: "bus", image: `${IMAGES}/travel-bus.webp`, title: "بلیتِ اتوبوس از هر پایانه", subtitle: "بیش از ۸۰۰ مسیرِ بین‌شهری با صندلیِ انتخابی." },
  { value: "hotel", label: "هتل", icon: "hotel", image: `${IMAGES}/travel-hotel.webp`, title: "هتلی که دنبالش هستی", subtitle: "رزروِ قطعی با بهترین قیمت و لغوِ رایگان در بیشترِ هتل‌ها." },
  { value: "villa", label: "ویلا", icon: "home", image: `${IMAGES}/travel-villa.webp`, title: "ویلا و اقامتگاهِ بومی", subtitle: "از کلبهٔ جنگلی تا ویلای ساحلی، با عکس و نظرِ مهمان‌ها." },
  { value: "tour", label: "تور", icon: "suitcase", image: `${IMAGES}/travel-tour.webp`, title: "تورهای داخلی و خارجی", subtitle: "بلیت و اقامت در یک بسته، یا تورِ گردشگری با راهنما." },
]

const DOMESTIC: Option[] = [
  { value: "THR", label: "تهران" },
  { value: "MHD", label: "مشهد" },
  { value: "IFN", label: "اصفهان" },
  { value: "SYZ", label: "شیراز" },
  { value: "TBZ", label: "تبریز" },
  { value: "KIH", label: "کیش" },
  { value: "AWZ", label: "اهواز" },
  { value: "RAS", label: "رشت" },
]
const FOREIGN: Option[] = [
  { value: "IST", label: "استانبول" },
  { value: "DXB", label: "دبی" },
  { value: "NJF", label: "نجف" },
  { value: "TBS", label: "تفلیس" },
  { value: "EVN", label: "ایروان" },
  { value: "KUL", label: "کوالالامپور" },
]
const VILLA_PLACES: Option[] = [
  { value: "ramsar", label: "رامسر" },
  { value: "chalus", label: "چالوس" },
  { value: "kordan", label: "کردان" },
  { value: "masuleh", label: "ماسوله" },
  { value: "kashan", label: "کاشان، اقامتگاهِ سنتی" },
  { value: "qeshm", label: "قشم" },
]
const ALL_CITIES = [...DOMESTIC, ...FOREIGN, ...VILLA_PLACES]
const cityName = (code: string) => ALL_CITIES.find((city) => city.value === code)?.label ?? ""

/** پیشنهادهای زیرِ کارت برای هر نوعِ سفر؛ مسیر برای حمل‌ونقل، شهر برای اقامت. */
const POPULAR: Record<ServiceId, { from?: string; to: string }[]> = {
  flight: [{ from: "THR", to: "MHD" }, { from: "THR", to: "KIH" }, { from: "IFN", to: "MHD" }, { from: "THR", to: "IST" }],
  train: [{ from: "THR", to: "MHD" }, { from: "THR", to: "TBZ" }, { from: "THR", to: "IFN" }, { from: "MHD", to: "SYZ" }],
  bus: [{ from: "THR", to: "RAS" }, { from: "THR", to: "IFN" }, { from: "SYZ", to: "IFN" }, { from: "THR", to: "TBZ" }],
  hotel: [{ to: "KIH" }, { to: "MHD" }, { to: "IST" }, { to: "SYZ" }],
  villa: [{ to: "ramsar" }, { to: "kordan" }, { to: "masuleh" }, { to: "kashan" }],
  tour: [{ from: "THR", to: "IST" }, { from: "THR", to: "KIH" }, { from: "THR", to: "DXB" }, { from: "THR", to: "TBS" }],
}

const TRIP_TYPES: Option[] = [
  { value: "oneway", label: "یک‌طرفه" },
  { value: "round", label: "رفت و برگشت" },
]
const DOM_FOR: Option[] = [{ value: "domestic", label: "داخلی" }, { value: "foreign", label: "خارجی" }]

/** داده و رفتارِ مشترکِ هر فرم: مبدأ، مقصد، خطای مقصد، تاریخ. */
type Trip = { origin: string; destination: string; missing: boolean; date: Date | undefined; range: DateRange | undefined }
const makeTrip = (origin = ""): Trip => ({ origin, destination: "", missing: false, date: undefined, range: undefined })
const trips = reactive<Record<ServiceId, Trip>>({
  flight: makeTrip("THR"),
  train: makeTrip("THR"),
  bus: makeTrip("THR"),
  hotel: makeTrip(),
  villa: makeTrip(),
  tour: makeTrip("THR"),
})

/** گزینه‌ها و شمارندهٔ هر فرم؛ هر برگه وضعیتِ خودش را نگه می‌دارد تا رفت‌وبرگشت بینِ برگه‌ها چیزی را پاک نکند. */
const form = reactive<Record<ServiceId, Record<string, string | number>>>({
  flight: { scope: "domestic", tripType: "oneway", cabin: "economy", adults: 1, children: 0, infants: 0 },
  train: { tripType: "oneway", wagon: "compartment", group: "regular", adults: 1, children: 0, infants: 0 },
  bus: { seats: 1 },
  hotel: { scope: "domestic", adults: 2, children: 0, rooms: 1 },
  villa: { scope: "domestic", adults: 2, children: 0 },
  tour: { kind: "package", adults: 2, rooms: 1 },
})

const minDate = new Date()
const num = (id: ServiceId, key: string) => Number(form[id][key])
const str = (id: ServiceId, key: string) => String(form[id][key])

type OptionControl = { kind: "scope" | "select"; label: string; key: string; options: Option[]; show?: boolean }
type PeopleRow = { label: string; hint?: string; key: string; min: number; max: number }

/** خلاصهٔ مسافران برای متنِ دکمه: فقط بزرگسال «۲ بزرگسال»، گروهِ مختلط «۳ مسافر» تا در ستونِ باریکِ دسکتاپ بریده نشود. */
function passengerSummary(adults: number, others: number) {
  return others > 0 ? `${toFaDigits(adults + others)} مسافر` : `${toFaDigits(adults)} بزرگسال`
}

/** هر چیزی که بینِ شش فرم فرق دارد در یک جا: گزینه‌های بالا، شهرها، برچسب‌ها، تاریخ و مسافران. */
function view(id: ServiceId) {
  const f = form[id]
  const transport = id === "flight" || id === "train" || id === "bus" || id === "tour"
  const base = { transport, options: [] as OptionControl[], cities: DOMESTIC, originLabel: "مبدأ", destinationLabel: "مقصد", noun: "شهر", round: false, dateLabels: ["", ""] as [string, string], peopleLabel: "مسافران", summary: "", rows: [] as PeopleRow[], stayPlaceholder: "", stayLabel: "" }
  if (id === "flight") {
    const scope = str(id, "scope")
    return {
      ...base,
      options: [
        { kind: "scope", label: "نوعِ پرواز", key: "scope", options: DOM_FOR },
        { kind: "select", label: "نوعِ سفر", key: "tripType", options: TRIP_TYPES },
        { kind: "select", label: "کلاسِ پرواز", key: "cabin", show: scope === "foreign", options: [{ value: "economy", label: "اکونومی" }, { value: "business", label: "بیزینس" }, { value: "first", label: "فرست" }] },
      ] as OptionControl[],
      cities: scope === "domestic" ? DOMESTIC : [...DOMESTIC.slice(0, 4), ...FOREIGN],
      noun: scope === "domestic" ? "شهر" : "شهر یا فرودگاه",
      round: str(id, "tripType") === "round",
      dateLabels: ["تاریخِ رفت", "تاریخِ رفت و برگشت"] as [string, string],
      summary: passengerSummary(num(id, "adults"), num(id, "children") + num(id, "infants")),
      rows: [
        { label: "بزرگسال", hint: "۱۲ سال به بالا", key: "adults", min: 1, max: 9 },
        { label: "کودک", hint: "۲ تا ۱۲ سال", key: "children", min: 0, max: 8 },
        { label: "نوزاد", hint: "زیرِ ۲ سال، یکی برای هر بزرگسال", key: "infants", min: 0, max: num(id, "adults") },
      ] as PeopleRow[],
    }
  }
  if (id === "train") {
    return {
      ...base,
      options: [
        { kind: "select", label: "نوعِ سفر", key: "tripType", options: TRIP_TYPES },
        { kind: "select", label: "نوعِ واگن", key: "wagon", options: [{ value: "compartment", label: "کوپهٔ عادی" }, { value: "private", label: "کوپهٔ دربست" }, { value: "salon", label: "سالنی" }] },
        { kind: "select", label: "نوعِ مسافر", key: "group", options: [{ value: "regular", label: "مسافرانِ عادی" }, { value: "women", label: "ویژهٔ بانوان" }, { value: "men", label: "ویژهٔ آقایان" }] },
      ] as OptionControl[],
      cities: DOMESTIC.filter((city) => city.value !== "KIH"),
      originLabel: "ایستگاهِ مبدأ",
      destinationLabel: "ایستگاهِ مقصد",
      round: str(id, "tripType") === "round",
      dateLabels: ["تاریخِ حرکت", "تاریخِ رفت و برگشت"] as [string, string],
      summary: passengerSummary(num(id, "adults"), num(id, "children") + num(id, "infants")),
      rows: [
        { label: "بزرگسال", hint: "۱۲ سال به بالا", key: "adults", min: 1, max: str(id, "wagon") === "private" ? 4 : 9 },
        { label: "کودک", hint: "۲ تا ۱۲ سال، نیم‌بها", key: "children", min: 0, max: 6 },
        { label: "نوزاد", hint: "زیرِ ۲ سال، بدونِ صندلی", key: "infants", min: 0, max: num(id, "adults") },
      ] as PeopleRow[],
    }
  }
  if (id === "bus") {
    return {
      ...base,
      cities: DOMESTIC.filter((city) => city.value !== "KIH"),
      noun: "شهر یا پایانه",
      dateLabels: ["تاریخِ حرکت", ""] as [string, string],
      peopleLabel: "صندلی",
      summary: `${toFaDigits(num(id, "seats"))} صندلی`,
      rows: [{ label: "تعدادِ صندلی", key: "seats", min: 1, max: 6 }] as PeopleRow[],
    }
  }
  if (id === "tour") {
    const pkg = str(id, "kind") === "package"
    return {
      ...base,
      options: [{ kind: "scope", label: "نوعِ تور", key: "kind", options: [{ value: "package", label: "بلیت + اقامت" }, { value: "sightseeing", label: "تورِ گردشگری" }] }] as OptionControl[],
      cities: [...DOMESTIC, ...FOREIGN],
      noun: pkg ? "شهر" : "شهر یا کشور",
      round: pkg,
      dateLabels: (pkg ? ["", "تاریخِ رفت و برگشت"] : ["از تاریخ", ""]) as [string, string],
      peopleLabel: "مسافران و اتاق",
      summary: `${toFaDigits(num(id, "adults"))} مسافر، ${toFaDigits(num(id, "rooms"))} اتاق`,
      rows: [
        { label: "مسافر", key: "adults", min: 1, max: 12 },
        { label: "اتاق", key: "rooms", min: 1, max: num(id, "adults") },
      ] as PeopleRow[],
    }
  }
  // hotel / villa
  const hotel = id === "hotel"
  const guests = num(id, "adults") + num(id, "children")
  return {
    ...base,
    options: (hotel ? [{ kind: "scope", label: "داخلی یا خارجی", key: "scope", options: DOM_FOR }] : []) as OptionControl[],
    cities: hotel ? (str(id, "scope") === "foreign" ? FOREIGN : DOMESTIC) : VILLA_PLACES,
    round: true,
    dateLabels: ["", "تاریخِ ورود و خروج"] as [string, string],
    stayLabel: hotel ? "شهر یا هتل" : "مقصد یا نوعِ اقامتگاه",
    stayPlaceholder: hotel ? "مثلاً کیش یا هتلِ داریوش" : "مثلاً رامسر یا کلبهٔ جنگلی",
    peopleLabel: hotel ? "مسافران و اتاق" : "تعدادِ مهمان",
    summary: hotel ? `${toFaDigits(guests)} مسافر، ${toFaDigits(num(id, "rooms"))} اتاق` : `${toFaDigits(guests)} مهمان`,
    rows: [
      { label: "بزرگسال", hint: "۱۲ سال به بالا", key: "adults", min: 1, max: 12 },
      { label: "کودک", hint: "زیرِ ۱۲ سال", key: "children", min: 0, max: 6 },
      ...(hotel ? [{ label: "اتاق", key: "rooms", min: 1, max: Math.max(1, num(id, "adults")) }] : []),
    ] as PeopleRow[],
  }
}

const SEARCH_TOAST: Record<ServiceId, (t: Trip) => string> = {
  flight: (t) => `پروازهای ${cityName(t.origin)} به ${cityName(t.destination)}…`,
  train: (t) => `قطارهای ${cityName(t.origin)} به ${cityName(t.destination)}…`,
  bus: (t) => `اتوبوس‌های ${cityName(t.origin)} به ${cityName(t.destination)}…`,
  hotel: (t) => `هتل‌های ${cityName(t.destination)}…`,
  villa: (t) => `اقامتگاه‌های ${cityName(t.destination)}…`,
  tour: (t) => `تورهای ${cityName(t.destination)}…`,
}

function setDestination(id: ServiceId, value: string) {
  trips[id].destination = value
  trips[id].missing = false
}
function swap(id: ServiceId) {
  const trip = trips[id]
  const origin = trip.origin
  trip.origin = trip.destination
  setDestination(id, origin)
}
function onOption(id: ServiceId, control: OptionControl, value: string | string[] | undefined) {
  if (!value) return
  form[id][control.key] = value as string
  // عوضِ شدنِ داخلی/خارجی در هتل مقصدِ قبلی را بی‌اعتبار می‌کند.
  if (id === "hotel" && control.key === "scope") setDestination(id, "")
}
function onSubmit(id: ServiceId) {
  const trip = trips[id]
  if (!trip.destination) {
    trip.missing = true
    document.getElementById(`${id}-destination`)?.focus()
    return
  }
  toast.success(SEARCH_TOAST[id](trip))
}
function pick(route: { from?: string; to: string }) {
  const trip = trips[service.value]
  if (route.from) trip.origin = route.from
  setDestination(service.value, route.to)
}

/**
 * جست‌وجوی سفر: شش نوعِ سفر (پرواز، قطار، اتوبوس، هتل، ویلا، تور) در برگه‌های خطیِ آیکون‌دار بالای کارت.
 * بنر با هر برگه عکس و تیترِ خودش را می‌گیرد و فرم فقط فیلدهایی را دارد که آن سفر لازم دارد: پرواز داخلی
 * یا خارجی با کلاسِ پرواز، قطار با نوعِ واگن و مسافر، اتوبوس با صندلی، هتل با اتاق، تور با «بلیت + اقامت»
 * یا گردشگری. هر برگه وضعیتِ خودش را نگه می‌دارد تا رفت‌وبرگشت بینِ برگه‌ها چیزی را پاک نکند. پیشنهادهای
 * زیرِ کارت هم با برگه عوض می‌شوند و با یک لمس فرم را پر می‌کنند.
 */
const service = ref<ServiceId>("flight")
const current = computed(() => SERVICES.find((item) => item.value === service.value) ?? SERVICES[0])
const isStay = computed(() => service.value === "hotel" || service.value === "villa")
</script>

<template>
  <ControlSize size="xl" as-child>
    <main class="mx-auto flex w-full max-w-5xl flex-col gap-8 p-4 sm:p-6">
      <div class="flex flex-col">
        <!-- بنر: عکسِ همان نوعِ سفر؛ گرادیانِ تیره از سمتِ متن (در موبایل از بالا) تا تیتر روی هر عکسی خوانا بماند. -->
        <header class="relative isolate overflow-hidden rounded-xl bg-inverse px-5 pt-6 pb-24 text-[var(--dig-white)] sm:px-10 sm:pt-10 sm:pb-28">
          <img :key="current.image" :src="current.image" alt="" aria-hidden="true" class="absolute inset-0 -z-20 size-full animate-in object-cover duration-500 fade-in" />
          <span aria-hidden="true" class="pointer-events-none absolute inset-0 -z-10 bg-[linear-gradient(to_bottom,var(--inverse)_15%,color-mix(in_oklab,var(--inverse)_60%,transparent))] sm:bg-[linear-gradient(to_left,var(--inverse)_5%,color-mix(in_oklab,var(--inverse)_70%,transparent)_45%,color-mix(in_oklab,var(--inverse)_10%,transparent))]" />
          <div class="flex max-w-md flex-col gap-2" aria-live="polite">
            <h1 class="text-2xl leading-snug font-black sm:text-4xl">{{ current.title }}</h1>
            <p class="text-sm text-[var(--dig-slate-200)] sm:text-base">{{ current.subtitle }}</p>
          </div>
        </header>

        <!-- کارتِ جست‌وجو روی لبهٔ بنر؛ برگه‌ها لبه‌به‌لبهٔ کارت، فرم با فاصله. -->
        <Tabs variant="line" :value="service" class="relative mx-3 -mt-14 gap-0 rounded-xl border border-border bg-card shadow-card sm:mx-6" @update:value="(value) => (service = value as ServiceId)">
          <TabsList aria-label="نوعِ سفر" class="px-1 sm:px-4">
            <TabsTrigger v-for="item in SERVICES" :key="item.value" :value="item.value" class="px-1 text-xs sm:px-4 sm:text-sm">
              <DigIcon :name="item.icon" class="size-5 sm:size-6" />
              {{ item.label }}
            </TabsTrigger>
          </TabsList>
          <div class="p-4 sm:p-6">
            <TabsContent v-for="svc in SERVICES" :key="svc.value" :value="svc.value" force-mount>
              <form novalidate class="flex flex-col gap-5" @submit.prevent="onSubmit(svc.value)">
                <!-- ردیفِ گزینه‌ها: سگمنتِ داخلی/خارجی و Selectهای کوچک، ۴۰ در دسکتاپ و ۳۶ در گوشی. -->
                <ControlSize v-if="view(svc.value).options.some((c) => c.show !== false)" size="lg" mobile-size="default" as-child>
                  <div class="flex flex-wrap items-center gap-2">
                    <template v-for="control in view(svc.value).options" :key="control.key">
                      <template v-if="control.show !== false">
                        <ToggleGroup v-if="control.kind === 'scope'" type="single" variant="segmented" :value="str(svc.value, control.key)" :aria-label="control.label" @update:value="(value) => onOption(svc.value, control, value)">
                          <ToggleGroupItem v-for="option in control.options" :key="option.value" :value="option.value">{{ option.label }}</ToggleGroupItem>
                        </ToggleGroup>
                        <Select v-else :value="str(svc.value, control.key)" @update:value="(value) => onOption(svc.value, control, value)">
                          <SelectTrigger :aria-label="control.label" class="w-auto min-w-28 gap-2 rounded-full">
                            <SelectValue />
                          </SelectTrigger>
                          <ControlSize size="xl" as-child>
                            <SelectContent>
                              <SelectItem v-for="option in control.options" :key="option.value" :value="option.value">{{ option.label }}</SelectItem>
                            </SelectContent>
                          </ControlSize>
                        </Select>
                      </template>
                    </template>
                  </div>
                </ControlSize>

                <div class="grid grid-cols-1 gap-4 lg:grid-cols-[minmax(0,1.7fr)_minmax(0,1fr)_minmax(0,0.85fr)_auto] lg:items-start">
                  <!-- مبدأ و مقصد با دکمهٔ جابه‌جایی؛ در دسکتاپ دکمه میانِ دو فیلد، در موبایل کنارِ برچسبِ مقصد. -->
                  <div v-if="view(svc.value).transport" class="grid grid-cols-1 gap-4 sm:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] sm:items-start sm:gap-2">
                    <div class="flex flex-col gap-2">
                      <Label :for="`${svc.value}-origin`">{{ view(svc.value).originLabel }}</Label>
                      <Autocomplete
                        :id="`${svc.value}-origin`"
                        :items="view(svc.value).cities.filter((city) => city.value !== trips[svc.value].destination)"
                        :value="trips[svc.value].origin"
                        :placeholder="`${view(svc.value).noun}ِ مبدأ`"
                        empty-text="پیدا نشد"
                        class="w-full"
                        @update:value="(value) => (trips[svc.value].origin = value)"
                      />
                    </div>
                    <Button type="button" variant="ghost" size="icon" aria-label="جابه‌جاییِ مبدأ و مقصد" :disabled="!trips[svc.value].origin || !trips[svc.value].destination" class="hidden rounded-full sm:mt-7 sm:flex" @click="swap(svc.value)">
                      <DigIcon name="swap" />
                    </Button>
                    <div class="flex flex-col gap-2">
                      <div class="flex h-5 items-center justify-between gap-2">
                        <Label :for="`${svc.value}-destination`">{{ view(svc.value).destinationLabel }}</Label>
                        <ControlSize size="lg" as-child>
                          <Button type="button" variant="ghost" aria-label="جابه‌جاییِ مبدأ و مقصد" :disabled="!trips[svc.value].origin || !trips[svc.value].destination" class="-me-2 gap-1.5 px-2 sm:hidden" @click="swap(svc.value)">
                            <DigIcon name="swap" class="rotate-90" />
                            جابه‌جایی
                          </Button>
                        </ControlSize>
                      </div>
                      <Autocomplete
                        :id="`${svc.value}-destination`"
                        :items="view(svc.value).cities.filter((city) => city.value !== trips[svc.value].origin)"
                        :value="trips[svc.value].destination"
                        :placeholder="`${view(svc.value).noun}ِ مقصد`"
                        empty-text="پیدا نشد"
                        :aria-invalid="trips[svc.value].missing || undefined"
                        :aria-describedby="trips[svc.value].missing ? `${svc.value}-destination-error` : undefined"
                        class="w-full"
                        @update:value="(value) => setDestination(svc.value, value)"
                      />
                      <p v-if="trips[svc.value].missing" :id="`${svc.value}-destination-error`" class="text-sm text-destructive">مقصد را انتخاب کن.</p>
                    </div>
                  </div>
                  <!-- هتل و ویلا: فقط مقصد. -->
                  <div v-else class="flex flex-col gap-2">
                    <Label :for="`${svc.value}-destination`">{{ view(svc.value).stayLabel }}</Label>
                    <Autocomplete
                      :id="`${svc.value}-destination`"
                      :items="view(svc.value).cities"
                      :value="trips[svc.value].destination"
                      :placeholder="view(svc.value).stayPlaceholder"
                      empty-text="پیدا نشد"
                      :aria-invalid="trips[svc.value].missing || undefined"
                      :aria-describedby="trips[svc.value].missing ? `${svc.value}-destination-error` : undefined"
                      class="w-full"
                      @update:value="(value) => setDestination(svc.value, value)"
                    />
                    <p v-if="trips[svc.value].missing" :id="`${svc.value}-destination-error`" class="text-sm text-destructive">مقصد را انتخاب کن.</p>
                  </div>

                  <div v-if="view(svc.value).round" class="flex flex-col gap-2">
                    <Label :id="`${svc.value}-range`">{{ view(svc.value).dateLabels[1] }}</Label>
                    <DateRangePicker calendar="jalali" :value="trips[svc.value].range" :aria-label="view(svc.value).dateLabels[1]" placeholder="انتخابِ دو تاریخ" class="w-full" @update:value="(value) => (trips[svc.value].range = value)" />
                  </div>
                  <DatePicker v-else :id="`${svc.value}-date`" :label="view(svc.value).dateLabels[0]" calendar="jalali" :value="trips[svc.value].date" :min-date="minDate" class="w-full" @update:value="(value) => (trips[svc.value].date = value)" />

                  <!-- شمارندهٔ مسافر و اتاق در پاپ‌اوور؛ متنِ دکمه خلاصهٔ انتخاب است و با هر تغییر به‌روز می‌شود. -->
                  <div class="flex flex-col gap-2">
                    <Label :id="`${svc.value}-people`">{{ view(svc.value).peopleLabel }}</Label>
                    <Popover>
                      <PopoverTrigger as-child>
                        <Button :id="`${svc.value}-people-trigger`" variant="outline" :aria-labelledby="`${svc.value}-people ${svc.value}-people-trigger`" class="justify-between font-normal">
                          <span class="truncate">{{ view(svc.value).summary }}</span>
                          <DigIcon name="chevron-down" class="text-muted-foreground" />
                        </Button>
                      </PopoverTrigger>
                      <ControlSize size="xl" as-child>
                        <PopoverContent align="end" :aria-label="view(svc.value).peopleLabel" class="flex w-80 max-w-[calc(100vw-2rem)] flex-col gap-4">
                          <div v-for="(row, index) in view(svc.value).rows" :key="row.label" class="flex items-center justify-between gap-3">
                            <div class="flex min-w-0 flex-col gap-0.5">
                              <Label :id="`${svc.value}-row-${index}`">{{ row.label }}</Label>
                              <span v-if="row.hint" class="text-xs text-muted-foreground">{{ row.hint }}</span>
                            </div>
                            <NumberField :aria-labelledby="`${svc.value}-row-${index}`" :value="num(svc.value, row.key)" :min="row.min" :max="row.max" class="w-32 shrink-0" @update:value="(value) => (form[svc.value][row.key] = value)" />
                          </div>
                          <PopoverClose as-child>
                            <Button class="mt-2">تأیید</Button>
                          </PopoverClose>
                        </PopoverContent>
                      </ControlSize>
                    </Popover>
                  </div>

                  <Button type="submit" class="lg:mt-7 lg:min-w-32">جست‌وجو</Button>
                </div>
              </form>
            </TabsContent>
          </div>
        </Tabs>
      </div>

      <!-- پیشنهادهای همان نوعِ سفر: یک لمس، فرم پر می‌شود. -->
      <section aria-labelledby="popular-title" class="flex flex-col gap-3">
        <h2 id="popular-title" class="font-bold">{{ isStay ? "مقصدهای پرطرفدار" : "مسیرهای پرطرفدار" }}</h2>
        <ControlSize size="lg" mobile-size="default" as-child>
          <div class="flex flex-wrap gap-2">
            <Button v-for="route in POPULAR[service]" :key="`${route.from}-${route.to}`" type="button" variant="outline" class="shrink-0" @click="pick(route)">
              <template v-if="route.from">
                {{ cityName(route.from) }}
                <span aria-label="به" class="text-muted-foreground">←</span>
              </template>
              {{ cityName(route.to) }}
            </Button>
          </div>
        </ControlSize>
      </section>
    </main>
  </ControlSize>
</template>

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

این موارد هنوز برای Svelte آماده نیستند: autocompletecontrol-sizedate-pickerdate-range-pickerlabelnumber-fieldpersianpopoverselecttabstoasttoggle-groupآیکون busآیکون chevron-downآیکون homeآیکون hotelآیکون planeآیکون suitcaseآیکون swapآیکون train

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

travel-search.ts
import { Component, ChangeDetectionStrategy, signal, computed } from "@angular/core"

import { DigControlSize } from "@/components/ui/control-size"
import { DigTabs, DigTabsList, DigTabsTrigger, DigTabsContent } from "@/components/ui/tabs"
import { DigIcon, type DigIconName } from "@/lib/icons"
import { DigToggleGroup, DigToggleGroupItem } from "@/components/ui/toggle-group"
import { DigSelect, DigSelectTrigger, DigSelectValue, DigSelectContent, DigSelectItem } from "@/components/ui/select"
import { DigLabel } from "@/components/ui/label"
import { DigAutocomplete } from "@/components/ui/autocomplete"
import { DigButton } from "@/components/ui/button"
import { DigDateRangePicker } from "@/components/ui/date-range-picker"
import { DigDatePicker } from "@/components/ui/date-picker"
import { DigPopover, DigPopoverTrigger, DigPopoverContent, DigPopoverClose } from "@/components/ui/popover"
import { DigNumberField } from "@/components/ui/number-field"
import { toast } from "@/components/ui/toast"
import { toFaDigits } from "@/lib/persian"

const IMAGES = "https://docs.digdesign.ir/images"

type Option = { value: string; label: string }

type ServiceId = "flight" | "train" | "bus" | "hotel" | "villa" | "tour"

type DateRange = { from?: Date; to?: Date }

const SERVICES: {
  value: ServiceId
  label: string
  icon: DigIconName
  image: string
  title: string
  subtitle: string
}[] = [
  {
    value: "flight",
    label: "پرواز",
    icon: "plane" as const,
    image: `${IMAGES}/travel-plane.webp`,
    title: "کجا پرواز کنیم؟",
    subtitle: "پروازهای داخلی و خارجی از ۲۰ ایرلاین، با قیمتِ نهایی.",
  },
  {
    value: "train",
    label: "قطار",
    icon: "train" as const,
    image: `${IMAGES}/travel-train.webp`,
    title: "سفر با قطار، راحت و به‌صرفه",
    subtitle: "همهٔ قطارهای رجا، فدک و سیر با انتخابِ کوپه.",
  },
  {
    value: "bus",
    label: "اتوبوس",
    icon: "bus" as const,
    image: `${IMAGES}/travel-bus.webp`,
    title: "بلیتِ اتوبوس از هر پایانه",
    subtitle: "بیش از ۸۰۰ مسیرِ بین‌شهری با صندلیِ انتخابی.",
  },
  {
    value: "hotel",
    label: "هتل",
    icon: "hotel" as const,
    image: `${IMAGES}/travel-hotel.webp`,
    title: "هتلی که دنبالش هستی",
    subtitle: "رزروِ قطعی با بهترین قیمت و لغوِ رایگان در بیشترِ هتل‌ها.",
  },
  {
    value: "villa",
    label: "ویلا",
    icon: "home" as const,
    image: `${IMAGES}/travel-villa.webp`,
    title: "ویلا و اقامتگاهِ بومی",
    subtitle: "از کلبهٔ جنگلی تا ویلای ساحلی، با عکس و نظرِ مهمان‌ها.",
  },
  {
    value: "tour",
    label: "تور",
    icon: "suitcase" as const,
    image: `${IMAGES}/travel-tour.webp`,
    title: "تورهای داخلی و خارجی",
    subtitle: "بلیت و اقامت در یک بسته، یا تورِ گردشگری با راهنما.",
  },
]

const DOMESTIC: Option[] = [
  { value: "THR", label: "تهران" },
  { value: "MHD", label: "مشهد" },
  { value: "IFN", label: "اصفهان" },
  { value: "SYZ", label: "شیراز" },
  { value: "TBZ", label: "تبریز" },
  { value: "KIH", label: "کیش" },
  { value: "AWZ", label: "اهواز" },
  { value: "RAS", label: "رشت" },
]

const FOREIGN: Option[] = [
  { value: "IST", label: "استانبول" },
  { value: "DXB", label: "دبی" },
  { value: "NJF", label: "نجف" },
  { value: "TBS", label: "تفلیس" },
  { value: "EVN", label: "ایروان" },
  { value: "KUL", label: "کوالالامپور" },
]

const VILLA_PLACES: Option[] = [
  { value: "ramsar", label: "رامسر" },
  { value: "chalus", label: "چالوس" },
  { value: "kordan", label: "کردان" },
  { value: "masuleh", label: "ماسوله" },
  { value: "kashan", label: "کاشان، اقامتگاهِ سنتی" },
  { value: "qeshm", label: "قشم" },
]

const ALL_CITIES = [...DOMESTIC, ...FOREIGN, ...VILLA_PLACES]

const cityName = (code: string) => ALL_CITIES.find((city) => city.value === code)?.label ?? ""

const POPULAR: Record<ServiceId, { from?: string; to: string }[]> = {
  flight: [
    { from: "THR", to: "MHD" },
    { from: "THR", to: "KIH" },
    { from: "IFN", to: "MHD" },
    { from: "THR", to: "IST" },
  ],
  train: [
    { from: "THR", to: "MHD" },
    { from: "THR", to: "TBZ" },
    { from: "THR", to: "IFN" },
    { from: "MHD", to: "SYZ" },
  ],
  bus: [
    { from: "THR", to: "RAS" },
    { from: "THR", to: "IFN" },
    { from: "SYZ", to: "IFN" },
    { from: "THR", to: "TBZ" },
  ],
  hotel: [{ to: "KIH" }, { to: "MHD" }, { to: "IST" }, { to: "SYZ" }],
  villa: [{ to: "ramsar" }, { to: "kordan" }, { to: "masuleh" }, { to: "kashan" }],
  tour: [
    { from: "THR", to: "IST" },
    { from: "THR", to: "KIH" },
    { from: "THR", to: "DXB" },
    { from: "THR", to: "TBS" },
  ],
}

const TRIP_TYPES: Option[] = [
  { value: "oneway", label: "یک‌طرفه" },
  { value: "round", label: "رفت و برگشت" },
]

const DOM_FOR: Option[] = [
  { value: "domestic", label: "داخلی" },
  { value: "foreign", label: "خارجی" },
]

type Trip = {
  origin: string
  destination: string
  missing: boolean
  date: Date | undefined
  range: DateRange | undefined
}

const makeTrip = (origin = ""): Trip => ({ origin, destination: "", missing: false, date: undefined, range: undefined })

const minDate = new Date()

type OptionControl = { kind: "scope" | "select"; label: string; key: string; options: Option[]; show?: boolean }

type PeopleRow = { label: string; hint?: string; key: string; min: number; max: number }

function passengerSummary(adults: number, others: number) {
  return others > 0 ? `${toFaDigits(adults + others)} مسافر` : `${toFaDigits(adults)} بزرگسال`
}

const SEARCH_TOAST: Record<ServiceId, (t: Trip) => string> = {
  flight: (t) => `پروازهای ${cityName(t.origin)} به ${cityName(t.destination)}…`,
  train: (t) => `قطارهای ${cityName(t.origin)} به ${cityName(t.destination)}…`,
  bus: (t) => `اتوبوس‌های ${cityName(t.origin)} به ${cityName(t.destination)}…`,
  hotel: (t) => `هتل‌های ${cityName(t.destination)}…`,
  villa: (t) => `اقامتگاه‌های ${cityName(t.destination)}…`,
  tour: (t) => `تورهای ${cityName(t.destination)}…`,
}

@Component({
  selector: "dig-block-travel-search",
  imports: [
    DigControlSize,
    DigTabs,
    DigTabsList,
    DigTabsTrigger,
    DigTabsContent,
    DigIcon,
    DigToggleGroup,
    DigToggleGroupItem,
    DigSelect,
    DigSelectTrigger,
    DigSelectValue,
    DigSelectContent,
    DigSelectItem,
    DigLabel,
    DigAutocomplete,
    DigButton,
    DigDateRangePicker,
    DigDatePicker,
    DigPopover,
    DigPopoverTrigger,
    DigPopoverContent,
    DigPopoverClose,
    DigNumberField,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <main digControlSize="xl" class="mx-auto flex w-full max-w-5xl flex-col gap-8 p-4 sm:p-6">
      <div class="flex flex-col">
        <!-- بنر: عکسِ همان نوعِ سفر؛ گرادیانِ تیره از سمتِ متن (در موبایل از بالا) تا تیتر روی هر عکسی خوانا بماند. -->
        <header
          class="relative isolate overflow-hidden rounded-xl bg-inverse px-5 pt-6 pb-24 text-[var(--dig-white)] sm:px-10 sm:pt-10 sm:pb-28"
        >
          <img
            [src]="current().image"
            alt=""
            aria-hidden="true"
            class="absolute inset-0 -z-20 size-full animate-in object-cover duration-500 fade-in"
          />
          <span
            aria-hidden="true"
            class="pointer-events-none absolute inset-0 -z-10 bg-[linear-gradient(to_bottom,var(--inverse)_15%,color-mix(in_oklab,var(--inverse)_60%,transparent))] sm:bg-[linear-gradient(to_left,var(--inverse)_5%,color-mix(in_oklab,var(--inverse)_70%,transparent)_45%,color-mix(in_oklab,var(--inverse)_10%,transparent))]"
          ></span>
          <div class="flex max-w-md flex-col gap-2" aria-live="polite">
            <h1 class="text-2xl leading-snug font-black sm:text-4xl">{{ current().title }}</h1>
            <p class="text-sm text-[var(--dig-slate-200)] sm:text-base">{{ current().subtitle }}</p>
          </div>
        </header>

        <!-- کارتِ جست‌وجو روی لبهٔ بنر؛ برگه‌ها لبه‌به‌لبهٔ کارت، فرم با فاصله. -->
        <div
          digTabs
          variant="line"
          [value]="service()"
          class="relative mx-3 -mt-14 gap-0 rounded-xl border border-border bg-card shadow-card sm:mx-6"
          (valueChange)="setService($event)"
        >
          <div digTabsList aria-label="نوعِ سفر" class="px-1 sm:px-4">
            @for (item of SERVICES; track item.value) {
              <button digTabsTrigger [value]="item.value" class="px-1 text-xs sm:px-4 sm:text-sm">
                <svg [digIcon]="item.icon" class="size-5 sm:size-6"></svg> {{ item.label }}
              </button>
            }
          </div>
          <div class="p-4 sm:p-6">
            @for (svc of SERVICES; track svc.value) {
              <div digTabsContent [value]="svc.value" forceMount>
                <form novalidate class="flex flex-col gap-5" (submit)="$event.preventDefault(); onSubmit(svc.value)">
                  <!-- ردیفِ گزینه‌ها: سگمنتِ داخلی/خارجی و Selectهای کوچک، ۴۰ در دسکتاپ و ۳۶ در گوشی. -->
                  @if (view(svc.value).options.some((c) => c.show !== false)) {
                    <div digControlSize="lg" mobileSize="default" class="flex flex-wrap items-center gap-2">
                      @for (control of view(svc.value).options; track control.key) {
                        @if (control.show !== false) {
                          @if (control.kind === "scope") {
                            <div
                              digToggleGroup
                              type="single"
                              variant="segmented"
                              [value]="str(svc.value, control.key)"
                              [attr.aria-label]="control.label"
                              (valueChange)="onOption(svc.value, control, $event)"
                            >
                              @for (option of control.options; track option.value) {
                                <button digToggleGroupItem [value]="option.value">{{ option.label }}</button>
                              }
                            </div>
                          } @else {
                            <ng-container
                              digSelect
                              [value]="str(svc.value, control.key)"
                              (valueChange)="onOption(svc.value, control, $event)"
                              ><button
                                digSelectTrigger
                                [attr.aria-label]="control.label"
                                class="w-auto min-w-28 gap-2 rounded-full"
                              >
                                <span digSelectValue></span>
                              </button>
                              <div digControlSize="xl" digSelectContent>
                                @for (option of control.options; track option.value) {
                                  <div digSelectItem [value]="option.value">{{ option.label }}</div>
                                }
                              </div></ng-container
                            >
                          }
                        }
                      }
                    </div>
                  }

                  <div
                    class="grid grid-cols-1 gap-4 lg:grid-cols-[minmax(0,1.7fr)_minmax(0,1fr)_minmax(0,0.85fr)_auto] lg:items-start"
                  >
                    <!-- مبدأ و مقصد با دکمهٔ جابه‌جایی؛ در دسکتاپ دکمه میانِ دو فیلد، در موبایل کنارِ برچسبِ مقصد. -->
                    @if (view(svc.value).transport) {
                      <div
                        class="grid grid-cols-1 gap-4 sm:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] sm:items-start sm:gap-2"
                      >
                        <div class="flex flex-col gap-2">
                          <label digLabel [htmlFor]="\`\${svc.value}-origin\`">{{ view(svc.value).originLabel }}</label>
                          <div
                            digAutocomplete
                            [id]="\`\${svc.value}-origin\`"
                            [items]="
                              view(svc.value).cities.filter((city) => city.value !== trips()[svc.value].destination)
                            "
                            [value]="trips()[svc.value].origin"
                            [placeholder]="\`\${view(svc.value).noun}ِ مبدأ\`"
                            emptyText="پیدا نشد"
                            class="w-full"
                            (valueChange)="updateTrip(svc.value, { origin: $event ?? '' })"
                          ></div>
                        </div>
                        <button
                          digButton
                          type="button"
                          variant="ghost"
                          size="icon"
                          aria-label="جابه‌جاییِ مبدأ و مقصد"
                          [disabled]="!trips()[svc.value].origin || !trips()[svc.value].destination"
                          class="hidden rounded-full sm:mt-7 sm:flex"
                          (click)="swap(svc.value)"
                        >
                          <svg digIcon="swap"></svg>
                        </button>
                        <div class="flex flex-col gap-2">
                          <div class="flex h-5 items-center justify-between gap-2">
                            <label digLabel [htmlFor]="\`\${svc.value}-destination\`">{{
                              view(svc.value).destinationLabel
                            }}</label>
                            <button
                              digControlSize="lg"
                              digButton
                              type="button"
                              variant="ghost"
                              aria-label="جابه‌جاییِ مبدأ و مقصد"
                              [disabled]="!trips()[svc.value].origin || !trips()[svc.value].destination"
                              class="-me-2 gap-1.5 px-2 sm:hidden"
                              (click)="swap(svc.value)"
                            >
                              <svg digIcon="swap" class="rotate-90"></svg>
                              جابه‌جایی
                            </button>
                          </div>
                          <div
                            digAutocomplete
                            [id]="\`\${svc.value}-destination\`"
                            [items]="view(svc.value).cities.filter((city) => city.value !== trips()[svc.value].origin)"
                            [value]="trips()[svc.value].destination"
                            [placeholder]="\`\${view(svc.value).noun}ِ مقصد\`"
                            emptyText="پیدا نشد"
                            [attr.aria-invalid]="trips()[svc.value].missing || undefined"
                            [attr.aria-describedby]="
                              trips()[svc.value].missing ? \`\${svc.value}-destination-error\` : undefined
                            "
                            class="w-full"
                            (valueChange)="setDestination(svc.value, $event)"
                          ></div>
                          @if (trips()[svc.value].missing) {
                            <p [id]="\`\${svc.value}-destination-error\`" class="text-sm text-destructive">
                              مقصد را انتخاب کن.
                            </p>
                          }
                        </div>
                      </div>

                    } @else {
                      <div class="flex flex-col gap-2">
                        <label digLabel [htmlFor]="\`\${svc.value}-destination\`">{{
                          view(svc.value).stayLabel
                        }}</label>
                        <div
                          digAutocomplete
                          [id]="\`\${svc.value}-destination\`"
                          [items]="view(svc.value).cities"
                          [value]="trips()[svc.value].destination"
                          [placeholder]="view(svc.value).stayPlaceholder"
                          emptyText="پیدا نشد"
                          [attr.aria-invalid]="trips()[svc.value].missing || undefined"
                          [attr.aria-describedby]="
                            trips()[svc.value].missing ? \`\${svc.value}-destination-error\` : undefined
                          "
                          class="w-full"
                          (valueChange)="setDestination(svc.value, $event)"
                        ></div>
                        @if (trips()[svc.value].missing) {
                          <p [id]="\`\${svc.value}-destination-error\`" class="text-sm text-destructive">
                            مقصد را انتخاب کن.
                          </p>
                        }
                      </div>
                    }

                    @if (view(svc.value).round) {
                      <div class="flex flex-col gap-2">
                        <label digLabel [id]="\`\${svc.value}-range\`">{{ view(svc.value).dateLabels[1] }}</label>
                        <button
                          digDateRangePicker
                          calendar="jalali"
                          [value]="trips()[svc.value].range"
                          [aria-label]="view(svc.value).dateLabels[1]"
                          placeholder="انتخابِ دو تاریخ"
                          class="w-full"
                          (valueChange)="updateTrip(svc.value, { range: $event })"
                        ></button>
                      </div>
                    } @else {
                      <button
                        digDatePicker
                        [id]="\`\${svc.value}-date\`"
                        [label]="view(svc.value).dateLabels[0]"
                        calendar="jalali"
                        [value]="trips()[svc.value].date"
                        [minDate]="minDate"
                        class="w-full"
                        (valueChange)="updateTrip(svc.value, { date: $event })"
                      ></button>
                    }

                    <div class="flex flex-col gap-2">
                      <label digLabel [id]="\`\${svc.value}-people\`">{{ view(svc.value).peopleLabel }}</label>
                      <ng-container digPopover
                        ><button
                          digPopoverTrigger
                          digButton
                          type="button"
                          [id]="\`\${svc.value}-people-trigger\`"
                          variant="outline"
                          [attr.aria-labelledby]="\`\${svc.value}-people \${svc.value}-people-trigger\`"
                          class="justify-between font-normal"
                        >
                          <span class="truncate">{{ view(svc.value).summary }}</span>
                          <svg digIcon="chevron-down" class="text-muted-foreground"></svg>
                        </button>
                        <div
                          digControlSize="xl"
                          digPopoverContent
                          align="end"
                          [attr.aria-label]="view(svc.value).peopleLabel"
                          class="flex w-80 max-w-[calc(100vw-2rem)] flex-col gap-4"
                        >
                          @for (row of view(svc.value).rows; track row.label; let index = $index) {
                            <div class="flex items-center justify-between gap-3">
                              <div class="flex min-w-0 flex-col gap-0.5">
                                <label digLabel [id]="\`\${svc.value}-row-\${index}\`">{{ row.label }}</label>
                                @if (row.hint) {
                                  <span class="text-xs text-muted-foreground">{{ row.hint }}</span>
                                }
                              </div>
                              <div
                                digNumberField
                                [attr.aria-labelledby]="\`\${svc.value}-row-\${index}\`"
                                [value]="num(svc.value, row.key)"
                                [min]="row.min"
                                [max]="row.max"
                                class="w-32 shrink-0"
                                (valueChange)="setOption(svc.value, row.key, $event)"
                              ></div>
                            </div>
                          }
                          <button digPopoverClose digButton type="button" class="mt-2">تأیید</button>
                        </div></ng-container
                      >
                    </div>

                    <button digButton type="submit" class="lg:mt-7 lg:min-w-32">جست‌وجو</button>
                  </div>
                </form>
              </div>
            }
          </div>
        </div>
      </div>

      <!-- پیشنهادهای همان نوعِ سفر: یک لمس، فرم پر می‌شود. -->
      <section aria-labelledby="popular-title" class="flex flex-col gap-3">
        <h2 id="popular-title" class="font-bold">{{ isStay() ? "مقصدهای پرطرفدار" : "مسیرهای پرطرفدار" }}</h2>
        <div digControlSize="lg" mobileSize="default" class="flex flex-wrap gap-2">
          @for (route of POPULAR[service()]; track \`\${route.from}-\${route.to}\`) {
            <button digButton type="button" variant="outline" class="shrink-0" (click)="pick(route)">
              @if (route.from) {
                {{ cityName(route.from) }}
                <span aria-label="به" class="text-muted-foreground">←</span>
              }
              {{ cityName(route.to) }}
            </button>
          }
        </div>
      </section>
    </main>
  `,
})
export class TravelSearchBlock {
  readonly minDate = minDate

  readonly POPULAR = POPULAR

  readonly cityName = cityName

  readonly SERVICES = SERVICES

  readonly trips = signal<Record<ServiceId, Trip>>({
    flight: makeTrip("THR"),
    train: makeTrip("THR"),
    bus: makeTrip("THR"),
    hotel: makeTrip(),
    villa: makeTrip(),
    tour: makeTrip("THR"),
  })

  readonly form = signal<Record<ServiceId, Record<string, string | number>>>({
    flight: { scope: "domestic", tripType: "oneway", cabin: "economy", adults: 1, children: 0, infants: 0 },
    train: { tripType: "oneway", wagon: "compartment", group: "regular", adults: 1, children: 0, infants: 0 },
    bus: { seats: 1 },
    hotel: { scope: "domestic", adults: 2, children: 0, rooms: 1 },
    villa: { scope: "domestic", adults: 2, children: 0 },
    tour: { kind: "package", adults: 2, rooms: 1 },
  })

  readonly num = (id: ServiceId, key: string) => Number(this.form()[id][key])

  readonly str = (id: ServiceId, key: string) => String(this.form()[id][key])

  view(id: ServiceId) {
    const f = this.form()[id]
    const transport = id === "flight" || id === "train" || id === "bus" || id === "tour"
    const base = {
      transport,
      options: [] as OptionControl[],
      cities: DOMESTIC,
      originLabel: "مبدأ",
      destinationLabel: "مقصد",
      noun: "شهر",
      round: false,
      dateLabels: ["", ""] as [string, string],
      peopleLabel: "مسافران",
      summary: "",
      rows: [] as PeopleRow[],
      stayPlaceholder: "",
      stayLabel: "",
    }
    if (id === "flight") {
      const scope = this.str(id, "scope")
      return {
        ...base,
        options: [
          { kind: "scope", label: "نوعِ پرواز", key: "scope", options: DOM_FOR },
          { kind: "select", label: "نوعِ سفر", key: "tripType", options: TRIP_TYPES },
          {
            kind: "select",
            label: "کلاسِ پرواز",
            key: "cabin",
            show: scope === "foreign",
            options: [
              { value: "economy", label: "اکونومی" },
              { value: "business", label: "بیزینس" },
              { value: "first", label: "فرست" },
            ],
          },
        ] as OptionControl[],
        cities: scope === "domestic" ? DOMESTIC : [...DOMESTIC.slice(0, 4), ...FOREIGN],
        noun: scope === "domestic" ? "شهر" : "شهر یا فرودگاه",
        round: this.str(id, "tripType") === "round",
        dateLabels: ["تاریخِ رفت", "تاریخِ رفت و برگشت"] as [string, string],
        summary: passengerSummary(this.num(id, "adults"), this.num(id, "children") + this.num(id, "infants")),
        rows: [
          { label: "بزرگسال", hint: "۱۲ سال به بالا", key: "adults", min: 1, max: 9 },
          { label: "کودک", hint: "۲ تا ۱۲ سال", key: "children", min: 0, max: 8 },
          {
            label: "نوزاد",
            hint: "زیرِ ۲ سال، یکی برای هر بزرگسال",
            key: "infants",
            min: 0,
            max: this.num(id, "adults"),
          },
        ] as PeopleRow[],
      }
    }
    if (id === "train") {
      return {
        ...base,
        options: [
          { kind: "select", label: "نوعِ سفر", key: "tripType", options: TRIP_TYPES },
          {
            kind: "select",
            label: "نوعِ واگن",
            key: "wagon",
            options: [
              { value: "compartment", label: "کوپهٔ عادی" },
              { value: "private", label: "کوپهٔ دربست" },
              { value: "salon", label: "سالنی" },
            ],
          },
          {
            kind: "select",
            label: "نوعِ مسافر",
            key: "group",
            options: [
              { value: "regular", label: "مسافرانِ عادی" },
              { value: "women", label: "ویژهٔ بانوان" },
              { value: "men", label: "ویژهٔ آقایان" },
            ],
          },
        ] as OptionControl[],
        cities: DOMESTIC.filter((city) => city.value !== "KIH"),
        originLabel: "ایستگاهِ مبدأ",
        destinationLabel: "ایستگاهِ مقصد",
        round: this.str(id, "tripType") === "round",
        dateLabels: ["تاریخِ حرکت", "تاریخِ رفت و برگشت"] as [string, string],
        summary: passengerSummary(this.num(id, "adults"), this.num(id, "children") + this.num(id, "infants")),
        rows: [
          {
            label: "بزرگسال",
            hint: "۱۲ سال به بالا",
            key: "adults",
            min: 1,
            max: this.str(id, "wagon") === "private" ? 4 : 9,
          },
          { label: "کودک", hint: "۲ تا ۱۲ سال، نیم‌بها", key: "children", min: 0, max: 6 },
          { label: "نوزاد", hint: "زیرِ ۲ سال، بدونِ صندلی", key: "infants", min: 0, max: this.num(id, "adults") },
        ] as PeopleRow[],
      }
    }
    if (id === "bus") {
      return {
        ...base,
        cities: DOMESTIC.filter((city) => city.value !== "KIH"),
        noun: "شهر یا پایانه",
        dateLabels: ["تاریخِ حرکت", ""] as [string, string],
        peopleLabel: "صندلی",
        summary: `${toFaDigits(this.num(id, "seats"))} صندلی`,
        rows: [{ label: "تعدادِ صندلی", key: "seats", min: 1, max: 6 }] as PeopleRow[],
      }
    }
    if (id === "tour") {
      const pkg = this.str(id, "kind") === "package"
      return {
        ...base,
        options: [
          {
            kind: "scope",
            label: "نوعِ تور",
            key: "kind",
            options: [
              { value: "package", label: "بلیت + اقامت" },
              { value: "sightseeing", label: "تورِ گردشگری" },
            ],
          },
        ] as OptionControl[],
        cities: [...DOMESTIC, ...FOREIGN],
        noun: pkg ? "شهر" : "شهر یا کشور",
        round: pkg,
        dateLabels: (pkg ? ["", "تاریخِ رفت و برگشت"] : ["از تاریخ", ""]) as [string, string],
        peopleLabel: "مسافران و اتاق",
        summary: `${toFaDigits(this.num(id, "adults"))} مسافر، ${toFaDigits(this.num(id, "rooms"))} اتاق`,
        rows: [
          { label: "مسافر", key: "adults", min: 1, max: 12 },
          { label: "اتاق", key: "rooms", min: 1, max: this.num(id, "adults") },
        ] as PeopleRow[],
      }
    }
    // hotel / villa
    const hotel = id === "hotel"
    const guests = this.num(id, "adults") + this.num(id, "children")
    return {
      ...base,
      options: (hotel
        ? [{ kind: "scope", label: "داخلی یا خارجی", key: "scope", options: DOM_FOR }]
        : []) as OptionControl[],
      cities: hotel ? (this.str(id, "scope") === "foreign" ? FOREIGN : DOMESTIC) : VILLA_PLACES,
      round: true,
      dateLabels: ["", "تاریخِ ورود و خروج"] as [string, string],
      stayLabel: hotel ? "شهر یا هتل" : "مقصد یا نوعِ اقامتگاه",
      stayPlaceholder: hotel ? "مثلاً کیش یا هتلِ داریوش" : "مثلاً رامسر یا کلبهٔ جنگلی",
      peopleLabel: hotel ? "مسافران و اتاق" : "تعدادِ مهمان",
      summary: hotel
        ? `${toFaDigits(guests)} مسافر، ${toFaDigits(this.num(id, "rooms"))} اتاق`
        : `${toFaDigits(guests)} مهمان`,
      rows: [
        { label: "بزرگسال", hint: "۱۲ سال به بالا", key: "adults", min: 1, max: 12 },
        { label: "کودک", hint: "زیرِ ۱۲ سال", key: "children", min: 0, max: 6 },
        ...(hotel ? [{ label: "اتاق", key: "rooms", min: 1, max: Math.max(1, this.num(id, "adults")) }] : []),
      ] as PeopleRow[],
    }
  }

  setDestination(id: ServiceId, value: string | undefined) {
    this.updateTrip(id, { destination: value ?? "", missing: false })
  }

  swap(id: ServiceId) {
    const trip = this.trips()[id]
    this.updateTrip(id, { origin: trip.destination, destination: trip.origin, missing: false })
  }

  onOption(id: ServiceId, control: OptionControl, value: string | string[] | undefined) {
    if (typeof value !== "string") return
    this.setOption(id, control.key, value)
    // عوضِ شدنِ داخلی/خارجی در هتل مقصدِ قبلی را بی‌اعتبار می‌کند.
    if (id === "hotel" && control.key === "scope") this.setDestination(id, "")
  }

  onSubmit(id: ServiceId) {
    const trip = this.trips()[id]
    if (!trip.destination) {
      this.updateTrip(id, { missing: true })
      document.getElementById(`${id}-destination`)?.focus()
      return
    }
    toast.success(SEARCH_TOAST[id](trip))
  }

  pick(route: { from?: string; to: string }) {
    const id = this.service()
    this.updateTrip(id, { origin: route.from ?? this.trips()[id].origin, destination: route.to, missing: false })
  }

  readonly service = signal<ServiceId>("flight")

  readonly current = computed(() => SERVICES.find((item) => item.value === this.service()) ?? SERVICES[0])

  readonly isStay = computed(() => this.service() === "hotel" || this.service() === "villa")

  setService(value: string | undefined) {
    const next = SERVICES.find((item) => item.value === value)
    if (next) this.service.set(next.value)
  }
  updateTrip(id: ServiceId, patch: Partial<Trip>) {
    this.trips.update((trips) => ({ ...trips, [id]: { ...trips[id], ...patch } }))
  }
  setOption(id: ServiceId, key: string, value: string | number) {
    this.form.update((form) => ({ ...form, [id]: { ...form[id], [key]: value } }))
  }
}

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

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

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