const { useState } = React;

function Icon({ className = "", children }) {
  return <svg className={className} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">{children}</svg>;
}
const CalendarDays = (p) => <Icon {...p}><rect x="3" y="4" width="18" height="18" rx="2" /><path d="M16 2v4M8 2v4M3 10h18" /></Icon>;
const ChevronDown = (p) => <Icon {...p}><path d="m6 9 6 6 6-6" /></Icon>;
const ChevronLeft = (p) => <Icon {...p}><path d="m15 18-6-6 6-6" /></Icon>;
const ChevronRight = (p) => <Icon {...p}><path d="m9 18 6-6-6-6" /></Icon>;
const Clock = (p) => <Icon {...p}><circle cx="12" cy="12" r="9" /><path d="M12 7v5l3 2" /></Icon>;
const Copy = (p) => <Icon {...p}><rect x="9" y="9" width="11" height="11" rx="2" /><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" /></Icon>;
const Minus = (p) => <Icon {...p}><path d="M5 12h14" /></Icon>;
const Plus = (p) => <Icon {...p}><path d="M12 5v14M5 12h14" /></Icon>;
const RotateCcw = (p) => <Icon {...p}><path d="M3 12a9 9 0 1 0 3-6.7" /><path d="M3 4v6h6" /></Icon>;
const Trash2 = (p) => <Icon {...p}><path d="M3 6h18M8 6V4h8v2M6 6l1 14h10l1-14M10 11v6M14 11v6" /></Icon>;
const X = (p) => <Icon {...p}><path d="M18 6 6 18M6 6l12 12" /></Icon>;

const steps = [
  { no: 1, sectionTitle: "Basic Information", tone: "bg-blue-500" },
  { no: 2, sectionTitle: "Customer Information", tone: "bg-emerald-500" },
  { no: 3, sectionTitle: "Participants Information", tone: "bg-purple-500" },
  { no: 4, sectionTitle: "Reservation Information", tone: "bg-orange-500" },
  { no: 5, sectionTitle: "Estimate", tone: "bg-slate-500" },
];

const initialDateRows = [
  { date: "2026/4/10", items: [{ id: 1 }, { id: 2 }, { id: 3 }] },
  { date: "2026/4/11", items: [] },
];

function addItemToRows(rows, date) {
  return rows.map((row) => {
    if (row.date !== date) return row;
    const nextId = row.items.length ? Math.max(...row.items.map((item) => item.id)) + 1 : 1;
    return { ...row, items: [...row.items, { id: nextId }] };
  });
}

function removeItemFromRows(rows, date, itemId) {
  return rows.map((row) => {
    if (row.date !== date) return row;
    return { ...row, items: row.items.filter((item) => item.id !== itemId) };
  });
}

function runPreviewAssertions() {
  const rowsAfterAdd = addItemToRows([{ date: "A", items: [] }], "A");
  console.assert(rowsAfterAdd[0].items.length === 1, "addItemToRows should add one item");

  const rowsAfterRemove = removeItemFromRows([{ date: "A", items: [{ id: 1 }, { id: 2 }] }], "A", 1);
  console.assert(rowsAfterRemove[0].items.length === 1 && rowsAfterRemove[0].items[0].id === 2, "removeItemFromRows should remove the selected item");

  const untouchedRows = addItemToRows([{ date: "A", items: [] }], "B");
  console.assert(untouchedRows[0].items.length === 0, "addItemToRows should not affect other dates");
}

runPreviewAssertions();

function Field({ label, required, children, hint }) {
  return (
    <label className="block">
      <div className="mb-2 text-[13px] font-bold tracking-wide text-slate-700">
        {label} {required && <span className="text-red-500">*</span>}
      </div>
      {children}
      {hint && <p className="mt-1 text-xs text-slate-400">{hint}</p>}
    </label>
  );
}

function TextInput({ value: initialValue = "", placeholder = "", type = "text", icon }) {
  const [value, setValue] = useState(initialValue);
  return (
    <div className="flex min-h-11 w-full items-center gap-2 rounded-xl border border-slate-200 bg-white px-3 shadow-sm focus-within:border-blue-400 focus-within:ring-2 focus-within:ring-blue-100">
      {icon}
      <input
        type={type}
        value={value}
        placeholder={placeholder}
        onChange={(event) => setValue(event.target.value)}
        className="min-w-0 flex-1 bg-transparent text-[15px] text-slate-800 outline-none placeholder:text-slate-400"
      />
    </div>
  );
}

