import{r as a,I,c as P,u as S,b6 as b,j as e,B as o}from"./index-BLjtKp_X.js";import{v as R,R as F,e as A}from"./network-BAebpUjs.js";import{H as u}from"./head-CXYXhTUP.js";import{F as n}from"./index-CM8WjZyp.js";import{I as x,R as B}from"./LockOutlined-Cb8Fzp1E.js";import{R as W}from"./CheckOutlined-Demjnj8G.js";var V={icon:{tag:"svg",attrs:{viewBox:"64 64 896 896",focusable:"false"},children:[{tag:"path",attrs:{d:"M608 112c-167.9 0-304 136.1-304 304 0 70.3 23.9 135 63.9 186.5l-41.1 41.1-62.3-62.3a8.15 8.15 0 00-11.4 0l-39.8 39.8a8.15 8.15 0 000 11.4l62.3 62.3-44.9 44.9-62.3-62.3a8.15 8.15 0 00-11.4 0l-39.8 39.8a8.15 8.15 0 000 11.4l62.3 62.3-65.3 65.3a8.03 8.03 0 000 11.3l42.3 42.3c3.1 3.1 8.2 3.1 11.3 0l253.6-253.6A304.06 304.06 0 00608 720c167.9 0 304-136.1 304-304S775.9 112 608 112zm161.2 465.2C726.2 620.3 668.9 644 608 644c-60.9 0-118.2-23.7-161.2-66.8-43.1-43-66.8-100.3-66.8-161.2 0-60.9 23.7-118.2 66.8-161.2 43-43.1 100.3-66.8 161.2-66.8 60.9 0 118.2 23.7 161.2 66.8 43.1 43 66.8 100.3 66.8 161.2 0 60.9-23.7 118.2-66.8 161.2z"}}]},name:"key",theme:"outlined"},E=function(l,i){return a.createElement(I,P({},l,{ref:i,icon:V}))},T=a.forwardRef(E);const H=()=>{const{t:s}=S(),[l]=b(),[i,c]=a.useState(""),[j,w]=a.useState(""),[y,N]=a.useState(!1),[f,m]=a.useState(!1),[p,d]=a.useState("");a.useEffect(()=>{const t=l.get("p")||l.get("P");t&&h(t)},[]);async function h(t){if(!f){m(!0),d("");try{const r=await R(t);r?.code===0?(w(t),N(!0)):d(r?.code===-1?"denied":"failed")}catch(r){console.error(r),d("failed")}m(!1)}}async function g(t){t.apPassword&&await h(t.apPassword)}async function v(t){if(!(!t.ssid||!t.password)&&i!=="loading"){c("loading");try{switch((await A(t.ssid,t.password,j))?.code){case 0:c("success");return;case-1:case-4:c("denied");return;case-2:case-3:c("failed");return}}catch(r){console.log(r)}c("success")}}return y?e.jsxs(e.Fragment,{children:[e.jsx(u,{title:s("head.wifi")}),e.jsxs("div",{className:"flex h-screen w-screen flex-col items-center justify-center",children:[e.jsxs(n,{style:{minWidth:300,maxWidth:500},initialValues:{remember:!0},onFinish:v,children:[e.jsxs("div",{className:"flex flex-col space-y-1 pb-5",children:[e.jsx("span",{className:"text-center text-2xl font-semibold text-neutral-100",children:s("wifi.title")}),e.jsx("span",{className:"text-center text-neutral-400",children:s("wifi.description")})]}),e.jsx(n.Item,{name:"ssid",children:e.jsx(x,{prefix:e.jsx(F,{}),placeholder:"SSID"})}),e.jsx(n.Item,{name:"password",children:e.jsx(x.Password,{prefix:e.jsx(B,{}),placeholder:"Password"})}),e.jsx(n.Item,{children:i==="success"?e.jsx(o,{className:"w-full",type:"primary",icon:e.jsx(W,{}),children:s("wifi.finishBtn")}):e.jsx(o,{className:"w-full",htmlType:"submit",type:"primary",loading:i==="loading",children:s("wifi.confirmBtn")})})]}),e.jsxs("div",{className:"flex max-w-[500px] justify-center px-5 pt-3 md:px-10",children:[i==="success"&&e.jsx("span",{className:"text-sm text-green-500",children:s("wifi.success")}),i==="failed"&&e.jsxs("span",{className:"text-sm text-red-500",children:[s("wifi.failed")," "]}),i==="denied"&&e.jsx("div",{className:"flex flex-col items-center space-y-5",children:e.jsxs("span",{className:"text-sm text-red-500",children:[s("wifi.invalidMode")," "]})})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(u,{title:s("head.wifi")}),e.jsxs("div",{className:"flex h-screen w-screen flex-col items-center justify-center",children:[e.jsxs(n,{style:{minWidth:300,maxWidth:500},initialValues:{remember:!0},onFinish:g,children:[e.jsxs("div",{className:"flex flex-col space-y-1 pb-5",children:[e.jsx("span",{className:"text-center text-2xl font-semibold text-red-500",children:s("wifi.ap.authTitle")}),e.jsx("span",{className:"text-center text-neutral-400",children:s("wifi.ap.authDescription")})]}),e.jsx(n.Item,{name:"apPassword",children:e.jsx(x.Password,{prefix:e.jsx(T,{}),placeholder:s("wifi.ap.passPlaceholder")})}),e.jsx(n.Item,{children:e.jsx(o,{className:"w-full",htmlType:"submit",type:"primary",loading:f,children:s("wifi.ap.verifyBtn")})})]}),e.jsxs("div",{className:"flex max-w-[500px] justify-center px-5 pt-3 md:px-10",children:[p==="failed"&&e.jsx("span",{className:"text-sm text-red-500",children:s("wifi.ap.authFailed")}),p==="denied"&&e.jsx("span",{className:"text-sm text-red-500",children:s("wifi.invalidMode")})]})]})]})};export{H as Wifi};
