import { KeyboardEvent } from 'react'; import wiredGlobalPlaceholderImage from '../../assets/images/wiredtools/wired_global_placeholder.png'; import { Button, LayoutAvatarImageView, LayoutPetImageView, LayoutRoomObjectImageView, Text } from '../../common'; import { INSPECTION_ELEMENTS } from './WiredCreatorTools.constants'; import { InspectionFurniSelection, InspectionUserSelection, InspectionVariable } from './WiredCreatorTools.types'; import { useWiredCreatorToolsUiStore } from './wiredCreatorToolsUiStore'; /** * Structural shape we need from the renderer's variable-definition * objects (`IWiredUserVariableDefinition` / `IWiredFurniVariableDefinition`). * Declared locally to avoid pulling the renderer SDK into the view. */ export interface InspectionGiveDefinition { itemId: number; name: string; hasValue: boolean; } export interface WiredInspectionTabViewProps { // preview selectedFurni: InspectionFurniSelection | null; selectedUser: InspectionUserSelection | null; roomId: number | null; previewPlaceholder: string; // keep-selected toggle keepSelected: boolean; onKeepSelectedChange: (next: boolean) => void; // variables table displayedVariables: InspectionVariable[]; selectedInspectionVariableKey: string; onSelectInspectionVariable: (variable: InspectionVariable) => void; // inline editor — `editingVariable` / `editingValue` come from the // store; this tab only needs the cancel / keydown / begin handlers // since each tab consumer wraps `onBeginVariableEdit` with its own // bookkeeping (variable-key tracking). onCancelVariableEdit: () => void; onVariableInputKeyDown: (event: KeyboardEvent) => void; onBeginVariableEdit: (variable: InspectionVariable) => void; // give-variable popover selectedInspectionGiveDefinition: InspectionGiveDefinition | null; onSelectGiveVariable: (itemId: number) => void; availableInspectionDefinitions: InspectionGiveDefinition[]; inspectionGiveValue: string; onInspectionGiveValueChange: (value: string) => void; canGiveInspectionVariable: boolean; onGiveInspectionVariable: () => void; // remove variable canRemoveInspectionVariable: boolean; onRemoveInspectionVariable: () => void; } /** * The "Inspection" tab body of WiredCreatorToolsView, extracted from * the parent's inline JSX. Same shape as WiredVariablesTabView: * pure presentation, all state and actions arrive as typed props. */ export const WiredInspectionTabView = (props: WiredInspectionTabViewProps) => { const { selectedFurni, selectedUser, roomId, previewPlaceholder, keepSelected, onKeepSelectedChange, displayedVariables, selectedInspectionVariableKey, onSelectInspectionVariable, onCancelVariableEdit, onVariableInputKeyDown, onBeginVariableEdit, selectedInspectionGiveDefinition, onSelectGiveVariable, availableInspectionDefinitions, inspectionGiveValue, onInspectionGiveValueChange, canGiveInspectionVariable, onGiveInspectionVariable, canRemoveInspectionVariable, onRemoveInspectionVariable } = props; const inspectionType = useWiredCreatorToolsUiStore(s => s.inspectionType); const setInspectionType = useWiredCreatorToolsUiStore(s => s.setInspectionType); const isInspectionGiveOpen = useWiredCreatorToolsUiStore(s => s.isInspectionGiveOpen); const setIsInspectionGiveOpen = useWiredCreatorToolsUiStore(s => s.setIsInspectionGiveOpen); const editingVariable = useWiredCreatorToolsUiStore(s => s.editingVariable); const editingValue = useWiredCreatorToolsUiStore(s => s.editingValue); const setEditingValue = useWiredCreatorToolsUiStore(s => s.setEditingValue); return (
Element type:
{ INSPECTION_ELEMENTS.map(element => ( )) }
Preview:
{ (inspectionType === 'furni') && selectedFurni && (roomId !== null) &&
} { (inspectionType === 'user') && selectedUser &&
{ (selectedUser.kind === 'pet') ? : }
} { (inspectionType === 'global') &&
Global placeholder
} { (((inspectionType === 'furni') && !selectedFurni) || ((inspectionType === 'user') && !selectedUser) || (inspectionType === 'global')) &&
{ previewPlaceholder }
}
Variables:
Variable Value
{ !displayedVariables.length &&
Nothing to display
} { !!displayedVariables.length &&
{ displayedVariables.map((variable, index) => ( onSelectInspectionVariable(variable) }> )) }
{ variable.key } { (editingVariable === variable.key) && event.stopPropagation() } onBlur={ onCancelVariableEdit } onChange={ event => setEditingValue(event.target.value) } onKeyDownCapture={ onVariableInputKeyDown } /> } { (editingVariable !== variable.key) && !variable.editable && { variable.value } } { (editingVariable !== variable.key) && variable.editable && }
}
{ isInspectionGiveOpen &&
Variable: Value: onInspectionGiveValueChange(event.target.value) } />
}
); };