function SelectInput({ value, options = [] }) {
  const [selected, setSelected] = useState(value || options[0] || "");
  return (
    <div className="relative">
      <select
        value={selected}
        onChange={(event) => setSelected(event.target.value)}
        className="min-h-11 w-full appearance-none rounded-xl border border-slate-200 bg-white px-3 pr-10 text-[15px] text-slate-800 shadow-sm outline-none focus:border-blue-400 focus:ring-2 focus:ring-blue-100"
      >
        {(options.length ? options : [selected]).map((option) => (
          <option key={option}>{option}</option>
        ))}
      </select>
      <ChevronDown className="pointer-events-none absolute right-3 top-1/2 h-5 w-5 -translate-y-1/2 text-slate-400" />
    </div>
  );
}

function TextArea({ placeholder }) {
  const [value, setValue] = useState("");
  return (
    <textarea
      value={value}
      onChange={(event) => setValue(event.target.value)}
      placeholder={placeholder}
      rows={4}
      className="w-full rounded-xl border border-slate-200 bg-white px-3 py-3 text-[15px] text-slate-800 shadow-sm outline-none placeholder:text-slate-400 focus:border-blue-400 focus:ring-2 focus:ring-blue-100"
    />
  );
}

function CheckRow({ label }) {
  const [checked, setChecked] = useState(false);
  return (
    <button
      type="button"
      onClick={() => setChecked(!checked)}
      className="flex w-full items-center gap-3 rounded-xl bg-slate-50 p-3 text-left text-[14px] font-semibold text-slate-700"
    >
      <span className={`flex h-5 w-5 shrink-0 items-center justify-center rounded border ${checked ? "border-slate-800 bg-slate-800" : "border-slate-300 bg-white"}`}>
        {checked && <span className="h-2 w-2 rounded-full bg-white" />}
      </span>
      {label}
    </button>
  );
}

function RadioGroup({ options, initial }) {
  const [value, setValue] = useState(initial || options[0]);
  return (
    <div className="grid grid-cols-2 gap-2">
      {options.map((option) => (
        <button
          key={option}
          type="button"
          onClick={() => setValue(option)}
          className={`flex min-h-11 items-center gap-2 rounded-xl border px-3 text-left text-[14px] font-bold ${value === option ? "border-slate-800 bg-white text-slate-900" : "border-slate-200 bg-white text-slate-600"}`}
        >
          <span className={`h-4 w-4 rounded-full border ${value === option ? "border-[5px] border-slate-900" : "border-slate-400"}`} />
          {option}
        </button>
      ))}
    </div>
  );
}

function Counter({ label, value, onChange }) {
  const [internalCount, setInternalCount] = useState(0);
  const count = value ?? internalCount;

  function update(nextValue) {
    const safeNext = Math.max(0, nextValue);
    if (onChange) onChange(safeNext);
    else setInternalCount(safeNext);
  }

  return (
    <div className="flex items-center justify-between rounded-xl bg-white px-3 py-2.5 ring-1 ring-slate-100">
      <span className="text-[14px] font-bold text-slate-700">{label}</span>
      <div className="flex items-center gap-2.5">
        <button type="button" onClick={() => update(count - 1)} className="flex h-8 w-8 items-center justify-center rounded-lg border border-slate-200 bg-white shadow-sm">
          <Minus className="h-4 w-4" />
        </button>
        <span className="w-7 text-center text-base font-bold text-slate-800">{count}</span>
        <button type="button" onClick={() => update(count + 1)} className="flex h-8 w-8 items-center justify-center rounded-lg border border-slate-200 bg-white shadow-sm">
          <Plus className="h-4 w-4" />
        </button>
      </div>
    </div>
  );
}

function Section({ children }) {
  return <section className="space-y-4">{children}</section>;
}

