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

/***/ 190:
/***/ ((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 */ UserPage)
/* 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_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_addressParser__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(9177);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_components_entity_entityEdit_EntityEdit__WEBPACK_IMPORTED_MODULE_5__]);
_components_entity_entityEdit_EntityEdit__WEBPACK_IMPORTED_MODULE_5__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];








function UserPage() {
    const client = (0,_cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_2__.getGraphQLClient)();
    const [roles, setRoles] = (0,react__WEBPACK_IMPORTED_MODULE_4__.useState)([]);
    const init = async ()=>{
        try {
            const roles = await (0,_cromwell_core_frontend__WEBPACK_IMPORTED_MODULE_2__.getGraphQLClient)().getRoles({
                pagedParams: {
                    pageSize: 1000
                }
            });
            setRoles(roles?.elements ?? []);
        } catch (error) {
            console.error(error);
        }
    };
    (0,react__WEBPACK_IMPORTED_MODULE_4__.useEffect)(()=>{
        init();
    }, []);
    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.User,
        entityListRoute: _constants_PageInfos__WEBPACK_IMPORTED_MODULE_6__/* .userListPageInfo.route */ .sG.route,
        entityBaseRoute: _constants_PageInfos__WEBPACK_IMPORTED_MODULE_6__/* .userPageInfo.baseRoute */ .Uu.baseRoute,
        listLabel: "Users",
        entityLabel: "User",
        getById: client.getUserById,
        update: client.updateUser,
        create: client.createUser,
        deleteOne: client.deleteUser,
        fields: [
            {
                key: "fullName",
                type: "Simple text",
                label: "Full name",
                required: true,
                width: {
                    sm: 6
                }
            },
            {
                key: "avatar",
                type: "Image",
                label: "Avatar",
                width: {
                    sm: 6
                }
            },
            {
                key: "email",
                type: "Simple text",
                label: "Email",
                required: true,
                width: {
                    sm: 6
                }
            },
            {
                key: "password",
                type: "Simple text",
                label: "Password",
                simpleTextType: "password",
                required: true,
                onlyOnCreate: true,
                width: {
                    sm: 6
                }
            },
            {
                key: "roles",
                type: "Select",
                label: "Role",
                required: true,
                customGraphQlFragment: `roles {
              name
              permissions
              title
          }`,
                options: roles.map((role)=>({
                        label: role.title ?? role.name,
                        value: role.name
                    })),
                saveValue: (name)=>({
                        roles: name && [
                            name
                        ]
                    }),
                getInitialValue: (roles)=>roles?.[0]?.name,
                width: {
                    sm: 6
                }
            },
            {
                key: "bio",
                type: "Simple text",
                label: "Bio",
                simpleTextType: "textarea"
            },
            {
                key: "address",
                type: "Simple text",
                label: "Address",
                component: ({ value , onChange  })=>{
                    // Support old and new address format
                    const { addressString , addressJson  } = (0,_helpers_addressParser__WEBPACK_IMPORTED_MODULE_7__/* .parseAddress */ .Cy)(value);
                    if (addressJson) return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, {
                        children: Object.entries(addressJson).map(([fieldKey, value])=>{
                            return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_material__WEBPACK_IMPORTED_MODULE_3__.Grid, {
                                item: true,
                                xs: 12,
                                sm: 6,
                                children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_material__WEBPACK_IMPORTED_MODULE_3__.TextField, {
                                    label: fieldKey,
                                    value: value || "",
                                    fullWidth: true,
                                    variant: "standard",
                                    style: {
                                        margin: "10px 0"
                                    },
                                    onChange: (e)=>{
                                        const newVal = e.target.value;
                                        onChange(JSON.stringify({
                                            ...addressJson,
                                            [fieldKey]: newVal
                                        }));
                                    }
                                })
                            }, fieldKey);
                        })
                    });
                    return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_mui_material__WEBPACK_IMPORTED_MODULE_3__.TextField, {
                        label: "Address",
                        value: addressString || "",
                        fullWidth: true,
                        variant: "standard",
                        style: {
                            margin: "10px 0"
                        },
                        onChange: (e)=>{
                            onChange(e.target.value);
                        }
                    });
                }
            },
            {
                key: "phone",
                type: "Simple text",
                label: "Phone",
                width: {
                    sm: 6
                }
            }
        ]
    });
}

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

/***/ })

};
;