exports.id = 557;
exports.ids = [557];
exports.modules = {

/***/ 9093:
/***/ ((module) => {

// Exports
module.exports = {
	"center": "Post_center__WVceg",
	"paper": "Post_paper__gOfZr",
	"styledScrollBarList": "Post_styledScrollBarList__XNjXF",
	"page": "Post_page__lFJH_",
	"pageHeader": "Post_pageHeader__Rz4FA",
	"pageContent": "Post_pageContent__ADaGl",
	"pageTitle": "Post_pageTitle__Sy3Kj",
	"customIcon": "Post_customIcon__BRZFW",
	"postTitle": "Post_postTitle__FCDnQ",
	"Post": "Post_Post__7yYAi",
	"editor": "Post_editor__zIeoB",
	"postHeader": "Post_postHeader__KIVRj",
	"headerLeft": "Post_headerLeft__YgSHM",
	"backIcon": "Post_backIcon__tAmeF",
	"notFoundPage": "Post_notFoundPage__2z7EJ",
	"notFoundText": "Post_notFoundText__upSvI",
	"publishBtn": "Post_publishBtn__0QwFD"
};


/***/ }),

/***/ 4832:
/***/ ((module) => {

// Exports
module.exports = {
	"center": "PostSettings_center__xi7RM",
	"paper": "PostSettings_paper__XaJrL",
	"styledScrollBarList": "PostSettings_styledScrollBarList__agRF8",
	"page": "PostSettings_page__kZQV3",
	"pageHeader": "PostSettings_pageHeader__NIWnV",
	"pageContent": "PostSettings_pageContent__awKyc",
	"pageTitle": "PostSettings_pageTitle__fqEtL",
	"customIcon": "PostSettings_customIcon__lHJl5",
	"popover": "PostSettings_popover__JrHaU",
	"PostSettings": "PostSettings_PostSettings__BNDLH",
	"settingItem": "PostSettings_settingItem__gDv5R",
	"headerText": "PostSettings_headerText__qB33q",
	"imageBox": "PostSettings_imageBox__uCbc7",
	"closeBtn": "PostSettings_closeBtn__w9GHk"
};


/***/ }),

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

"use strict";
__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 */ PostPage)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2322);
/* harmony import */ var _apollo_client__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9114);
/* harmony import */ var _apollo_client__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_apollo_client__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _cromwell_core__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(1815);
/* harmony import */ var _cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4536);
/* 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_entityEdit_EntityEdit__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(4342);
/* harmony import */ var _constants_PageInfos__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(379);
/* harmony import */ var _helpers_customFields__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(9143);
/* harmony import */ var _components_HeaderActions__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(3096);
/* harmony import */ var _components_PageContent__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(9803);
/* harmony import */ var _contexts_PostContext__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(8679);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_components_entity_entityEdit_EntityEdit__WEBPACK_IMPORTED_MODULE_5__, _helpers_customFields__WEBPACK_IMPORTED_MODULE_7__, _components_HeaderActions__WEBPACK_IMPORTED_MODULE_8__, _components_PageContent__WEBPACK_IMPORTED_MODULE_9__]);
([_components_entity_entityEdit_EntityEdit__WEBPACK_IMPORTED_MODULE_5__, _helpers_customFields__WEBPACK_IMPORTED_MODULE_7__, _components_HeaderActions__WEBPACK_IMPORTED_MODULE_8__, _components_PageContent__WEBPACK_IMPORTED_MODULE_9__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);











function PostPage() {
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_contexts_PostContext__WEBPACK_IMPORTED_MODULE_10__/* .PostContextProvider */ .v, {
        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(PostEdit, {})
    });
}
function PostEdit() {
    const client = (0,_cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_3__.getGraphQLClient)();
    const context = (0,react__WEBPACK_IMPORTED_MODULE_4__.useContext)(_contexts_PostContext__WEBPACK_IMPORTED_MODULE_10__/* .PostContext */ .W);
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_entity_entityEdit_EntityEdit__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z, {
        entityCategory: _cromwell_core__WEBPACK_IMPORTED_MODULE_2__.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: "",
        onSave: ()=>{
            context.hasChangesRef.current = false;
            return context.getInput();
        },
        getById: async (id)=>{
            return client.getPostById(id, _apollo_client__WEBPACK_IMPORTED_MODULE_1__.gql`
          fragment AdminPanelPostFragment on Post {
            id
            slug
            pageTitle
            pageDescription
            meta {
              keywords
            }
            createDate
            updateDate
            isEnabled
            title
            author {
              id
              fullName
              email
              avatar
            }
            mainImage
            publishDate
            featured
            tags {
              id
              slug
              name
              color
            }
            content
            delta
            published 
            customMeta (keys: ${JSON.stringify((0,_helpers_customFields__WEBPACK_IMPORTED_MODULE_7__/* .getCustomMetaKeysFor */ .He)(_cromwell_core__WEBPACK_IMPORTED_MODULE_2__.EDBEntity.Post))})
          }`, "AdminPanelPostFragment");
        },
        update: client.updatePost,
        create: client.createPost,
        deleteOne: client.deletePost,
        customElements: {
            getEntityFields: (props)=>/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_PageContent__WEBPACK_IMPORTED_MODULE_9__/* .PageContent */ .J, {
                    ...props
                }),
            getEntityHeaderCenter: (props)=>/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_HeaderActions__WEBPACK_IMPORTED_MODULE_8__/* .HeaderActions */ .k, {
                    ...props
                })
        }
    });
}

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

