import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { FieldContext, SchemaContext } from "@tachybase/schema";
import { Card } from "antd";
import { useTranslation } from "react-i18next";
import { SortableItem } from "../../index.mjs";
import { Icon } from "../../../index.mjs";
import { DragHandleMenu } from "../../common/sortable-item/DragHandleMenu.mjs";
import { useStyles } from "./AdminMenu.style.mjs";
const AdminMenu = (props)=>{
    const { items, onClick } = props;
    const { styles } = useStyles();
    return /*#__PURE__*/ jsx(Card, {
        className: styles.adminMenuStyle,
        children: null == items ? void 0 : items.map((item)=>/*#__PURE__*/ jsx(AdminMenuCard, {
                item: item,
                onClick: onClick
            }, item.key))
    });
};
const AdminMenuCard = (props)=>{
    const { item, onClick } = props;
    const { icon, field, Designer, schema } = (null == item ? void 0 : item.menu) || {};
    const { t } = useTranslation();
    const { styles } = useStyles();
    const handleClick = ()=>onClick(item);
    return /*#__PURE__*/ jsx(Card.Grid, {
        className: styles.adminMenuCardStyle,
        onClick: handleClick,
        children: item.menu ? /*#__PURE__*/ jsx(SchemaContext.Provider, {
            value: schema,
            children: /*#__PURE__*/ jsx(FieldContext.Provider, {
                value: field,
                children: /*#__PURE__*/ jsx(SortableItem, {
                    className: "card-wrapper",
                    role: "button",
                    "aria-label": t(field.title),
                    removeParentsIfNoChildren: false,
                    overStyle: {
                        background: 'transparent'
                    },
                    children: /*#__PURE__*/ jsxs(DragHandleMenu, {
                        className: "drag-handle-menu",
                        isAdminMenu: true,
                        children: [
                            /*#__PURE__*/ jsxs("div", {
                                className: "field-link",
                                role: "button",
                                "aria-label": t(field.title),
                                title: t(field.title),
                                children: [
                                    /*#__PURE__*/ jsx("div", {
                                        className: "icon-wrapper",
                                        children: /*#__PURE__*/ jsx(Icon, {
                                            type: null != icon ? icon : 'QuestionCircleOutlined'
                                        })
                                    }),
                                    /*#__PURE__*/ jsx("div", {
                                        className: "field-title",
                                        children: t(field.title)
                                    })
                                ]
                            }),
                            /*#__PURE__*/ jsx(Designer, {
                                isAdminMenu: true
                            })
                        ]
                    })
                })
            })
        }) : /*#__PURE__*/ jsx(Fragment, {
            children: item.label
        })
    });
};
export { AdminMenu };