function TopHeader({ step, setStep }) {
  const current = steps[step - 1];
  return (
    <header className="sticky top-0 z-50 border-b border-slate-200 bg-white px-4 pb-2.5 pt-3">
      <div className="flex items-start justify-between gap-3">
        <div className="min-w-0">
          <p className="text-[11px] font-bold text-slate-500">New Reservation · {step} / 5</p>
          <div className="mt-1.5 flex min-w-0 items-center gap-2">
            <span className={`h-2.5 w-2.5 shrink-0 rounded-full ${current.tone}`} />
            <h1 className="truncate text-[17px] font-extrabold tracking-tight text-slate-800">{current.sectionTitle}</h1>
          </div>
        </div>
        <button type="button" className="rounded-full p-1.5 text-slate-500 hover:bg-slate-100">
          <X className="h-5 w-5" />
        </button>
      </div>
      <div className="mt-2.5 grid grid-cols-5 gap-2">
        {steps.map((s) => (
          <button key={s.no} type="button" onClick={() => setStep(s.no)} className={`h-1.5 rounded-full ${s.no <= step ? current.tone : "bg-slate-200"}`} />
        ))}
      </div>
    </header>
  );
}

function BottomNav({ step, setStep }) {
  return (
    <footer className="fixed inset-x-0 bottom-0 z-50 border-t border-slate-200 bg-white px-4 py-2">
      <div className="mx-auto flex max-w-[560px] gap-2">
        <button type="button" disabled={step === 1} onClick={() => setStep(step - 1)} className="flex h-10 flex-1 items-center justify-center gap-1.5 rounded-lg border border-slate-200 bg-white text-[13px] font-bold text-slate-600 shadow-sm disabled:opacity-40">
          <ChevronLeft className="h-4 w-4" />Previous
        </button>
        <button type="button" disabled={step === 5} onClick={() => setStep(step + 1)} className="flex h-10 flex-1 items-center justify-center gap-1.5 rounded-lg bg-slate-800 text-[13px] font-bold text-white shadow-sm disabled:opacity-40">
          Next<ChevronRight className="h-4 w-4" />
        </button>
      </div>
    </footer>
  );
}

function BasicInfo() {
  return (
    <div className="space-y-4">
      <Section>
        <Field label="Reservation Type" required>
          <RadioGroup options={["Lesson", "Guide"]} initial="Lesson" />
        </Field>
        <Field label="Reference Type" required>
          <RadioGroup options={["OBP", "Referral"]} initial="OBP" />
        </Field>
        <Field label="Referrer" required>
          <SelectInput value="Select referrer" options={["Select referrer", "Hakuba Office", "Niseko Partner", "Hotel Front", "Travel Agent"]} />
        </Field>
        <Field label="Customer Accommodation">
          <TextInput placeholder="Enter customer accommodation" />
        </Field>
        <CheckRow label="Customer needs Pick Up" />
        <Field label="Meet Up Location">
          <TextInput placeholder="Enter meet up location" />
        </Field>
      </Section>
    </div>
  );
}

function CustomerInfo() {
  return (
    <div className="space-y-4">
      <Section>
        <CheckRow label="This is the first time this customer visit fes" />
        <CheckRow label="Search from customer list" />
        <Field label="Email" required>
          <TextInput value="kosei0275@gmail.com" />
        </Field>
        <div className="grid grid-cols-2 gap-3">
          <Field label="First Name" required>
            <TextInput value="kosei" />
          </Field>
          <Field label="Last Name" required>
            <TextInput value="kurosaki" />
          </Field>
        </div>
        <Field label="Phone" required>
          <TextInput value="+81 80 4802 7..." />
        </Field>
        <Field label="Contact">
          <TextInput value="test_contact_1" />
        </Field>
        <div className="grid grid-cols-2 gap-3">
          <Field label="Gender" required>
            <SelectInput value="Male" options={["Male", "Female", "Other"]} />
          </Field>
          <Field label="Date of Birth" required>
            <TextInput value="2026/02/16" icon={<CalendarDays className="h-4 w-4 text-slate-400" />} />
          </Field>
        </div>
        <div className="grid grid-cols-2 gap-3">
          <Field label="Nationality" required>
            <SelectInput value="Japan" options={["Japan", "Australia", "United States", "United Kingdom", "Singapore"]} />
          </Field>
          <Field label="Country of Residence" required>
            <SelectInput value="Japan" options={["Japan", "Australia", "United States", "United Kingdom", "Singapore"]} />
          </Field>
        </div>
        <Field label="Province">
          <TextInput placeholder="Enter province" />
        </Field>
        <Field label="Ski Level (1-6)">
          <SelectInput value="Level 2 - Beginner" options={["Not Applicable", "Level 1 - First Time", "Level 2 - Beginner", "Level 3 - Intermediate", "Level 4 - Advanced", "Level 5 - Expert", "Level 6 - Professional"]} />
        </Field>
        <Field label="Snowboard Level (1-6)">
          <SelectInput value="Not Applicable" options={["Not Applicable", "Level 1 - First Time", "Level 2 - Beginner", "Level 3 - Intermediate", "Level 4 - Advanced", "Level 5 - Expert", "Level 6 - Professional"]} />
        </Field>
        <Field label="How did they hear about us?" required>
          <SelectInput value="Other" options={["Other", "Google", "Instagram", "Friend", "Hotel", "Travel Agency"]} />
        </Field>
        <Field label="Could you please specify?">
          <TextInput placeholder="Please specify..." />
        </Field>
      </Section>
    </div>
  );
}

