1import{i as e}from"./rolldown-runtime-jxEyR9vv.js";import{v as t}from"./charts-BqcS3ABW.js";import{t as a}from"./react-aNZyGp20.js";import{o as s}from"./redux-CNAj8k4q.js";import{t as l}from"./axios-DPlPz_4c.js";import{Dt as i,E as n,St as r,i as o,tt as d,wr as c}from"./icons-B3484nFG.js";var x=e(t(),1),p=a(),m={hospital:"",api_token:"",opd_template:"opd_report_1_",lab_template:"lab_report_new_2",template_language:"en",is_active:!0};function g(){const e=s(e=>e.hospital.hospitalId)||localStorage.getItem("hospitalId"),[t,a]=(0,x.useState)([]),[g,h]=(0,x.useState)(!1),[u,f]=(0,x.useState)(!1),[b,j]=(0,x.useState)(null),[y,N]=(0,x.useState)(m),[v,_]=(0,x.useState)(!1),[w,k]=(0,x.useState)(""),C=(0,x.useCallback)(async()=>{h(!0);try{const e=await l.get("/api/whatsapp/config/");a(Array.isArray(e.data)?e.data:[])}catch(e){}finally{h(!1)}},[e]);(0,x.useEffect)(()=>{C()},[C]);return(0,p.jsxs)("div",{className:"p-4 md:p-6",children:[(0,p.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,p.jsxs)("div",{className:"flex items-center gap-3",children:[(0,p.jsx)(d,{className:"w-6 h-6 text-indigo-600"}),(0,p.jsx)("h1",{className:"text-xl font-semibold text-gray-800",children:"WhatsApp Config"})]}),(0,p.jsxs)("button",{onClick:()=>{N({...m,hospital:e||""}),j(null),k(""),f(!0)},className:"flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white rounded-lg text-sm hover:bg-indigo-700",children:[(0,p.jsx)(r,{className:"w-4 h-4"})," Add Config"]})]}),u&&(0,p.jsxs)("div",{className:"bg-white rounded-xl shadow p-5 mb-6 border border-indigo-100",children:[(0,p.jsx)("h2",{className:"text-base font-semibold text-gray-700 mb-4",children:b?"Edit Config":"Add New Config"}),(0,p.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,p.jsxs)("div",{children:[(0,p.jsx)("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Hospital ID"}),(0,p.jsx)("input",{value:y.hospital,onChange:e=>N({...y,hospital:e.target.value}),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500",placeholder:"Hospital ID"})]}),(0,p.jsxs)("div",{children:[(0,p.jsx)("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"API Token (wapromo.in)"}),(0,p.jsx)("input",{value:y.api_token,onChange:e=>N({...y,api_token:e.target.value}),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500",placeholder:"Paste API token from wapromo.in â API Info"})]}),(0,p.jsxs)("div",{children:[(0,p.jsx)("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"OPD Template Name"}),(0,p.jsx)("input",{value:y.opd_template,onChange:e=>N({...y,opd_template:e.target.value}),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500",placeholder:"e.g. opd_report_1_"})]}),(0,p.jsxs)("div",{children:[(0,p.jsx)("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Lab Template Name"}),(0,p.jsx)("input",{value:y.lab_template,onChange:e=>N({...y,lab_template:e.target.value}),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-indigo-500",placeholder:"e.g. utility_lab_report"})]}),(0,p.jsxs)("div",{children:[(0,p.jsx)("label",{className:"block text-xs font-medium text-gray-600 mb-1",children:"Template Language"}),(0,p.jsxs)("select",{value:y.template_language,onChange:e=>N({...y,template_language:e.target.value}),className:"w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none",children:[(0,p.jsx)("option",{value:"en",children:"English (en)"}),(0,p.jsx)("option",{value:"en_US",children:"English US (en_US)"}),(0,p.jsx)("option",{value:"hi",children:"Hindi (hi)"})]})]}),(0,p.jsxs)("div",{className:"flex items-center gap-3 mt-5",children:[(0,p.jsx)("input",{type:"checkbox",id:"is_active",checked:y.is_active,onChange:e=>N({...y,is_active:e.target.checked}),className:"w-4 h-4 text-indigo-600"}),(0,p.jsx)("label",{htmlFor:"is_active",className:"text-sm text-gray-700",children:"Active (enable WhatsApp notifications)"})]})]}),w&&(0,p.jsx)("p",{className:"mt-3 text-sm text-red-500",children:w}),(0,p.jsxs)("div",{className:"flex gap-3 mt-4",children:[(0,p.jsxs)("button",{onClick:async()=>
1{if(y.hospital&&y.api_token){_(!0),k("");try{b?await l.put(`/api/whatsapp/config/${b}/`,y):await l.post("/api/whatsapp/config/",y),f(!1),C()}catch(e){k(e.response?.data?.error||JSON.stringify(e.response?.data)||"Save failed.")}finally{_(!1)}}else k("Hospital and API Token are required.")},disabled:v,className:"flex items-center gap-2 px-5 py-2 bg-indigo-600 text-white rounded-lg text-sm hover:bg-indigo-700 disabled:opacity-50",children:[(0,p.jsx)(c,{className:"w-4 h-4"})," ",v?"Saving...":"Save"]}),(0,p.jsxs)("button",{onClick:()=>f(!1),className:"flex items-center gap-2 px-5 py-2 border border-gray-300 rounded-lg text-sm hover:bg-gray-50",children:[(0,p.jsx)(o,{className:"w-4 h-4"})," Cancel"]})]})]}),(0,p.jsx)("div",{className:"bg-white rounded-xl shadow overflow-hidden",children:(0,p.jsx)("div",{className:"overflow-x-auto",children:(0,p.jsxs)("table",{className:"w-full text-sm",children:[(0,p.jsx)("thead",{className:"bg-gray-50 border-b border-gray-200",children:(0,p.jsxs)("tr",{children:[(0,p.jsx)("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Hospital"}),(0,p.jsx)("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"OPD Template"}),(0,p.jsx)("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Lab Template"}),(0,p.jsx)("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Language"}),(0,p.jsx)("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Status"}),(0,p.jsx)("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Actions"})]})}),(0,p.jsx)("tbody",{className:"divide-y divide-gray-100",children:g?(0,p.jsx)("tr",{children:(0,p.jsx)("td",{colSpan:6,className:"text-center py-10 text-gray-400",children:"Loading..."})}):0===t.length?(0,p.jsx)("tr",{children:(0,p.jsx)("td",{colSpan:6,className:"text-center py-10 text-gray-400",children:'No config found. Click "Add Config" to set up WhatsApp for a hospital.'})}):t.map(e=>(0,p.jsxs)("tr",{className:"hover:bg-gray-50",children:[(0,p.jsx)("td",{className:"px-4 py-3 font-medium text-gray-800",children:e.hospital_name}),(0,p.jsx)("td",{className:"px-4 py-3 text-gray-600",children:e.opd_template}),(0,p.jsx)("td",{className:"px-4 py-3 text-gray-600",children:e.lab_template}),(0,p.jsx)("td",{className:"px-4 py-3 text-gray-500",children:e.template_language}),(0,p.jsx)("td",{className:"px-4 py-3",children:(0,p.jsx)("span",{className:"px-2 py-1 rounded-full text-xs font-medium "+(e.is_active?"bg-green-100 text-green-700":"bg-red-100 text-red-600"),children:e.is_active?"Active":"Inactive"})}),(0,p.jsx)("td",{className:"px-4 py-3",children:(0,p.jsxs)("div",{className:"flex items-center gap-3",children:[(0,p.jsx)("button",{onClick:()=>(e=>{N({hospital:e.hospital,api_token:e.api_token,opd_template:e.opd_template,lab_template:e.lab_template,template_language:e.template_language,is_active:e.is_active}),j(e.id),k(""),f(!0)})(e),className:"text-blue-600 hover:text-blue-800",children:(0,p.jsx)(i,{className:"w-4 h-4"})}),(0,p.jsx)("button",{onClick:()=>(async e=>{if(window.confirm("Delete this WhatsApp config?"))try{await l.delete(`/api/whatsapp/config/${e}/`),C()}catch(t){alert("Delete failed.")}})(e.id),className:"text-red-500 hover:text-red-700",children:(0,p.jsx)(n,{className:"w-4 h-4"})})]})})]},e.id))})]})})})]})}export{g 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.