"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_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 index_1 = require("@/components/index");
const index_2 = require("@/constants/index");
const system_1 = require("@/pages/system");
const index_3 = require("@/utils/index");
const IdLabel = styled_components_1.default.div `
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: rgba(0, 0, 0, 0.75);
  margin-top: 8px;
`;
const ProjectContentList = (props) => {
    const { type, loading, fileDetail, contentList, extendRecord, deleteContent, openDrawer, openAuthDrawer, } = props;
    // url search params
    const { pathname, search, applicationId, folderId, fileId } = (0, index_3.getLocationIfo)((0, react_router_dom_1.useLocation)());
    // i18n
    const { locale } = (0, react_1.useContext)(system_1.GlobalContext);
    const { global, content, version } = locale.business;
    const handleAuthorize = (open, content) => {
        if (typeof openAuthDrawer === 'function') {
            openAuthDrawer(open, content);
        }
    };
    const authorizeAdmin = (0, react_1.useMemo)(() => type === 'personal' || type === 'application', [type]);
    const columns = [
        {
            title: global.nameLabel,
            dataIndex: 'title',
            render: (text, record) => {
                var _a;
                return (react_1.default.createElement(react_1.default.Fragment, null,
                    react_1.default.createElement(index_1.NameContainer, null,
                        react_1.default.createElement(react_router_dom_1.Link, { to: {
                                pathname: '/builder',
                                search: `?applicationId=${applicationId}&folderId=${folderId}&fileId=${fileId}&contentId=${record.id}`,
                                state: { backPathname: pathname, backSearch: search },
                            } },
                            react_1.default.createElement(antd_1.Tooltip, { placement: "topLeft", mouseEnterDelay: 1, title: text },
                                react_1.default.createElement(index_1.Name, { style: { maxWidth: type === 'projects' ? 240 : 150 } }, text))),
                        (fileDetail === null || fileDetail === void 0 ? void 0 : fileDetail.type) === index_2.FileType.page && !record.isBase && ((_a = record.urls) === null || _a === void 0 ? void 0 : _a.length) > 0 && (react_1.default.createElement(antd_1.Popover, { placement: "bottom", content: react_1.default.createElement(react_1.default.Fragment, null, record.urls.map((url) => {
                                return (react_1.default.createElement("p", { key: url },
                                    react_1.default.createElement("a", { href: url, target: "_blank" }, url)));
                            })), trigger: "hover" },
                            react_1.default.createElement(icons_1.LinkOutlined, { style: { marginLeft: 6 } })))),
                    react_1.default.createElement(IdLabel, null,
                        global.idLabel,
                        ": ",
                        record.id)));
            },
        },
        {
            title: react_1.default.createElement(antd_1.Tooltip, { title: version.liveVersion }, version.name),
            dataIndex: 'version',
            key: 'version',
            width: 90,
            render: (text) => {
                return text ? react_1.default.createElement(antd_1.Tag, { color: "orange" }, text) : '';
            },
        },
        {
            title: global.locale,
            dataIndex: 'tag',
            key: 'tag',
            width: 170,
            render: (_text, record) => {
                if (record.isBase) {
                    return react_1.default.createElement(index_1.LocaleTag, { color: "blue" }, "base");
                }
                const localesTag = record.tags ? record.tags.filter((item) => item.locale) : [];
                return react_1.default.createElement(index_1.LocaleView, { locales: localesTag.map((item) => item.locale) });
            },
        },
        {
            title: global.creator,
            dataIndex: 'creator',
            key: 'creator',
            render: (_text, record) => {
                return record.creator ? record.creator.account : '--';
            },
        },
        {
            title: global.createTime,
            dataIndex: 'createTime',
            key: 'createTime',
            width: 170,
            render: (text) => (0, index_3.periodFormat)(text, 'unknown'),
        },
    ];
    if ((fileDetail === null || fileDetail === void 0 ? void 0 : fileDetail.type) === index_2.FileType.page) {
        columns.unshift({
            title: '',
            key: '',
            width: 20,
            render: (_text, record) => {
                var _a;
                if (record.isBase && ((_a = extendRecord[record.id]) === null || _a === void 0 ? void 0 : _a.length)) {
                    return react_1.default.createElement(index_1.BasicTemRing, null);
                }
                if (record.extendId) {
                    return (react_1.default.createElement(react_1.default.Fragment, null,
                        react_1.default.createElement(index_1.Ring, null),
                        react_1.default.createElement(index_1.VLine, null)));
                }
                return react_1.default.createElement(react_1.default.Fragment, null);
            },
        });
    }
    if (authorizeAdmin) {
        columns.push({
            title: global.actions,
            key: '',
            width: 130,
            render: (_text, record) => {
                var _a;
                return (react_1.default.createElement(react_1.default.Fragment, null,
                    react_1.default.createElement(antd_1.Button, { type: "default", size: "small", shape: "circle", title: global.edit, onClick: () => openDrawer(true, record) },
                        react_1.default.createElement(icons_1.EditOutlined, null)),
                    react_1.default.createElement(antd_1.Popconfirm, { title: `${content.deleteMessage} ${record.title}?`, onConfirm: () => {
                            if (applicationId && fileId && fileDetail) {
                                deleteContent({
                                    applicationId,
                                    id: record.id,
                                    status: true,
                                    fileId,
                                    fileType: fileDetail.type,
                                });
                            }
                        }, okText: global.yes, cancelText: global.no },
                        react_1.default.createElement(index_1.DeleteButton, { type: "default", size: "small", shape: "circle", title: global.remove, style: { marginLeft: 8 }, disabled: !!(record.isBase && ((_a = extendRecord[record.id]) === null || _a === void 0 ? void 0 : _a.length)) })),
                    react_1.default.createElement(antd_1.Button, { type: "default", size: "small", shape: "circle", title: global.userPermission, onClick: () => handleAuthorize(true, record) },
                        react_1.default.createElement(icons_1.UserOutlined, null))));
            },
        });
    }
    return (react_1.default.createElement(antd_1.Table, { rowKey: "id", loading: loading, pagination: false, columns: columns, dataSource: contentList }));
};
exports.default = ProjectContentList;
