1import{u as P,r as n,d as x,a as p,g as O,j as e,b as U,s as $,c as T,e as W,f as z,h as H}from"./index-DR1Ivosq.js";function q(){const{user:l}=P(),[F,A]=n.useState(!0),[b,h]=n.useState(!1),[g,y]=n.useState(null),[i,j]=n.useState({}),[v,m]=n.useState(null),[N,f]=n.useState(null),k=n.useRef(null),w=n.useRef(null),[r,d]=n.useState({number:"",issuer:"",grade:"",expiryDate:""});n.useEffect(()=>{l?.uid&&M()},[l]);const M=async()=>{if(l?.uid)try{const s=x(p,"userProfiles",l.uid),a=await O(s);if(a.exists()){const o=a.data().license||{};j(o);let u="";if(o.expiryDate){const c=o.expiryDate.split("/");c.length===3&&(u=`${c[2]}-${c[1]}-${c[0]}`)}d({number:o.number||"",issuer:o.issuer||"",grade:o.grade||"",expiryDate:u})}}catch(s){console.error("Error loading license data:",s)}finally{A(!1)}},L=async(s,a)=>{if(l?.uid){if(!s.type.startsWith("image/")){alert("Please select an image file.");return}if(s.size>10*1024*1024){alert("Image must be smaller than 10MB.");return}y(a);try{const t=`license-${a}-${l.uid}-${Date.now()}.jpg`,o=T(W,`license-images/${t}`);await z(o,s);const u=await H(o),c=x(p,"userProfiles",l.uid),S=a==="front"?"frontImageURL":"backImageURL";await U(c,{[`license.${S}`]:u,updatedAt:$()}),j(E=>({...E,[S]:u})),m(`${a==="front"?"Front":"Back"} of license uploaded successfully!`),setTimeout(()=>m(null),3e3)}catch(t){console.error("Error uploading license image:",t),alert("Failed to upload image. Please try again.")}finally{y(null)}}},D=(s,a)=>{const t=s.target.files?.[0];t&&L(t,a),s.target.value=""},R=(s,a)=>{s.preventDefault(),f(null);const t=s.dataTransfer.files?.[0];t&&L(t,a)},C=(s,a)=>{s.preventDefault(),f(a)},I=()=>{f(null)},B=async()=>{if(l?.uid){h(!0);try{const s=x(p,"userProfiles",l.uid);let a=null;if(r.expiryDate){const t=r.expiryDate.split("-");t.length===3&&(a=`${t[2]}/${t[1]}/${t[0]}`)}await U(s,{"license.number":r.number||null,"license.issuer":r.issuer||null,"license.grade":r.grade||null,"license.expiryDate":a,updatedAt:$()}),m("License details saved successfully!"),setTimeout(()=>m(null),3e3)}catch(s){console.error("Error saving license data:",s),alert("Failed to save license details. Please try again.")}finally{h(!1)}}};return F?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-mrl-900"})}):e.jsxs("div",{className:"max-w-4xl mx-auto",children:[v&&e.jsxs("div",{className:"mb-6 bg-green-50 border border-green-200 text-green-700 px-4 py-3 rounded-lg flex items-center gap-2",children:[e.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),v]}),e.jsxs("div",{className:"bg-mrl-900 rounded-t-xl p-8",children:[e.jsx("h1",{className:"text-3xl font-heading text-white uppercase tracking-wide",children:"Racing License"}),e.jsx("p",{className:"text-gray-400 mt-1",children:"Manage your racing license details and upload images of your license card."})]}),e.jsxs("div",{className:"bg-white border-l-4 border-accent-500 px-6 py-4",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900 uppercase tracking-wide",children:"License Requirement 2026"}),e.jsx("p",{className:"text-sm text-gray-600 mt-1",children:"All drivers must hold a valid racing license to compete. Please upload both sides of your current license and ensure your details are up to date before entering events."})]}),e.jsxs("div",{className:"bg-white shadow p-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"License Images"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Front of License"}),e.jsx("button",{type:"button",onClick:()=>k.current?.click(),onDrop:s=>R(s,"front"),onDragOver:s=>C(s,"front"),onDragLeave:I,disabled:g==="front",className:` 2 relative w-full aspect-[3/2] rounded-lg border-2 border-dashed overflow-hidden 3 transition-colors focus:outline-none focus:ring-2 focus:ring-accent-500 focus:ring-offset-2 4 ${N==="front"?"border-accent-500 bg-accent-50":i.frontImageURL?"border-gray-200 bg-gray-50":"border-gray-300 bg-gray-50 hover:border-gray-400"} 5 `,children:g==="front"?e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-accent-500"}),e.jsx("span",{className:"text-sm text-gray-500 mt-2",children:"Uploading..."})]}):i.frontImageURL?e.jsxs("div",{className:"group relative w-full h-full",children:[e.jsx("img",{src:i.frontImageURL,alt:"Front of license",className:"w-full h-full object-contain"}),e.jsx("div",{className:"absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-40 transition-all flex items-center justify-center",children:e.jsx("span",{className:"text-white opacity-0 group-hover:opacity-100 transition-opacity font-medium text-sm",children:"Click to replace"})})]}):e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-gray-400",children:[e.jsxs("svg",{className:"w-10 h-10 mb-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.
5664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M15 13a3 3 0 11-6 0 3 3 0 016 0z"})]}),e.jsx("span",{className:"text-sm",children:"Click or drag to upload front"})]})}),e.jsx("input",{ref:k,type:"file",accept:"image/*",onChange:s=>D(s,"front"),className:"hidden"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Back of License"}),e.jsx("button",{type:"button",onClick:()=>w.current?.click(),onDrop:s=>R(s,"back"),onDragOver:s=>C(s,"back"),onDragLeave:I,disabled:g==="back",className:` 6 relative w-full aspect-[3/2] rounded-lg border-2 border-dashed overflow-hidden 7 transition-colors focus:outline-none focus:ring-2 focus:ring-accent-500 focus:ring-offset-2 8 ${N==="back"?"border-accent-500 bg-accent-50":i.backImageURL?"border-gray-200 bg-gray-50":"border-gray-300 bg-gray-50 hover:border-gray-400"} 9 `,children:g==="back"?e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-accent-500"}),e.jsx("span",{className:"text-sm text-gray-500 mt-2",children:"Uploading..."})]}):i.backImageURL?e.jsxs("div",{className:"group relative w-full h-full",children:[e.jsx("img",{src:i.backImageURL,alt:"Back of license",className:"w-full h-full object-contain"}),e.jsx("div",{className:"absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-40 transition-all flex items-center justify-center",children:e.jsx("span",{className:"text-white opacity-0 group-hover:opacity-100 transition-opacity font-medium text-sm",children:"Click to replace"})})]}):e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center text-gray-400",children:[e.jsxs("svg",{className:"w-10 h-10 mb-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M15 13a3 3 0 11-6 0 3 3 0 016 0z"})]}),e.jsx("span",{className:"text-sm",children:"Click or drag to upload back"})]})}),e.jsx("input",{ref:w,type:"file",accept:"image/*",onChange:s=>D(s,"back"),className:"hidden"})]})]})]}),e.jsxs("div",{className:"bg-white rounded-b-xl shadow p-6 border-t border-gray-100",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900 mb-4",children:"License Details"}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"License Number"}),e.jsx("input",{type:"text",value:r.number,onChange:s=>d({...r,number:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-accent-500 focus:border-transparent",placeholder:"Enter license number"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Expiry Date"}),e.jsx("input",{type:"date",value:r.expiryDate,onChange:s=>d({...r,expiryDate:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-accent-500 focus:border-transparent"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Issuing Body"}),e.jsx("input",{type:"text",value:r.issuer,onChange:s=>d({...r,issuer:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-accent-500 focus:border-transparent",placeholder:"e.g., Motorsport UK, FIA, FFSA"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Grade / Type"}
9),e.jsx("input",{type:"text",value:r.grade,onChange:s=>d({...r,grade:s.target.value}),className:"w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-accent-500 focus:border-transparent",placeholder:"e.g., National A, Race National, ITC-C"})]})]}),e.jsx("div",{className:"mt-8 pt-6 border-t border-gray-200",children:e.jsx("button",{type:"button",onClick:B,disabled:b,className:"px-6 py-2 bg-accent-500 text-white font-semibold rounded-md hover:bg-accent-600 focus:outline-none focus:ring-2 focus:ring-accent-500 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:b?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white"}),"Saving..."]}):"Save License Details"})})]})]})}export{q as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.