/***/ }),

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

"use strict";
__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "k": () => (/* binding */ HeaderActions)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2322);
/* harmony import */ var _components_buttons_IconButton__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4137);
/* harmony import */ var _components_buttons_TextButton__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2789);
/* harmony import */ var _cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4536);
/* harmony import */ var _helpers_forceUpdate__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(8673);
/* harmony import */ var _mui_icons_material__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(7915);
/* harmony import */ var _mui_icons_material__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_mui_icons_material__WEBPACK_IMPORTED_MODULE_5__);
/* harmony import */ var _mui_material__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(5692);
/* harmony import */ var _mui_material__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_mui_material__WEBPACK_IMPORTED_MODULE_6__);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(6689);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_7__);
/* harmony import */ var _contexts_PostContext__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(8679);
/* harmony import */ var _Post_module_scss__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(9093);
/* harmony import */ var _Post_module_scss__WEBPACK_IMPORTED_MODULE_10___default = /*#__PURE__*/__webpack_require__.n(_Post_module_scss__WEBPACK_IMPORTED_MODULE_10__);
/* harmony import */ var _PostSettings__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(31);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_PostSettings__WEBPACK_IMPORTED_MODULE_9__]);
_PostSettings__WEBPACK_IMPORTED_MODULE_9__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];