function ParticipantCard({ title, representative, index, type }) {
  const [open, setOpen] = useState(representative || index === 1);
  return (
    <article className="rounded-2xl bg-slate-50 shadow-sm ring-1 ring-slate-200">
      <button
        type="button"
        onClick={() => setOpen(!open)}
        className="sticky top-[76px] z-20 flex w-full cursor-pointer items-center justify-between rounded-t-2xl border-b border-slate-200 bg-slate-50 px-4 py-3 text-left"
      >
        <div className="min-w-0">
          {representative && <span className="mb-0.5 inline-block rounded-full bg-indigo-100 px-2 py-0.5 text-[11px] font-bold text-indigo-700">Representative</span>}
          <h3 className="truncate text-[16px] font-extrabold text-slate-800">{title}</h3>
        </div>
        <ChevronDown className={`h-5 w-5 shrink-0 text-slate-500 ${open ? "rotate-180" : ""}`} />
      </button>
      {open && (
        <div className="space-y-4 p-4">
          {representative && (
            <button type="button" className="flex h-10 w-full items-center justify-center gap-2 rounded-xl bg-slate-800 text-[13px] font-bold text-white">
              <Copy className="h-4 w-4" />Copy from Customer
            </button>
          )}
          <div className="grid grid-cols-2 gap-3">
            <Field label="First Name" required>
              <TextInput placeholder="Enter first name" />
            </Field>
            <Field label="Last Name">
              <TextInput placeholder="Enter last name" />
            </Field>
          </div>
          <div className="grid grid-cols-2 gap-3">
            <Field label="Gender">
              <SelectInput value={type === "child" ? "Other" : "Male"} options={["Male", "Female", "Other"]} />
            </Field>
            <Field label="Age">
              <TextInput placeholder="Enter age" type="number" />
            </Field>
          </div>
          <Field label="Ski Level (1-6)">
            <SelectInput value="Not Applicable" options={["Not Applicable", "Level 1", "Level 2", "Level 3", "Level 4", "Level 5", "Level 6"]} />
          </Field>
          <Field label="Snowboard Level (1-6)">
            <SelectInput value="Not Applicable" options={["Not Applicable", "Level 1", "Level 2", "Level 3", "Level 4", "Level 5", "Level 6"]} />
          </Field>
        </div>
      )}
    </article>
  );
}

function Participants() {
  const [adultCount, setAdultCount] = useState(1);
  const [childCount, setChildCount] = useState(0);
  return (
    <div className="space-y-4">
      <Section>
        <div className="grid grid-cols-2 gap-3">
          <div className="rounded-2xl bg-white p-3 shadow-sm ring-1 ring-slate-200">
            <Counter label="Adults" value={adultCount} onChange={setAdultCount} />
          </div>
          <div className="rounded-2xl bg-white p-3 shadow-sm ring-1 ring-slate-200">
            <Counter label="Children" value={childCount} onChange={setChildCount} />
          </div>
        </div>
      </Section>

      <div className="space-y-3">
        {Array.from({ length: adultCount }).map((_, index) => (
          <ParticipantCard key={`adult-${index + 1}`} title={`Adult ${index + 1}`} index={index + 1} type="adult" representative={index === 0} />
        ))}
        {Array.from({ length: childCount }).map((_, index) => (
          <ParticipantCard key={`child-${index + 1}`} title={`Child ${index + 1}`} index={index + 1} type="child" />
        ))}
      </div>

      {adultCount + childCount === 0 && (
        <p className="rounded-xl bg-white p-4 text-center text-sm text-slate-500 ring-1 ring-slate-200">No participants added yet.</p>
      )}
    </div>
  );
}

