import{r,j as s}from"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f.js";import{a as y}from"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f7.js";import{m as P}from"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f23.js";import{R as U,i as k}from"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f24.js";import{u as A,d as B}from"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f20.js";import{V as M,W as n}from"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f19.js";import{D as T,H as E,K as _,X as v,Q as w,I as q}from"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f11.js";import{u as D}from"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f46.js";import"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f8.js";import"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f4.js";import"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f3.js";import"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f2.js";import"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f10.js";import"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f6.js";import"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f9.js";import"./v_7_4_3_6_3dde09db-99f5-4187-8a7e-903456f0360f34.js";function te(){const{language:t}=A(),{config:m,checkout:z}=B(D(e=>({config:e.config,checkout:e.getUrl("principais","checkout")}))),{close:u}=P(),[c,f]=r.useState(""),[o,g]=r.useState(),[l,C]=r.useState([]),[S,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"}});C(e.data.modelos),d(e.data.modelos)}catch(e){console.error(t.erroAoCapturarModelos,e)}})()},[]),r.useEffect(()=>{if(c.length===0)d(l);else{let e=[];l.forEach(i=>{i.nome?.toUpperCase().includes(c.toUpperCase())&&e.push(i)}),d(e)}},[c]);const h=async()=>{const e=await n.Conn("getMyUserId"),i=await n.Utils("getContato",e),N=await n.Contact("getProfilePictureUrl",e),R=await n.Profile("isBusiness"),a=await n.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.nameID,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)}},b=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);U(e.userTabs||[]),chrome.storage.local.set({guardaMsg:e.guardaMsg||[],categoria:e.categoria||[],medias:e.medias||[]},()=>{k()}),q({type:"Success",message:t.cRMAdicionadoAoSistema,position:"top-right"})};return s.jsxs("div",{className:"w-[600px] grid gap-4",children:[s.jsx(T,{children:t.segmentoDeAtuacao}),s.jsx(E,{children:t.voceReceberaUmCRM}),s.jsxs("div",{className:"flex gap-4",children:[s.jsx("input",{type:"text",value:c,onChange:e=>f(e.target.value),placeholder:t.pesquisarPorSegmento,className:"input input-bordered input-sm w-full"}),c.length>0&&s.jsx(_,{name:t.limparBusca,funcao:()=>f("")})]}),s.jsxs("div",{className:"grid gap-1 overflow-auto py-2",style:{maxHeight:"calc(100vh - 270px)"},children:[S.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(w,{name:t.cancel,funcao:()=>{u(),chrome.storage.local.set({initSystem:!0}),h()}}),s.jsx(w,{name:t.select,funcao:b})]})]})}export{te as default};