function HeaderActions(props) {
    const { entityData: data , isSaving , refetchMeta  } = props;
    const actionsRef = (0,react__WEBPACK_IMPORTED_MODULE_7__.useRef)(null);
    const [allTags, setAllTags] = (0,react__WEBPACK_IMPORTED_MODULE_7__.useState)(null);
    const [isUpdating, setIsUpdating] = (0,react__WEBPACK_IMPORTED_MODULE_7__.useState)(false);
    const context = (0,react__WEBPACK_IMPORTED_MODULE_7__.useContext)(_contexts_PostContext__WEBPACK_IMPORTED_MODULE_8__/* .PostContext */ .W);
    const forceUpdate = (0,_helpers_forceUpdate__WEBPACK_IMPORTED_MODULE_4__/* .useForceUpdate */ .N)();
    const getPostTags = async ()=>{
        const client = (0,_cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_3__.getGraphQLClient)();
        try {
            const data = (await client?.getTags({
                pagedParams: {
                    pageSize: 10000
                }
            }))?.elements;
            if (data && Array.isArray(data)) {
                setAllTags(data.sort((a, b)=>a.name < b.name ? -1 : 1));
            }
        } catch (e) {
            console.error(e);
        }
    };
    (0,react__WEBPACK_IMPORTED_MODULE_7__.useEffect)(()=>{
        getPostTags();
    }, []);
    const handleToggleSettings = ()=>{
        context.setSettingsOpen(!context.settingsOpen);
    };
    const handleUnpublish = async ()=>{
        setIsUpdating(true);
        const data = context.dataRef?.current;
        if (!data) {
            console.error("!context.dataRef?.current");
            return;
        }
        data.published = false;
        await props.onSave();
        setIsUpdating(false);
    };
    const handlePublish = async ()=>{
        setIsUpdating(true);
        const data = context.dataRef?.current;
        if (!data) {
            console.error("!context.dataRef?.current");
            return;
        }
        data.published = true;
        data.publishDate = new Date(Date.now());
        await props.onSave();
        setIsUpdating(false);
    };
    const handleChangeTitle = (event)=>{
        context.dataRef.current.title = event.target.value;
        forceUpdate();
    };
    return /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_mui_material__WEBPACK_IMPORTED_MODULE_6__.Box, {
        sx: {
            display: "flex",
            alignItems: "center",
            justifyContent: "space-between",
            width: "100%",
            paddingRight: "15px"
        },
        children: [
            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("input", {
                className: (_Post_module_scss__WEBPACK_IMPORTED_MODULE_10___default().postTitle),
                value: data?.title ?? "",
                onChange: handleChangeTitle
            }),
            /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(_mui_material__WEBPACK_IMPORTED_MODULE_6__.Box, {
                ref: actionsRef,
                sx: {
                    display: "flex",
                    alignItems: "center"
                },
                children: [
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_material__WEBPACK_IMPORTED_MODULE_6__.Tooltip, {
                        title: "Post meta info",
                        children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_buttons_IconButton__WEBPACK_IMPORTED_MODULE_1__/* .IconButton */ .h, {
                            onClick: handleToggleSettings,
                            style: {
                                marginRight: "10px"
                            },
                            id: "more-button",
                            children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_icons_material__WEBPACK_IMPORTED_MODULE_5__.MoreHoriz, {})
                        })
                    }),
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_PostSettings__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .Z, {
                        allTags: allTags,
                        isSettingsOpen: context.settingsOpen,
                        onClose: handleToggleSettings,
                        anchorEl: actionsRef.current,
                        isSaving: isSaving || isUpdating,
                        handleUnpublish: handleUnpublish,
                        refetchMeta: refetchMeta
                    }),
                    !data?.published && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_buttons_TextButton__WEBPACK_IMPORTED_MODULE_2__/* .TextButton */ .A, {
                        className: (_Post_module_scss__WEBPACK_IMPORTED_MODULE_10___default().publishBtn),
                        disabled: isSaving || isUpdating,
                        onClick: handlePublish,
                        children: "Publish"
                    })
                ]
            })
        ]
    });
}

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

/***/ }),

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

"use strict";
__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "J": () => (/* binding */ PageContent)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2322);
/* harmony import */ var _helpers_editor__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(7586);
/* harmony import */ var _helpers_forceUpdate__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8673);
/* 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 _contexts_PostContext__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(8679);
/* harmony import */ var _Post_module_scss__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(9093);
/* harmony import */ var _Post_module_scss__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_Post_module_scss__WEBPACK_IMPORTED_MODULE_6__);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_helpers_editor__WEBPACK_IMPORTED_MODULE_1__]);
_helpers_editor__WEBPACK_IMPORTED_MODULE_1__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];







