1import{j as e,r as y}from"./vendor-framework-Dk7zq_Wq.js";import{A as J}from"./AdminLayout-BUOnoiEb.js";import{l as H}from"./logger-CpJ-e-X4.js";import{u as w,t as Y}from"./zod-CAoH2rOC.js";import{l as P,q as E,r as M,t as C,w as V,v as _,o as k,Z,n as $}from"./index-Ti_iaIEA.js";import{I as a}from"./input-D11hYysL.js";import{L as g}from"./label-CpobBxg7.js";import{S as L,a as O,b as R,c as X,d as F}from"./select-CFi4AXUi.js";import{L as U,M as B,aY as z,aa as G}from"./vendor-icons-DDRqfAiY.js";import{F as K,a as m,b as p,c as u,d as h,f as x,e as j}from"./form-WCUMhE3f.js";import{o as D,s as o}from"./types-BIQ_OQgH.js";import{T as Q,a as W,b as q,c as A}from"./tabs-qGKGo1qJ.js";import"./Sidebar-BZNxpSx9.js";function ee(){const{register:t,handleSubmit:l,watch:d,setValue:v,formState:{errors:f,isSubmitting:i}}=w({defaultValues:{messageType:"prescription",patientName:"Test Patient",doctorName:"Dr. Smith",prescriptionId:"P12345",appointmentDate:"2025-05-10",appointmentTime:"10:00 AM"}}),{toast:T}=P(),S=d("messageType"),N=async r=>{try{const n=await(await $("POST","/api/admin/testing/sms",r)).json();if(n.success)T({title:"Success",description:`Test SMS sent successfully to ${r.phoneNumber} using ${n.provider}`,variant:"default"});else{let I=n.message||"Failed to send test SMS";n.error&&(I+=`: ${n.error}`),T({title:"SMS Sending Failed",description:I,variant:"destructive"}),H.error("SMS test failed:",n)}}catch(c){let n=c.message||"An error occurred";if(c.response)try{const I=await c.response.json();I.message&&(n=I.message),I.error&&(n+=`: ${I.error}`)}catch{}T({title:"Error",description:n,variant:"destructive"})}},s=r=>{v("messageType",r)};return e.jsxs(E,{className:"w-full max-w-2xl mx-auto",children:[e.jsxs(M,{children:[e.jsx(C,{children:"Test SMS Service"}),e.jsx(V,{children:"Send a test SMS using Cellcast SMS API v3. Enter a phone number with country code (e.g., +61) or without it (we'll add it automatically)."})]}),e.jsx(_,{children:e.jsx("form",{onSubmit:l(N),children:e.jsxs("div",{className:"grid gap-6",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(g,{htmlFor:"phoneNumber",children:"Phone Number"}),e.jsx(a,{id:"phoneNumber",placeholder:"+61 4XX XXX XXX",...t("phoneNumber",{required:"Phone number is required"})}),f.phoneNumber&&e.jsx("p",{className:"text-sm text-red-500",children:f.phoneNumber.message})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(g,{htmlFor:"messageType",children:"Message Type"}),e.jsxs(L,{defaultValue:"prescription",onValueChange:s,children:[e.jsx(O,{children:e.jsx(R,{placeholder:"Select message type"})}),e.jsxs(X,{children:[e.jsx(F,{value:"prescription",children:"Prescription Notification"}),e.jsx(F,{value:"appointment",children:"Appointment Booking"}),e.jsx(F,{value:"message",children:"Practitioner Message"})]})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(g,{htmlFor:"patientName",children:"Patient Name"}),e.jsx(a,{id:"patientName",placeholder:"John Smith",...t("patientName")})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(g,{htmlFor:"doctorName",children:"Doctor Name"}),e.jsx(a,{id:"doctorName",placeholder:"Dr. Jane Smith",...t("doctorName")})]}),S==="prescription"&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(g,{htmlFor:"prescriptionId",children:"Prescription ID"}),e.jsx(a,{id:"prescriptionId",placeholder:"P12345",...t("prescriptionId")})]}),S==="appointment"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(g,{htmlFor:"appointmentDate",children:"Appointment Date"}),e.jsx(a,{id:"appointmentDate",placeholder:"2025-05-10",...t("appointmentDate")})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(g,{htmlFor:"appointmentTime",children:"Appointment Time"}),e.jsx(a,{id:"appointmentTime",placeholder:"10:00 AM",...t("appointmentTime")})]})]}),e.jsx(k,{type:"submit",disabled:i,className:"w-full",children:i?e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send Test SMS"})]})})}),e.jsxs(Z,{className:"flex flex-col space-y-2 text-xs text-gray-500",children:[e.jsxs("div",{className:"flex justify-between w-full",children:[e.jsx("div",{children:"Provider: Cellcast API v3"}),e.jsx("div",{children:"Templates are fetched from the database"})]}),e.jsx("div",{className:"text-xs text-blue-500",children:"Note: Australian phone numbers will be formatted automatically with country code (61). SMS delivery may take a few seconds to complete."})]})]})}
1const b={appointment_confirmation:{label:"Appointment Confirmation",requiredFields:["userId","appointmentId"],description:"Test appointment confirmation email"},appointment_rescheduled_patient:{label:"Appointment Rescheduled (Patient)",requiredFields:["userId","appointmentId","previousAppointmentId"],description:"Test appointment rescheduled by patient email"},appointment_rescheduled_practitioner:{label:"Appointment Rescheduled (Practitioner)",requiredFields:["userId","appointmentId","previousAppointmentId"],description:"Test appointment rescheduled by practitioner email"},patient_appointment_reminder:{label:"Patient Appointment Reminder",requiredFields:["userId","appointmentId"],description:"Test patient appointment reminder email"},practitioner_appointment_reminder:{label:"Practitioner Appointment Reminder",requiredFields:["practitionerId","appointmentIds"],description:"Test practitioner appointment reminder email"},prescription:{label:"Prescription Ready",requiredFields:["userId","prescriptionId"],description:"Test prescription ready notification email"},prescription_repeat_preparing:{label:"Prescription Repeat Preparing",requiredFields:["userId","prescriptionId"],description:"Test prescription repeat being prepared email"},assessment_complete:{label:"Assessment Approved",requiredFields:["userId","assessmentId"],description:"Test assessment approved email"},assessment_declined:{label:"Assessment Declined",requiredFields:["userId","assessmentId"],description:"Test assessment declined email"},email_verification:{label:"Email Verification OTP",requiredFields:["userId"],description:"Test email verification OTP email"},message_notification:{label:"Message Notification",requiredFields:["userId"],description:"Test new message notification email"},promo_code_delivery:{label:"Promo Code Delivery",requiredFields:["userId"],description:"Test promo code delivery email"},order_pending_payment:{label:"Order Pending Payment",requiredFields:["userId","orderId"],description:"Test order pending payment reminder email"}},se=t=>{const l=b[t];if(!l)return D({templateType:o().min(1,"Template type is required"),recipientEmail:o().email("Valid email is required")});const d={templateType:o().min(1,"Template type is required"),recipientEmail:o().email("Valid email is required")};return l.requiredFields.includes("userId")&&(d.userId=o().min(1,"User ID is required").regex(/^\d+$/,"User ID must be a number")),l.requiredFields.includes("appointmentId")&&(d.appointmentId=o().min(1,"Appointment ID is required").regex(/^\d+$/,"Appointment ID must be a number")),l.requiredFields.includes("previousAppointmentId")&&(d.previousAppointmentId=o().min(1,"Previous Appointment ID is required").regex(/^\d+$/,"Previous Appointment ID must be a number")),l.requiredFields.includes("prescriptionId")&&(d.prescriptionId=o().min(1,"Prescription ID is required").regex(/^\d+$/,"Prescription ID must be a number")),l.requiredFields.includes("trackingNumber")&&(d.trackingNumber=o().min(1,"Tracking number is required")),l.requiredFields.includes("assessmentId")&&(d.assessmentId=o().min(1,"Assessment ID is required").regex(/^\d+$/,"Assessment ID must be a number")),l.requiredFields.includes("orderId")&&(d.orderId=o().min(1,"Order ID is required").regex(/^\d+$/,"Order ID must be a number")),D(d)};function re(){const[t,l]=y.useState(""),[d,v]=y.useState(!1),{toast:f}=P(),i=w({resolver:Y(se(t)),defaultValues:{templateType:"",recipientEmail:"",userId:"",appointmentId:"",previousAppointmentId:"",prescriptionId:"",trackingNumber:"",assessmentId:"",orderId:""}}),T=s=>{l(s),i.setValue("templateType",s),i.setValue("userId",""),i.setValue("appointmentId",""),i.setValue("previousAppointmentId",""),i.setValue("prescriptionId",""),i.setValue("trackingNumber",""),i.setValue("assessmentId",""),i.setValue("orderId","")},S=async s=>{v(!0);try{const r={templateType:s.templateType,recipientEmail:s.recipientEmail},c=b[s.templateType];c&&c.requiredFields.forEach(n=>{s[n]&&(r[n]=parseInt(s[n],10)||s[n])}),await $("POST","/api/admin/testing/email",r),f({title:"Test Email Sent",description:`Test email for ${c?.label||s.templateType} has been sent to ${s.recipientEmail}`}),i.reset(),l("")}catch(r){f({title:"Error",description:r?.message||"Failed to send test email. Please try again.",variant:"destructive"})}finally{v(!1)}},N=()=>
1{if(!t)return null;const s=b[t];return s?e.jsxs("div",{className:"space-y-4",children:[s.requiredFields.includes("userId")&&e.jsx(m,{control:i.control,name:"userId",render:({field:r})=>e.jsxs(p,{children:[e.jsx(u,{children:"User ID"}),e.jsx(h,{children:e.jsx(a,{...r,placeholder:"Enter user ID"})}),e.jsx(x,{children:"The ID of the user who will receive the email"}),e.jsx(j,{})]})}),s.requiredFields.includes("appointmentId")&&e.jsx(m,{control:i.control,name:"appointmentId",render:({field:r})=>e.jsxs(p,{children:[e.jsx(u,{children:"Appointment ID"}),e.jsx(h,{children:e.jsx(a,{...r,placeholder:"Enter appointment ID"})}),e.jsx(x,{children:"The ID of the appointment for this email"}),e.jsx(j,{})]})}),s.requiredFields.includes("previousAppointmentId")&&e.jsx(m,{control:i.control,name:"previousAppointmentId",render:({field:r})=>e.jsxs(p,{children:[e.jsx(u,{children:"Previous Appointment ID"}),e.jsx(h,{children:e.jsx(a,{...r,placeholder:"Enter previous appointment ID"})}),e.jsx(x,{children:"The ID of the previous appointment that was rescheduled"}),e.jsx(j,{})]})}),s.requiredFields.includes("prescriptionId")&&e.jsx(m,{control:i.control,name:"prescriptionId",render:({field:r})=>e.jsxs(p,{children:[e.jsx(u,{children:"Prescription ID"}),e.jsx(h,{children:e.jsx(a,{...r,placeholder:"Enter prescription ID"})}),e.jsx(x,{children:"The ID of the prescription for this email"}),e.jsx(j,{})]})}),s.requiredFields.includes("trackingNumber")&&e.jsx(m,{control:i.control,name:"trackingNumber",render:({field:r})=>e.jsxs(p,{children:[e.jsx(u,{children:"Tracking Number"}),e.jsx(h,{children:e.jsx(a,{...r,placeholder:"Enter tracking number"})}),e.jsx(x,{children:"The postal tracking number for the prescription"}),e.jsx(j,{})]})}),s.requiredFields.includes("assessmentId")&&e.jsx(m,{control:i.control,name:"assessmentId",render:({field:r})=>e.jsxs(p,{children:[e.jsx(u,{children:"Assessment ID"}),e.jsx(h,{children:e.jsx(a,{...r,placeholder:"Enter assessment ID"})}),e.jsx(x,{children:"The ID of the assessment for this email"}),e.jsx(j,{})]})}),s.requiredFields.includes("orderId")&&e.jsx(m,{control:i.control,name:"orderId",render:({field:r})=>e.jsxs(p,{children:[e.jsx(u,{children:"Order ID"}),e.jsx(h,{children:e.jsx(a,{...r,placeholder:"Enter order ID"})}),e.jsx(x,{children:"The ID of the order for this email"}),e.jsx(j,{})]})})]}):null};return e.jsxs(E,{children:[e.jsxs(M,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{className:"h-5 w-5"}),e.jsx(C,{children:"Test Email Templates"})]}),e.jsx(V,{children:"Send test emails to verify email templates are working correctly with real data"})]}),e.jsx(_,{children:e.jsx(K,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(S),className:"space-y-6",children:[e.jsx(m,{control:i.control,name:"templateType",render:({field:s})=>e.jsxs(p,{children:[e.jsx(u,{children:"Email Template"}),e.jsxs(L,{onValueChange:T,value:s.value,children:[e.jsx(h,{children:e.jsx(O,{children:e.jsx(R,{placeholder:"Select an email template to test"})})}),e.jsx(X,{children:Object.entries(b).map(([r,c])=>e.jsx(F,{value:r,children:c.label},r))})]}),e.jsx(x,{children:t&&b[t]?.description}),e.jsx(j,{})]})}),e.jsx(m,{control:i.control,name:"recipientEmail",render:({field:s})=>e.jsxs(p,{children:[e.jsx(u,{children:"Recipient Email"}),e.jsx(h,{children:e.jsx(a,{...s,placeholder:"Enter email address to receive test email",type:"email"})}),e.jsx(x,{children:"The email address where the test email will be sent"}),e.jsx(j,{})]})}),N(),e.jsx(k,{type:"submit",disabled:d||!t,className:"w-full",children:d?e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending Test Email..."]}):e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"mr-2 h-4 w-4"}),"Send Test Email"]})})]})})})]})}function je(){return e.jsx(J,{title:"Testing",children:e.jsx("div",{className:"container py-6",children:e.jsxs(Q,{defaultValue:"sms",className:"w-full",children:[e.jsxs(W,{className:"mb-6",children:[e.jsxs(q,{value:"sms",className:"flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"Test SMS"]}),e.jsxs(q,{value:"email",className:"flex items-center gap-2",children:[e.jsx(B,{className:"h-4 w-4"}),"Test Email"]})]}),e.jsx(A,{value:"sms",children:e.jsx(ee,{})}),e.jsx(A,{value:"email",children:e.jsx(re,{})})]})})})}export{je 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.