function AddOnRow() {
  const [open, setOpen] = useState(false);
  return (
    <div className="rounded-xl bg-white p-3 ring-1 ring-slate-100">
      <button type="button" onClick={() => setOpen(!open)} className="flex w-full items-center justify-between font-bold text-slate-700">
        Add-on <span className="flex items-center gap-1 text-sm text-blue-600"><Plus className="h-4 w-4" />Add-ons</span>
      </button>
      {open && (
        <div className="mt-3 space-y-3">
          <Field label="Select add-on" required>
            <SelectInput value="Select add-on" options={["Select add-on", "Insurance", "Lift Ticket", "Photo Service"]} />
          </Field>
          <div className="grid grid-cols-2 gap-3">
            <Field label="Total Amount">
              <TextInput value="¥0" />
            </Field>
            <Field label="Add-on's To">
              <SelectInput value="Item" options={["Item", "Reservation", "Participant"]} />
            </Field>
          </div>
        </div>
      )}
    </div>
  );
}

function ItemCard({ n, total, date, onRemove }) {
  const [open, setOpen] = useState(n === 1);
  return (
    <article className="rounded-2xl bg-[#fffdea] shadow-sm ring-1 ring-amber-100">
      <button
        type="button"
        onClick={() => setOpen(!open)}
        className="sticky top-[139px] z-20 flex w-full items-center justify-between rounded-t-2xl border-b border-amber-100 bg-[#fffdea] px-4 py-3 text-left"
      >
        <div className="min-w-0">
          <p className="text-[11px] font-bold text-amber-700">{date}</p>
          <h3 className="truncate text-[16px] font-extrabold text-slate-800">Item {n} / {total}</h3>
          <p className="mt-0.5 truncate text-[11px] text-slate-500">Item: not selected · Instructor: not assigned · ¥0</p>
        </div>
        <ChevronDown className={`h-5 w-5 shrink-0 text-slate-500 ${open ? "rotate-180" : ""}`} />
      </button>
      {open && (
        <div className="space-y-4 p-4">
          <div className="flex justify-end">
            <button type="button" onClick={onRemove} className="text-red-500">
              <Trash2 className="h-5 w-5" />
            </button>
          </div>
          <Field label="Item" required>
            <SelectInput value="Select item" options={["Select item", "Private Lesson", "Group Lesson", "Guided Tour", "Kids Lesson"]} />
          </Field>
          <Field label="Instructor">
            <SelectInput value="not assigned yet" options={["not assigned yet", "Tanaka", "Sato", "Suzuki"]} />
          </Field>
          <div className="grid grid-cols-2 gap-3">
            <Field label="Meet at">
              <TextInput value="09:30" icon={<Clock className="h-4 w-4 text-slate-400" />} />
            </Field>
            <Field label="End at">
              <TextInput value="13:30" icon={<Clock className="h-4 w-4 text-slate-400" />} />
            </Field>
          </div>
          <Field label="Meeting Place">
            <TextInput placeholder="Enter meeting place" />
          </Field>
          <Counter label="Adults" />
          <Counter label="Children" />
          <Field label="Discount">
            <div className="grid grid-cols-[1fr_auto_auto] gap-2">
              <TextInput placeholder="Enter discount" />
              <div className="flex h-11 items-center rounded-xl px-1 font-bold">%</div>
              <button type="button" className="flex h-11 w-12 items-center justify-center rounded-xl border border-slate-200 bg-white shadow-sm">
                <RotateCcw className="h-4 w-4" />
              </button>
            </div>
          </Field>
          <button type="button" className="h-11 w-full rounded-xl bg-slate-800 font-bold text-white">Apply</button>
          <Field label="Price">
            <TextInput value="¥0" />
          </Field>
          <AddOnRow />
        </div>
      )}
    </article>
  );
}

