import {useState} from 'react'; import {factText, sanitizeUnits, PlaceCategory} from '@o2o/shared'; import {useSite} from '@site/lib/site-context'; import {sectionName, unitSpec, unitViews, type UnitView} from '@site/lib/derive'; import {Car} from '../paper/Car'; import {BOOK_EVENT} from '../paper/Rooms'; import {Sheet} from '../paper/Sheet'; function splitName(name: string): [string, string | undefined] { const m = /^(.+?)\s*\((.+)\)\s*$/.exec(name); return m ? [m[1], m[2]] : [name, undefined]; } function specRows(unit: UnitView, facts: Parameters[0]) { const bed = [factText(facts, 'bed_type'), factText(facts, 'room_size')].filter(Boolean).join(' · '); const std = factText(facts, 'standard_capacity'); const max = factText(facts, 'max_capacity'); const people = [std && `기준 ${std.replace(/명$/, '인')}`, max && `최대 ${max.replace(/명$/, '인')}`] .filter(Boolean) .join(' · '); const price = unit.priceText ?? unit.prices.map((p) => `${p.label} ${p.value}`).join(' · '); return [ ['침대', bed], ['정원', people], ['요금', price], ].filter(([, value]) => value) as [string, string][]; } const HOME_MAX = 4; export function Rooms() { const payload = useSite(); const lodging = payload.place.category === PlaceCategory.LODGING; const units = unitViews(payload); const spec = unitSpec(payload); const raw = new Map(sanitizeUnits(payload.units).map((unit) => [unit.unitId, unit])); const [open, setOpen] = useState(null); if (units.length === 0) return null; const rowsOf = (unit: UnitView) => specRows(unit, raw.get(unit.unitId)?.facts ?? []); const people = (unit: UnitView) => rowsOf(unit).find(([label]) => label === '정원')?.[1]; return ( <>

{spec.label}

{sectionName(payload, spec.path, `${spec.label} 안내`)}

{units.slice(0, HOME_MAX).map((unit) => ( {unit.images[0] && (
{unit.images[0].alt}
)}

{unit.name}

{people(unit) &&

{people(unit)}

}
))}
이용안내에서 전체 보기
{units.map((unit, i) => { const [main, sub] = splitName(unit.name); return (

{spec.label} {String.fromCharCode(65 + i)}

{main} {sub && {sub}}

{unit.images.length > 0 && ( ( {image.alt} ))} /> )}
{unit.intro &&

{unit.intro}

}
{rowsOf(unit).map(([label, value]) => (
{label}
{value}
))}
{lodging && ( )}
); })}
setOpen(null)} label={open?.name ?? ''}> {open && ( <> {open.images[0] && {open.images[0].alt}}

{open.name}

{open.intro &&

{open.intro}

} {open.rows.map((row) => (

{row.label} — {row.value}

))} )}
); }