(function(){const p="data-taily-vm-page",T="data-taily-vm-request",v="data-taily-vm-response",_='[id*="medcard-healing-process-tabpanel"]';document.documentElement.setAttribute(p,"1");function w(t){return new Promise(e=>setTimeout(e,t))}function u(t){return t.replace(/\u00a0/g," ").replace(/\s+/g," ").trim()}function L(){return window.Ext??null}function M(){const t=Array.from(document.querySelectorAll(_)).filter(e=>e instanceof HTMLElement);return t.find(e=>!e.classList.contains("x-hide-display"))??t[0]??null}function b(t){if(!(t!=null&&t.id))return null;const e="__",r=t.id.lastIndexOf(e);return r===-1?null:t.id.slice(r+e.length)||null}function m(t,e){const r=u(e);for(const n of t.querySelectorAll(".x-tab-strip-text"))if(u(n.textContent??"")===r)return n instanceof HTMLElement?n:null;return null}function o(t,e){const r=m(t,e);if(!r)return!1;const n=r.closest("li");if(!(n!=null&&n.classList.contains("x-tab-strip-active")))return!1;const i=b(n);if(!i)return!0;const a=t.querySelector(`.x-tab-panel-body > .x-panel[id="${i}"], .x-tab-panel-body [id="${i}"]`);return a instanceof HTMLElement?!a.classList.contains("x-hide-display"):!0}function S(t,e){const r=u(e);return Array.from(t.querySelectorAll(".x-tab-strip-text")).findIndex(i=>u(i.textContent??"")===r)}function y(t,e){const r=m(t,e);if(!r)return!1;const n=r.closest("li"),i=r.closest("a.x-tab-right")??(n==null?void 0:n.querySelector("a.x-tab-right"));if(i&&(i.dispatchEvent(new MouseEvent("mousedown",{bubbles:!0,cancelable:!0})),i.dispatchEvent(new MouseEvent("mouseup",{bubbles:!0,cancelable:!0})),i.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0})),i.click()),n instanceof HTMLElement&&n.click(),o(t,e))return!0;for(const s of t.querySelectorAll(".x-tab-strip li"))s.classList.remove("x-tab-strip-active");n==null||n.classList.add("x-tab-strip-active");const a=b(n);if(a)for(const s of t.querySelectorAll(".x-tab-panel-body > .x-panel[id], .x-tab-panel-body [id]"))s instanceof HTMLElement&&(s.id===a?s.classList.remove("x-hide-display"):s.classList.add("x-hide-display"));const c=window;return typeof c.__tailyActivateMedcardTab=="function"&&c.__tailyActivateMedcardTab(e),o(t,e)}async function l(t,e){const r=Date.now()+2500;for(;Date.now()<r;){if(o(t,e))return!0;await w(50)}return o(t,e)}async function I(t){var s,A;const e=M();if(!(e!=null&&e.id))return!1;if(o(e,t)||(y(e,t),await l(e,t)))return!0;const r=S(e,t);if(r<0)return!1;const n=(A=(s=L())==null?void 0:s.getCmp)==null?void 0:A.call(s,e.id),i=m(e,t),a=(i==null?void 0:i.closest("li"))??null,c=b(a);return n!=null&&n.setActiveTab&&(c&&(n.setActiveTab(c),await l(e,t))||(n.setActiveTab(r),await l(e,t)))?!0:(y(e,t),l(e,t))}function d(t,e,r,n){document.documentElement.setAttribute(v,JSON.stringify({requestId:t,ok:e,result:r,error:n}))}let f=!1;async function x(t){let e;try{e=JSON.parse(t)}catch{return}const{requestId:r,action:n,payload:i}=e;if(!(!r||!n))try{if(n==="activateMedcardTab"){d(r,!0,await I(i.tabText));return}d(r,!1,!1,`Неизвестное действие: ${n}`)}catch(a){d(r,!1,!1,a instanceof Error?a.message:"Ошибка на странице VetManager")}}async function E(){if(f)return;const t=document.documentElement.getAttribute(T);if(t){f=!0,document.documentElement.removeAttribute(T);try{await x(t)}finally{f=!1}}}window.setInterval(()=>{E()},40);E();
})()
