"use strict";
/*
 * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
 * This devtool is neither made for production nor for readable output files.
 * It uses "eval()" calls to create a separate source file in the browser devtools.
 * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 * or disable the default devtool with "devtool: false".
 * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 */
(self["webpackChunkwoocommerce_rtm_custom_emails"] = self["webpackChunkwoocommerce_rtm_custom_emails"] || []).push([["defaultVendors-1011~1013-9ae493a7d34d77e7630c8147e58c5e26-sanitizeDataForNewSchema.js"],{

/***/ 87235:
/*!*************************************************************************!*\
  !*** ./node_modules/@rjsf/utils/lib/schema/sanitizeDataForNewSchema.js ***!
  \*************************************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */   \"default\": () => (/* binding */ sanitizeDataForNewSchema)\n/* harmony export */ });\n/* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash/get */ 27361);\n/* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_get__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var lodash_has__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash/has */ 18721);\n/* harmony import */ var lodash_has__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_has__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../constants */ 27322);\n/* harmony import */ var _retrieveSchema__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./retrieveSchema */ 11913);\n\n\n\n\nconst NO_VALUE = Symbol('no Value');\n/** Sanitize the `data` associated with the `oldSchema` so it is considered appropriate for the `newSchema`. If the new\n * schema does not contain any properties, then `undefined` is returned to clear all the form data. Due to the nature\n * of schemas, this sanitization happens recursively for nested objects of data. Also, any properties in the old schema\n * that are non-existent in the new schema are set to `undefined`. The data sanitization process has the following flow:\n *\n * - If the new schema is an object that contains a `properties` object then:\n *   - Create a `removeOldSchemaData` object, setting each key in the `oldSchema.properties` having `data` to undefined\n *   - Create an empty `nestedData` object for use in the key filtering below:\n *   - Iterate over each key in the `newSchema.properties` as follows:\n *     - Get the `formValue` of the key from the `data`\n *     - Get the `oldKeySchema` and `newKeyedSchema` for the key, defaulting to `{}` when it doesn't exist\n *     - Retrieve the schema for any refs within each `oldKeySchema` and/or `newKeySchema`\n *     - Get the types of the old and new keyed schemas and if the old doesn't exist or the old & new are the same then:\n *       - If `removeOldSchemaData` has an entry for the key, delete it since the new schema has the same property\n *       - If type of the key in the new schema is `object`:\n *         - Store the value from the recursive `sanitizeDataForNewSchema` call in `nestedData[key]`\n *       - Otherwise, check for default or const values:\n *         - Get the old and new `default` values from the schema and check:\n *           - If the new `default` value does not match the form value:\n *             - If the old `default` value DOES match the form value, then:\n *               - Replace `removeOldSchemaData[key]` with the new `default`\n *               - Otherwise, if the new schema is `readOnly` then replace `removeOldSchemaData[key]` with undefined\n *         - Get the old and new `const` values from the schema and check:\n *           - If the new `const` value does not match the form value:\n *           - If the old `const` value DOES match the form value, then:\n *             - Replace `removeOldSchemaData[key]` with the new `const`\n *             - Otherwise, replace `removeOldSchemaData[key]` with undefined\n *   - Once all keys have been processed, return an object built as follows:\n *     - `{ ...removeOldSchemaData, ...nestedData, ...pick(data, keysToKeep) }`\n * - If the new and old schema types are array and the `data` is an array then:\n *   - If the type of the old and new schema `items` are a non-array objects:\n *     - Retrieve the schema for any refs within each `oldKeySchema.items` and/or `newKeySchema.items`\n *     - If the `type`s of both items are the same (or the old does not have a type):\n *       - If the type is \"object\", then:\n *         - For each element in the `data` recursively sanitize the data, stopping at `maxItems` if specified\n *       - Otherwise, just return the `data` removing any values after `maxItems` if it is set\n *   - If the type of the old and new schema `items` are booleans of the same value, return `data` as is\n * - Otherwise return `undefined`\n *\n * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary\n * @param rootSchema - The root JSON schema of the entire form\n * @param [newSchema] - The new schema for which the data is being sanitized\n * @param [oldSchema] - The old schema from which the data originated\n * @param [data={}] - The form data associated with the schema, defaulting to an empty object when undefined\n * @returns - The new form data, with all the fields uniquely associated with the old schema set\n *      to `undefined`. Will return `undefined` if the new schema is not an object containing properties.\n */\nfunction sanitizeDataForNewSchema(validator, rootSchema, newSchema, oldSchema, data = {}) {\n    // By default, we will clear the form data\n    let newFormData;\n    // If the new schema is of type object and that object contains a list of properties\n    if (lodash_has__WEBPACK_IMPORTED_MODULE_1___default()(newSchema, _constants__WEBPACK_IMPORTED_MODULE_2__.PROPERTIES_KEY)) {\n        // Create an object containing root-level keys in the old schema, setting each key to undefined to remove the data\n        const removeOldSchemaData = {};\n        if (lodash_has__WEBPACK_IMPORTED_MODULE_1___default()(oldSchema, _constants__WEBPACK_IMPORTED_MODULE_2__.PROPERTIES_KEY)) {\n            const properties = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(oldSchema, _constants__WEBPACK_IMPORTED_MODULE_2__.PROPERTIES_KEY, {});\n            Object.keys(properties).forEach((key) => {\n                if (lodash_has__WEBPACK_IMPORTED_MODULE_1___default()(data, key)) {\n                    removeOldSchemaData[key] = undefined;\n                }\n            });\n        }\n        const keys = Object.keys(lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(newSchema, _constants__WEBPACK_IMPORTED_MODULE_2__.PROPERTIES_KEY, {}));\n        // Create a place to store nested data that will be a side-effect of the filter\n        const nestedData = {};\n        keys.forEach((key) => {\n            const formValue = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(data, key);\n            let oldKeyedSchema = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(oldSchema, [_constants__WEBPACK_IMPORTED_MODULE_2__.PROPERTIES_KEY, key], {});\n            let newKeyedSchema = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(newSchema, [_constants__WEBPACK_IMPORTED_MODULE_2__.PROPERTIES_KEY, key], {});\n            // Resolve the refs if they exist\n            if (lodash_has__WEBPACK_IMPORTED_MODULE_1___default()(oldKeyedSchema, _constants__WEBPACK_IMPORTED_MODULE_2__.REF_KEY)) {\n                oldKeyedSchema = (0,_retrieveSchema__WEBPACK_IMPORTED_MODULE_3__[\"default\"])(validator, oldKeyedSchema, rootSchema, formValue);\n            }\n            if (lodash_has__WEBPACK_IMPORTED_MODULE_1___default()(newKeyedSchema, _constants__WEBPACK_IMPORTED_MODULE_2__.REF_KEY)) {\n                newKeyedSchema = (0,_retrieveSchema__WEBPACK_IMPORTED_MODULE_3__[\"default\"])(validator, newKeyedSchema, rootSchema, formValue);\n            }\n            // Now get types and see if they are the same\n            const oldSchemaTypeForKey = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(oldKeyedSchema, 'type');\n            const newSchemaTypeForKey = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(newKeyedSchema, 'type');\n            // Check if the old option has the same key with the same type\n            if (!oldSchemaTypeForKey || oldSchemaTypeForKey === newSchemaTypeForKey) {\n                if (lodash_has__WEBPACK_IMPORTED_MODULE_1___default()(removeOldSchemaData, key)) {\n                    // SIDE-EFFECT: remove the undefined value for a key that has the same type between the old and new schemas\n                    delete removeOldSchemaData[key];\n                }\n                // If it is an object, we'll recurse and store the resulting sanitized data for the key\n                if (newSchemaTypeForKey === 'object' || (newSchemaTypeForKey === 'array' && Array.isArray(formValue))) {\n                    // SIDE-EFFECT: process the new schema type of object recursively to save iterations\n                    const itemData = sanitizeDataForNewSchema(validator, rootSchema, newKeyedSchema, oldKeyedSchema, formValue);\n                    if (itemData !== undefined || newSchemaTypeForKey === 'array') {\n                        // only put undefined values for the array type and not the object type\n                        nestedData[key] = itemData;\n                    }\n                }\n                else {\n                    // Ok, the non-object types match, let's make sure that a default or a const of a different value is replaced\n                    // with the new default or const. This allows the case where two schemas differ that only by the default/const\n                    // value to be properly selected\n                    const newOptionDefault = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(newKeyedSchema, 'default', NO_VALUE);\n                    const oldOptionDefault = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(oldKeyedSchema, 'default', NO_VALUE);\n                    if (newOptionDefault !== NO_VALUE && newOptionDefault !== formValue) {\n                        if (oldOptionDefault === formValue) {\n                            // If the old default matches the formValue, we'll update the new value to match the new default\n                            removeOldSchemaData[key] = newOptionDefault;\n                        }\n                        else if (lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(newKeyedSchema, 'readOnly') === true) {\n                            // If the new schema has the default set to read-only, treat it like a const and remove the value\n                            removeOldSchemaData[key] = undefined;\n                        }\n                    }\n                    const newOptionConst = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(newKeyedSchema, 'const', NO_VALUE);\n                    const oldOptionConst = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(oldKeyedSchema, 'const', NO_VALUE);\n                    if (newOptionConst !== NO_VALUE && newOptionConst !== formValue) {\n                        // Since this is a const, if the old value matches, replace the value with the new const otherwise clear it\n                        removeOldSchemaData[key] = oldOptionConst === formValue ? newOptionConst : undefined;\n                    }\n                }\n            }\n        });\n        newFormData = Object.assign(Object.assign(Object.assign({}, data), removeOldSchemaData), nestedData);\n        // First apply removing the old schema data, then apply the nested data, then apply the old data keys to keep\n    }\n    else if (lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(oldSchema, 'type') === 'array' && lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(newSchema, 'type') === 'array' && Array.isArray(data)) {\n        let oldSchemaItems = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(oldSchema, 'items');\n        let newSchemaItems = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(newSchema, 'items');\n        // If any of the array types `items` are arrays (remember arrays are objects) then we'll just drop the data\n        // Eventually, we may want to deal with when either of the `items` are arrays since those tuple validations\n        if (typeof oldSchemaItems === 'object' &&\n            typeof newSchemaItems === 'object' &&\n            !Array.isArray(oldSchemaItems) &&\n            !Array.isArray(newSchemaItems)) {\n            if (lodash_has__WEBPACK_IMPORTED_MODULE_1___default()(oldSchemaItems, _constants__WEBPACK_IMPORTED_MODULE_2__.REF_KEY)) {\n                oldSchemaItems = (0,_retrieveSchema__WEBPACK_IMPORTED_MODULE_3__[\"default\"])(validator, oldSchemaItems, rootSchema, data);\n            }\n            if (lodash_has__WEBPACK_IMPORTED_MODULE_1___default()(newSchemaItems, _constants__WEBPACK_IMPORTED_MODULE_2__.REF_KEY)) {\n                newSchemaItems = (0,_retrieveSchema__WEBPACK_IMPORTED_MODULE_3__[\"default\"])(validator, newSchemaItems, rootSchema, data);\n            }\n            // Now get types and see if they are the same\n            const oldSchemaType = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(oldSchemaItems, 'type');\n            const newSchemaType = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(newSchemaItems, 'type');\n            // Check if the old option has the same key with the same type\n            if (!oldSchemaType || oldSchemaType === newSchemaType) {\n                const maxItems = lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(newSchema, 'maxItems', -1);\n                if (newSchemaType === 'object') {\n                    newFormData = data.reduce((newValue, aValue) => {\n                        const itemValue = sanitizeDataForNewSchema(validator, rootSchema, newSchemaItems, oldSchemaItems, aValue);\n                        if (itemValue !== undefined && (maxItems < 0 || newValue.length < maxItems)) {\n                            newValue.push(itemValue);\n                        }\n                        return newValue;\n                    }, []);\n                }\n                else {\n                    newFormData = maxItems > 0 && data.length > maxItems ? data.slice(0, maxItems) : data;\n                }\n            }\n        }\n        else if (typeof oldSchemaItems === 'boolean' &&\n            typeof newSchemaItems === 'boolean' &&\n            oldSchemaItems === newSchemaItems) {\n            // If they are both booleans and have the same value just return the data as is otherwise fall-thru to undefined\n            newFormData = data;\n        }\n        // Also probably want to deal with `prefixItems` as tuples with the latest 2020 draft\n    }\n    return newFormData;\n}\n//# sourceMappingURL=sanitizeDataForNewSchema.js.map\n\n//# sourceURL=webpack://woocommerce-rtm-custom-emails/./node_modules/@rjsf/utils/lib/schema/sanitizeDataForNewSchema.js?");

/***/ })

}]);