"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,i,r){void 0===r&&(r=i);var o=Object.getOwnPropertyDescriptor(t,i);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,r,o)}:function(e,t,i,r){void 0===r&&(r=i),e[r]=t[i]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var i in e)"default"!==i&&Object.prototype.hasOwnProperty.call(e,i)&&__createBinding(t,e,i);return __setModuleDefault(t,e),t};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShareLinkToField=exports.LinkToField=void 0,exports.generateDeepLink=generateDeepLink;const jsx_runtime_1=require("react/jsx-runtime"),styled_components_1=__importStar(require("styled-components")),react_router_dom_1=require("react-router-dom"),theme_1=require("@redocly/theme"),utils_1=require("../../utils"),services_1=require("../../services"),helpers_1=require("../../services/history/helpers"),linkify_1=require("./linkify");function generateDeepLink(e,t){const i=e.deps.operation,r=(0,helpers_1.constructFieldDeepFragment)(e,t);if(!(null==i?void 0:i.id)&&!i.isCallback)return"#"+r.toLowerCase();const o=(0,services_1.joinWithSeparator)(i.href,(0,services_1.joinWithSeparator)(i.id,r),"#");return(0,utils_1.encodeBackSlashes)(o.toLowerCase())}const LinkToField=({to:e,className:t})=>{const i=e,r=(0,react_router_dom_1.useLocation)(),o=null==i?void 0:i.split("#")[1],n=!!r&&r.hash===`#${o}`;return(0,jsx_runtime_1.jsx)(exports.ShareLinkToField,{ariaLabel:`link  to ${i}`,className:t,isActive:n,to:i,id:o})};exports.LinkToField=LinkToField,exports.ShareLinkToField=(0,styled_components_1.default)(linkify_1.ShareLink)`
  display: flex;
  ${theme_1.LinkIcon} {
    visibility: hidden;
    cursor: pointer;
    background-color: var(--bg-color);
  }

  ${({isActive:e})=>e&&styled_components_1.css`
      ${theme_1.LinkIcon} {
        visibility: visible;
        opacity: 1;
      }
    `}
  :hover ${theme_1.LinkIcon}, :focus ${theme_1.LinkIcon} {
    visibility: visible;
    opacity: 1;
  }
`;
//# sourceMappingURL=LinkToField.js.map