import{_ as g}from"./ButtonDefault-CghIUDY0.js";import{_ as E}from"./BasicInput-BYe5b9L8.js";import{u as y,d as V,x as b,r as D,f,H as S,s as B,c as M,o as U,a as _,b as C,W as A,am as w}from"./index-CipWZKo_.js";import"./_plugin-vue_export-helper-DlAUqK2U.js";import"./component-DWBAga-C.js";const R={class:"modal__body"},$={class:"modal__input-row"},W={__name:"ModalWindowCreateVK",emits:["modalClose","buttonClicked"],setup(K,{emit:v}){const r=y(),l=V(),h=b("emitter"),c=D(""),k=v,i=f(()=>r.userInfo),I=f(()=>Object.keys(i.value?.Contacts).map(t=>{if(!i.value?.Contacts?.[t]?.IsHidden)return i.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:"VKontakte",Address:c.value,TimeBegin:"00",TimeEnd:"00",IsActive:"yes",ContactID:"0"};r.userEditContact(t).then(e=>{e.response==="SUCCESS"&&(r.fetchUserData().then(async()=>{l.currentRoute.value?.fullPath!=="/profile/UserProfile"&&l.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(`${A}/API/Confirm`,a);s.Status==="Ok"?h.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(){k("modalClose")}const p=t=>{t.key==="Enter"&&d()};return S(()=>{document.addEventListener("keyup",p)}),B(()=>{document.removeEventListener("keyup",p)}),(t,e)=>{const o=E,n=g;return U(),M("div",R,[e[2]||(e[2]=_("div",{class:"list-item__title"},"Добавление VKontakte",-1)),_("div",$,[C(o,{label:"VKontakte сообщения",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{W as default};