function RentalBlock({ date }) {
  const [open, setOpen] = useState(false);
  return (
    <div className="rounded-2xl bg-white p-4 ring-1 ring-slate-200">
      <div className="mb-3 flex items-center justify-between">
        <h4 className="font-extrabold text-slate-800">Rentals</h4>
        <button type="button" onClick={() => setOpen(!open)} className="rounded-lg bg-slate-800 px-3 py-1.5 text-sm font-bold text-white">
          <Plus className="mr-1 inline h-4 w-4" />Rentals
        </button>
      </div>
      {open ? (
        <div className="space-y-3 rounded-xl bg-slate-50 p-3">
          <p className="text-sm font-bold text-slate-700">{date} · Rental 1</p>
          <Field label="Rental">
            <SelectInput value="Select rental" options={["Select rental", "Ski set", "Snowboard set", "Helmet", "Wear"]} />
          </Field>
          <Field label="Total Amount">
            <TextInput value="¥0" />
          </Field>
        </div>
      ) : (
        <p className="rounded-xl bg-slate-50 p-4 text-center text-sm text-slate-500">No rentals added yet. Click Add Rental to add one.</p>
      )}
    </div>
  );
}

function DateBlock({ row, onAddItem, onRemoveItem }) {
  const itemCount = row.items.length;
  return (
    <section className="rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200">
      <div className="sticky top-[76px] z-30 -mx-4 -mt-4 mb-4 flex items-center justify-between border-b border-slate-200 bg-white px-4 py-3">
        <div className="flex min-w-0 items-center gap-2">
          <CalendarDays className="h-5 w-5 shrink-0 text-slate-500" />
          <div className="min-w-0">
            <h3 className="truncate text-lg font-extrabold text-slate-800">{row.date}</h3>
            <p className="text-xs text-slate-500">Reservation date</p>
          </div>
        </div>
        <span className="shrink-0 rounded-xl bg-slate-100 px-3 py-1.5 text-sm font-bold text-slate-600">{itemCount} items</span>
      </div>
      <button type="button" onClick={onAddItem} className="mb-4 flex h-11 w-full items-center justify-center gap-2 rounded-xl bg-slate-800 font-bold text-white">
        <Plus className="h-5 w-5" />Items
      </button>
      {itemCount > 0 ? (
        <div className="space-y-3">
          {row.items.map((item, index) => (
            <ItemCard key={item.id} n={index + 1} total={itemCount} date={row.date} onRemove={() => onRemoveItem(item.id)} />
          ))}
        </div>
      ) : (
        <p className="rounded-xl bg-slate-50 p-5 text-center text-slate-500">No items added yet. Click Add Item to add one.</p>
      )}
      <div className="mt-4">
        <RentalBlock date={row.date} />
      </div>
    </section>
  );
}

function Reservation() {
  const [rows, setRows] = useState(initialDateRows);

  function addItem(date) {
    setRows((currentRows) => addItemToRows(currentRows, date));
  }

  function removeItem(date, itemId) {
    setRows((currentRows) => removeItemFromRows(currentRows, date, itemId));
  }

  return (
    <div className="space-y-4">
      <Section>
        <Field label="Date" required>
          <TextInput value="2026/4/10 - 2026/4/11" icon={<CalendarDays className="h-4 w-4 text-slate-400" />} />
        </Field>
        <button type="button" className="flex h-11 w-full items-center justify-center gap-2 rounded-xl border border-blue-200 bg-blue-50 font-bold text-blue-700">
          <Copy className="h-4 w-4" />Apply to all selected dates
        </button>
      </Section>

      {rows.map((row) => (
        <DateBlock key={row.date} row={row} onAddItem={() => addItem(row.date)} onRemoveItem={(itemId) => removeItem(row.date, itemId)} />
      ))}

      <div className="space-y-4 rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200">
        <div className="flex items-center gap-3 border-b border-slate-200 pb-3">
          <span className="h-3 w-3 rounded-full bg-emerald-500" />
          <h2 className="text-[16px] font-extrabold uppercase tracking-wide text-slate-800">Default Add-on Setting</h2>
        </div>
        <p className="text-sm text-slate-500">Apply the rental or add-on quantity setting from one item to all selected dates.</p>
        <Field label="Add-on">
          <SelectInput value="Select add-on to copy to all target items" options={["Select add-on to copy to all target items", "Insurance", "Lift Ticket", "Photo Service"]} />
        </Field>
        <button type="button" className="h-11 w-full rounded-xl bg-slate-500 font-bold text-white">Apply selected to all items</button>
      </div>

      <div className="space-y-4 rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200">
        <div className="flex items-center gap-3 border-b border-slate-200 pb-3">
          <span className="h-3 w-3 rounded-full bg-amber-500" />
          <h2 className="text-[16px] font-extrabold uppercase tracking-wide text-slate-800">Default Item Discount</h2>
        </div>
        <p className="text-sm text-slate-500">Apply the same discount to all items on selected dates.</p>
        <Field label="Discount">
          <div className="grid grid-cols-[1fr_auto_auto] gap-2">
            <TextInput placeholder="Enter discount to apply to all items" />
            <div className="flex h-11 items-center font-bold">%</div>
            <button type="button" className="flex h-11 w-12 items-center justify-center rounded-xl border border-slate-200 bg-white">
              <RotateCcw className="h-4 w-4" />
            </button>
          </div>
        </Field>
        <button type="button" className="h-11 w-full rounded-xl bg-slate-500 font-bold text-white">Apply selected to all items</button>
      </div>
    </div>
  );
}

