"use strict";
exports.id = 982;
exports.ids = [982];
exports.modules = {

/***/ 1134:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "UB": () => (/* reexport safe */ _Confirmation__WEBPACK_IMPORTED_MODULE_0__.UB)
/* harmony export */ });
/* harmony import */ var _Confirmation__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1571);
/* harmony import */ var _Modal__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(248);




/***/ }),

/***/ 5976:
/***/ ((module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "A": () => (/* reexport safe */ _toast__WEBPACK_IMPORTED_MODULE_0__.A)
/* harmony export */ });
/* harmony import */ var _toast__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9035);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_toast__WEBPACK_IMPORTED_MODULE_0__]);
_toast__WEBPACK_IMPORTED_MODULE_0__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];


__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });

/***/ }),

/***/ 4982:
/***/ ((module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (/* binding */ PluginList)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2322);
/* harmony import */ var _components_buttons_IconButton__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4137);
/* harmony import */ var _components_entity_entityTable_components_EntityTableItem_module_scss__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(6382);
/* harmony import */ var _components_entity_entityTable_components_EntityTableItem_module_scss__WEBPACK_IMPORTED_MODULE_13___default = /*#__PURE__*/__webpack_require__.n(_components_entity_entityTable_components_EntityTableItem_module_scss__WEBPACK_IMPORTED_MODULE_13__);
/* harmony import */ var _components_entity_entityTable_EntityTable__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(256);
/* harmony import */ var _components_modal__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(1134);
/* harmony import */ var _components_toast__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5976);
/* harmony import */ var _constants_PageInfos__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(379);
/* harmony import */ var _cromwell_core__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(1815);
/* harmony import */ var _cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(4536);
/* harmony import */ var _heroicons_react_24_outline__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(2135);
/* harmony import */ var _heroicons_react_24_outline__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(_heroicons_react_24_outline__WEBPACK_IMPORTED_MODULE_8__);
/* harmony import */ var _heroicons_react_24_solid__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(8802);
/* harmony import */ var _heroicons_react_24_solid__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(_heroicons_react_24_solid__WEBPACK_IMPORTED_MODULE_9__);
/* harmony import */ var _mui_material__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(5692);
/* harmony import */ var _mui_material__WEBPACK_IMPORTED_MODULE_10___default = /*#__PURE__*/__webpack_require__.n(_mui_material__WEBPACK_IMPORTED_MODULE_10__);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(6689);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_11___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_11__);
/* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(4661);
/* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_12___default = /*#__PURE__*/__webpack_require__.n(react_router_dom__WEBPACK_IMPORTED_MODULE_12__);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_components_entity_entityTable_EntityTable__WEBPACK_IMPORTED_MODULE_2__, _components_toast__WEBPACK_IMPORTED_MODULE_4__]);
([_components_entity_entityTable_EntityTable__WEBPACK_IMPORTED_MODULE_2__, _components_toast__WEBPACK_IMPORTED_MODULE_4__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);














function PluginList() {
    const graphQLClient = (0,_cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_7__.getGraphQLClient)();
    const [isPageLoading, setIsPageLoading] = (0,react__WEBPACK_IMPORTED_MODULE_11__.useState)(false);
    const pluginsResolver = react__WEBPACK_IMPORTED_MODULE_11___default().useRef();
    const pluginsPromise = react__WEBPACK_IMPORTED_MODULE_11___default().useRef(new Promise((done)=>{
        pluginsResolver.current = done;
    }));
    const getPlugins = async ()=>{
        try {
            const [pluginPackages, pluginEntities] = await Promise.all([
                // Read node_modules and get packages
                (0,_cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_7__.getRestApiClient)().getPluginList(),
                // Get info from DB
                graphQLClient.getAllEntities("Plugin", graphQLClient.PluginFragment, "PluginFragment")
            ]);
            return pluginPackages?.map((pckg)=>{
                const pluginEntity = pluginEntities?.find((ent)=>ent.name === pckg.name);
                return {
                    id: `?pluginName=${pckg.name}`,
                    package: pckg,
                    entity: pluginEntity
                };
            }).sort((a, b)=>{
                if (!a.entity || !b.entity) return 0;
                return new Date(b.entity.createDate).getTime() - new Date(a.entity.createDate).getTime();
            });
        } catch (e) {
            console.error(e);
        }
    };
    (0,react__WEBPACK_IMPORTED_MODULE_11__.useEffect)(()=>{
        getPlugins().then(pluginsResolver.current).catch((error)=>{
            console.error(error);
            pluginsResolver.current?.([]);
        });
    }, []);
    const reloadPlugins = ()=>{
        pluginsPromise.current = new Promise((done)=>{
            getPlugins().then((plugins)=>done(plugins ?? [])).catch((error)=>{
                console.error(error);
                done([]);
            });
        });
        return pluginsPromise.current;
    };
    const handleActivatePlugin = async (pluginName)=>{
        if (isPageLoading) return;
        setIsPageLoading(true);
        let success = false;
        try {
            success = await (0,_cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_7__.getRestApiClient)()?.activatePlugin(pluginName);
            await this.getPluginList();
        } catch (e) {
            console.error(e);
        }
        await reloadPlugins();
        setIsPageLoading(false);
        if (success) {
            _components_toast__WEBPACK_IMPORTED_MODULE_4__/* .toast.success */ .A.success("Plugin installed");
        } else {
            _components_toast__WEBPACK_IMPORTED_MODULE_4__/* .toast.error */ .A.error("Failed to install plugin");
        }
    };
    const handleDeletePlugin = (info)=>async ()=>{
            const positive = await (0,_components_modal__WEBPACK_IMPORTED_MODULE_3__/* .askConfirmation */ .UB)({
                title: `Delete plugin ${info.title ?? info.name}?`
            });
            if (!positive) return;
            const pluginName = info.name;
            setIsPageLoading(true);
            try {
                await (0,_cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_7__.getRestApiClient)().deletePlugin(pluginName);
                _components_toast__WEBPACK_IMPORTED_MODULE_4__/* .toast.info */ .A.info("Plugin deleted");
            } catch (error) {
                console.error(error);
                _components_toast__WEBPACK_IMPORTED_MODULE_4__/* .toast.error */ .A.error("Failed to delete plugin");
            }
            await reloadPlugins();
            setIsPageLoading(false);
        };
    return /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_mui_material__WEBPACK_IMPORTED_MODULE_10__.Box, {
        sx: {
            position: "relative",
            height: "100%"
        },
        children: [
            isPageLoading && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                className: "flex flex-row h-full w-full top-0 left-0 z-30 absolute backdrop-filter backdrop-blur-md items-center",
                children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_heroicons_react_24_solid__WEBPACK_IMPORTED_MODULE_9__.ArrowPathIcon, {
                    className: "bg-white rounded-full mx-auto h-16 p-2 animate-spin fill-indigo-600 w-16 self-center"
                })
            }),
            !isPageLoading && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_entity_entityTable_EntityTable__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z, {
                entityCategory: _cromwell_core__WEBPACK_IMPORTED_MODULE_6__.EDBEntity.Plugin,
                listLabel: "Plugins",
                entityLabel: "Plugin",
                hideDelete: true,
                getMany: async ()=>{
                    const plugins = await pluginsPromise.current;
                    return {
                        pagedMeta: {
                            pageNumber: 1,
                            pageSize: plugins.length,
                            totalPages: 1,
                            totalElements: plugins.length
                        },
                        elements: plugins
                    };
                },
                columns: [
                    {
                        name: "Icon",
                        label: "Icon",
                        type: "Image",
                        visible: true,
                        disableSearch: true,
                        disableSort: true,
                        disableTooltip: true,
                        getValueView: (value, plugin)=>{
                            const pluginIcon = plugin?.package?.icon;
                            return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_material__WEBPACK_IMPORTED_MODULE_10__.Box, {
                                sx: {
                                    maxWidth: "42px",
                                    minWidth: "42px",
                                    width: "100%",
                                    height: "50px",
                                    padding: "8px 0"
                                },
                                children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                                    className: (_components_entity_entityTable_components_EntityTableItem_module_scss__WEBPACK_IMPORTED_MODULE_13___default().imageItem),
                                    style: {
                                        borderRadius: "0px",
                                        backgroundSize: "contain",
                                        backgroundRepeat: "no-repeat",
                                        backgroundImage: pluginIcon ? `url("data:image/png;base64,${pluginIcon}")` : ""
                                    }
                                })
                            });
                        }
                    },
                    {
                        name: "title",
                        label: "Title",
                        type: "Simple text",
                        visible: true,
                        disableSearch: true,
                        disableSort: true,
                        getValueView: (value, plugin)=>{
                            return plugin?.package?.title;
                        },
                        getTooltipValueView: (value, plugin)=>{
                            return plugin?.package?.title;
                        }
                    },
                    {
                        name: "package",
                        label: "Package",
                        type: "Simple text",
                        visible: true,
                        disableSearch: true,
                        disableSort: true,
                        getValueView: (value, plugin)=>{
                            return plugin?.package?.name;
                        },
                        getTooltipValueView: (value, plugin)=>{
                            return plugin?.package?.name;
                        }
                    },
                    {
                        name: "version",
                        label: "Version",
                        type: "Simple text",
                        visible: true,
                        disableSearch: true,
                        disableSort: true,
                        disableTooltip: true,
                        getValueView: (value, plugin)=>{
                            return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_material__WEBPACK_IMPORTED_MODULE_10__.Typography, {
                                sx: {
                                    fontSize: "12px",
                                    color: "#666"
                                },
                                children: plugin?.package?.version
                            });
                        }
                    }
                ],
                customElements: {
                    getItemCustomActions: ({ data  })=>{
                        if (data.entity?.isUpdating) {
                            return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                                className: "flex flex-row h-full w-full top-0 left-0 z-30 absolute backdrop-filter backdrop-blur-md items-center",
                                children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_heroicons_react_24_solid__WEBPACK_IMPORTED_MODULE_9__.ArrowPathIcon, {
                                    className: "bg-white rounded-full mx-auto h-10 p-2 animate-spin fill-indigo-600 w-10 self-center"
                                })
                            });
                        }
                        return /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_mui_material__WEBPACK_IMPORTED_MODULE_10__.Box, {
                            sx: {
                                display: "flex"
                            },
                            children: [
                                !data.entity?.isInstalled && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_material__WEBPACK_IMPORTED_MODULE_10__.Tooltip, {
                                    title: "Install plugin",
                                    children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_buttons_IconButton__WEBPACK_IMPORTED_MODULE_1__/* .IconButton */ .h, {
                                        onClick: ()=>handleActivatePlugin(data.package?.name),
                                        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_heroicons_react_24_outline__WEBPACK_IMPORTED_MODULE_8__.FolderPlusIcon, {
                                            className: "h-4 w-4 text-gray-300"
                                        })
                                    })
                                }),
                                data.entity?.isInstalled && data.entity?.hasAdminBundle && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(react_router_dom__WEBPACK_IMPORTED_MODULE_12__.Link, {
                                    to: `${_constants_PageInfos__WEBPACK_IMPORTED_MODULE_5__/* .pluginPageInfo.route */ .P8.route}?pluginName=${data.package?.name}`,
                                    children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_buttons_IconButton__WEBPACK_IMPORTED_MODULE_1__/* .IconButton */ .h, {
                                        className: "ml-0",
                                        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_heroicons_react_24_outline__WEBPACK_IMPORTED_MODULE_8__.CogIcon, {
                                            className: "h-4 w-4 text-gray-300"
                                        })
                                    })
                                }),
                                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_buttons_IconButton__WEBPACK_IMPORTED_MODULE_1__/* .IconButton */ .h, {
                                    onClick: handleDeletePlugin(data.package),
                                    className: "ml-0",
                                    children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_heroicons_react_24_outline__WEBPACK_IMPORTED_MODULE_8__.TrashIcon, {
                                        "aria-label": "delete",
                                        className: "h-4 text-gray-300 w-4"
                                    })
                                })
                            ]
                        });
                    }
                }
            })
        ]
    });
}

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });

/***/ })

};
;