import{a as d}from"./chunk-2E5Q76HC.js";import{d as u}from"./chunk-TY33ZR3E.js";import{a as e}from"./chunk-OC3NYLOT.js";import"./chunk-UNITEU6O.js";var m="http://127.0.0.1:9000";function v(){let l=u(""),n=u(""),s=u(null),a=u(!1);async function c(o){if(o.preventDefault(),s.value=null,a.value=!0,!l.value.trim()||!n.value.trim()){s.value="Username and password are required.",a.value=!1;return}try{let t=new URLSearchParams;t.append("username",l.value),t.append("password",n.value);let r=await fetch(`${m}/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:t});if(!r.ok){let p=await r.json().catch(()=>({detail:`HTTP error! Status: ${r.status}`}));throw new Error(p.detail||`Login failed. Status: ${r.status}`)}let i=await r.json();d.value=i.access_token,typeof localStorage<"u"&&localStorage.setItem("jwt",i.access_token),l.value="",n.value=""}catch(t){s.value=t instanceof Error?t.message:"An unexpected error occurred."}finally{a.value=!1}}return e("form",{onSubmit:c,class:"w-full max-w-sm bg-white p-6 rounded-lg shadow-md my-4",children:[e("h2",{class:"text-xl font-semibold mb-4 text-gray-700",children:"Login"}),s.value&&e("p",{class:"text-red-500 text-sm mb-3",children:s.value}),e("div",{class:"mb-4",children:e("input",{type:"text",placeholder:"Username",value:l.value,onInput:o=>l.value=o.target.value,class:"input input-bordered w-full",disabled:a.value})}),e("div",{class:"mb-4",children:e("input",{type:"password",placeholder:"Password",value:n.value,onInput:o=>n.value=o.target.value,class:"input input-bordered w-full",disabled:a.value})}),e("button",{type:"submit",class:"btn btn-primary w-full",disabled:a.value,children:a.value?"Logging in...":"Login"})]})}export{v as default};