const textPreloader = [];
for(let i = 0; i < 30; i++){
    textPreloader.push(/*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_material__WEBPACK_IMPORTED_MODULE_3__.Skeleton, {
        variant: "text",
        height: "10px",
        style: {
            margin: "3px 0"
        }
    }, i));
}
function PageContent(props) {
    const { isLoading  } = props;
    const forceUpdate = (0,_helpers_forceUpdate__WEBPACK_IMPORTED_MODULE_2__/* .useForceUpdate */ .N)();
    const editorId = "post-text-editor";
    const context = (0,react__WEBPACK_IMPORTED_MODULE_4__.useContext)(_contexts_PostContext__WEBPACK_IMPORTED_MODULE_5__/* .PostContext */ .W);
    const _initEditor = async (postContent)=>{
        await (0,_helpers_editor__WEBPACK_IMPORTED_MODULE_1__/* .initTextEditor */ .V$)({
            htmlId: editorId,
            data: postContent,
            autofocus: true,
            onChange: ()=>{
                if (!context.hasChangesRef.current) {
                    context.hasChangesRef.current = true;
                    forceUpdate();
                }
            }
        });
        context.getEditorDataRef.current = async ()=>{
            return {
                content: await (0,_helpers_editor__WEBPACK_IMPORTED_MODULE_1__/* .getEditorHtml */ .eZ)(editorId),
                delta: JSON.stringify(await (0,_helpers_editor__WEBPACK_IMPORTED_MODULE_1__/* .getEditorData */ .Hd)(editorId))
            };
        };
    };
    (0,react__WEBPACK_IMPORTED_MODULE_4__.useEffect)(()=>{
        context.dataRef.current = props.entityData;
        context.dataRef.current.title = context.dataRef.current.title ?? "Untitled";
        (async ()=>{
            try {
                await _initEditor(JSON.parse(props.entityData?.delta || "{}"));
            } catch (error) {
                console.error(error);
            }
        })();
    }, [
        props.entityData
    ]);
    return /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
        className: (_Post_module_scss__WEBPACK_IMPORTED_MODULE_6___default().Post),
        style: {
            margin: "0 0 20px 0"
        },
        children: [
            isLoading && /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, {
                children: [
                    /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_material__WEBPACK_IMPORTED_MODULE_3__.Skeleton, {
                        width: "100%",
                        height: "100px"
                    }),
                    textPreloader
                ]
            }),
            /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                className: (_Post_module_scss__WEBPACK_IMPORTED_MODULE_6___default().editor),
                id: editorId
            })
        ]
    });
}

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

/***/ }),

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

