import{_ as E}from"./ButtonDefault-CghIUDY0.js";import{_ as y}from"./BasicInput-BYe5b9L8.js";import{u as k,d as b,x as D,r as S,f,H as B,s as M,c as U,o as A,a as _,b as C,W as T,am as w}from"./index-CipWZKo_.js";import"./_plugin-vue_export-helper-DlAUqK2U.js";import"./component-DWBAga-C.js";const R={class:"modal__body"},V={class:"modal__input-row"},j={__name:"ModalWindowCreateTelegram",emits:["modalClose","buttonClicked"],setup($,{emit:g}){const r=k(),i=b(),v=D("emitter"),c=S(""),h=g,l=f(()=>r.userInfo),I=f(()=>Object.keys(l.value?.Contacts).map(t=>{if(!l.value?.Contacts?.[t]?.IsHidden)return l.value?.Contacts?.[t]}).filter(Boolean)),u=async(t,e)=>{try{return(await w.post(t,e)).data}catch(o){throw new Error(`Error sending confirm request: ${o.message}`)}};function d(){const t={MethodID:"Telegram",Address:c.value,TimeBegin:"00",TimeEnd:"00",IsActive:"yes",ContactID:"0"};r.userEditContact(t).then(e=>{e.response==="SUCCESS"&&(r.fetchUserData().then(async()=>{i.currentRoute.value?.fullPath!=="/profile/UserProfile"&&i.push("profile/UserProfile");const o=I.value,n=o[o.length-1];if(n){const a={Method:n.MethodID,Value:n.Address,ContactID:n.ID};try{const s=await u(`${T}/API/Confirm`,a);s.Status==="Ok"?v.emit("open-modal",{component:"AcceptContact",data:{contactId:n.ID,sendConfirmRequest:u}}):console.error(`Error confirming code. Status: ${s.Status}, Message: ${s.Message}`)}catch(s){console.error("Error accepting contact:",s.message)}}}),m())})}function m(){h("modalClose")}const p=t=>{t.key==="Enter"&&d()};return B(()=>{document.addEventListener("keyup",p)}),M(()=>{document.removeEventListener("keyup",p)}),(t,e)=>{const o=y,n=E;return A(),U("div",R,[e[2]||(e[2]=_("div",{class:"list-item__title"},"Добавление Telegram",-1)),_("div",V,[C(o,{label:"Telegram сообщения",name:"name",placeholder:"Ссылка или id",vertical:"",modelValue:c.value,"onUpdate:modelValue":e[0]||(e[0]=a=>c.value=a)},null,8,["modelValue"]),C(n,{class:"profile-info__add-button",label:"Добавить контакт",onClick:d,onButtonClicked:e[1]||(e[1]=a=>m())})])])}}};export{j as default};
