"use strict";
exports.id = 225;
exports.ids = [225];
exports.modules = {

/***/ 1225:
/***/ ((module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (/* binding */ PostTable)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2322);
/* harmony import */ var _cromwell_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1815);
/* harmony import */ var _cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4536);
/* harmony import */ var _mui_material__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5692);
/* harmony import */ var _mui_material__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_mui_material__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6689);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var _components_entity_entityTable_EntityTable__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(256);
/* harmony import */ var _constants_PageInfos__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(379);
/* harmony import */ var _helpers_customEntities__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(4531);
/* harmony import */ var _helpers_time__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(1454);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_components_entity_entityTable_EntityTable__WEBPACK_IMPORTED_MODULE_5__, _helpers_customEntities__WEBPACK_IMPORTED_MODULE_7__, _helpers_time__WEBPACK_IMPORTED_MODULE_8__]);
([_components_entity_entityTable_EntityTable__WEBPACK_IMPORTED_MODULE_5__, _helpers_customEntities__WEBPACK_IMPORTED_MODULE_7__, _helpers_time__WEBPACK_IMPORTED_MODULE_8__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);









function PostTable() {
    const client = (0,_cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_2__.getGraphQLClient)();
    const [users, setUsers] = (0,react__WEBPACK_IMPORTED_MODULE_4__.useState)(null);
    const [tags, setTags] = (0,react__WEBPACK_IMPORTED_MODULE_4__.useState)(null);
    const ellipsisStyle = {
        whiteSpace: "nowrap",
        overflow: "hidden",
        textOverflow: "ellipsis"
    };
    const getUsers = async ()=>{
        const authors = await client.getUsers({
            pagedParams: {
                pageSize: 10000
            },
            filterParams: {
                permissions: [
                    "create_post",
                    "update_post",
                    "all"
                ]
            }
        }).catch((err)=>{
            console.error(err);
            return undefined;
        });
        setUsers(authors?.elements ?? []);
    };
    const getPostTags = async ()=>{
        const data = (await client?.getTags({
            pagedParams: {
                pageSize: 10000
            }
        }).catch((err)=>{
            console.error(err);
            return undefined;
        }))?.elements;
        setTags(data?.sort((a, b)=>a.name < b.name ? -1 : 1) ?? []);
    };
    (0,react__WEBPACK_IMPORTED_MODULE_4__.useEffect)(()=>{
        getUsers();
        getPostTags();
    }, []);
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_entity_entityTable_EntityTable__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
        entityCategory: _cromwell_core__WEBPACK_IMPORTED_MODULE_1__.EDBEntity.Post,
        entityListRoute: _constants_PageInfos__WEBPACK_IMPORTED_MODULE_6__/* .postListInfo.route */ .pv.route,
        entityBaseRoute: _constants_PageInfos__WEBPACK_IMPORTED_MODULE_6__/* .postPageInfo.baseRoute */ .QW.baseRoute,
        listLabel: "Posts",
        entityLabel: "Post",
        nameProperty: "title",
        getMany: client.getPosts,
        deleteOne: client.deletePost,
        deleteMany: client.deleteManyPosts,
        columns: [
            {
                name: "mainImage",
                label: "Image",
                type: "Image",
                visible: true
            },
            {
                name: "title",
                label: "Title",
                type: "Simple text",
                visible: true,
                minWidth: "25%",
                width: "25%"
            },
            {
                name: "author",
                label: "Author",
                type: "Simple text",
                visible: true,
                customGraphQlFragment: "author {\n id\n fullName\n }\n",
                getValueView: (value)=>/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("p", {
                        style: ellipsisStyle,
                        children: value?.fullName
                    }),
                searchOptions: users?.map((user)=>({
                        value: user.id,
                        label: user.fullName
                    })) ?? [],
                applyFilter: (value, filter)=>{
                    filter.authorId = value;
                    return filter;
                }
            },
            {
                name: "published",
                label: "Status",
                type: "Simple text",
                visible: true,
                exactSearch: true,
                searchOptions: [
                    {
                        label: "Published",
                        value: true
                    },
                    {
                        label: "Draft",
                        value: false
                    }
                ],
                getValueView: (value)=>/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("p", {
                        style: ellipsisStyle,
                        children: value ? "Published" : "Draft"
                    })
            },
            {
                name: "publishDate",
                label: "Published at",
                type: "Datetime",
                visible: true,
                getValueView: (value)=>(0,_helpers_time__WEBPACK_IMPORTED_MODULE_8__/* .formatTimeAgo */ .BK)(value)
            },
            {
                name: "tags",
                label: "Tags",
                type: "Simple text",
                visible: true,
                disableSort: true,
                customGraphQlFragment: "tags {\n id\n name\n }\n",
                getValueView: (tags)=>{
                    const text = tags?.map((tag)=>tag.name)?.join(", ") ?? "";
                    if (!text) return "";
                    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_material__WEBPACK_IMPORTED_MODULE_3__.Tooltip, {
                        title: text,
                        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("p", {
                            style: ellipsisStyle,
                            children: text
                        })
                    });
                },
                multipleOptions: true,
                searchOptions: tags?.map((tag)=>({
                        value: tag.id,
                        label: tag.name
                    })) ?? [],
                applyFilter: (value, filter)=>{
                    let ids = [];
                    if (typeof value === "string") {
                        try {
                            ids = JSON.parse(value);
                        } catch (error) {
                            console.error(error);
                        }
                    }
                    if (typeof value === "number") {
                        ids.push(value);
                    }
                    filter.tagIds = ids;
                    return filter;
                }
            },
            ..._helpers_customEntities__WEBPACK_IMPORTED_MODULE_7__/* .baseEntityColumns.map */ .xz.map((col)=>{
                if (col.name === "createDate") return {
                    ...col,
                    visible: true
                };
                return {
                    ...col,
                    visible: false
                };
            })
        ]
    });
}

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });

/***/ })

};
;