"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 icons_1 = require("@ant-design/icons");
const antd_1 = require("antd");
const styled_components_1 = __importDefault(require("styled-components"));
const ACTIONS = __importStar(require("@/actions/applications/detail/packages/detail"));
const index_1 = require("@/constants/index");
const index_2 = require("@/utils/index");
const Avatar = (0, styled_components_1.default)(antd_1.Avatar) `
  background: rgb(253, 227, 207) !important;
  width: 64px !important;
  height: 64px !important;
  font-size: 24px !important;
  display: inline-flex !important;
  justify-content: center !important;
  align-items: center;
  color: rgb(245, 106, 0) !important;
`;
const Content = styled_components_1.default.div `
  display: inline-flex;
  flex-direction: column;
  margin-left: 12px;
  > h1 {
    font-size: 24px;
  }
  > div {
    color: rgb(112, 112, 112);
    > span {
      margin-right: 24px;
    }
  }
`;
const Name = styled_components_1.default.span `
  display: inline-block;
  margin-right: 12px;
  vertical-align: bottom;
`;
const mapStateToProps = (store) => ({
    applicationId: store.applications.detail.settings.app.applicationId,
    compInfoLoading: store.applications.detail.packages.detail.compInfoLoading,
    componentInfo: store.applications.detail.packages.detail.componentInfo,
    fileDetail: store.applications.detail.packages.detail.fileDetail,
});
const mapDispatchToProps = {
    fetchComponentInfo: ACTIONS.fetchComponentInfoAction,
};
const Main = (props) => {
    var _a;
    const { applicationId, compInfoLoading, componentInfo, fileDetail, fetchComponentInfo } = props;
    const { title = '', type = '', fileId = '', creator = {
        account: '',
    }, liveVersion = '', createTime = '', } = componentInfo || {};
    const { tags } = fileDetail || {};
    const isReference = tags && tags.find((tag) => tag.type === index_1.StoreGoodsPurchaseType.reference);
    // url params
    const { fileId: id } = (0, index_2.getLocationIfo)((0, react_router_dom_1.useLocation)());
    (0, react_1.useEffect)(() => {
        if (applicationId && id)
            fetchComponentInfo({
                applicationId,
                id,
            });
    }, [applicationId]);
    return (react_1.default.createElement(antd_1.Skeleton, { active: true, round: true, avatar: {
            shape: 'circle',
            size: 64,
        }, paragraph: {
            rows: 1,
        }, title: {
            width: 200,
        }, loading: compInfoLoading },
        react_1.default.createElement("div", { style: { display: 'flex', alignItems: 'flex-end' } },
            react_1.default.createElement(Avatar, { size: "large" }, ((_a = type.substring(0, 1)) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || ''),
            react_1.default.createElement(Content, null,
                react_1.default.createElement("h1", { style: { lineHeight: '24px', fontWeight: 'bold' } },
                    react_1.default.createElement(Name, null, title),
                    isReference && (react_1.default.createElement(antd_1.Tag, { color: index_1.suffixTagColor.refer, style: { zoom: 0.9 } }, "refer"))),
                react_1.default.createElement("div", null,
                    react_1.default.createElement(antd_1.Tooltip, { title: "File Id" },
                        react_1.default.createElement(icons_1.CodeOutlined, { style: { marginRight: 6 } }),
                        react_1.default.createElement("span", null, fileId)),
                    react_1.default.createElement(antd_1.Tooltip, { title: "Creator" },
                        react_1.default.createElement(icons_1.UserOutlined, { style: { marginRight: 6 } }),
                        react_1.default.createElement("span", null, (creator === null || creator === void 0 ? void 0 : creator.account) || '--')),
                    react_1.default.createElement(antd_1.Tooltip, { title: "Live Version" },
                        react_1.default.createElement(icons_1.TagOutlined, { style: { marginRight: 6 } }),
                        react_1.default.createElement("span", null, liveVersion || '--')),
                    react_1.default.createElement(antd_1.Tooltip, { title: "Create Time" },
                        react_1.default.createElement(icons_1.CalendarOutlined, { style: { marginRight: 6 } }),
                        react_1.default.createElement("span", null, (0, index_2.periodFormat)(createTime, 'unknown'))))))));
};
exports.default = (0, react_redux_1.connect)(mapStateToProps, mapDispatchToProps)(Main);
