"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FieldDetails=void 0;const jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),jotai_1=require("jotai"),styled_components_1=__importDefault(require("styled-components")),theme_1=require("@redocly/theme"),common_1=require("../common"),ExternalDocumentation_1=require("../ExternalDocumentation"),Markdown_1=require("../Markdown"),FieldDetail_1=require("./FieldDetail"),Extensions_1=require("./Extensions"),EnumValues_1=require("./EnumValues"),Examples_1=require("./Examples"),store_1=require("../../jotai/store"),SchemaTypeInfo_1=require("./SchemaTypeInfo"),LinkToField_1=require("../common/LinkToField"),Pattern_1=require("./Pattern"),RenderHook_1=require("../RenderHook");function FieldDetailsComponent({field:e,renderDiscriminatorSwitch:t,deepLink:i,fieldParentsName:r=[]}){var n;const{hidePropertiesPrefix:a,hideSchemaTitles:o}=(0,jotai_1.useAtomValue)(store_1.globalOptionsAtom),{schema:s,description:l,example:m,deprecated:c,examples:_,kind:d,required:u,name:p}=e,x="header"===e.in,j=(0,react_1.useMemo)((()=>{if(void 0!==m||void 0!==_){if(void 0!==_)return(0,jsx_runtime_1.jsx)(Examples_1.Examples,{field:e});{const t=!!e.in;return(0,jsx_runtime_1.jsx)(FieldDetail_1.FieldDetail,{label:"Example:",value:(0,Examples_1.getSerializedValue)(e,e.example),raw:t})}}return null}),[m,_,e]),f=(0,RenderHook_1.getAccessModeLabelText)(e.schema);return(0,jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment,{children:[(0,jsx_runtime_1.jsxs)(Row,{children:[p&&(0,jsx_runtime_1.jsxs)(Name,{children:[i&&(0,jsx_runtime_1.jsx)(LinkToField_1.LinkToField,{to:i}),!a&&r.map((e=>e+".")),(0,jsx_runtime_1.jsx)(SchemaName,{className:"schema-name",children:p})]}),(0,jsx_runtime_1.jsx)(SchemaTypeInfo_1.SchemaTypeInfo,{type:s.typePrefix+s.displayType}),(0,jsx_runtime_1.jsx)(SchemaTypeInfo_1.SchemaTypeInfo,{type:s.displayFormat&&`(${s.displayFormat})`}),(0,jsx_runtime_1.jsx)(SchemaTypeInfo_1.SchemaTypeInfo,{type:s.contentEncoding}),(0,jsx_runtime_1.jsx)(SchemaTypeInfo_1.SchemaTypeInfo,{type:s.title&&!o?`(${s.title})`:""}),null===(n=s.constraints)||void 0===n?void 0:n.map((e=>(0,jsx_runtime_1.jsx)(SchemaTypeInfo_1.SchemaTypeInfo,{type:e},e))),c&&(0,jsx_runtime_1.jsx)(DeprecatedLabel,{children:"Deprecated"}),(0,jsx_runtime_1.jsx)(Pattern_1.Pattern,{pattern:s.pattern}),"additionalProperties"===d&&(0,jsx_runtime_1.jsx)(common_1.Tag,{children:"additional property"}),"patternProperties"===d&&(0,jsx_runtime_1.jsx)(common_1.Tag,{children:"pattern property"}),f&&(0,jsx_runtime_1.jsx)(common_1.AccessLabel,{children:f}),u&&(0,jsx_runtime_1.jsx)(common_1.RequiredLabel,{children:"required"}),s.isCircular&&(0,jsx_runtime_1.jsx)(common_1.RecursiveLabel,{children:"Recursive"})]}),(0,jsx_runtime_1.jsx)(StyledDescription,{source:l}),(0,jsx_runtime_1.jsx)(FieldDetail_1.FieldDetail,{raw:x,label:"Default",value:s.default}),(0,jsx_runtime_1.jsx)(EnumValues_1.EnumValues,{type:s.type,values:s["x-enumDescriptions"]||s.enum}),j,(0,jsx_runtime_1.jsx)(Extensions_1.Extensions,{extensions:Object.assign(Object.assign({},e.extensions),s.extensions)}),s.externalDocs&&(0,jsx_runtime_1.jsx)(ExternalDocumentation_1.ExternalDocumentation,{externalDocs:s.externalDocs,compact:!0}),null==t?void 0:t(),(0,jsx_runtime_1.jsx)(FieldDetail_1.FieldDetail,{label:"Value",value:e.const||void 0})]})}exports.FieldDetails=(0,react_1.memo)(FieldDetailsComponent);const Row=styled_components_1.default.div`
  display: flex;
  align-items: center;
  gap: calc(var(--spacing-xxs) / 4) var(--spacing-xxs);
  flex-wrap: wrap;
  margin-bottom: 2px;
  position: relative;
`,DeprecatedLabel=(0,styled_components_1.default)(common_1.Tag)`
  color: var(--badge-deprecated-text-color);
  background-color: var(--badge-deprecated-bg-color);
  font-family: var(--font-family-base);
`,StyledDescription=(0,styled_components_1.default)(Markdown_1.Markdown)`
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);

  article p:last-child {
    margin-bottom: 0;
  }
`,Name=styled_components_1.default.span`
  position: relative;
  font-family: var(--font-family-monospaced);
  line-height: var(--line-height-base);
  font-size: var(--font-size-base);
  color: var(--text-color-description);
  max-width: 100%;
  display: flex;
  flex-wrap: wrap;

  :hover {
    ${theme_1.LinkIcon} {
      opacity: 1;
      visibility: visible;
      background-color: var(--bg-color);
    }
  }
`,SchemaName=styled_components_1.default.span`
  font-family: var(--font-family-monospaced);
  font-weight: var(--font-weight-semibold);
  font-size: var(--schemas-property-name-font-size);
  line-height: var(--schemas-property-name-line-height);
  color: var(--text-color-primary);
`;
//# sourceMappingURL=FieldDetails.js.map