"use strict";
__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Z": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2322);
/* harmony import */ var date_fns__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4146);
/* harmony import */ var date_fns__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(date_fns__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _components_buttons_IconButton__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4137);
/* harmony import */ var _components_buttons_TextButton__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2789);
/* harmony import */ var _components_inputs_AutocompleteInput__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(8943);
/* harmony import */ var _components_inputs_DateInput_DateInput__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(8810);
/* harmony import */ var _components_inputs_SwitchInput__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(1239);
/* harmony import */ var _components_inputs_TextInput_TextInput__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(2032);
/* harmony import */ var _cromwell_core__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(1815);
/* harmony import */ var _mui_icons_material__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(7915);
/* harmony import */ var _mui_icons_material__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(_mui_icons_material__WEBPACK_IMPORTED_MODULE_9__);
/* harmony import */ var _mui_material__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(5692);
/* harmony import */ var _mui_material__WEBPACK_IMPORTED_MODULE_10___default = /*#__PURE__*/__webpack_require__.n(_mui_material__WEBPACK_IMPORTED_MODULE_10__);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(6689);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_11___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_11__);
/* harmony import */ var _components_inputs_Image_ImageInput__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(8332);
/* harmony import */ var _helpers_customFields__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(9143);
/* harmony import */ var _helpers_forceUpdate__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(8673);
/* harmony import */ var _contexts_PostContext__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(8679);
/* harmony import */ var _PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(4832);
/* harmony import */ var _PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default = /*#__PURE__*/__webpack_require__.n(_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16__);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_components_inputs_SwitchInput__WEBPACK_IMPORTED_MODULE_6__, _helpers_customFields__WEBPACK_IMPORTED_MODULE_13__]);
([_components_inputs_SwitchInput__WEBPACK_IMPORTED_MODULE_6__, _helpers_customFields__WEBPACK_IMPORTED_MODULE_13__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);

















const PostSettings = (props)=>{
    const { refetchMeta , isSettingsOpen  } = props;
    const context = (0,react__WEBPACK_IMPORTED_MODULE_11__.useContext)(_contexts_PostContext__WEBPACK_IMPORTED_MODULE_15__/* .PostContext */ .W);
    const data = context.dataRef.current;
    const forceUpdate = (0,_helpers_forceUpdate__WEBPACK_IMPORTED_MODULE_14__/* .useForceUpdate */ .N)();
    const changeValue = (key, value)=>{
        context.dataRef.current[key] = value;
        forceUpdate();
    };
    const getValue = (key)=>{
        return context.dataRef.current?.[key];
    };
    const handleChangeTags = (event, newValue)=>{
        changeValue("tags", newValue);
    };
    const handleChangeKeywords = (event, newValue)=>{
        if (!context.dataRef.current.meta) context.dataRef.current.meta = {};
        context.dataRef.current.meta.keywords = newValue;
        forceUpdate();
    };
    const handleClose = async ()=>{
        context.dataRef.current.customMeta = Object.assign({}, context.dataRef.current.customMeta, await (0,_helpers_customFields__WEBPACK_IMPORTED_MODULE_13__/* .getCustomMetaFor */ .Q7)(_cromwell_core__WEBPACK_IMPORTED_MODULE_8__.EDBEntity.Post));
        props.onClose();
    };
    const handleChangePublishDate = (newValue)=>{
        if (!newValue) {
            changeValue("publishDate", null);
            return;
        }
        const date = new Date(newValue);
        if (isNaN(date.getTime())) {
            changeValue("publishDate", null);
            return;
        }
        changeValue("publishDate", date);
    };
    const pageFullUrl = _cromwell_core__WEBPACK_IMPORTED_MODULE_8__.serviceLocator.getFrontendUrl() + (0,_cromwell_core__WEBPACK_IMPORTED_MODULE_8__.resolvePageRoute)("post", {
        slug: data?.slug ?? data?.id + ""
    });
    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_material__WEBPACK_IMPORTED_MODULE_10__.Popover, {
        disableEnforceFocus: true,
        open: isSettingsOpen,
        elevation: 0,
        anchorEl: props.anchorEl,
        onClose: handleClose,
        anchorOrigin: {
            vertical: "bottom",
            horizontal: "center"
        },
        classes: {
            paper: (_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default().popover)
        },
        transformOrigin: {
            vertical: "top",
            horizontal: "center"
        },
        children: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", {
            className: (_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default().PostSettings),
            children: [
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("p", {
                    className: (_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default().headerText),
                    children: "Post meta"
                }),
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_buttons_IconButton__WEBPACK_IMPORTED_MODULE_2__/* .IconButton */ .h, {
                    className: (_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default().closeBtn),
                    id: "post-settings-close-btn",
                    onClick: handleClose,
                    children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_icons_material__WEBPACK_IMPORTED_MODULE_9__.Close, {})
                }),
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_inputs_TextInput_TextInput__WEBPACK_IMPORTED_MODULE_7__/* .TextInput */ .o, {
                    label: "Title",
                    value: getValue("title") ?? "",
                    className: (_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default().settingItem),
                    onChange: (e)=>changeValue("title", e.target.value)
                }),
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_inputs_TextInput_TextInput__WEBPACK_IMPORTED_MODULE_7__/* .TextInput */ .o, {
                    label: "Page URL",
                    className: (_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default().settingItem),
                    value: getValue("slug") ?? "",
                    onChange: (e)=>changeValue("slug", e.target.value),
                    description: pageFullUrl
                }),
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_inputs_Image_ImageInput__WEBPACK_IMPORTED_MODULE_12__/* .ImageInput */ .a, {
                    label: "Main image",
                    onChange: (val)=>changeValue("mainImage", val),
                    value: getValue("mainImage"),
                    className: (_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default().imageBox),
                    backgroundSize: "cover",
                    showRemove: true
                }),
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_inputs_AutocompleteInput__WEBPACK_IMPORTED_MODULE_4__/* .AutocompleteInput */ .P, {
                    multiple: true,
                    className: (_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default().settingItem),
                    options: props.allTags ?? [],
                    value: getValue("tags")?.map((tag)=>(props.allTags ?? []).find((allTag)=>allTag.name === tag.name)) ?? [],
                    getOptionLabel: (option)=>typeof option === "object" ? option.name : option,
                    onChange: handleChangeTags,
                    label: "Tags"
                }),
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_inputs_DateInput_DateInput__WEBPACK_IMPORTED_MODULE_5__/* .DateInput */ .W, {
                    label: "Publish date",
                    dateType: "datetime",
                    value: getValue("publishDate"),
                    onChange: handleChangePublishDate,
                    className: (_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default().settingItem)
                }),
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_inputs_SwitchInput__WEBPACK_IMPORTED_MODULE_6__/* .SwitchInput */ .D, {
                    value: getValue("featured"),
                    onChange: ()=>changeValue("featured", !getValue("featured")),
                    className: (_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default().settingItem),
                    label: "Featured post"
                }),
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_inputs_TextInput_TextInput__WEBPACK_IMPORTED_MODULE_7__/* .TextInput */ .o, {
                    label: "Meta title",
                    className: (_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default().settingItem),
                    value: getValue("pageTitle") ?? "",
                    onChange: (e)=>changeValue("pageTitle", e.target.value)
                }),
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_inputs_TextInput_TextInput__WEBPACK_IMPORTED_MODULE_7__/* .TextInput */ .o, {
                    label: "Meta description",
                    className: (_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default().settingItem),
                    value: getValue("pageDescription") ?? "",
                    onChange: (e)=>changeValue("pageDescription", e.target.value)
                }),
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_inputs_AutocompleteInput__WEBPACK_IMPORTED_MODULE_4__/* .AutocompleteInput */ .P, {
                    multiple: true,
                    freeSolo: true,
                    options: [],
                    value: getValue("meta")?.keywords ?? [],
                    getOptionLabel: (option)=>option,
                    onChange: handleChangeKeywords,
                    label: "Meta keywords",
                    tooltip: "Press ENTER to add",
                    className: (_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default().settingItem)
                }),
                getValue("published") && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_material__WEBPACK_IMPORTED_MODULE_10__.Tooltip, {
                    title: "Remove post from publication",
                    children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_buttons_TextButton__WEBPACK_IMPORTED_MODULE_3__/* .TextButton */ .A, {
                        className: (_PostSettings_module_scss__WEBPACK_IMPORTED_MODULE_16___default().publishBtn),
                        disabled: props.isSaving,
                        onClick: props.handleUnpublish,
                        children: "Unpublish"
                    })
                }),
                /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", {
                    style: {
                        marginBottom: "15px"
                    }
                }),
                data && isSettingsOpen && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_helpers_customFields__WEBPACK_IMPORTED_MODULE_13__/* .RenderCustomFields */ ._i, {
                    entityType: _cromwell_core__WEBPACK_IMPORTED_MODULE_8__.EDBEntity.Post,
                    entityData: data,
                    refetchMeta: refetchMeta
                })
            ]
        })
    });
};
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (PostSettings);

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

