import {buildMenuTree} from "./buildMenuTree.ts";
import type {AuthorRoleMenuFormItem} from "../type/authorRoleMenu.types.ts";
import {AuthorRoleMenuTreeItem} from "./AuthorRoleMenuTreeItem.tsx";

type Props = {
    items: AuthorRoleMenuFormItem[];
    isChecked: (menuNo: AuthorRoleMenuFormItem["menuNo"]) => boolean;
    onCheck: (menuNo: AuthorRoleMenuFormItem["menuNo"], checked: boolean) => void;
};

export const AuthorRoleMenuDetailTable = ({
                                              items,
                                              isChecked,
                                              onCheck,
                                          }: Props) => {

    const tree = buildMenuTree(items);

    return (
        <div className={"tree"}>

            <div className={"tree_title"}>
                메뉴목록
            </div>

            <div className={"tree_body"}>

                {tree.map((node) => (
                    <AuthorRoleMenuTreeItem
                        key={node.menuNo}
                        node={node}
                        isChecked={isChecked}
                        onCheck={onCheck}
                    />
                ))}

            </div>

        </div>
    );
};
