"use client"; import { useLayoutEffect, useRef } from 'react'; import { Avatar, AvatarFallback, AvatarImage, Button, Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@hm-design/ui'; import type { OrgChartEmployeeSelection, OrgChartEmployeePopupProps } from './types.js'; const statusNames = { active: '재직', dispatched: '파견', onLeave: '휴직' } as const; /** Explicit React-only adapter. The Core and default entry stay UI-independent. */ export default function HMEmployeeDialog({ selection, onClose }: OrgChartEmployeePopupProps) { const returnTarget = useRef(null); const returnRoot = useRef(null); const returnContainer = useRef(null); useLayoutEffect(() => { if (!selection) return; returnTarget.current = selection; const root = selection.context.trigger.getRootNode(); const Shadow = selection.context.trigger.ownerDocument.defaultView?.ShadowRoot; returnRoot.current = Shadow && root instanceof Shadow ? root : null; returnContainer.current = returnRoot.current?.host.parentElement ?? null; }, [selection]); function restoreFocus(event: Event) { event.preventDefault(); const previous = returnTarget.current; returnTarget.current = null; if (!previous) return; const { trigger } = previous.context; // A mode/selection render can replace the card while the Portal is open. // Retain its ShadowRoot before replacement and resolve the same employee. const shadow = returnRoot.current; const currentRoot = shadow?.host.isConnected ? shadow : returnContainer.current?.firstElementChild?.shadowRoot; const replacement = [...currentRoot?.querySelectorAll('.hm-orgchart-employee') ?? []] .find(card => card.dataset.employeeId === previous.employee.id); const target = trigger.isConnected ? trigger : replacement ?? currentRoot?.querySelector('.hm-orgchart-shell'); target?.focus({ preventScroll: true }); } const displayed = selection ?? returnTarget.current; const employee = displayed?.employee; const context = displayed?.context; const image = employee?.profileImage ?? context?.trigger.querySelector('.hm-orgchart-avatar img')?.src; const fields: [string, string | null | undefined][] = employee ? [ ['이름', employee.name], ['직위', employee.position], ['소속 회사', context?.affiliation?.name], ['소속 조직', context?.organization?.name], ['직책', employee.jobTitle], ['근무 상태', statusNames[employee.workStatus]], ] : []; return { if (!open) onClose(); }}> 직원 정보 조직도에서 선택한 직원의 정보를 확인합니다. {image ? : null} {employee?.name.slice(0, 1)}
{fields.filter(([, value]) => Boolean(value)).map(([label, value]) =>
{label}
{value}
)}
; }