import{j as s,y as A,J as T,Q as E,Z as v,V as C,I as q}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c9910.js";import{a as r}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c994.js";import{a as b}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c996.js";import{q as _,o as k}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c9923.js";import{R as P,i as B}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c9925.js";import{u as z}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c9919.js";import{V as w,W as n}from"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c9918.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c998.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c99.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c995.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c997.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c999.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c992.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c993.js";import"./v_7_4_2_1_59f2e4f7-dc00-41f3-9942-b1c61b935c9935.js";function se(){const{language:t}=z(),{label:u}=_(),{close:f}=k(),[c,g]=r.useState(""),[o,h]=r.useState(),[l,S]=r.useState([]),[N,p]=r.useState([]);r.useEffect(()=>{(async()=>{try{const e=await b.get(`${w.backend}api/modelosCRM/v3/get.php`,{headers:{"Content-Type":"application/json",accept:"application/json"}});S(e.data.modelos),p(e.data.modelos)}catch(e){console.error(t.erroAoCapturarModelos,e)}})()},[]),r.useEffect(()=>{if(c.length===0)p(l);else{let e=[];l.forEach(i=>{var d;(d=i.nome)!=null&&d.toUpperCase().includes(c.toUpperCase())&&e.push(i)}),p(e)}},[c]);const x=async()=>{var M;const e=await n.Conn("getMyUserId"),i=await n.Utils("getContato",e),d=await n.Contact("getProfilePictureUrl",e),I=await n.Profile("isBusiness"),a=await n.Contact("getBusinessProfile",e);let j="";a&&a.website&&a.website[0]&&(j=a.website[0]);let y="";a&&a.categories&&((M=a.categories[0])!=null&&M.localized_display_name)&&(y=a.categories[0].localized_display_name);const U={whatsapp:e,label:u.name,wl_id:u.chromeStoreID,nome:i.name,picture:d,segmento:o?l.find(m=>m.id===o).nome:"Outros",descricao:(a==null?void 0:a.description)||"",email:(a==null?void 0:a.email)||"",website:j,categoria:y,isBussines:I};try{await b.post(`${w.backend}api/modelosCRM/v3/set.php`,{...U},{headers:{"Content-Type":"application/json",accept:"application/json"}})}catch(m){console.error(t.erroAoSalvarModeloCRM,m)}},R=async()=>{if(f(),chrome.storage.local.set({initSystem:!0}),x(),o===1/0||o===void 0||o===null)return;const e=JSON.parse(l.find(i=>i.id===o).arquivo);P(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(A,{children:t.segmentoDeAtuacao}),s.jsx(T,{children:t.voceReceberaUmCRM}),s.jsxs("div",{className:"flex gap-4",children:[s.jsx("input",{type:"text",value:c,onChange:e=>g(e.target.value),placeholder:t.pesquisarPorSegmento,className:"input input-bordered input-sm w-full"}),c.length>0&&s.jsx(E,{name:t.limparBusca,funcao:()=>g("")})]}),s.jsxs("div",{className:"grid gap-1 overflow-auto py-2",style:{maxHeight:"calc(100vh - 270px)"},children:[N.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:()=>h(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:()=>h(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:()=>{f(),chrome.storage.local.set({initSystem:!0}),x()}}),s.jsx(C,{name:t.select,funcao:R})]})]})}export{se as default};
