"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importStar(require("react"));
const react_redux_1 = require("react-redux");
const react_router_dom_1 = require("react-router-dom");
const antd_1 = require("antd");
const styled_components_1 = __importDefault(require("styled-components"));
const ACTIONS = __importStar(require("@/actions/applications/detail/resources/detail"));
const index_1 = require("@/components/index");
const resource_1 = require("@/constants/resource");
const system_1 = require("@/pages/system");
const useRelativePathData_1 = __importDefault(require("./hooks/useRelativePathData"));
const components_1 = require("./components");
const UrlInfo = styled_components_1.default.div `
  width: calc(100% - 250px);
  padding: 20px 0 20px 24px;
`;
const UrlInfoItem = styled_components_1.default.div `
  strong {
    margin-right: 4px;
  }
`;
const mapStateToProps = (store) => ({
    storeApplicationId: store.applications.detail.settings.app.applicationId,
    groupInfo: store.applications.detail.resources.detail.groupInfo,
});
const mapDispatchToProps = {
    updateFolderPath: ACTIONS.updateFolderPath,
    fetchGroupInfo: ACTIONS.fetchGroupInfo,
};
const ResourceDetail = (props) => {
    var _a, _b, _c;
    const { storeApplicationId, groupInfo, updateFolderPath, fetchGroupInfo } = props;
    const [applicationId, setApplicationId] = (0, react_1.useState)();
    // url search params
    const { folderPath, relativePathBreadCrumb = [] } = (0, useRelativePathData_1.default)();
    const { resourceRoot } = (0, react_router_dom_1.useParams)();
    // i18n
    const { locale } = (0, react_1.useContext)(system_1.GlobalContext);
    const { global, resource, application: applicationI18n } = locale.business;
    (0, react_1.useEffect)(() => {
        if (storeApplicationId)
            setApplicationId(storeApplicationId);
    }, [storeApplicationId]);
    (0, react_1.useEffect)(() => {
        updateFolderPath(folderPath);
    }, [folderPath]);
    (0, react_1.useEffect)(() => {
        if (applicationId)
            fetchGroupInfo({
                applicationId,
                path: resourceRoot,
            });
    }, [applicationId]);
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(index_1.FoxPageContent, { breadcrumb: react_1.default.createElement(index_1.FoxPageBreadcrumb, { breadCrumb: [
                    { name: applicationI18n.applicationList, link: '/#/workspace/applications' },
                    {
                        name: resource.resourceGroup,
                        link: `/applications/${applicationId}/resources/list`,
                    },
                    ...relativePathBreadCrumb,
                ] }) },
            react_1.default.createElement(react_1.default.Fragment, null,
                react_1.default.createElement("div", { style: { display: 'flex' } },
                    react_1.default.createElement(antd_1.Card, { style: { width: 250, padding: 38, textAlign: 'center', display: 'inline-block' } },
                        react_1.default.createElement("div", null, groupInfo.name || '')),
                    react_1.default.createElement(UrlInfo, null,
                        react_1.default.createElement(UrlInfoItem, null,
                            react_1.default.createElement("strong", null,
                                resource.groupName,
                                ":"),
                            react_1.default.createElement("span", null, groupInfo.name || '')),
                        react_1.default.createElement(UrlInfoItem, null,
                            react_1.default.createElement("strong", null,
                                resource.groupInfo,
                                ":"),
                            react_1.default.createElement("span", null, groupInfo.intro || '')),
                        react_1.default.createElement(UrlInfoItem, null,
                            react_1.default.createElement("strong", null,
                                resource.groupType,
                                ":"),
                            react_1.default.createElement("span", null, resource[((_a = resource_1.ResourceTypeArray.find((item) => { var _a; return item.type === ((_a = groupInfo.group) === null || _a === void 0 ? void 0 : _a.type); })) === null || _a === void 0 ? void 0 : _a.label) ||
                                resource_1.ResourceTypeArray[0].label])),
                        react_1.default.createElement(UrlInfoItem, null,
                            react_1.default.createElement("strong", null,
                                global.host,
                                ":"),
                            react_1.default.createElement("span", null, (_c = (_b = groupInfo.group) === null || _b === void 0 ? void 0 : _b.detail) === null || _c === void 0 ? void 0 : _c.host)))),
                react_1.default.createElement(antd_1.Divider, null),
                react_1.default.createElement(components_1.ToolBar, null),
                react_1.default.createElement(components_1.List, null))),
        react_1.default.createElement(components_1.FolderDrawer, null),
        react_1.default.createElement(components_1.FileDrawer, null)));
};
exports.default = (0, react_redux_1.connect)(mapStateToProps, mapDispatchToProps)(ResourceDetail);
