import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_dayjs__ from "dayjs";
import * as __WEBPACK_EXTERNAL_MODULE_dayjs_plugin_relativeTime__ from "dayjs/plugin/relativeTime";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__ from "../../api-client/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__PluginDocument_mjs__ from "./PluginDocument.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__style_mjs__ from "./style.mjs";
__WEBPACK_EXTERNAL_MODULE_dayjs__["default"].extend(__WEBPACK_EXTERNAL_MODULE_dayjs_plugin_relativeTime__["default"]);
const PluginDetail = (param)=>{
    let { plugin, onCancel } = param;
    var _data_data, _data_data1, _data_data2, _data_data3, _data_data4, _data_data5, _data_data6, _data_data7, _data_data8, _data_data9;
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const dependenciesCompatibleTableColumns = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>[
            {
                title: t('Name'),
                dataIndex: 'name',
                key: 'name'
            },
            {
                title: t('Version range'),
                dataIndex: 'versionRange',
                key: 'versionRange'
            },
            {
                title: t("Plugin's version"),
                dataIndex: 'packageVersion',
                key: 'packageVersion'
            },
            {
                title: t('Result'),
                dataIndex: 'result',
                key: 'result',
                render: (result)=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Tag, {
                        color: result ? 'success' : 'error',
                        children: result ? 'Yes' : 'No'
                    })
            }
        ], [
        t
    ]);
    const { data, loading } = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useRequest)({
        url: "pm:get",
        params: {
            filterByTk: plugin.name
        }
    }, {
        refreshDeps: [
            plugin.name
        ],
        ready: !!plugin.name
    });
    const repository = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
        var _data_data_packageJson, _data_data, _data_data1;
        if (!(null == data ? void 0 : null === (_data_data = data.data) || void 0 === _data_data ? void 0 : null === (_data_data_packageJson = _data_data.packageJson) || void 0 === _data_data_packageJson ? void 0 : _data_data_packageJson.repository)) return null;
        const repository = null == data ? void 0 : null === (_data_data1 = data.data) || void 0 === _data_data1 ? void 0 : _data_data1.packageJson.repository;
        const url = 'string' == typeof repository ? repository : repository.url;
        return url.replace(/\.git$/, '').replace(/^git\+/, '');
    }, [
        data
    ]);
    const author = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
        var _data_data;
        const author = null == data ? void 0 : null === (_data_data = data.data) || void 0 === _data_data ? void 0 : _data_data.packageJson.author;
        if (!author) return null;
        if ('string' == typeof author) return author;
        return author.name;
    }, [
        data
    ]);
    const { styles, theme } = (0, __WEBPACK_EXTERNAL_MODULE__style_mjs__.useStyles)();
    const tabItems = [
        {
            key: 'readme',
            label: t('Readme'),
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_antd__.Row, {
                gutter: 20,
                children: [
                    plugin.name && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Col, {
                        span: 12,
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                            className: styles.PluginDetailBaseInfo,
                            children: [
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    type: "secondary",
                                    children: t('Name')
                                }),
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    strong: true,
                                    children: plugin.name
                                })
                            ]
                        })
                    }),
                    plugin.displayName && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Col, {
                        span: 12,
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                            className: styles.PluginDetailBaseInfo,
                            children: [
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    type: "secondary",
                                    children: t('DisplayName')
                                }),
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    strong: true,
                                    children: plugin.displayName
                                })
                            ]
                        })
                    }),
                    /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Col, {
                        span: 24,
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                            className: styles.PluginDetailBaseInfo,
                            children: [
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    type: "secondary",
                                    children: t('PackageName')
                                }),
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    strong: true,
                                    children: plugin.packageName
                                })
                            ]
                        })
                    }),
                    repository && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Col, {
                        span: 24,
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                            className: styles.PluginDetailBaseInfo,
                            children: [
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    type: "secondary",
                                    children: t('Repository')
                                }),
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    strong: true,
                                    children: repository
                                })
                            ]
                        })
                    }),
                    (null == data ? void 0 : null === (_data_data = data.data) || void 0 === _data_data ? void 0 : _data_data.packageJson.homepage) && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Col, {
                        span: 24,
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                            className: styles.PluginDetailBaseInfo,
                            children: [
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    type: "secondary",
                                    children: t('Homepage')
                                }),
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("a", {
                                    href: null == data ? void 0 : null === (_data_data1 = data.data) || void 0 === _data_data1 ? void 0 : _data_data1.packageJson.homepage,
                                    target: "_blank",
                                    rel: "noreferrer",
                                    children: null == data ? void 0 : null === (_data_data2 = data.data) || void 0 === _data_data2 ? void 0 : _data_data2.packageJson.homepage
                                })
                            ]
                        })
                    }),
                    plugin.description && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Col, {
                        span: 24,
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                            className: styles.PluginDetailBaseInfo,
                            children: [
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    type: "secondary",
                                    children: t('Description')
                                }),
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    strong: true,
                                    children: plugin.description
                                })
                            ]
                        })
                    }),
                    (null == data ? void 0 : null === (_data_data3 = data.data) || void 0 === _data_data3 ? void 0 : _data_data3.packageJson.license) && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Col, {
                        span: 12,
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                            className: styles.PluginDetailBaseInfo,
                            children: [
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    type: "secondary",
                                    children: t('License')
                                }),
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    strong: true,
                                    children: null == data ? void 0 : null === (_data_data4 = data.data) || void 0 === _data_data4 ? void 0 : _data_data4.packageJson.license
                                })
                            ]
                        })
                    }),
                    author && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Col, {
                        span: 12,
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                            className: styles.PluginDetailBaseInfo,
                            children: [
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    type: "secondary",
                                    children: t('Author')
                                }),
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    strong: true,
                                    children: author
                                })
                            ]
                        })
                    }),
                    /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Col, {
                        span: 12,
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                            className: styles.PluginDetailBaseInfo,
                            children: [
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    type: "secondary",
                                    children: t('Last updated')
                                }),
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    strong: true,
                                    children: (0, __WEBPACK_EXTERNAL_MODULE_dayjs__["default"])(null == data ? void 0 : null === (_data_data5 = data.data) || void 0 === _data_data5 ? void 0 : _data_data5.lastUpdated).fromNow()
                                })
                            ]
                        })
                    }),
                    /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Col, {
                        span: 12,
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
                            className: styles.PluginDetailBaseInfo,
                            children: [
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    type: "secondary",
                                    children: t('Version')
                                }),
                                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                                    strong: true,
                                    children: null == plugin ? void 0 : plugin.version
                                })
                            ]
                        })
                    })
                ]
            })
        },
        {
            key: 'dependencies',
            label: t('Dependencies compatibility check'),
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
                children: (null == data ? void 0 : null === (_data_data6 = data.data) || void 0 === _data_data6 ? void 0 : _data_data6.depsCompatible) === false ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Text, {
                    type: "danger",
                    children: t('`dist/externalVersion.js` not found or failed to `require`. Please rebuild this plugin.')
                }) : /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
                    children: [
                        !(null == data ? void 0 : null === (_data_data7 = data.data) || void 0 === _data_data7 ? void 0 : _data_data7['isCompatible']) && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Alert, {
                            showIcon: true,
                            type: 'error',
                            message: t('Plugin dependencies check failed, you should change the dependent version to meet the version requirements.')
                        }),
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Table, {
                            style: {
                                marginTop: theme.margin
                            },
                            rowKey: 'name',
                            pagination: false,
                            columns: dependenciesCompatibleTableColumns,
                            dataSource: null == data ? void 0 : null === (_data_data8 = data.data) || void 0 === _data_data8 ? void 0 : _data_data8.depsCompatible
                        })
                    ]
                })
            })
        },
        {
            key: 'changelog',
            label: t('Changelog'),
            children: (null == plugin ? void 0 : plugin.changelogUrl) ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__PluginDocument_mjs__.PluginDocument, {
                url: null == plugin ? void 0 : plugin.changelogUrl
            }) : t('No CHANGELOG.md file')
        }
    ];
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Modal, {
        open: !!plugin,
        footer: false,
        destroyOnClose: true,
        width: 600,
        onCancel: onCancel,
        children: loading ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Spin, {}) : plugin && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
            children: [
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Typography.Title, {
                    level: 3,
                    children: plugin.packageName
                }),
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_antd__.Space, {
                    split: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("span", {
                        children: "\xa0•\xa0"
                    }),
                    children: [
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("span", {
                            children: plugin.version
                        }),
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("span", {
                            children: [
                                t('Last updated'),
                                " ",
                                (0, __WEBPACK_EXTERNAL_MODULE_dayjs__["default"])(null == data ? void 0 : null === (_data_data9 = data.data) || void 0 === _data_data9 ? void 0 : _data_data9.lastUpdated).fromNow()
                            ]
                        })
                    ]
                }),
                /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Tabs, {
                    style: {
                        minHeight: '50vh'
                    },
                    items: tabItems,
                    defaultActiveKey: plugin.isCompatible ? void 0 : 'dependencies'
                })
            ]
        })
    });
};
export { PluginDetail };
