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