import{a as e,l as t}from"./preact.module-CNakwbc9.js";import{d as n,l as r,s as i}from"./hooks.module-BrXTvcfS.js";import{G as a,h as o}from"./content_renderer-DOj8g78V.js";import{L as s,a as c}from"./i18n-BaLR3UdQ.js";import{t as l}from"./server-BXh06Wz_.js";import{i as u}from"./toast-C6WyPqyA.js";import{t as d}from"./jsxRuntime.module-Cao1NCKs.js";import{J as f}from"./hooks-ClTXKdUl.js";import{t as p}from"./Modal-hBkTa-Ee.js";import{t as m}from"./Button-Du0dYm4Z.js";n(),t();function h(){let[e,t]=i(!1),[n,r]=i(``),[a,o]=i(``);return f(`showOcrTextDialog`,({textUrl:e,processUrl:n})=>{r(e),o(n),t(!0)}),e&&d(g,{textUrl:n,processUrl:a,onHidden:()=>t(!1)})}function g({textUrl:t,processUrl:n,onHidden:f}){let[h,g]=i({kind:`loading`}),[_,v]=i(!1);async function y(){g({kind:`loading`});try{let e=await l.get(t);if(!e.success){g({kind:`error`,message:e.message||c(`ocr.failed_to_load`)});return}if(!e.hasOcr||!e.text){g({kind:`empty`});return}g({kind:`loaded`,text:e.text})}catch(e){console.error(`Error loading text representation:`,e),g({kind:`error`,message:e.message||c(`ocr.failed_to_load`)})}}r(()=>{y()},[t]);async function b(){v(!0);try{let e=await l.post(n,{forceReprocess:!0});if(e.success){let t=e.result,n=e.minConfidence??0;if(t&&!t.text&&t.processingType===`pdf`)u.showPersistent({id:`ocr-pdf-unsupported-${s(8)}`,icon:`bx bx-info-circle`,message:c(`ocr.image_based_pdf_not_supported`),timeout:15e3});else if(t&&!t.text&&t.confidence>0&&n>0){let e=Math.round(t.confidence*100),r=Math.round(n*100);u.showPersistent({id:`ocr-low-confidence-${s(8)}`,icon:`bx bx-info-circle`,message:c(`ocr.text_filtered_low_confidence`,{confidence:e,threshold:r}),timeout:15e3,buttons:[{text:c(`ocr.open_media_settings`),onClick:({dismissToast:e})=>{a.triggerCommand(`showOptions`,{section:`_optionsMedia`}),e()}}]})}else u.showMessage(c(`ocr.processing_complete`));setTimeout(y,500)}else u.showError(e.message||c(`ocr.processing_failed`))}catch{}finally{v(!1)}}function x(){h.kind===`loaded`&&o(h.text)}let S=h.kind!==`loading`&&d(e,{children:[d(m,{icon:_?`bx-loader-alt bx-spin`:`bx-refresh`,text:c(_?`ocr.processing`:`ocr.process_now`),size:`small`,disabled:_,onClick:b}),h.kind===`loaded`&&d(m,{icon:`bx-copy`,text:c(`info.copy_to_clipboard`),size:`small`,onClick:x})]});return d(p,{className:`ocr-text-modal`,title:c(`ocr.extracted_text_title`),footer:S,footerAlignment:`between`,show:!0,onHidden:f,size:`lg`,scrollable:!0,children:[h.kind===`loading`&&d(`div`,{className:`ocr-text-modal-loading`,children:[d(`span`,{className:`bx bx-loader-alt bx-spin`}),` `,c(`ocr.loading_text`)]}),h.kind===`loaded`&&d(`div`,{className:`ocr-text-modal-content`,children:h.text}),h.kind===`empty`&&d(`div`,{className:`ocr-text-modal-empty`,children:[d(`span`,{className:`bx bx-info-circle`}),d(`div`,{children:c(`ocr.no_text_available`)}),d(`div`,{className:`ocr-text-modal-explanation`,children:c(`ocr.no_text_explanation`)})]}),h.kind===`error`&&d(`div`,{className:`ocr-text-modal-error`,children:[d(`span`,{className:`bx bx-error`}),` `,h.message]})]})}export{h as default};