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