1import{f as J,r as n,iw as K,j as i,P as Q,G as X,H as Z,L as $,n as ee,f6 as te,c1 as ae,iD as ne,s as R,e as f,iy as se,N as ie}from"./index-BiR4tHPa.js";import{U as oe}from"./UpdateNotificationReview-D5YRW3sD.js";import{U as le,M as A}from"./UpdateVariables-tv5-jcIs.js";import"./index-D0a2oRRq.js";import"./index-BVQZfgQa.js";import"./fade-WpTyRwrX.js";import"./UploadOutlined-hDi33Qtx.js";const he=()=>{const{t:o}=J(["common","noti"]),[a,u]=n.useState({database_name:"yb_db",collection_name:"notification_details",new_data:{}}),[E,ce]=n.useState({database_name:"yb_db",collection_name:"notification_details",new_data:{notification_type:"appointment_confirmation",template_name:"",template_type:"",variables:[],enabled:!0,notification_time:"",send_unsubscribed_user:!1,email:"",language:"",client_type:K}}),[L,re]=n.useState([{name:o("noti:select"),value:""},{name:o("patientsDetails:patientname"),value:"patient_name"},{name:o("patientsDetails:doctorname"),value:"doctor_name"},{name:o("noti:date"),value:"date"},{name:o("noti:time"),value:"time"},{name:o("noti:status"),value:"status"},{name:o("patientsDetails:patientType"),value:"patient_type"},{name:o("noti:language_used"),value:"language_used"}]),[c,P]=n.useState([{name:o("noti:select"),value:""}]),[p,w]=n.useState(""),[_,k]=n.useState(""),[H,y]=n.useState(!1),[M,U]=n.useState(""),[g,j]=n.useState(!1),[V,r]=n.useState(!1),[h,D]=n.useState(!1),[x,O]=n.useState({}),[b,B]=n.useState("");n.useState(!1);const[v,S]=n.useState(!1),F=async()=>{var e;r(!0);try{const t=await te("APPROVED","","");console.log(t,"get template response"),P([...c,...(e=t==null?void 0:t.data)==null?void 0:e.document]),r(!1)}catch(t){console.log(t,"get template error"),r(!1)}},T=async()=>{r(!0);try{const e=await ae(),t=e.data.document;console.log(e,"nntt");const s=t.find(l=>l.notification_type==="appointment_confirmation");s?(y(!0),j(s.enabled),D(s.send_unsubscribed_user),w(s.notification_time),U(s._id),u({...a,new_data:{...s}})):y(!1),r(!1)}catch(e){console.log(e,"get ERROR"),r(!1)}},I=async()=>{r(!0);try{const e=await ne(E);R(o("noti:addappoitmnetconfirSuccess")),T()}catch(e){console.log(e,"Review Message error"),f(o("noti:addappointmentconfirmfail"))}finally{r(!1)}},W=async()=>{var s;if(!a.new_data.template_name)return f("Please select a template first.");const e=(s=a==null?void 0:a.new_data)==null?void 0:s.variables,t=e==null?void 0:e.some(l=>!l||l.trim()==="");if((e==null?void 0:e.length)>0&&t)return f("Please select all variables.");S(!0);try{const l=await se(M,a.new_data);R(l.data.message)}catch(l){console.log(l,"update ERROR"),f(o("noti:somethingWentWrong"))}finally{S(!1)}},Y=e=>{j(e),u({...a,new_data:{...a.new_data}})},z=e=>{D(e)},G=e=>{const t=ie(e,"HH:mm").format("HH:mm");w(t)},q=(e,t)=>{const s=[...a.new_data.variables];s[t]=e,u({...a,new_data:{...a.new_data,variables:[...s]}})};return n.useEffect(()=>{var d,N,C;if(!_||!Array.isArray(c))return;const e=c.find(m=>m.name===_);if(!e)return;const t=(d=e.components)==null?void 0:d.find(m=>m.type==="BODY");let s=[];const l=(C=(N=t==null?void 0:t.example)==null?void 0:N.body_text)==null?void 0:C[0];Array.isArray(l)&&(s=l.map(()=>"")),u(m=>({...m,new_data:{...m.new_data,template_name:e.name,language:e.language,variables:s}}))},[_,c]),n.useEffect(()=>{u({...a,new_data:{...a.new_data,enabled:g,notification_time:p,send_unsubscribed_user:h}})},[g,h,p]),n.useEffect(()=>{T(),F()},[]),n.useEffect(()=>{var s,l;if(!((s=a==null?void 0:a.new_data)!=null&&s.template_name)||!Array.isArray(c))return;const e=c.find(d=>d.name===a.new_data.template_name);if(!e)return;const t=(l=e.components)==null?void 0:l.find(d=>d.type==="BODY");O(e),B((t==null?void 0:t.text)||"")},[a.new_data.template_name,c]),i.jsxs("div",{children:[i.jsx(Q,{activeMenu:"Appointment Confirmation",motherMenu:"Notification"}),i.jsx(X,{children:i.jsx(Z,{children:V?i.jsx($,{}):H?i.jsxs("div",{className:"d-flex flex-column flex-md-row gap-5",children:[i.jsxs("div",{className:"flex-fill",children:[i.jsx(oe,{handlNotificationtChange:Y,notificationChecked:g,handleUnsubscribedChange:z,unsubscribedChecked:h,setSelectedTime:G,selectedTime:a.new_data.notification_time||p}),a.new_data.template_name?null:i.jsxs("div",{className:"alert alert-warning text-center mt-3",role:"alert",style:{borderRadius:"10px",width:"300px",fontWeight:"500",marginLeft:"10px"},children:["â ï¸ ",o("noti:selecttemplate")]}),i.jsx(le,{loader:v,postData:a,setSelectedTemplate:k,templateList:c,handleVariables:q,variablesData:L,postAppointmentConfirmationFun:W,previewData:x,previewText:b})]}),i.jsx("div",{className:"d-none d-md-block",children:i.jsx(A,{previewText:b,previewData:x})}),i.jsx("div",{className:"d-block d-md-none",children:i.jsx(A,{previewText:b,previewData:x})})]}):i.jsx("div",{className:"d-flex justify-content-center align-items-center",style:{height:"80vh"},children:i.jsx(ee,{type:"submit",disabled:v,variant:"primary",size:"lg",onClick:I,children:v?i.jsxs("div",{children:[i.jsx("span",{className:"spinner"}),o("noti:adding")]}):o("noti:addappointconfirm")})})})})]})};export{he as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.