import{a as _}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf6.js";import{aq as M,ar as A,z as w,y as E}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf23.js";import{u as p}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf19.js";import{S as T,C as g,I as l,G as f}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf10.js";import{W as v,V as x}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf18.js";import{c as H}from"./v_7_4_2_9_8cb79d4f-81e0-49c1-b597-7f2344477fbf7.js";const k="/assets/png/Translate.chunk.png",u=document.createElement("div");u.setAttribute("data-id","btn-tradutor");u.setAttribute("class","cursor-pointer !mx-1 lg:tooltip");u.innerHTML=`<img src='${chrome.runtime.getURL("content/"+k)}' class='h-6 w-6 pulse shadow-2xl brightness-125 dark:brightness-100' />`;u.addEventListener("click",()=>c.getState().translateMsg());const C=t=>{const{getListElement:r}=w.getState(),a=document.createElement("section");a.setAttribute("data-id","audio-transcriber");const e=t.querySelector('section[data-id="audio-transcriber"]');return e||((t.querySelector(r("useTradutor","main_audio_1"))||t.querySelector(r("useTradutor","main_audio_2"))).appendChild(a),a)},b=(t,r)=>{const{language:a}=p.getState(),e=document.createElement("div");e.setAttribute("data-id","btn-trascription-audio"),e.className="flex justify-center pb-3",e.innerHTML=`
        <div class="flex gap-2 text-[var(--primaria)] justify-center items-center mt-2 border border-solid rounded-2xl max-w-32 p-1 px-2 cursor-pointer pulse hover:bg-[var(--terciaria)]">
            <span>
                <svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlnsxlink="http://www.w3.org/1999/xlink" width="512" height="512" x="0" y="0" viewBox="0 0 60 60" xmlbase="preserve" style="
                    fill: var(--primaria);
                    stroke: var(--primaria);
                    height: 22px;
                    width: 22px;
                ">
                    <g>
                        <path d="M10 48.41V53a4 4 0 0 0-4 4v1a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-1a4 4 0 0 0-4-4v-4.59A14.02 14.02 0 0 0 28 35v-3a3 3 0 0 0-3-3 2.966 2.966 0 0 0-1 .184V23a10 10 0 0 0-20 0v6.184A2.966 2.966 0 0 0 3 29a3 3 0 0 0-3 3v3a14.02 14.02 0 0 0 10 13.41ZM20 57v1H8v-1a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2Zm-4-4h-4v-4.16a13.884 13.884 0 0 0 2 .16 13.884 13.884 0 0 0 2-.16Zm-2-38a8.008 8.008 0 0 1 7.931 7H18a1 1 0 0 0 0 2h4v4h-4a1 1 0 0 0 0 2h4v4h-4a1 1 0 0 0 0 2h3.931a7.993 7.993 0 0 1-15.862 0H10a1 1 0 0 0 0-2H6v-4h4a1 1 0 0 0 0-2H6v-4h4a1 1 0 0 0 0-2H6.069A8.008 8.008 0 0 1 14 15ZM2 32a1 1 0 0 1 2 0v3a10 10 0 0 0 20 0v-3a1 1 0 0 1 2 0v3a12 12 0 0 1-24 0ZM54 0H34a6.006 6.006 0 0 0-6 6v14a6.006 6.006 0 0 0 6 6v4.171a2.791 2.791 0 0 0 1.674 2.579 2.836 2.836 0 0 0 1.162.25 2.791 2.791 0 0 0 1.873-.727L45.684 26H54a6.006 6.006 0 0 0 6-6V6a6.006 6.006 0 0 0-6-6Zm4 20a4 4 0 0 1-4 4h-8.7a1 1 0 0 0-.669.257l-7.259 6.53A.824.824 0 0 1 36 30.172V25a1 1 0 0 0-1-1h-1a4 4 0 0 1-4-4V6a4 4 0 0 1 4-4h20a4 4 0 0 1 4 4Z" opacity="1" data-original="#000000"></path>
                        <path d="M53 9H35a1 1 0 0 0 0 2h18a1 1 0 0 0 0-2ZM48 15H35a1 1 0 0 0 0 2h13a1 1 0 0 0 0-2Z" opacity="1" data-original="#000000"></path>
                    </g>
                </svg>
            </span>
    
            <span class="text-sm font-medium">
                ${a.trascrever}
            </span>
        </div>
    `,e.addEventListener("click",async function i(){const{trascreverAudio:s}=c.getState();await A("trascrever_audio")!==!0&&(t.setAttribute("translate","await"),t.innerHTML="",t.appendChild(S()),s(t,r),e.removeEventListener("click",i))}),t.innerHTML="",t.appendChild(e)},S=()=>{const{language:t}=p.getState(),r=document.createElement("div");return r.setAttribute("data-id","await-trascription"),r.className="flex justify-center pb-3",r.innerHTML=`
        <div class="px-2 flex gap-2 text-[var(--primaria)] justify-center items-center mt-2 border border-solid rounded-2xl max-w-32 p-1 cursor-pointer pulse hover:bg-[var(--terciaria)]">
            <svg class="animate-spin -ml-1 h-5 w-5 text-[var(--primaria)]" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
                <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
                <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
            </svg>
 
            <span class="text-sm font-medium text-nowrap">
                ${t.aguarde}...
            </span>
        </div>
    `,r},y=t=>{const r=document.createElement("div");return r.setAttribute("data-id","viwer-text"),r.setAttribute("class","selectable-text copyable-text"),r.innerHTML=`
        <span style="
            width: 336px;
            display: block;
            padding: 0 12px 12px 12px;
        ">
            <span>${t}</span>
        </span>
    `,r},c=H()((t,r)=>({activeLanguage:{value:"pt",label:"Português"},activeMsgID:"",trascriptionAudio:[],stateTraducao:{message:!1,trascreverAudio:!1},setActiveLanguage:a=>t(()=>(localStorage.setItem("activeLanguage",JSON.stringify(a)),{activeLanguage:a})),insertBtnTradutor:()=>{const{stateTraducao:a}=r(),{getSeletor:e,getListElement:i}=w.getState(),s=()=>{e("allMensages",n=>{n==null||n.forEach(o=>{if(!a.message&&!o.classList.contains(i("useTradutor","camp_text_1"))&&o.querySelector(i("useTradutor","camp_text_2"))&&(o.addEventListener("mouseenter",()=>{c.setState({activeMsgID:o.getAttribute("data-id")}),u.setAttribute("data-tip",p.getState().language.traduzirMensagem),o.querySelector(i("useTradutor","add_btn_tradutor")).prepend(u)}),o.classList.add(i("useTradutor","camp_text_1"))),!a.trascreverAudio&&(o.querySelector(i("useTradutor","camp_audio_1"))||o.querySelector(i("useTradutor","camp_audio_2")))){const m=o.getAttribute("data-id"),h=c.getState().trascriptionAudio.find(L=>L.id===m),d=C(o);h?(d.innerHTML="",d.appendChild(y(h.text))):d.getAttribute("translate")==="await"?(d.innerHTML="",d.appendChild(S())):b(d,m)}})})};s(),setTimeout(()=>{s()},1500),e("listMensages",n=>{n==null||n.addEventListener("scroll",s)})},translateMsg:async()=>{const a=p.getState().language,e=await v.Chat("getMessageById",c.getState().activeMsgID);let i;switch(e.type){case"image":case"video":case"document":i=e.caption;break;default:i=e.body;break}if(!i||i.length<=1){l({type:"Error",message:a.invalidTranslationMessage,position:"top-right"});return}const s=await M(i,"tradutor",c.getState().activeLanguage.label);if(!s.success){l({type:"Error",message:a.tryAgain,position:"top-right"});return}await A("useTradutor")!==!0&&v.Msg("replaceMensage",{mensagemID:e.id._serialized,text:s.response})},trascreverAudio:async(a,e)=>{const{setTrascriptionAudio:i}=r(),{language:s}=p.getState();try{const n=await v.Chat("downloadMedia",e),{data:o}=await _.post(x.audio_transcriber,{audio:n},{headers:{"Content-Type":"application/json",accept:"application/json","Secret-Key":x.cript_key}});i({id:e,text:o.transcription}),a.innerHTML="",a.appendChild(y(o.transcription)),l({type:"Success",message:s.transcribe_audio_success,position:"top-right"})}catch(n){console.error(n),l({type:"Error",message:n.response.data.code?s[n.response.data.code]:s.transcribe_audio_could_not,position:"top-right"}),b(a,e)}finally{a.removeAttribute("translate")}},setTrascriptionAudio:a=>t(e=>(T("useTrascription","trascription-audio",[g.encryptData([...e.trascriptionAudio,a])]),{trascriptionAudio:[...e.trascriptionAudio,a]})),setStateTraducao:(a,e)=>t(i=>{const s={...i.stateTraducao,[a]:e};return T("useStateTraducao","stateTraducao",[g.encryptData(s)]),{stateTraducao:s}})}));E.subscribe(()=>{c.getState().insertBtnTradutor()});const j=()=>{const t=JSON.parse(localStorage.getItem("activeLanguage"));t&&c.setState({activeLanguage:t})};(async()=>{const t=await f("useTrascription","trascription-audio");if(t&&t[0]&&t[0][0]){const r=g.decryptData(t[0][0]);c.setState({trascriptionAudio:r})}})();(async()=>{const t=await f("useStateTraducao","stateTraducao");if(t&&t[0]&&t[0][0]){const r=g.decryptData(t[0][0]);c.setState({stateTraducao:r})}})();export{j as i,c as u};
