import{_ as g}from"./ButtonDefault-BIBStZbJ.js";import{_ as E}from"./BasicInput-KlObNzdO.js";import{u as y,d as V,x as k,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-CmCGXBst.js";import"./_plugin-vue_export-helper-DlAUqK2U.js";import"./component-0WedTVCo.js";const R={class:"modal__body"},$={class:"modal__input-row"},j={__name:"ModalWindowCreateViber",emits:["modalClose","buttonClicked"],setup(q,{emit:v}){const a=y(),l=V(),b=k("emitter"),c=D(""),h=v,i=f(()=>a.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:"Viber",Address:c.value,TimeBegin:"00",TimeEnd:"00",IsActive:"yes",ContactID:"0"};a.userEditContact(t).then(e=>{e.response==="SUCCESS"&&(a.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 r={Method:n.MethodID,Value:n.Address,ContactID:n.ID};try{const s=await u(`${A}/API/Confirm`,r);s.Status==="Ok"?b.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 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"},"Добавление Viber",-1)),_("div",$,[C(o,{label:"Viber сообщения",name:"name",placeholder:"Ссылка или id",vertical:"",modelValue:c.value,"onUpdate:modelValue":e[0]||(e[0]=r=>c.value=r)},null,8,["modelValue"]),C(n,{class:"profile-info__add-button",label:"Добавить контакт",onClick:d,onButtonClicked:e[1]||(e[1]=r=>m())})])])}}};export{j as default};
