import {IDockviewPanelProps} from "dockview";
import {MenuBar, MenuItem} from "../Components/Menu.tsx";
import "./EntityHierarchyWindow.css";
import {MouseEventHandler, ReactElement, MouseEvent} from "react";
import IconVisible from "../assets/Icons/AntDesign/eye-visible.svg";
import IconInvisible from "../assets/Icons/AntDesign/eye-invisible.svg";
import {Updater, useImmer} from "use-immer";
import {EngineGlue} from "../EngineGlue";
type EntityId = number;
class Entity
{
name: string;
id: EntityId;
visible: boolean = true;
children: EntityId[];
constructor(name: string, key: number, children: EntityId[] = [])
{
this.name = name;
this.id = key;
this.children = children;
}
}
type EntityMap = {
selectedIds: EntityId[];
[id: EntityId]: Entity;
};
const entityHierarchy: EntityMap = {
selectedIds: [],
0: new Entity("Entity Root", 0, [1, 4]),
1: new Entity("Entity Entity 1", 1, [2, 3]),
2: new Entity("Entity Entity 1.1", 2),
3: new Entity("Entity Entity 1.2", 3),
4: new Entity("Entity Entity 2", 4, [5, 6]),
5: new Entity("Entity Entity 2.1", 5),
6: new Entity("Entity Entity 2.2", 6, [7]),
7: new Entity("Entity Entity 2.2.1", 7, [8, 9]),
8: new Entity("Entity Entity 2.2.1.1", 8),
9: new Entity("Entity Entity 2.2.1.2", 9)
};
export default function EntityHierarchyWindow(props: IDockviewPanelProps)
{
const [entities, updateEntities] = useImmer(entityHierarchy);
return (
<>
>
);
}
function EntityTreeItem({item, allEntities, updateEntities}: {
item: Entity,
allEntities: EntityMap, updateEntities: Updater}) : ReactElement
{
//const [isOpen, setOpen] = useState(false);
const isSelected = allEntities.selectedIds.includes(item.id);
//const isVisible = allEntities[item.id].visible;
function handleClick(event: MouseEvent)
{
console.log("Clicked" + item.name);
updateEntities(draft => {
if (isSelected)
{
draft.selectedIds = allEntities.selectedIds.filter((id) => {return id != item.id});
}
else
{
draft.selectedIds.push(item.id);
}
});
event.stopPropagation();
}
function toggleVisibility(event: MouseEvent)
{
event.stopPropagation();
// updateEntities(draft => {
// draft[item.id].visible = !draft[item.id].visible;
// });
//event.stopPropagation();
}
return (
{
item.children.length > 0 &&
{
item.children.map((childId) => {
const entity: Entity = allEntities[childId];
if (entity === undefined)
return;
return ;
})
}
}
);
}
function VisibilityToggle({item, onClick, updateEntities} : {item: Entity, onClick: MouseEventHandler, updateEntities: Updater}) {
function clickHandler(event: MouseEvent)
{
updateEntities(draft => {
draft[item.id].visible = !item.visible;
});
console.log("Clickidy" + item.visible);
onClick(event);
event.stopPropagation();
}
return (
);
}
function EntityTree({items, updateItems}: { items: EntityMap, updateItems: Updater })
{
return (
{
items[0].children.map((childId) => {
const entity: Entity = items[childId];
return ;
})
}
);
}