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

/***/ 5763:
/***/ ((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 */ CategoryPage)
/* 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 react__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6689);
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _components_inputs_Search_SearchInput__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(9376);
/* harmony import */ var _components_entity_entityEdit_EntityEdit__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(4342);
/* harmony import */ var _components_entity_entityEdit_helpers__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(9198);
/* harmony import */ var _constants_PageInfos__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(379);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_components_inputs_Search_SearchInput__WEBPACK_IMPORTED_MODULE_4__, _components_entity_entityEdit_EntityEdit__WEBPACK_IMPORTED_MODULE_5__, _components_entity_entityEdit_helpers__WEBPACK_IMPORTED_MODULE_6__]);
([_components_inputs_Search_SearchInput__WEBPACK_IMPORTED_MODULE_4__, _components_entity_entityEdit_EntityEdit__WEBPACK_IMPORTED_MODULE_5__, _components_entity_entityEdit_helpers__WEBPACK_IMPORTED_MODULE_6__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);








function CategoryPage() {
    const client = (0,_cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_2__.getGraphQLClient)();
    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_1__.EDBEntity.ProductCategory,
        entityListRoute: _constants_PageInfos__WEBPACK_IMPORTED_MODULE_7__/* .categoryListPageInfo.route */ .ZE.route,
        entityBaseRoute: _constants_PageInfos__WEBPACK_IMPORTED_MODULE_7__/* .categoryPageInfo.baseRoute */ .t9.baseRoute,
        listLabel: "Categories",
        entityLabel: "Category",
        defaultPageName: "category",
        getById: client.getProductCategoryById,
        update: client.updateProductCategory,
        create: client.createProductCategory,
        deleteOne: client.deleteProductCategory,
        fields: [
            {
                key: "name",
                type: "Simple text",
                label: "Name",
                required: true
            },
            {
                key: "parent",
                type: "custom",
                customGraphQlProperty: {
                    parent: {
                        id: true,
                        slug: true
                    }
                },
                saveValue: (parent)=>{
                    return {
                        parentId: parent?.id
                    };
                },
                component: (props)=>{
                    const { onChange  } = props;
                    const category = props.entity;
                    const [parentCategory, setParentCategory] = (0,react__WEBPACK_IMPORTED_MODULE_3__.useState)(null);
                    const handleSearchRequest = async (text, params)=>{
                        return client.getProductCategories({
                            filterParams: {
                                nameSearch: text
                            },
                            pagedParams: params
                        });
                    };
                    const handleParentCategoryChange = (data)=>{
                        if (data && category && category.id === data.id) return;
                        onChange(data ?? undefined);
                    };
                    const getParentCategory = async (parentId)=>{
                        try {
                            const parent = await client.getProductCategoryById(parentId);
                            if (parent) {
                                setParentCategory(parent);
                                handleParentCategoryChange(parent);
                            }
                        } catch (e) {
                            console.error(e);
                        }
                    };
                    (0,react__WEBPACK_IMPORTED_MODULE_3__.useEffect)(()=>{
                        const urlParams = new URLSearchParams(window.location?.search);
                        const parentIdParam = urlParams.get("parentId");
                        if (parentIdParam) {
                            getParentCategory(parseInt(parentIdParam));
                        } else if (category?.parent?.id) {
                            getParentCategory(category?.parent?.id);
                        }
                    }, []);
                    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_inputs_Search_SearchInput__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z, {
                        loader: handleSearchRequest,
                        onSelect: handleParentCategoryChange,
                        getOptionLabel: (data)=>`${data.name} (id: ${data.id}${data?.parent?.id ? `; parent id: ${data.parent.id}` : ""})`,
                        getOptionValue: (data)=>data.name,
                        fullWidth: true,
                        defaultValue: parentCategory,
                        label: "Parent category"
                    });
                }
            },
            {
                key: "mainImage",
                type: "Image",
                label: "Image"
            },
            {
                key: "description",
                type: "Text editor",
                label: "Description",
                saveValue: _components_entity_entityEdit_helpers__WEBPACK_IMPORTED_MODULE_6__/* .setValueOfTextEditorField */ .al,
                getInitialValue: _components_entity_entityEdit_helpers__WEBPACK_IMPORTED_MODULE_6__/* .getInitialValueOfTextEditorField */ .Js,
                customGraphQlProperty: {
                    description: true,
                    descriptionDelta: true
                }
            }
        ]
    });
}

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

/***/ })

};
;