import { jsx } from "react/jsx-runtime";
import { useContext } from "react";
import { SchemaOptionsContext } from "@tachybase/schema";
import { createStyles } from "antd-style";
import { get } from "lodash";
import { useACLRoleContext } from "../acl/index.mjs";
import { PinnedPluginListContext } from "./context.mjs";
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n      display: inline-block;\n      .ant-btn {\n        border: 0;\n        height: var(--tb-header-height);\n        width: 46px;\n        border-radius: 0;\n        background: none;\n        color: rgba(255, 255, 255, 0.65);\n        &:hover {\n          background: rgba(255, 255, 255, 0.1) !important;\n        }\n      }\n      .ant-float-btn {\n        margin-bottom: 16px;\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const PinnedPluginListProvider = (props)=>{
    const { children, items } = props;
    const ctx = useContext(PinnedPluginListContext);
    return /*#__PURE__*/ jsx(PinnedPluginListContext.Provider, {
        value: {
            items: {
                ...ctx.items,
                ...items
            }
        },
        children: children
    });
};
const useStyles = createStyles((param)=>{
    let { css } = param;
    return {
        container: css(_templateObject())
    };
});
const PinnedPluginList = (param)=>{
    let { belongToFilter } = param;
    const { allowAll, snippets } = useACLRoleContext();
    const getSnippetsAllow = function(aclKey) {
        let isPublic = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : false;
        return allowAll || isPublic || (null == snippets ? void 0 : snippets.includes(aclKey));
    };
    const { styles } = useStyles(belongToFilter);
    const ctx = useContext(PinnedPluginListContext);
    const { components } = useContext(SchemaOptionsContext);
    return /*#__PURE__*/ jsx("div", {
        className: styles.container,
        children: Object.keys(ctx.items).filter((key)=>ctx.items[key].belongTo === belongToFilter).sort((a, b)=>ctx.items[a].order - ctx.items[b].order).filter((key)=>getSnippetsAllow(ctx.items[key].snippet, ctx.items[key].isPublic)).map((key)=>{
            const Action = get(components, ctx.items[key].component);
            return Action ? /*#__PURE__*/ jsx(Action, {}, key) : null;
        })
    });
};
export { PinnedPluginList, PinnedPluginListProvider };
