import{V as a,a as c,i as f,d as i,c as u,f as s,b as l}from"./messages-C0uwUAtt.js";import"./formatExtractHtml-Dev9W6Dj.js";function d(e){return!!c(e)||f(e)}async function M(e){try{const r=await s(document,e.extract,e.agentVersion,e.section);return r.ok?{ok:!0,filled:r.filled}:{ok:!1,error:l(r)}}catch(r){return{ok:!1,error:r instanceof Error?r.message:"Не удалось подставить данные"}}}async function g(e){try{return i(document)!=="medcard_form"?{ok:!1,error:"Форма медкарты VetManager не найдена"}:{ok:!0,hasContent:await u(document,e)}}catch(r){return{ok:!1,error:r instanceof Error?r.message:"Не удалось проверить поле"}}}function k(){return{ok:!0,state:i(document),url:window.location.href}}chrome.runtime.onMessage.addListener((e,r,n)=>{var o;if(!e||typeof e!="object"||!d(document))return!1;if(e.type===a.PING)return n(k()),!1;if(e.type===a.CHECK_SECTION_CONTENT){const t=(o=e.payload)==null?void 0:o.section;return t?(g(t).then(n),!0):(n({ok:!1,error:"Не указана вкладка для проверки"}),!1)}if(e.type===a.FILL_SECTION||e.type===a.FILL_ANAMNESIS){const t=e.payload;return t!=null&&t.extract?(M({extract:t.extract,agentVersion:t.agentVersion??1,section:t.section??"healing_process"}).then(n),!0):(n({ok:!1,error:"Нет данных анализа для подстановки"}),!1)}return!1});