/***/ }),

/***/ 8679:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

"use strict";

// EXPORTS
__webpack_require__.d(__webpack_exports__, {
  "W": () => (/* binding */ PostContext),
  "v": () => (/* binding */ PostContextProvider)
});

// EXTERNAL MODULE: ../../node_modules/react/jsx-runtime.js
var jsx_runtime = __webpack_require__(2322);
// EXTERNAL MODULE: ../core/common/dist/index.js
var dist = __webpack_require__(1815);
// EXTERNAL MODULE: external "react"
var external_react_ = __webpack_require__(6689);
var external_react_default = /*#__PURE__*/__webpack_require__.n(external_react_);
// EXTERNAL MODULE: external "react-router-dom"
var external_react_router_dom_ = __webpack_require__(4661);
;// CONCATENATED MODULE: ./src/hooks/useBlocker.ts


/**
 * Blocks all navigation attempts. This is useful for preventing the page from
 * changing until some condition is met, like saving form data.
 *
 * @param  blocker
 * @param  when
 * @see https://reactrouter.com/api/useBlocker
 */ function useBlocker(blocker, when = true) {
    const navigator = (0,external_react_.useContext)(external_react_router_dom_.UNSAFE_NavigationContext).navigator;
    (0,external_react_.useEffect)(()=>{
        if (!when) return;
        const unblock = navigator.block((tx)=>{
            const autoUnblockingTx = {
                ...tx,
                retry () {
                    // Automatically unblock the transition so it can play all the way
                    // through before retrying it. TODO: Figure out how to re-enable
                    // this block if the transition is cancelled for some reason.
                    unblock();
                    tx.retry();
                }
            };
            blocker(autoUnblockingTx);
        });
        return unblock;
    }, [
        navigator,
        blocker,
        when
    ]);
}
/**
 * Prompts the user with an Alert before they leave the current screen.
 *
 * @param  message
 * @param  when
 */ function usePrompt(message, when = true) {
    const blocker = (0,external_react_.useCallback)((tx)=>{
        // eslint-disable-next-line no-alert
        if (window.confirm(message)) tx.retry();
    }, [
        message
    ]);
    useBlocker(blocker, when);
}

