import{useAtomValue,useAtom}from"jotai/index";import{useEffect}from"react";import{useMount,useUnmount}from"@redocly/theme";import{getActiveMediaType}from"../../models";import{operationStore}from"../../jotai/operation";import{getAllNestedSchema}from"./getAllNestedSchema";import{activeMimeNameAtom}from"../../jotai/app";export function useUpdateExpandedFields(e,t,s,i){var o;const a=useAtomValue(activeMimeNameAtom),n=s&&(null===(o=getActiveMediaType(s,a))||void 0===o?void 0:o.schema),[{activeOneOf:m},c]=useAtom(operationStore(i)),r=(i=!1)=>{((null==t?void 0:t.length)||s)&&c((s=>{const o=getAllNestedSchema({schema:n,activeOneOf:s.activeOneOf,skipReadOnly:"request"===e,skipWriteOnly:"response"===e})||{},a=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({},o),a),i?s[e].expandedFields:{})}})}))};useMount((()=>{r(!0)})),useUnmount((()=>{((null==t?void 0:t.length)||s)&&c((t=>Object.assign(Object.assign({},t),{[e]:{expandedFields:{}}})))})),useEffect((()=>{Object.keys(m).length>1&&r(!0)}),[m])}
//# sourceMappingURL=useUpdateExpandedFields.js.map