import{R as X,j as e}from"./index-DWp6u1Ix.js";import{a as d,p as T,q as L,s as C,R as S,C as A,j as O}from"./icons-BLu1UXn4.js";import"./react-Cfa4jLPc.js";function P({currentUser:r,onSaveRadioTest:$,radioTests:F}){const[o,R]=d.useState(new Date),[n,x]=d.useState(()=>X.map((t,s)=>({stationId:`s_${s+1}`,stationName:t,txLevel:"5",rxLevel:"5",channelType:"T",note:""}))),[m,k]=d.useState(Array(5).fill(null).map(()=>({stationName:"",txLevel:"5",rxLevel:"5",channelType:"T",note:""}))),[b,i]=d.useState("");d.useEffect(()=>{const t=setInterval(()=>{R(new Date)},1e3);return()=>clearInterval(t)},[]);const p=t=>t.toLocaleTimeString("th-TH",{hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}),g=t=>{const s=t.getHours();return s>=8&&s<16?"เช้า":s>=16&&s<24?"บ่าย":"ดึก"},v=`“เจ็บป่วยฉุกเฉิน โทร 1669 ที่นี่ศูนย์รับแจ้งเหตุนเรนทรอ่าวไทย ขณะนี้เวลา ${p(o)} นเรนทรอ่าวไทยแจ้งลูกข่ายและในข่าย จะทำการทดสอบ ว.16 ลูกข่ายและในข่ายนเรนทรอ่าวไทย มี ว.29 ไม่เร่งด่วน ให้ ว.00 หากมี ว.29 เร่งด่วน ให้ขออนุญาต ว.6 เข้ามาได้”`,h=m.filter(t=>t.stationName.trim()!==""),I=n.filter(t=>t.txLevel!=="ติดต่อไม่ได้"||t.rxLevel!=="ติดต่อไม่ได้").length,E=h.filter(t=>t.txLevel!=="ติดต่อไม่ได้"||t.rxLevel!=="ติดต่อไม่ได้").length,u=I+E,D=n.filter(t=>t.txLevel==="ติดต่อไม่ได้"&&t.rxLevel==="ติดต่อไม่ได้").length,f=[...n.filter(t=>t.txLevel==="ติดต่อไม่ได้"&&t.rxLevel==="ติดต่อไม่ได้").map(t=>t.stationName),...h.filter(t=>t.txLevel==="ติดต่อไม่ได้"&&t.rxLevel==="ติดต่อไม่ได้").map(t=>t.stationName)],j=`“มีอีกหรือไม่ ลูกข่ายและในข่ายนเรนทรอ่าวไทยที่ต้องการทดสอบ ว.16 ให้ ว.6 เข้ามาได้ ว.24 นี้ [ ${p(o)} ] นเรนทรอ่าวไทยแจ้ง ว.14 ว.16 วันนี้มีผู้ร่วมทดสอบ ว.16 จำนวน ${u} สถานี นเรนทรอ่าวไทยขอขอบคุณทุกสถานีที่ร่วมทดสอบ ว.16 แจ้งลูกข่ายและในข่ายใช้ความถี่ได้ตามปกติ ทดสอบโดย สมุย [ ${r.fullName.split(" ")[0]} ] นเรนทรอ่าวไทย [ ${p(o)} ]”`,N=(t,s)=>{navigator.clipboard.writeText(t),i(`คัดลอกข้อความ ${s} เรียบร้อยแล้ว`),setTimeout(()=>i(""),3e3)},w=(t,s,l)=>{const a=[...n];a[t][s]=l,x(a)},y=(t,s)=>{const l=[...n];l[t].channelType=s,x(l)},M=(t,s)=>{const l=[...n];l[t].note=s,x(l)},c=(t,s,l)=>{const a=[...m];a[t]={...a[t],[s]:l},k(a)},_=()=>{const t=o.toISOString().split("T")[0],s={id:`rt_${Date.now()}`,date:t,time:o.toTimeString().split(" ")[0].substring(0,5),shift:g(o),testerUsername:r.username,testerName:r.fullName,items:n,extraStations:h,testedCount:u,untestedCount:D,unreachableStations:f};$(s),i("บันทึกผลทดสอบวิทยุ ว.16 สำเร็จเรียบร้อยแล้ว!"),window.scrollTo({top:0,behavior:"smooth"}),setTimeout(()=>i(""),4e3)};return e.jsxs("div",{className:"space-y-6",children:[b&&e.jsxs("div",{className:"fixed top-24 right-4 z-50 bg-emerald-600 text-white px-6 py-3.5 rounded-xl shadow-xl flex items-center gap-3 animate-bounce",children:[e.jsx(T,{className:"w-5 h-5"}),e.jsx("span",{className:"font-semibold",children:b})]}),e.jsxs("div",{className:"bg-gradient-to-br from-blue-900 to-indigo-900 text-white rounded-2xl p-5 md:p-6 shadow-lg border border-blue-800",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(L,{className:"w-5 h-5 text-blue-300 animate-pulse"}),e.jsx("span",{className:"text-sm font-bold uppercase tracking-wider text-blue-200",children:"ข้อความประกาศ ว.16 - ก่อนทดสอบ"})]}),e.jsxs("button",{onClick:()=>N(v,"เปิดพิธี"),className:"flex items-center gap-1.5 bg-blue-800/80 hover:bg-blue-700 text-xs px-3 py-1.5 rounded-lg border border-blue-600/50 transition-all cursor-pointer font-medium",children:[e.jsx(C,{className:"w-3.5 h-3.5"})," คัดลอกบทพูด"]})]}),e.jsx("div",{className:"bg-slate-950/50 p-4 rounded-xl border border-blue-800/50 font-mono text-xs md:text-sm leading-relaxed whitespace-pre-line text-slate-100",children:v})]}),e.jsxs("div",{className:"bg-white rounded-2xl shadow-sm border border-slate-200/80 overflow-hidden",children:[e.jsxs("div",{className:"p-4 md:p-5 bg-slate-50 border-b border-slate-200/80 flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-base font-bold text-slate-800 flex items-center gap-2",children:[e.jsx(S,{className:"w-4.5 h-4.5 text-indigo-600 animate-pulse"})," ตารางทดสอบวิทยุ (16 สถานีหลัก)"]}),e.jsx("p",{className:"text-xs text-slate-400 mt-0.5 font-medium",children:"ระบุระดับสัญญาณรับส่ง (5 หมายถึงดีที่สุด, ติดต่อไม่ได้ หมายถึงสัญญาณขาดหาย)"})]}),e.jsxs("div",{className:"text-xs font-bold bg-indigo-50 text-indigo-700 px-3 py-1.5 rounded-lg border border-indigo-100 self-start sm:self-auto flex items-center gap-1.5",children:[e.jsx(A,{className:"w-3.5 h-3.5 text-indigo-500"})," เวร",g(o)," | ผู้บันทึก: ",r.fullName.split(" ")[0]]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left border-collapse text-xs md:text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-slate-100/50 text-slate-600 font-bold border-b border-slate-200/80",children:[e.jsx("th",{className:"py-3 px-4 w-12 text-center",children:"ลำดับ"}),e.jsx("th",{className:"py-3 px-3 min-w-[150px]",children:"ชื่อสถานี"}),e.jsx("th",{className:"py-3 px-3 text-center min-w-[130px]",children:"สัญญาณส่ง (TX)"}),e.jsx("th",{className:"py-3 px-3 text-center min-w-[130px]",children:"สัญญาณรับ (RX)"}),e.jsx("th",{className:"py-3 px-3 text-center w-36",children:"ช่องรับสัญญาณ"}),e.jsx("th",{className:"py-3 px-3 min-w-[150px]",children:"หมายเหตุเพิ่มเติม"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-100 text-slate-700 font-medium",children:n.map((t,s)=>{const l=t.txLevel==="ติดต่อไม่ได้"&&t.rxLevel==="ติดต่อไม่ได้";return e.jsxs("tr",{className:`hover:bg-slate-50/50 transition-colors ${l?"bg-red-50/20":""}`,children:[e.jsx("td",{className:"py-2.5 px-4 text-center text-slate-400 font-semibold",children:s+1}),e.jsx("td",{className:"py-2.5 px-3",children:e.jsx("div",{className:"font-bold text-slate-800",children:t.stationName})}),e.jsx("td",{className:"py-2.5 px-3 text-center",children:e.jsxs("select",{value:t.txLevel,onChange:a=>w(s,"txLevel",a.target.value),className:`w-full py-1.5 px-2 rounded-lg border border-slate-200 text-xs font-bold text-slate-700 focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 outline-none transition-all ${t.txLevel==="5"?"bg-emerald-50 text-emerald-700 border-emerald-200":""} ${t.txLevel==="ติดต่อไม่ได้"?"bg-rose-100 text-rose-700 border-rose-200":""} `,children:[e.jsx("option",{value:"5",children:"5/5 - ดีมาก"}),e.jsx("option",{value:"4",children:"4/5 - ดี"}),e.jsx("option",{value:"3",children:"3/5 - ปานกลาง"}),e.jsx("option",{value:"2",children:"2/5 - อ่อน"}),e.jsx("option",{value:"1",children:"1/5 - แย่มาก"}),e.jsx("option",{value:"ติดต่อไม่ได้",children:"❌ ติดต่อไม่ได้"})]})}),e.jsx("td",{className:"py-2.5 px-3 text-center",children:e.jsxs("select",{value:t.rxLevel,onChange:a=>w(s,"rxLevel",a.target.value),className:`w-full py-1.5 px-2 rounded-lg border border-slate-200 text-xs font-bold text-slate-700 focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 outline-none transition-all ${t.rxLevel==="5"?"bg-emerald-50 text-emerald-700 border-emerald-200":""} ${t.rxLevel==="ติดต่อไม่ได้"?"bg-rose-100 text-rose-700 border-rose-200":""} `,children:[e.jsx("option",{value:"5",children:"5/5 - ดีมาก"}),e.jsx("option",{value:"4",children:"4/5 - ดี"}),e.jsx("option",{value:"3",children:"3/5 - ปานกลาง"}),e.jsx("option",{value:"2",children:"2/5 - อ่อน"}),e.jsx("option",{value:"1",children:"1/5 - แย่มาก"}),e.jsx("option",{value:"ติดต่อไม่ได้",children:"❌ ติดต่อไม่ได้"})]})}),e.jsx("td",{className:"py-2.5 px-3 text-center",children:e.jsxs("div",{className:"flex rounded-lg overflow-hidden border border-slate-200 p-0.5 bg-slate-100",children:[e.jsx("button",{type:"button",onClick:()=>y(s,"T"),className:`flex-1 py-1 text-[10px] font-bold rounded-md transition-all cursor-pointer ${t.channelType==="T"?"bg-indigo-600 text-white shadow-sm":"text-slate-600 hover:text-slate-800"}`,children:"T (ช่องตรง)"}),e.jsx("button",{type:"button",onClick:()=>y(s,"R"),className:`flex-1 py-1 text-[10px] font-bold rounded-md transition-all cursor-pointer ${t.channelType==="R"?"bg-indigo-600 text-white shadow-sm":"text-slate-600 hover:text-slate-800"}`,children:"R (Repeater)"})]})}),e.jsx("td",{className:"py-2.5 px-3",children:e.jsx("input",{type:"text",placeholder:"ไม่มีความเห็นพิเศษ...",value:t.note||"",onChange:a=>M(s,a.target.value),className:"w-full px-2.5 py-1.5 border border-slate-200 rounded-lg text-xs font-medium outline-none focus:border-indigo-400 focus:ring-1 focus:ring-indigo-400 transition-all bg-slate-50/50 hover:bg-white focus:bg-white"})})]},t.stationId)})})]})})]}),e.jsxs("div",{className:"bg-white rounded-2xl shadow-sm border border-slate-100 overflow-hidden",children:[e.jsxs("div",{className:"p-4 md:p-5 bg-slate-50 border-b border-slate-100",children:[e.jsxs("h3",{className:"text-base font-bold text-slate-800 flex items-center gap-2",children:[e.jsx(S,{className:"w-4 h-4 text-emerald-600"})," ตารางทดสอบวิทยุเพิ่มเติม (ลูกข่ายอื่น ๆ 5 ช่องพิเศษ)"]}),e.jsx("p",{className:"text-xs text-slate-500 mt-0.5",children:"ระบุชื่อลูกข่ายและผลทดสอบวิทยุ (หากมีการกรอกชื่อ ระบบจึงจะนำข้อมูลมาคำนวณจำนวนผลสรุป)"})]}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-5 gap-3 font-bold text-xs text-slate-500 border-b border-slate-100 pb-2 hidden md:grid",children:[e.jsx("div",{className:"col-span-2 px-1",children:"ระบุชื่อสถานีลูกข่ายเพิ่มเติม"}),e.jsx("div",{className:"text-center",children:"สัญญาณส่ง (TX)"}),e.jsx("div",{className:"text-center",children:"สัญญาณรับ (RX)"}),e.jsx("div",{className:"px-1",children:"หมายเหตุเพิ่มเติม"})]}),m.map((t,s)=>e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-5 gap-3 items-center bg-slate-50/30 p-2.5 md:p-1 rounded-xl border border-slate-100 md:border-none md:bg-transparent",children:[e.jsxs("div",{className:"col-span-2 flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-bold text-slate-400 w-6 text-center",children:s+17}),e.jsx("input",{type:"text",placeholder:"เช่น กู้ชีพตลิ่งงาม (ปล่อยว่างเพื่อไม่บันทึก)",value:t.stationName,onChange:l=>c(s,"stationName",l.target.value),className:"flex-1 px-3 py-2 border border-slate-200 rounded-lg text-xs font-semibold outline-none focus:border-emerald-400 focus:ring-1 focus:ring-emerald-400 transition-all bg-white"})]}),e.jsx("div",{children:e.jsxs("select",{value:t.txLevel,onChange:l=>c(s,"txLevel",l.target.value),disabled:t.stationName.trim()==="",className:"w-full py-2 px-2.5 rounded-lg border border-slate-200 text-xs font-bold text-slate-700 outline-none transition-all disabled:opacity-50 disabled:bg-slate-50",children:[e.jsx("option",{value:"5",children:"5/5 - ดีมาก"}),e.jsx("option",{value:"4",children:"4/5 - ดี"}),e.jsx("option",{value:"3",children:"3/5 - ปานกลาง"}),e.jsx("option",{value:"2",children:"2/5 - อ่อน"}),e.jsx("option",{value:"1",children:"1/5 - แย่มาก"}),e.jsx("option",{value:"ติดต่อไม่ได้",children:"❌ ติดต่อไม่ได้"})]})}),e.jsx("div",{children:e.jsxs("select",{value:t.rxLevel,onChange:l=>c(s,"rxLevel",l.target.value),disabled:t.stationName.trim()==="",className:"w-full py-2 px-2.5 rounded-lg border border-slate-200 text-xs font-bold text-slate-700 outline-none transition-all disabled:opacity-50 disabled:bg-slate-50",children:[e.jsx("option",{value:"5",children:"5/5 - ดีมาก"}),e.jsx("option",{value:"4",children:"4/5 - ดี"}),e.jsx("option",{value:"3",children:"3/5 - ปานกลาง"}),e.jsx("option",{value:"2",children:"2/5 - อ่อน"}),e.jsx("option",{value:"1",children:"1/5 - แย่มาก"}),e.jsx("option",{value:"ติดต่อไม่ได้",children:"❌ ติดต่อไม่ได้"})]})}),e.jsx("div",{className:"col-span-1",children:e.jsx("input",{type:"text",placeholder:"หมายเหตุเพิ่มเติม...",value:t.note,onChange:l=>c(s,"note",l.target.value),disabled:t.stationName.trim()==="",className:"w-full px-3 py-2 border border-slate-200 rounded-lg text-xs font-medium outline-none focus:border-emerald-400 focus:ring-1 focus:ring-emerald-400 transition-all bg-white disabled:opacity-50 disabled:bg-slate-50"})})]},`extra_${s}`))]})]}),e.jsxs("div",{className:"bg-gradient-to-br from-indigo-900 to-slate-900 text-white rounded-2xl p-5 md:p-6 shadow-lg border border-indigo-800",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(L,{className:"w-5 h-5 text-indigo-300 animate-pulse"}),e.jsx("span",{className:"text-sm font-bold uppercase tracking-wider text-indigo-200",children:"ข้อความประกาศ ว.16 - ปิดการทดสอบ"})]}),e.jsxs("button",{onClick:()=>N(j,"ปิดการทดสอบ"),className:"flex items-center gap-1.5 bg-indigo-800/80 hover:bg-indigo-700 text-xs px-3 py-1.5 rounded-lg border border-indigo-600/50 transition-all cursor-pointer font-medium",children:[e.jsx(C,{className:"w-3.5 h-3.5"})," คัดลอกบทพูด"]})]}),e.jsx("div",{className:"bg-slate-950/50 p-4 rounded-xl border border-indigo-800/50 font-mono text-xs md:text-sm leading-relaxed whitespace-pre-line text-slate-100",children:j})]}),e.jsxs("div",{className:"bg-slate-50 rounded-2xl p-4 md:p-5 border border-slate-200/80 flex flex-col sm:flex-row items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-indigo-100 rounded-xl text-indigo-700 border border-indigo-200/50",children:e.jsx(T,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-slate-800",children:"ยืนยันและสรุปผลตรวจ ว.16"}),e.jsxs("p",{className:"text-xs text-slate-400 mt-0.5 font-medium",children:["เข้าร่วม ",u," สถานี | ติดต่อไม่ได้ ",f.length," สถานี | ผู้ทดสอบ: ",r.fullName]})]})]}),e.jsxs("button",{onClick:_,className:"w-full sm:w-auto flex items-center justify-center gap-2.5 bg-indigo-600 hover:bg-indigo-700 text-white font-bold text-sm px-6 py-3 rounded-xl shadow-md shadow-indigo-100 transition-all active:scale-95 cursor-pointer",id:"btn-save-radio-test",children:[e.jsx(O,{className:"w-4 h-4"})," บันทึกและส่งข้อมูลเข้ารายงานเวร"]})]})]})}export{P as default};