"use client"; import React, { useState, useTransition, useEffect } from "react"; import { useRouter } from "next/navigation"; import { LoginOccupantProps } from "./types"; import { selectOccupantHook } from "./hook"; function LoginOccupant({ selectionList, translation, lang }: LoginOccupantProps) { const Router = useRouter(); const [isPending, startTransition] = useTransition(); const [error, setError] = useState(null); const [jsonText, setJsonText] = useState(null); const onSubmitOccupant = async (data: any) => { selectOccupantHook(startTransition, data, setError, setJsonText, Router, lang) }; const isArrayLengthZero = Array.isArray(selectionList) && selectionList.length === 0; // Render an occupant card with consistent styling const OccupantCard = ({ occupant, buildKey, idx }: { occupant: any, buildKey: string, idx: number }) => (
onSubmitOccupant({ build_living_space_uu_id: occupant.build_living_space_uu_id })} >
{/* Occupant description and code */}

{occupant.description}

{occupant.code}
{/* Part name */}
{occupant.part_name}
{/* Level information */}
{translation.level}: {occupant.part_level}
); // Render a building section with its occupants const BuildingSection = ({ building, buildKey }: { building: any, buildKey: string }) => (

{building.build_name} No: {building.build_no}

{building.occupants.map((occupant: any, idx: number) => ( ))}
); return (

{translation.occupantSelection}

{translation.loggedInAs}

{/* No occupants available */} {!isArrayLengthZero ? (

{translation.noSelections}

) : ( /* Building sections with occupants */
{Object.keys(selectionList).map((buildKey: string) => ( ))}
)} {/* Show error if any */} {error &&

{error}

} {/* Loading indicator */} {isPending && (
)}
); } export default LoginOccupant;