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