import{jsx as o,jsxs as p}from"react/jsx-runtime";import{useAtomValue as b}from"jotai";import{useState as d}from"react";import{Button as C}from"@redocly/theme/components/Button/Button";import{CopyLinkIcon as T}from"@redocly/theme/icons/CopyLinkIcon/CopyLinkIcon";import{ShareIcon as w}from"@redocly/theme/icons/ShareIcon/ShareIcon";import{ClipboardService as S}from"@redocly/theme/core/openapi";import{Tooltip as r}from"@redocly/theme/components/Tooltip/Tooltip";import{styled as t}from"../../styled-components.js";import{IS_BROWSER as L}from"../../utils/dom.js";import{globalStoreAtom as y}from"../../jotai/store.js";import{useTranslate as O}from"../../hooks/index.js";function J({schemaRef:m}){const{parser:h}=b(y),[n,l]=d("idle"),[g,c]=d(void 0),i=O(),s=h.definition["x-schema-catalog-link"];if(!s)return null;const e=L?window.location.origin:globalThis.SSR_HOSTNAME||"http://127.0.0.1:4000",a=s+m,k=e+a,u=n==="copied"?i("openapi.schemaCatalogLink.copiedTooltip","Copied!"):i("openapi.schemaCatalogLink.copyButtonTooltip","Copy to clipboard"),f=n==="copied"?!0:void 0,v=()=>{S.copyCustom(k),l("copied"),clearTimeout(g);const x=setTimeout(()=>{l("idle"),c(void 0)},1e3);c(x)};return p(j,{children:[o(r,{tip:i("openapi.schemaCatalogLink.title","Shared schema"),placement:"bottom",children:o(I,{children:o(w,{})})}),o(B,{children:p(E,{tip:e+a,placement:"bottom",width:"380px",children:[o(_,{children:e}),o(W,{children:o(A,{dir:"ltr",children:a})})]})}),o(r,{tip:u,isOpen:f,placement:"bottom",children:o(C,{icon:o(T,{}),onClick:v})})]})}const j=t.div`
  display: flex;
  gap: var(--spacing-xs);
  align-items: center;
  margin-bottom: var(--schema-catalog-link-margin-bottom);
  padding: var(--schema-catalog-link-padding);
  border-radius: var(--schema-catalog-link-border-radius);
  background-color: var(--schema-catalog-link-background-color);
`,I=t.div`
  width: var(--schema-catalog-link-share-icon-wrapper-size);
  height: var(--schema-catalog-link-share-icon-wrapper-size);
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--schema-catalog-link-share-icon-background-color);
  color: var(--schema-catalog-link-share-icon-color);
  border-radius: var(--schema-catalog-link-share-icon-border-radius);
`,_=t.span`
  flex-shrink: 0;
`,W=t.span`
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
`,A=t.span`
  /* Override direction so that characters like '/ or '_' do no change order in the pathname */
  direction: ltr;
`,B=t.div`
  color: var(--schema-catalog-link-text-color);
  text-overflow: ellipsis;
  overflow: hidden;
  display: flex;
  flex-grow: 1;
`,E=t(r)`
  max-width: 100%;
`;export{J as SchemaCatalogLink};
