import r from"react";import l from"styled-components";import{WarningFilledIcon as m}from"@redocly/theme/icons/WarningFilledIcon/WarningFilledIcon";import{Button as f}from"@redocly/theme/components/Button/Button";import{DetailedErrors as h}from"./DetailedErrors";import{useSocketMessages as v}from"../../runtime/useSocketMessages";const E="errors-updated",k=99,N=()=>{const[e,s]=r.useState([]),[i,a]=r.useState(!1);v(E,n=>s(n.errors));const o=r.useMemo(()=>{const n=e.filter(t=>t.type==="BROKEN_LINK"),p=e.filter(t=>t.type==="MARKDOC"),g=e.filter(t=>t.type!=="BROKEN_LINK"&&t.type!=="MARKDOC");return{brokenLinks:n,markdocErrors:p,otherErrors:g}},[e]);if(!e.length)return null;const c=o.markdocErrors.length?r.createElement("span",null,"(",o.markdocErrors.length," markdoc)"):null,b=o.brokenLinks.length?r.createElement("span",null,"(",o.brokenLinks.length," broken links) "):null,u=o.otherErrors.length?r.createElement("span",null,"(",o.otherErrors.length," other) "):null;if(i)return r.createElement(h,{onHide:()=>a(!1),problems:e});const d=e.length>k?r.createElement(m,{color:"currentColor"}):r.createElement(x,null,r.createElement("span",null,e.length));return r.createElement(w,null,r.createElement(f,{tone:"danger",variant:"primary",size:"large","aria-label":"Show detailed error message",icon:d,onClick:()=>a(!0)},r.createElement(y,null,"Problems:",c,b,u)))},x=l.div`
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background-color: currentcolor;
  font-size: 16px;
  font-weight: bold;

  > span {
    color: var(--text-color-on-color);
  }
`,y=l.div`
  display: flex;
  gap: var(--error-bubble-gap);
  white-space: nowrap;
  padding: 0;
  font-size: var(--error-card-font-size);
  color: var(--text-color-on-color);
`,w=l.div`
  display: flex;
  flex-direction: row;
  align-items: center;
  position: fixed;
  top: calc(var(--navbar-height) + 20px);
  right: 0;

  transition:
    transform 0.2s ease-in-out,
    opacity 0.2s ease-in-out;

  transform: translateX(calc(100% - (24px + var(--spacing-sm) + var(--button-gap))));
  width: fit-content;

  &:hover {
    transform: translateX(0);
    opacity: 1;
  }

  text-overflow: var(--error-bubble-text-overflow);
  font-family: var(--error-bubble-font-family);
  z-index: var(--error-bubble-z-index);

  && button {
    --button-icon-size: 24px;
    --button-font-size: var(--error-bubble-font-size);
    --button-icon-left-padding: var(--error-bubble-padding);
    --button-bg-color-primary-danger: var(--error-bubble-bg-color);
    --button-bg-color-primary-danger-hover: var(--error-bubble-bg-color-hover);
    --button-bg-color-primary-danger-pressed: var(--error-bubble-bg-colorpressed);
    --button-content-color-danger: var(--error-bubble-content-color);
    --button-content-color-danger-hover: var(--error-bubble-content-color-hover);
    --button-content-color-danger-pressed: var(--error-bubble-content-color-pressed);
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }
`;export{N as ErrorBubble};
