"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useUpdateExpandedFields=void 0;const index_1=require("jotai/index"),react_1=require("react"),theme_1=require("@redocly/theme"),models_1=require("../../models"),operation_1=require("../../jotai/operation"),getAllNestedSchema_1=require("./getAllNestedSchema"),app_1=require("../../jotai/app");function useUpdateExpandedFields(e,t,s,i){var a;const d=(0,index_1.useAtomValue)(app_1.activeMimeNameAtom),n=s&&(null===(a=(0,models_1.getActiveMediaType)(s,d))||void 0===a?void 0:a.schema),[{activeOneOf:l},o]=(0,index_1.useAtom)((0,operation_1.operationStore)(i)),r=(i=!1)=>{((null==t?void 0:t.length)||s)&&o((s=>{const a=(0,getAllNestedSchema_1.getAllNestedSchema)({schema:n,activeOneOf:s.activeOneOf,skipReadOnly:"request"===e,skipWriteOnly:"response"===e})||{},d=(0,getAllNestedSchema_1.getAllNestedSchema)({schema:{type:"object",fields:t},activeOneOf:s.activeOneOf,skipReadOnly:"request"===e,skipWriteOnly:"response"===e});return Object.assign(Object.assign({},s),{[e]:{expandedFields:Object.assign(Object.assign(Object.assign({},a),d),i?s[e].expandedFields:{})}})}))};(0,theme_1.useMount)((()=>{r(!0)})),(0,theme_1.useUnmount)((()=>{((null==t?void 0:t.length)||s)&&o((t=>Object.assign(Object.assign({},t),{[e]:{expandedFields:{}}})))})),(0,react_1.useEffect)((()=>{Object.keys(l).length>1&&r(!0)}),[l])}exports.useUpdateExpandedFields=useUpdateExpandedFields;
//# sourceMappingURL=useUpdateExpandedFields.js.map