import{K as q,r as c,m as H,j as e,L as V}from"./app-BMysVXg2.js";import{M as U}from"./Modal-CGc-2kMT.js";import{m as z}from"./utils-BpqJBFla.js";import{A as G}from"./arrow-left-rrEND8lI.js";import{c as O}from"./createLucideIcon-D5220jan.js";/* empty css            */import"./InputGroup-DaetTDdb.js";import"./iconBase-BRa7Gs07.js";import"./circle-alert-YqkuI-V9.js";import"./x-Qqq-yD2O.js";/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const J=[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],Q=O("EyeOff",J);/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const W=[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]],X=O("Eye",W),ie=({setHasPined:_,hasPin:D,open:M,onClose:k})=>{const{auth:A,data:h,errors:o}=q().props,[m,x]=c.useState("phone"),[d,y]=c.useState(0),{data:n,setData:j,post:g,processing:i,reset:C}=H({phone:"",otp:"",pin:"",pin_confirmation:""}),[b,T]=c.useState("password"),l=c.useRef(Array(6).fill(null)),p=c.useRef(Array(6).fill(null)),f=c.useRef(Array(6).fill(null));c.useEffect(()=>{if(d>0){const r=setTimeout(()=>y(d-1),1e3);return()=>clearTimeout(r)}},[d]);const K=r=>{r.preventDefault();const t=route("otp.send",h.nouid);g(t,{onSuccess:()=>{x("otp"),y(60),l.current[0]&&l.current[0].focus()}})},I=r=>{r.preventDefault(),g(route("otp.verif",h.nouid),{onSuccess:()=>{x("pin"),p.current[0]&&p.current[0].focus()}})},F=r=>{r.preventDefault(),g(route("siswa.process-setup-pin",h.nouid),{onSuccess:()=>{k(),_(),C(),x("phone")}})},$=()=>{g(route("otp.send",h.nouid),{onSuccess:()=>{y(60)}})},E=(r,t)=>{var u;const s=r.target.value.replace(/\D/g,""),a=n.otp.split("");a[t]=s.charAt(s.length-1)||"",j("otp",a.join("")),s&&t<5&&l.current[t+1]&&((u=l.current[t+1])==null||u.focus())},w=(r,t,s,a)=>{var P,S;const u=r.target.value.replace(/\D/g,""),v=n[s].split("");v[t]=u.charAt(u.length-1)||"",j(s,v.join("")),u&&t<5&&a.current[t+1]&&((P=a.current[t+1])==null||P.focus()),s==="pin"&&v.join("").length===6&&f.current[0]&&((S=f.current[0])==null||S.focus())},N=(r,t,s)=>{var a;r.key==="Backspace"&&!n.otp[t]&&t>0&&s.current[t-1]&&((a=s.current[t-1])==null||a.focus())},L=()=>{var r;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-center text-2xl font-bold text-gray-900",children:D?"Masukkan Nomor HP Anda yang terdaftar":"Daftarkan Nomor HP Anda"}),e.jsxs("p",{className:"mt-2 text-center text-sm text-gray-600",children:["Kami akan mengirimkan kode OTP ke nomor ini ",e.jsx("br",{}),z(((r=A.user)==null?void 0:r.tel)??"")]})]}),e.jsxs("form",{onSubmit:K,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"phone",className:"block text-sm font-medium text-gray-700",children:"Nomor Handphone"}),e.jsxs("div",{className:"relative mt-1 rounded-md shadow-sm",children:[e.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3",children:e.jsx("span",{className:"text-gray-500 sm:text-sm",children:"+62"})}),e.jsx("input",{type:"tel",id:"phone",name:"phone",autoComplete:"tel",className:`block w-full rounded-md border-2 ${o.phone||o.message?"border-red-500":"border-gray-300"} py-2 pl-12 focus:border-blue-500 focus:ring-blue-500`,placeholder:"8123456789",value:n.phone,onChange:t=>j("phone",t.target.value.replace(/\D/g,"")),required:!0})]}),(o.phone||o.message)&&e.jsx("div",{className:"text-center text-sm text-red-500",children:o.phone||o.message})]}),e.jsx("div",{children:e.jsx("button",{type:"submit",disabled:i||n.phone.length<10,className:`flex w-full justify-center rounded-md border border-transparent px-4 py-2 text-sm font-medium text-white shadow-sm ${n.phone.length>=10?"bg-blue-600 hover:bg-blue-700 focus:ring-blue-500":"cursor-not-allowed bg-gray-400"} focus:ring-2 focus:ring-offset-2 focus:outline-none`,children:i?"Mengirim OTP...":"Kirim Kode OTP"})})]})]})},R=()=>e.jsxs("div",{className:"space-y-6",children:[e.jsxs("button",{onClick:()=>x("phone"),className:"flex items-center text-sm text-gray-600 hover:text-gray-800",children:[e.jsx(G,{className:"mr-1 h-4 w-4"}),"Kembali"]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-center text-2xl font-bold text-gray-900",children:"Verifikasi OTP"}),e.jsxs("p",{className:"mt-2 text-center text-sm text-gray-600",children:["Masukkan 6 digit kode OTP yang dikirim ke +62",n.phone]})]}),e.jsxs("form",{onSubmit:I,className:"space-y-6",children:[e.jsx("div",{className:"flex justify-center space-x-2",children:Array.from({length:6}).map((r,t)=>e.jsx("input",{ref:s=>{l.current[t]=s},type:"text",inputMode:"numeric",pattern:"[0-9]",maxLength:1,required:!0,autoComplete:"off",className:`h-12 w-12 rounded-md border text-center text-2xl focus:ring-1 focus:outline-none ${o?"border-red-500 focus:ring-red-500":"border-gray-300 focus:border-blue-500 focus:ring-blue-500"}`,value:n.otp[t]||"",onChange:s=>E(s,t),onKeyDown:s=>N(s,t,l),onFocus:s=>s.target.select()},t))}),o.message&&e.jsx("div",{className:"text-center text-sm text-red-500",children:o.message}),e.jsx("div",{className:"text-center",children:d>0?e.jsxs("p",{className:"text-sm text-gray-500",children:["Kirim ulang OTP dalam ",d," detik"]}):e.jsx("button",{type:"button",onClick:$,className:"text-sm text-blue-600 hover:text-blue-800",children:"Kirim Ulang OTP"})}),e.jsx("div",{children:e.jsx("button",{type:"submit",disabled:i||n.otp.length!==6,className:`flex w-full justify-center rounded-md border border-transparent px-4 py-2 text-sm font-medium text-white shadow-sm ${n.otp.length===6?"bg-blue-600 hover:bg-blue-700 focus:ring-blue-500":"cursor-not-allowed bg-gray-400"} focus:ring-2 focus:ring-offset-2 focus:outline-none`,children:i?"Memverifikasi...":"Verifikasi"})})]})]}),B=()=>e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-center text-2xl font-bold text-gray-900",children:"Buat PIN 6 Digit Baru"}),e.jsx("p",{className:"mt-2 text-center text-sm text-gray-600",children:"Untuk keamanan akun Anda"})]}),e.jsxs("form",{onSubmit:F,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"pin",className:"mb-2 block text-center text-sm font-medium text-gray-700",children:"Masukkan PIN Baru"}),e.jsx("div",{className:"flex justify-center space-x-2",children:Array.from({length:6}).map((r,t)=>e.jsx("input",{ref:s=>{p.current[t]=s},type:b,inputMode:"numeric",pattern:"[0-9]",maxLength:1,required:!0,autoComplete:"off",className:`h-12 w-12 rounded-md border text-center text-2xl focus:ring-1 focus:outline-none ${o.pin?"border-red-500 focus:ring-red-500":"border-gray-300 focus:border-blue-500 focus:ring-blue-500"}`,value:n.pin[t]||"",onChange:s=>w(s,t,"pin",p),onKeyDown:s=>N(s,t,p),onFocus:s=>s.target.select()},t))})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"pin_confirmation",className:"mb-2 block text-center text-sm font-medium text-gray-700",children:"Konfirmasi PIN Baru"}),e.jsx("div",{className:"flex justify-center space-x-2",children:Array.from({length:6}).map((r,t)=>e.jsx("input",{ref:s=>{f.current[t]=s},type:b,inputMode:"numeric",pattern:"[0-9]",maxLength:1,required:!0,autoComplete:"off",className:`h-12 w-12 rounded-md border text-center text-2xl focus:ring-1 focus:outline-none ${o.pin_confirmation?"border-red-500 focus:ring-red-500":"border-gray-300 focus:border-blue-500 focus:ring-blue-500"}`,value:n.pin_confirmation[t]||"",onChange:s=>w(s,t,"pin_confirmation",f),onKeyDown:s=>N(s,t,f),onFocus:s=>s.target.select()},t))})]}),(o.pin||o.pin_confirmation||o.message)&&e.jsx("div",{className:"text-center text-sm text-red-500",children:o.pin||o.pin_confirmation||o.message}),e.jsx("div",{className:"flex justify-center",children:e.jsx("button",{type:"button",className:"flex items-center text-sm text-gray-600 hover:text-gray-800",onClick:()=>T(b==="password"?"text":"password"),children:b==="password"?e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"mr-1 h-4 w-4"}),"Tampilkan PIN"]}):e.jsxs(e.Fragment,{children:[e.jsx(Q,{className:"mr-1 h-4 w-4"}),"Sembunyikan PIN"]})})})]}),e.jsx("div",{children:e.jsx("button",{type:"submit",disabled:i||n.pin.length!==6||n.pin!==n.pin_confirmation,className:`flex w-full justify-center rounded-md border border-transparent px-4 py-2 text-sm font-medium text-white shadow-sm ${n.pin.length===6&&n.pin===n.pin_confirmation?"bg-blue-600 hover:bg-blue-700 focus:ring-blue-500":"cursor-not-allowed bg-gray-400"} focus:ring-2 focus:ring-offset-2 focus:outline-none`,children:i?"Menyimpan...":"Simpan PIN"})})]})]});return e.jsx(U,{isOpen:M,onClose:k,header:!1,children:e.jsxs("div",{className:"flex items-center justify-center p-2",children:[e.jsx(V,{title:m==="phone"?"Daftar Nomor HP":m==="otp"?"Verifikasi OTP":"Buat PIN"}),e.jsxs("div",{className:"w-full max-w-md rounded-lg",children:[m==="phone"&&L(),m==="otp"&&R(),m==="pin"&&B()]})]})})};export{ie as default};
