"use client"; import { SectionEditor } from "../_components/SectionEditor"; import { InputField, SelectField } from "../_components/FormField"; import { ArrayEditor } from "../_components/ArrayEditor"; interface PricingItem { name: string; price: string; note?: string; popular?: boolean; featured?: boolean; } interface PricingData { title: string; subtitle: string; items: PricingItem[]; rentalTitle: string; rentalItems: { name: string; price: string; note?: string }[]; rules: string[]; showContactHint?: boolean; } function PriceField({ label, value, onChange }: { label: string; value: string; onChange: (v: string) => void }) { // Strip "BYN" suffix for editing, add back on save const raw = value.replace(/\s*BYN\s*$/i, "").trim(); return (
{ const v = e.target.value; onChange(v ? `${v} BYN` : ""); }} placeholder="0" className="flex-1 bg-transparent px-4 py-2.5 text-white placeholder-neutral-500 outline-none min-w-0" /> BYN
); } export default function PricingEditorPage() { return ( sectionKey="pricing" title="Цены"> {(data, update) => ( <> update({ ...data, title: v })} /> update({ ...data, subtitle: v })} /> {/* Featured selector */} {(() => { const itemOptions = data.items .map((it, idx) => ({ value: String(idx), label: it.name })) .filter((o) => o.label.trim() !== ""); const noneOption = { value: "", label: "— Нет —" }; const featuredIdx = data.items.findIndex((it) => it.featured); return ( = 0 ? String(featuredIdx) : ""} onChange={(v) => { const items = data.items.map((it, idx) => ({ ...it, featured: v ? idx === Number(v) : false, })); update({ ...data, items }); }} options={[noneOption, ...itemOptions]} placeholder="Выберите..." /> ); })()} update({ ...data, items })} renderItem={(item, _i, updateItem) => (
updateItem({ ...item, name: v })} /> updateItem({ ...item, price: v })} /> updateItem({ ...item, note: v })} />
)} createItem={() => ({ name: "", price: "", note: "" })} addLabel="Добавить абонемент" /> update({ ...data, rentalTitle: v })} /> update({ ...data, rentalItems })} renderItem={(item, _i, updateItem) => (
updateItem({ ...item, name: v })} /> updateItem({ ...item, price: v })} /> updateItem({ ...item, note: v })} />
)} createItem={() => ({ name: "", price: "", note: "" })} addLabel="Добавить вариант аренды" /> update({ ...data, rules })} renderItem={(rule, _i, updateItem) => ( )} createItem={() => ""} addLabel="Добавить правило" /> )} ); }