"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SchemaDefinition=void 0;const jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),styled_components_1=__importDefault(require("styled-components")),theme_1=require("@redocly/theme"),jotai_1=require("jotai"),use_write_atom_1=require("../../jotai/use-write-atom"),common_1=require("../common"),models_1=require("../../models"),PayloadSamples_1=require("../PayloadSamples"),Schema_1=require("../Schema"),Markdown_1=require("../Markdown"),app_1=require("../../jotai/app"),store_1=require("../../jotai/store"),operation_1=require("../../jotai/operation"),getMediaTypeInfo=(e,o)=>{if(!e)return{};const t={schema:{$ref:e}};return o&&(t.examples={example:{$ref:o}}),t};function SchemaDefinitionComponent({schemaRef:e,exampleRef:o,showReadOnly:t=!0,showWriteOnly:i=!1}){var a,r,n;const s=(0,jotai_1.useAtomValue)(app_1.layoutAtom),{parser:m,options:l}=(0,jotai_1.useAtomValue)(store_1.globalStoreAtom),c=(0,use_write_atom_1.useWriteAtom)(),_=(0,react_1.useMemo)((()=>(0,models_1.getMediaType)(m,"json",!1,getMediaTypeInfo(e,o),l,{operation:{pointer:"SchemaDefinitionComponent"}})),[o,l,m,e]),[u,p]=(0,jotai_1.useAtom)((0,operation_1.operationStore)(null===(a=_.operation)||void 0===a?void 0:a.pointer)),d=(0,react_1.useCallback)((e=>{var o,t;if(!_.schema)return;const i=_.schema,a=i.oneOf;if(a&&(null==_?void 0:_.examples)&&Object.keys(null==_?void 0:_.examples).includes(e)){const r=a.findIndex((o=>o.title===e));-1!==r&&i&&c((0,operation_1.operationStore)(i.operationPointer),{activeExampleName:null===(t=null===(o=i.oneOf)||void 0===o?void 0:o[r])||void 0===t?void 0:t.title,activeOneOf:{[i.pointer]:r}})}u.activeExampleName!==e&&p({activeExampleName:e})}),[null==_?void 0:_.examples,_.schema,u.activeExampleName,p,c]),x=s===theme_1.LayoutVariant.STACKED;return(0,jsx_runtime_1.jsx)(common_1.Section,{children:(0,jsx_runtime_1.jsxs)(common_1.Row,{layout:s,children:[(0,jsx_runtime_1.jsxs)(common_1.SamplesMiddlePanel,{isStacked:x,children:[(null===(r=_.schema)||void 0===r?void 0:r.description)&&(0,jsx_runtime_1.jsx)(Description,{children:(0,jsx_runtime_1.jsx)(Markdown_1.Markdown,{source:null===(n=_.schema)||void 0===n?void 0:n.description})}),(0,jsx_runtime_1.jsx)(Schema_1.Schema,{skipWriteOnly:!i,skipReadOnly:!t,schema:_.schema,level:1})]}),(0,jsx_runtime_1.jsx)(common_1.SamplesPanel,{isStacked:x,children:(0,jsx_runtime_1.jsx)(common_1.CodeBlockPanel,{className:"panel-response-samples",children:(0,jsx_runtime_1.jsx)(PayloadSamples_1.MediaTypeSamples,{mediaType:_,onChange:d})})})]})})}exports.SchemaDefinition=(0,react_1.memo)(SchemaDefinitionComponent);const Description=styled_components_1.default.div`
  margin-bottom: var(--spacing-vertical);
`;
//# sourceMappingURL=SchemaDefinition.js.map