;// CONCATENATED MODULE: ./src/router-pages/post/contexts/PostContext.tsx




const PostContext = /*#__PURE__*/ external_react_default().createContext({
    settingsOpen: false
});
const PostContextProvider = (props)=>{
    const [settingsOpen, setSettingsOpen] = (0,external_react_.useState)(false);
    const getEditorDataRef = (0,external_react_.useRef)(null);
    const dataRef = (0,external_react_.useRef)(null);
    const hasChangesRef = (0,external_react_.useRef)(false);
    usePrompt("Your unsaved changes will be lost. Do you want to discard and leave this page?", hasChangesRef.current);
    const getInput = async ()=>{
        const data = dataRef.current;
        if (!data || !getEditorDataRef.current) return;
        const userInfo = (0,dist.getStoreItem)("userInfo");
        const editorData = await getEditorDataRef.current();
        return {
            slug: data.slug,
            pageTitle: data.pageTitle,
            pageDescription: data.pageDescription,
            title: data.title,
            mainImage: data.mainImage,
            publishDate: data.publishDate,
            published: data.published,
            featured: data.featured,
            isEnabled: data.isEnabled,
            meta: {
                keywords: data.meta?.keywords
            },
            tagIds: data.tags?.map((tag)=>tag.id)?.filter(Boolean),
            authorId: data?.author?.id ?? userInfo?.id,
            delta: editorData.delta,
            content: editorData.content,
            customMeta: data.customMeta
        };
    };
    return /*#__PURE__*/ jsx_runtime.jsx(PostContext.Provider, {
        value: {
            settingsOpen,
            setSettingsOpen,
            getEditorDataRef,
            dataRef,
            hasChangesRef,
            getInput
        },
        children: props.children
    });
};


/***/ })

};
;