"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.OAuthRequiredScopes=exports.OAuthOptionalScopes=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"),Markdown_1=require("../Markdown"),SecuritySchemeItem_1=require("./SecuritySchemeItem"),styled_1=require("./styled"),hooks_1=require("../../hooks"),helper_1=require("./helper");function OAuthOptionalScopesComponent({flow:e}){const t=Object.keys((null==e?void 0:e.scopes)||{}),r=(0,hooks_1.useTranslate)(),[s,o]=(0,react_1.useState)(!1);if(!t.length)return null;return(0,jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment,{children:[(0,jsx_runtime_1.jsx)(SecuritySchemeItem_1.SecuritySchemeItem,{label:(0,jsx_runtime_1.jsxs)(ScopeHeader,{onClick:()=>{o((e=>!e))},children:[r(s?"openapi.hideOptionalScopes":"openapi.showOptionalScopes",s?"Hide optional scopes":"Show optional scopes"),(0,jsx_runtime_1.jsx)(AnimatedChevronWrapper,{isOpen:s,children:(0,jsx_runtime_1.jsx)(theme_1.ChevronRightIcon,{size:"var(--font-size-base)",color:"var(--tree-content-color-default)"})})]}),value:" "}),(0,jsx_runtime_1.jsx)(ScopesListWrapper,{isOpen:s,children:t.map((t=>(0,jsx_runtime_1.jsx)(SecuritySchemeItem_1.SecuritySchemeItem,{label:(0,jsx_runtime_1.jsx)(StyledTag,{className:"tag-grey",children:t}),value:(0,jsx_runtime_1.jsx)(Markdown_1.Markdown,{source:(null==e?void 0:e.scopes[t])||""})},t)))})]})}function OAuthRequiredScopesComponent({id:e,securities:t,flow:r}){const s=(0,helper_1.getRequiredScopes)(e,t),o=(0,hooks_1.useTranslate)();return s.length?(0,jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment,{children:[(0,jsx_runtime_1.jsx)(SecuritySchemeItem_1.SecuritySchemeItem,{label:o("openapi.requiredScopes","Required scopes"),value:" "}),(0,jsx_runtime_1.jsx)(Row,{children:s.map((e=>(0,jsx_runtime_1.jsx)(SecuritySchemeItem_1.SecuritySchemeItem,{label:(0,jsx_runtime_1.jsx)(StyledTag,{className:"tag-grey",children:e}),value:(0,jsx_runtime_1.jsx)(Markdown_1.Markdown,{source:(null==r?void 0:r.scopes[e])||""})},e)))})]}):null}const StyledTag=(0,styled_components_1.default)(styled_1.Tag)`
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  align-self: flex-start;
  padding: 0 var(--spacing-xs);
  border: var(--tag-border-width) var(--tag-border-style) var(--tag-bg-color);
  border-radius: var(--tag-border-radius);
`,ScopeHeader=styled_components_1.default.div`
  cursor: pointer;
  display: flex;
  gap: var(--spacing-xxs);
  align-items: center;
  user-select: none;
`,Row=styled_components_1.default.div`
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-xxs);
  word-break: normal;
`,ScopesListWrapper=styled_components_1.default.div`
  max-height: ${e=>e.isOpen?"1000px":"0"};
  opacity: ${e=>e.isOpen?"1":"0"};
  overflow: hidden;
  transition:
    max-height 0.5s ease-in-out,
    opacity 0.5s ease-in-out;
`,AnimatedChevronWrapper=styled_components_1.default.span`
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: ${e=>e.isOpen?"rotate(90deg)":"rotate(0deg)"};
  transition: transform 0.5s ease-in-out;
`;exports.OAuthOptionalScopes=(0,react_1.memo)(OAuthOptionalScopesComponent),exports.OAuthRequiredScopes=(0,react_1.memo)(OAuthRequiredScopesComponent);
//# sourceMappingURL=OAuthScopes.js.map