import{c as T,r as t,P as c,j as e,X as S,C as L,T as U,I as B,B as C,a as x}from"./main-D-T5fPSb.js";/** * @license lucide-react v0.545.0 - ISC * * This source code is licensed under the ISC license. * See the LICENSE file in the root directory of this source tree. */const A=[["path",{d:"m10 17 5-5-5-5",key:"1bsop3"}],["path",{d:"M15 12H3",key:"6jk70r"}],["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}]],H=T("log-in",A),_=({isOpen:z,machine:a,onClose:k,onSubmit:I})=>{const[y,g]=t.useState(""),[m,f]=t.useState(""),[n,h]=t.useState(""),[j,b]=t.useState(""),[o,v]=t.useState(!1),[N,w]=t.useState(null),[u,F]=t.useState(!0),[P,M]=t.useState("/"),l=t.useMemo(()=>a?c.parseOS(a.os):{family:"unknown"},[a==null?void 0:a.os]),d=t.useMemo(()=>c.getRecommendedProtocols(l),[l]),p=t.useMemo(()=>c.getCompatibilityInfo(l),[l]),r=t.useMemo(()=>d.find(s=>s.value===n),[n,d]);t.useEffect(()=>{if(a&&d.length>0){const s=c.getDefaultProtocol(l);h(s.value),b(s.defaultPort.toString())}},[a,l,d]),t.useEffect(()=>{r&&b(r.defaultPort.toString())},[r]);const E=async s=>{s.preventDefault(),v(!0),w(null);try{const i=x.sanitizeUsername(y);x.validatePassword(m);const R=x.sanitizeProtocol(n),D=x.validatePort(j);if(!c.validatePort(n,D).valid)throw new Error("Invalid port for selected protocol");const q=n==="ssh"?{enableSftp:u,sftpRootDirectory:P.trim()||"/"}:void 0;await I(i,m,R,q),g(""),f(""),k()}catch(i){w(i instanceof Error?i.message:"Connection failed")}finally{v(!1)}};return!z||!a?null:e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-60 flex items-center justify-center z-50 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-kaspersky-bg-card rounded-lg p-6 w-full max-w-md shadow-2xl border border-kaspersky-border select-none",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("h2",{className:"text-2xl font-bold text-kaspersky-text-dark",children:["Connect to ",a.name]}),e.jsx("button",{onClick:k,className:"text-kaspersky-text-light hover:text-kaspersky-danger transition-colors p-1 rounded-lg hover:bg-kaspersky-bg",disabled:o,children:e.jsx(S,{size:24})})]}),e.jsxs("div",{className:"mb-4 p-4 bg-kaspersky-bg rounded-lg border border-kaspersky-border",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"text-2xl",children:l.family==="windows"?"🖥️":l.family==="linux"?"🐧":l.family==="macos"?"🍎":"💻"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-kaspersky-text-dark",children:a.name}),e.jsxs("p",{className:"text-xs text-kaspersky-text-light",children:[a.ip," • ",a.os]})]})]}),p.recommendations.length>0&&e.jsxs("div",{className:"mt-3 p-3 bg-kaspersky-primary bg-opacity-10 border border-kaspersky-primary border-opacity-30 rounded-lg text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx(L,{size:14,className:"text-kaspersky-primary"}),e.jsx("span",{className:"font-semibold text-kaspersky-primary",children:"Recommendation"})]}),e.jsx("p",{className:"text-kaspersky-text-dark",children:p.recommendations[0]})]}),p.warnings.length>0&&e.jsxs("div",{className:"mt-2 p-3 bg-kaspersky-warning bg-opacity-10 border border-kaspersky-warning border-opacity-30 rounded-lg text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx(U,{size:14,className:"text-kaspersky-warning"}),e.jsx("span",{className:"font-semibold text-kaspersky-warning",children:"Warning"})]}),e.jsx("p",{className:"text-kaspersky-text-dark",children:p.warnings[0]})]})]}),e.jsxs("form",{onSubmit:E,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"protocol",className:"block text-sm font-semibold text-kaspersky-text-dark mb-2",children:"Connection Protocol"}),e.jsx("select",{id:"protocol",value:n,onChange:s=>h(s.target.value),className:"w-full px-4 py-2.5 bg-kaspersky-bg border-2 border-kaspersky-border rounded-lg text-kaspersky-text-dark focus:outline-none focus:border-kaspersky-primary focus:bg-white transition-all duration-200 select-text",disabled:o,children:d.map(s=>e.jsxs("option",{value:s.value,children:[s.icon," ",s.label]},s.value))}),r&&e.jsxs("div",{className:"mt-2 p-3 bg-kaspersky-bg border border-kaspersky-border rounded-lg text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-1",children:[e.jsx(B,{size:14,className:"text-kaspersky-primary"}),e.jsx("span",{className:"font-semibold text-kaspersky-text-dark",children:"Protocol Info"})]}),e.jsx("p",{className:"text-kaspersky-text mb-1",children:r.description}),r.requirements&&e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-kaspersky-text-dark",children:"Requirements:"}),e.jsx("ul",{className:"list-disc list-inside text-kaspersky-text mt-1",children:r.requirements.map((s,i)=>e.jsx("li",{children:s},i))})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"port",className:"block text-sm font-semibold text-kaspersky-text-dark mb-2",children:"Port"}),e.jsx("input",{type:"number",id:"port",value:j,onChange:s=>b(s.target.value),className:"w-full px-4 py-2.5 bg-kaspersky-bg border-2 border-kaspersky-border rounded-lg text-kaspersky-text-dark focus:outline-none focus:border-kaspersky-primary focus:bg-white transition-all duration-200 select-text",required:!0,disabled:o,min:"1",max:"65535",placeholder:r==null?void 0:r.defaultPort.toString()}),r&&e.jsxs("p",{className:"text-xs text-kaspersky-text-light mt-1",children:["Default port for ",r.label,": ",r.defaultPort]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"machine-username",className:"block text-sm font-semibold text-kaspersky-text-dark mb-2",children:"Machine Username"}),e.jsx("input",{type:"text",id:"machine-username",value:y,onChange:s=>g(s.target.value),className:"w-full px-4 py-2.5 bg-kaspersky-bg border-2 border-kaspersky-border rounded-lg text-kaspersky-text-dark focus:outline-none focus:border-kaspersky-primary focus:bg-white transition-all duration-200 select-text",required:!0,disabled:o,autoFocus:!0,placeholder:"Administrator"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"machine-password",className:"block text-sm font-semibold text-kaspersky-text-dark mb-2",children:"Machine Password"}),e.jsx("input",{type:"password",id:"machine-password",value:m,onChange:s=>f(s.target.value),className:"w-full px-4 py-2.5 bg-kaspersky-bg border-2 border-kaspersky-border rounded-lg text-kaspersky-text-dark focus:outline-none focus:border-kaspersky-primary focus:bg-white transition-all duration-200 select-text",required:!0,disabled:o,placeholder:"••••••••"})]}),n==="ssh"&&e.jsxs("div",{className:"space-y-3 p-4 bg-kaspersky-primary bg-opacity-10 border border-kaspersky-primary border-opacity-30 rounded-lg",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"text-sm font-semibold text-kaspersky-primary",children:"📁 SFTP File Transfer"})}),e.jsxs("div",{className:"flex items-center gap-3 p-3 bg-kaspersky-bg-card rounded-lg border border-kaspersky-border",children:[e.jsx("input",{type:"checkbox",id:"enable-sftp",checked:u,onChange:s=>F(s.target.checked),className:"w-5 h-5 text-kaspersky-primary bg-white border-2 border-kaspersky-border rounded focus:ring-2 focus:ring-kaspersky-primary cursor-pointer",disabled:o}),e.jsx("label",{htmlFor:"enable-sftp",className:"text-sm font-medium text-kaspersky-text-dark cursor-pointer flex-1",children:"Enable file browser (download/upload with drag'n'drop)"})]}),u&&e.jsxs("div",{children:[e.jsx("label",{htmlFor:"sftp-root-directory",className:"block text-xs font-semibold text-kaspersky-text-dark mb-2",children:"Root Directory (optional)"}),e.jsx("input",{type:"text",id:"sftp-root-directory",value:P,onChange:s=>M(s.target.value),className:"w-full px-3 py-2 text-sm bg-kaspersky-bg border-2 border-kaspersky-border rounded-lg text-kaspersky-text-dark focus:outline-none focus:border-kaspersky-primary focus:bg-white transition-all duration-200 select-text",disabled:o,placeholder:"/"}),e.jsx("p",{className:"text-xs text-kaspersky-text-light mt-1",children:"Restrict SFTP access to this directory (default: /)"})]})]}),N&&e.jsx("div",{className:"bg-kaspersky-danger bg-opacity-10 border border-kaspersky-danger text-kaspersky-danger px-4 py-3 rounded-lg text-sm font-medium animate-shake",children:N}),e.jsxs("div",{className:"flex gap-3 pt-2",children:[e.jsx(C,{type:"submit",variant:"primary",fullWidth:!0,disabled:o,isLoading:o,leftIcon:o?void 0:e.jsx(H,{size:18}),children:o?"Connecting...":"Connect"}),e.jsx(C,{type:"button",variant:"secondary",onClick:k,disabled:o,leftIcon:e.jsx(S,{size:18}),children:"Cancel"})]})]})]})})};export{_ as default};