function Estimate() {
  return (
    <div className="space-y-4">
      <div className="space-y-4 rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200">
        <div className="flex items-center gap-3 border-b border-slate-200 pb-3">
          <span className="h-3 w-3 rounded-full bg-purple-500" />
          <h2 className="text-[16px] font-extrabold uppercase tracking-wide text-slate-800">Voucher Discount</h2>
        </div>
        <Field label="Promotion ID">
          <TextInput placeholder="Enter promotion ID" />
        </Field>
        <Field label="Voucher Price">
          <TextInput value="¥0" />
        </Field>
      </div>

      <div className="space-y-4 rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200">
        <div className="flex items-center gap-3 border-b border-slate-200 pb-3">
          <span className="h-3 w-3 rounded-full bg-orange-500" />
          <h2 className="text-[16px] font-extrabold uppercase tracking-wide text-slate-800">Internal Note</h2>
        </div>
        <TextArea placeholder="Add an internal note" />
      </div>

      <div className="space-y-4 rounded-2xl bg-white p-4 shadow-sm ring-1 ring-slate-200">
        <div className="flex items-center gap-3 border-b border-slate-200 pb-3">
          <span className="h-3 w-3 rounded-full bg-blue-500" />
          <h2 className="text-[16px] font-extrabold uppercase tracking-wide text-slate-800">Estimated Price</h2>
        </div>
        <div className="space-y-2 text-sm text-slate-700">
          <div className="font-bold text-slate-800">2026/4/10</div>
          <div className="flex justify-between"><span>Lesson Item</span><span>¥0</span></div>
          <div className="flex justify-between"><span>Rental</span><span>¥0</span></div>
          <div className="flex justify-between border-b border-slate-100 pb-2"><span>Daily Total</span><span>¥0</span></div>
          <div className="font-bold text-slate-800">2026/4/11</div>
          <div className="flex justify-between border-b border-slate-100 pb-2"><span>Daily Total</span><span>¥0</span></div>
          <div className="flex justify-between pt-2"><span>Subtotal</span><span>¥0</span></div>
          <div className="flex justify-between"><span>Tax</span><span>¥0</span></div>
          <div className="flex justify-between"><span>Tip</span><span>¥0</span></div>
          <div className="flex justify-between text-lg font-extrabold"><span>Grand Total</span><span>¥0</span></div>
        </div>
      </div>

      <button type="button" className="h-12 w-full rounded-xl bg-slate-800 font-extrabold text-white">Save reservation</button>
    </div>
  );
}

function Screen({ step }) {
  if (step === 1) return <BasicInfo />;
  if (step === 2) return <CustomerInfo />;
  if (step === 3) return <Participants />;
  if (step === 4) return <Reservation />;
  return <Estimate />;
}

function ReservationMobilePreview() {
  const [step, setStep] = useState(1);
  return (
    <div className="min-h-screen bg-slate-100 text-slate-800">
      <div className="mx-auto min-h-screen max-w-[560px] bg-slate-50">
        <TopHeader step={step} setStep={setStep} />
        <main className="px-4 pb-20 pt-3">
          <Screen step={step} />
        </main>
        <BottomNav step={step} setStep={setStep} />
      </div>
    </div>
  );
}

ReactDOM.createRoot(document.getElementById("root")).render(<ReservationMobilePreview />);
