'use strict';
import { z } from 'zod';
import { userDisplayProps } from '../user-dto.js';
import { apiPathNames } from '../../../fd-toolbox/api/api-path-names.js';
import { apiPut, apiPost } from '../../../fd-toolbox/api/api-client.js';
import { navigate } from '../../../fd-toolbox/redirect/redirect-functions.js';
import { routes } from '../../../fd-toolbox/routing/routes.js';
import { formMessages } from '../constants/form-constants.js';
import { wellKnownUserProps } from '../../../fd-toolbox/constants/common-user-fields.js';

var __defProp=Object['defineProperty'],__name=(_0x24b664,_0x18c8d5)=>__defProp(_0x24b664,'name',{'value':_0x18c8d5,'configurable':!![]});const editUserFormModes={'add':0x0,'edit':0x1};const createValidationSchema=z['object']({'email':z['string']()['email'](formMessages['invalidEmailAdress']),'firstName':z['string']()['min'](-0x1*-0x7c4+0x1883+-0x2046,formMessages['enterFirstName']),'lastName':z['string']()['min'](0x43*0x1d+-0x2325+0x1b8f,formMessages['enterLastName']),'password':z['string']()['min'](-0x1ab3*0x1+-0xf98*0x1+0x2a51,formMessages['passwordMustBe6Characters'])['refine'](_0x52dd47=>/[A-Z]/['test'](_0x52dd47),formMessages['mustIncludeUppercase'])['refine'](_0x15dd27=>/[a-z]/['test'](_0x15dd27),formMessages['mustIncludeLowercase'])['refine'](_0x25e94e=>/[^a-zA-Z0-9]/['test'](_0x25e94e),formMessages['requiresSpecialCharacter']),'repeatPassword':z['string']()['min'](-0x1*0x1a12+-0x39*-0x15+0x1566,'Please\x20repeat\x20your\x20password'),'isDisabled':z['boolean']()})['refine'](_0x3893bf=>_0x3893bf['password']===_0x3893bf['repeatPassword'],{'message':formMessages['passwordDoNotMatch'],'path':[wellKnownUserProps['repeatPassword']]}),editValidationSchema=z['object']({'email':z['union']([z['string']()['email'](formMessages['invalidEmailAdress'])['nullish'](),z['literal']('')]),'firstName':z['string']()['min'](-0xb*-0xa6+-0x1e37+-0x7b2*-0x3,formMessages['enterFirstName']),'lastName':z['string']()['min'](-0x14dd+-0x469*-0x1+0x1075*0x1,formMessages['enterLastName']),'password':z['union']([z['string']()['min'](0x7*0x43+0x13e4+-0x15b3,formMessages['passwordMustBe6Characters'])['refine'](_0x4c4a0a=>/[A-Z]/['test'](_0x4c4a0a),formMessages['mustIncludeUppercase'])['refine'](_0x182945=>/[A-Z]/['test'](_0x182945),formMessages['mustIncludeLowercase'])['refine'](_0x5315ff=>/[^a-zA-Z0-9]/['test'](_0x5315ff),formMessages['requiresSpecialCharacter'])['nullish'](),z['literal']('')]),'repeatPassword':z['string'](),'isDisabled':z['boolean']()})['refine'](_0x548f22=>_0x548f22['password']===_0x548f22['repeatPassword'],{'message':formMessages['passwordDoNotMatch'],'path':[wellKnownUserProps['repeatPassword']]});function getUserFormMode(_0x135787){return _0x135787?editUserFormModes['edit']:editUserFormModes['add'];}__name(getUserFormMode,'getUserFormMode');function getUserHandler(_0x3fe64e){return isUserFormAddMode(_0x3fe64e)?addUser:editUser;}__name(getUserHandler,'getUserHandler');function getUserFormValidationSchema(_0x23646b){return isUserFormAddMode(_0x23646b)?createValidationSchema:editValidationSchema;}__name(getUserFormValidationSchema,'getUserFormValidationSchema');function createUserFormDataForSubmission(_0x490ce4,_0x460129){if(_0x460129?.['id'])return {..._0x460129,..._0x490ce4};return {..._0x490ce4};}__name(createUserFormDataForSubmission,'createUserFormDataForSubmission');function getUserFormDefaultFormValues(_0x45aa15){return {'firstName':_0x45aa15?.['firstName']??'','lastName':_0x45aa15?.['lastName']??'','email':_0x45aa15?.['email']??'','password':_0x45aa15?.['password']??'','repeatPassword':_0x45aa15?.['repeatPassword']??'','isDisabled':_0x45aa15?.['isDisabled']??![]};}__name(getUserFormDefaultFormValues,'getUserFormDefaultFormValues');async function onUserFormUserSubmission(_0xedebf0,_0x30f582,_0x552df1){const _0x7371f9=createUserFormDataForSubmission(_0x30f582,_0x552df1);await _0xedebf0(_0x7371f9),navigate(routes['userList']);}__name(onUserFormUserSubmission,'onUserFormUserSubmission');function onTogglePasswordVisibility(_0x34d465,_0x5a381b,_0x4d6125){_0x34d465===userDisplayProps['password']?_0x5a381b(_0x164f73=>!_0x164f73):_0x4d6125(_0x3bd7ae=>!_0x3bd7ae);}__name(onTogglePasswordVisibility,'onTogglePasswordVisibility');function isUserFormAddMode(_0x21f5c1){return _0x21f5c1===editUserFormModes['add'];}__name(isUserFormAddMode,'isUserFormAddMode');function editUser(_0x24e1f1){return apiPut(apiPathNames['otherUser'],_0x24e1f1);}__name(editUser,'editUser');function addUser(_0x5f4f8f){return apiPost(apiPathNames['otherUser'],_0x5f4f8f);}__name(addUser,'addUser');

export { createUserFormDataForSubmission, editUserFormModes, getUserFormDefaultFormValues, getUserFormMode, getUserFormValidationSchema, getUserHandler, onTogglePasswordVisibility, onUserFormUserSubmission };
