import{r,j as s}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b.js";import{a as y}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b7.js";import{s as P,p as U}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b24.js";import{R as A,i as B}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b26.js";import{u as T}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b20.js";import{V as M,W as c}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b19.js";import{Q as E,$ as _,a1 as k,a5 as v,a2 as C,I as q}from"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b11.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b9.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b6.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b8.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b4.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b3.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b2.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b10.js";import"./v_7_4_2_25_48461181-0d14-4d2a-b9c3-5de50369a90b36.js";function ee(){const{language:t}=T(),{label:m}=P(),{close:u}=U(),[n,f]=r.useState(""),[o,g]=r.useState(),[l,b]=r.useState([]),[w,d]=r.useState([]);r.useEffect(()=>{(async()=>{try{const e=await y.get(`${M.backend}api/modelosCRM/get`,{headers:{"Content-Type":"application/json",accept:"application/json"}});b(e.data.modelos),d(e.data.modelos)}catch(e){console.error(t.erroAoCapturarModelos,e)}})()},[]),r.useEffect(()=>{if(n.length===0)d(l);else{let e=[];l.forEach(i=>{i.nome?.toUpperCase().includes(n.toUpperCase())&&e.push(i)}),d(e)}},[n]);const h=async()=>{const e=await c.Conn("getMyUserId"),i=await c.Utils("getContato",e),N=await c.Contact("getProfilePictureUrl",e),R=await c.Profile("isBusiness"),a=await c.Contact("getBusinessProfile",e);let x="";a&&a.website&&a.website[0]&&(x=a.website[0]);let j="";a&&a.categories&&a.categories[0]?.localized_display_name&&(j=a.categories[0].localized_display_name);const I={whatsapp:e,label:m.name,wl_id:m.chromeStoreID,nome:i.name,picture:N,segmento:o?l.find(p=>p.id===o).nome:"Outros",descricao:a?.description||"",email:a?.email||"",website:x,categoria:j,isBussines:R};try{await y.post(`${M.backend}api/clientesRegistrados/set`,{...I},{headers:{"Content-Type":"application/json",accept:"application/json"}})}catch(p){console.error(t.erroAoSalvarModeloCRM,p)}},S=async()=>{if(u(),chrome.storage.local.set({initSystem:!0}),h(),o===1/0||o===void 0||o===null)return;const e=JSON.parse(l.find(i=>i.id===o).arquivo);A(e.userTabs||[]),chrome.storage.local.set({guardaMsg:e.guardaMsg||[],categoria:e.categoria||[],medias:e.medias||[]},()=>{B()}),q({type:"Success",message:t.cRMAdicionadoAoSistema,position:"top-right"})};return s.jsxs("div",{className:"w-[600px] grid gap-4",children:[s.jsx(E,{children:t.segmentoDeAtuacao}),s.jsx(_,{children:t.voceReceberaUmCRM}),s.jsxs("div",{className:"flex gap-4",children:[s.jsx("input",{type:"text",value:n,onChange:e=>f(e.target.value),placeholder:t.pesquisarPorSegmento,className:"input input-bordered input-sm w-full"}),n.length>0&&s.jsx(k,{name:t.limparBusca,funcao:()=>f("")})]}),s.jsxs("div",{className:"grid gap-1 overflow-auto py-2",style:{maxHeight:"calc(100vh - 270px)"},children:[w.slice().sort((e,i)=>e.nome.localeCompare(i.nome)).map(e=>s.jsx("div",{className:"py-2",children:s.jsxs("label",{htmlFor:e.id,className:"flex items-center cursor-pointer ",children:[s.jsx(v,{estado:o===e.id,id:e.id,checkedUpdade:()=>g(e.id)}),s.jsx("span",{className:"pl-1",children:e.nome})]})},e.id)),s.jsx("div",{className:"py-2",children:s.jsxs("label",{htmlFor:"Infinity",className:"flex items-center cursor-pointer ",children:[s.jsx(v,{estado:o===1/0,id:"Infinity",checkedUpdade:()=>g(1/0)}),s.jsx("span",{className:"pl-1",children:"Outros"})]})})]}),s.jsxs("div",{className:"flex justify-end pt-2",children:[s.jsx(C,{name:t.cancel,funcao:()=>{u(),chrome.storage.local.set({initSystem:!0}),h()}}),s.jsx(C,{name:t.select,funcao:S})]})]})}export{ee as default};
