import{_ as b}from"./ButtonDefault-BIBStZbJ.js";import{_ as y}from"./BasicInput-KlObNzdO.js";import{u as k,ao as B,x as P,d as D,r as U,f as u,H as A,s as R,c as $,o as w,a as f,b as _,W as V,am as x}from"./index-CmCGXBst.js";import"./_plugin-vue_export-helper-DlAUqK2U.js";import"./component-0WedTVCo.js";const q={class:"modal__body"},N={class:"modal__input-row"},K={__name:"ModalWindowCreatePhone",emits:["modalClose","buttonClicked"],setup(T,{emit:C}){const a=k(),h=B(),g=P("emitter"),i=D(),c=U(""),v=C,S=u(()=>h.data.Messages?.Prompts),l=u(()=>a.userInfo),E=u(()=>Object.keys(l.value?.Contacts).map(e=>{if(!l.value?.Contacts?.[e]?.IsHidden)return l.value?.Contacts?.[e]}).filter(Boolean));function I(){const e=S.value.SMS,t=/<B>Например:<\/B>\s*([^<]+)/,o=e.match(t);return o&&o[1]?`${o[1]}`:e}const d=async(e,t)=>{try{return(await x.post(e,t)).data}catch(o){throw new Error(`Error sending confirm request: ${o.message}`)}};function m(){const e={MethodID:"SMS",Address:c.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=E.value,n=o[o.length-1];if(n){const r={Method:n.MethodID,Value:n.Address,ContactID:n.ID};try{const s=await d(`${V}/API/Confirm`,r);s.Status==="Ok"?g.emit("open-modal",{component:"AcceptContact",data:{contactId:n.ID,sendConfirmRequest:d}}):console.error(`Error confirming code. Status: ${s.Status}, Message: ${s.Message}`)}catch(s){console.error("Error accepting contact:",s.message)}}})})}function M(){v("modalClose")}const p=e=>{e.key==="Enter"&&m()};return A(()=>{document.addEventListener("keyup",p)}),R(()=>{document.removeEventListener("keyup",p)}),(e,t)=>{const o=y,n=b;return w(),$("div",q,[t[2]||(t[2]=f("div",{class:"list-item__title"},"Добавление номера телефона",-1)),f("div",N,[_(o,{label:"Номер телефона",name:"phoneNumberSMS",placeholder:I(),vertical:"",modelValue:c.value,"onUpdate:modelValue":t[0]||(t[0]=r=>c.value=r)},null,8,["placeholder","modelValue"]),_(n,{class:"profile-info__add-button",label:"Добавить контакт",onClick:m,onButtonClicked:t[1]||(t[1]=r=>M())})])])}}};export{K as default};
