"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    SwitchAction: ()=>SwitchAction,
    PluginCard: ()=>PluginCard
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const icons_namespaceObject = require("@ant-design/icons");
const external_antd_namespaceObject = require("antd");
const external_classnames_namespaceObject = require("classnames");
var external_classnames_default = /*#__PURE__*/ __webpack_require__.n(external_classnames_namespaceObject);
const external_react_i18next_namespaceObject = require("react-i18next");
const external_react_router_dom_namespaceObject = require("react-router-dom");
const index_js_namespaceObject = require("../../api-client/index.js");
const external_application_index_js_namespaceObject = require("../../application/index.js");
const external_PluginDetail_js_namespaceObject = require("./PluginDetail.js");
const PluginNpmForm_js_namespaceObject = require("./PluginForm/form/PluginNpmForm.js");
const PluginUpgradeModal_js_namespaceObject = require("./PluginForm/modal/PluginUpgradeModal.js");
const external_style_js_namespaceObject = require("./style.js");
const SwitchAction = (props)=>{
    const { name, enabled, builtIn, error, isCompatible } = props;
    const api = (0, index_js_namespaceObject.useAPIClient)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { modal, message } = external_antd_namespaceObject.App.useApp();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Switch, {
        "aria-label": "enable",
        size: 'small',
        disabled: builtIn || error,
        onChange: async (checked, e)=>{
            e.stopPropagation();
            if (!isCompatible && checked) {
                message.error(t("Dependencies check failed, can't enable."));
                return;
            }
            if (checked) await api.request({
                url: "pm:enable",
                params: {
                    filterByTk: name
                }
            });
            else modal.confirm({
                title: t('Are you sure to disable this plugin?'),
                onOk: async ()=>{
                    await api.request({
                        url: "pm:disable",
                        params: {
                            filterByTk: name
                        }
                    });
                }
            });
        },
        checked: !!enabled
    }, 'enable');
};
function PluginInfo(props) {
    const { data, onClick } = props;
    const app = (0, external_application_index_js_namespaceObject.useApp)();
    const { name, displayName, isCompatible, packageName, updatable, builtIn, enabled, description, error, homepage } = data;
    const { styles, theme } = (0, external_style_js_namespaceObject.useStyles)();
    const navigate = (0, external_react_router_dom_namespaceObject.useNavigate)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const api = (0, index_js_namespaceObject.useAPIClient)();
    const { modal, message } = external_antd_namespaceObject.App.useApp();
    const [showUploadForm, setShowUploadForm] = (0, external_react_namespaceObject.useState)(false);
    const title = displayName || name || packageName;
    const quickUpdate = ()=>{
        api.request({
            url: 'pm:update',
            method: 'post',
            data: {
                name,
                packageName,
                registry: PluginNpmForm_js_namespaceObject.NPM_REGISTRY_ADDRESS
            }
        });
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
        children: [
            showUploadForm && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(PluginUpgradeModal_js_namespaceObject.PluginUpgradeModal, {
                isShow: showUploadForm,
                pluginData: data,
                onClose: (isRefresh)=>{
                    setShowUploadForm(false);
                }
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Card, {
                role: "button",
                "aria-label": title,
                size: 'small',
                bordered: false,
                onClick: ()=>{
                    error || onClick();
                },
                headStyle: {
                    border: 'none',
                    minHeight: 'inherit',
                    paddingTop: 14
                },
                bodyStyle: {
                    paddingTop: 10
                },
                title: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                    children: title
                }),
                hoverable: true,
                className: styles.card,
                actions: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Space, {
                        split: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Divider, {
                            type: "vertical"
                        }),
                        children: [
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("a", {
                                href: homepage,
                                target: "_blank",
                                onClick: (event)=>{
                                    event.stopPropagation();
                                },
                                rel: "noreferrer",
                                children: [
                                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.ReadOutlined, {}),
                                    " ",
                                    t('Docs')
                                ]
                            }, '5'),
                            updatable && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
                                children: [
                                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("a", {
                                        onClick: (e)=>{
                                            e.stopPropagation();
                                            setShowUploadForm(true);
                                        },
                                        children: [
                                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.ReloadOutlined, {}),
                                            " ",
                                            t('Update')
                                        ]
                                    }, '3'),
                                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("a", {
                                        onClick: (e)=>{
                                            e.stopPropagation();
                                            quickUpdate();
                                        },
                                        children: [
                                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.ClockCircleOutlined, {}),
                                            " ",
                                            t('Quick Update')
                                        ]
                                    })
                                ]
                            }),
                            enabled ? app.systemSettingsManager.has(name) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("a", {
                                onClick: (e)=>{
                                    e.stopPropagation();
                                    navigate(app.systemSettingsManager.getRoutePath(name));
                                },
                                children: [
                                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.SettingOutlined, {}),
                                    " ",
                                    t('Settings')
                                ]
                            }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Popconfirm, {
                                disabled: builtIn,
                                title: t('Are you sure to delete this plugin?'),
                                onConfirm: async (e)=>{
                                    e.stopPropagation();
                                    api.request({
                                        url: "pm:remove",
                                        params: {
                                            filterByTk: name
                                        }
                                    });
                                },
                                onCancel: (e)=>e.stopPropagation(),
                                okText: t('Yes'),
                                cancelText: t('No'),
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("a", {
                                    onClick: (e)=>{
                                        e.stopPropagation();
                                    },
                                    className: external_classnames_default()({
                                        [styles.cardActionDisabled]: builtIn
                                    }),
                                    children: [
                                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icons_namespaceObject.DeleteOutlined, {}),
                                        " ",
                                        t('Remove')
                                    ]
                                })
                            }, 'delete')
                        ]
                    }, '1'),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Switch, {
                        "aria-label": "enable",
                        size: 'small',
                        disabled: builtIn || error,
                        onChange: async (checked, e)=>{
                            e.stopPropagation();
                            if (!isCompatible && checked) {
                                message.error(t("Dependencies check failed, can't enable."));
                                return;
                            }
                            if (checked) await api.request({
                                url: "pm:enable",
                                params: {
                                    filterByTk: name
                                }
                            });
                            else modal.confirm({
                                title: t('Are you sure to disable this plugin?'),
                                onOk: async ()=>{
                                    await api.request({
                                        url: "pm:disable",
                                        params: {
                                            filterByTk: name
                                        }
                                    });
                                }
                            });
                        },
                        checked: !!enabled
                    }, 'enable')
                ].filter(Boolean),
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Card.Meta, {
                    description: error ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Typography.Text, {
                        type: "danger",
                        children: t('Plugin loading failed. Please check the server logs.')
                    }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Typography.Paragraph, {
                        style: {
                            height: theme.fontSize * theme.lineHeight * 3
                        },
                        type: isCompatible ? 'secondary' : 'danger',
                        ellipsis: {
                            rows: 3
                        },
                        children: isCompatible ? description : t('Plugin dependencies check failed')
                    })
                })
            })
        ]
    });
}
const PluginCard = (props)=>{
    const { data } = props;
    const [plugin, setPlugin] = (0, external_react_namespaceObject.useState)(void 0);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
        children: [
            plugin && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_PluginDetail_js_namespaceObject.PluginDetail, {
                plugin: plugin,
                onCancel: ()=>setPlugin(void 0)
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(PluginInfo, {
                onClick: ()=>{
                    setPlugin(data);
                },
                data: data
            })
        ]
    });
};
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
