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 {unitWord} from '../kit/unitWord'; 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_UNITS = 4; const book = () => window.dispatchEvent(new Event(BOOK_EVENT)); 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 rows = (unit: UnitView) => specRows(unit, raw.get(unit.unitId)?.facts ?? []); const people = (unit: UnitView) => rows(unit).find(([label]) => label === '정원')?.[1]; return ( <>

{unitWord(payload.place.category).toUpperCase()}

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

{units.slice(0, HOME_UNITS).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 (

{unitWord(payload.place.category).toUpperCase()} {String(i + 1).padStart(2, '0')}

{main} {sub && {sub}}

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

{unit.intro}

}
{rows(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}

))} )}
); }