PageSourceSearch

https://a2zworkhub.com/assets/js/VendorManagementPage-BNG1Vl0T.js

js a2zworkhub.com collected 2026-10-02 00:46:20 UTC 95,275 bytes, 1 lines download raw bytes

1import{a as o,s as v,j as e,u as B,A as M,o as $,D as ve,y as le,a4 as Ne,N as ne,L as z,a3 as W,ae as ze,X as ie,a5 as J,d as q,Q as ye,t as ge,g as be,ab as we,W as $e,Y as ae,a6 as oe,a7 as D,U as _e,a2 as de,b as ke}from"./index-WXqAjLLd.js";import{S as V,a as Ye,G as Ge}from"./store-CZuiQaQR.js";import{C as ce}from"./check-circle-CTolFltB.js";import{N as Q,S as I,L as Y,E as Se,b as X,M as Ce,F as L,V as He,C as Je,O as Ke,W as Qe,a as Xe,A as Ze}from"./CommissionsTab-BTHbWjLc.js";import{U as fe}from"./upload-XaDX6mtA.js";import{P as U}from"./plus-Cw03IAwU.js";import{S as re}from"./save-DVNPgJu2.js";import{C as Z}from"./clock-AQg9J35L.js";import{X as je}from"./x-circle-ClV1d2B_.js";import{S as te}from"./square-pen-Dtm-eL2p.js";import{L as Pe}from"./layout-dashboard-CoCwQHaG.js";import{S as Ae}from"./shopping-bag-BX1Aamd3.js";import{T as me}from"./tag-CqGT9SKl.js";import{M as De}from"./menu-C3A3bMmC.js";import{A as es}from"./arrow-up-right-BVPyLLrK.js";import{A as ss}from"./arrow-down-right-B24r48Bm.js";import{C as ts}from"./credit-card-Bgnnsh-m.js";import{P as as}from"./percent-CrrD6mop.js";import{F as rs}from"./file-text-Bp5tg47i.js";import{D as ls}from"./dollar-sign-KWUVu5S8.js";import{L as ns,U as is}from"./user-plus-CMOyNfPj.js";import"./chevron-right-Dpz6XquG.js";const Ee=o.createContext(void 0);async function os(s){const h=new TextEncoder().encode(s),g=await crypto.subtle.digest("SHA-256",h);return Array.from(new Uint8Array(g)).map(m=>m.toString(16).padStart(2,"0")).join("")}function ds({children:s}){const[d,h]=o.useState(null),[g,j]=o.useState(null),[m,N]=o.useState(!0),[n,f]=o.useState(null);o.useEffect(()=>{p()},[]);async function p(){try{N(!0);const _=localStorage.getItem("vendor_session");if(_){const{data:y,error:P}=await v.from("vendor_users").select("*").eq("id",_).single();P||!y?(localStorage.removeItem("vendor_session"),h(null)):y.status!=="active"?(localStorage.removeItem("vendor_session"),h(null),f("Your account is not active. Please contact admin.")):(h(y),await r(y.id))}}catch(_){console.error("Error checking vendor session:",_)}finally{N(!1)}}async function r(_){try{const{data:y,error:P}=await v.from("vendor_wallets").select("*").eq("vendor_id",_).single();!P&&y&&j(y)}catch(y){console.error("Error fetching wallet:",y)}}async function w(_,y){try{N(!0),f(null);const P=await os(y),{data:A,error:E}=await v.from("vendor_users").select("*").eq("email",_.toLowerCase()).eq("password_hash",P).single();return E||!A?(f("Invalid email or password"),{error:"Invalid email or password"}):A.status==="pending"?(f("Your account is pending approval. Please wait for admin approval."),{error:"Your account is pending approval. Please wait for admin approval."}):A.status==="suspended"?(f("Your account has been suspended. Please contact admin."),{error:"Your account has been suspended. Please contact admin."}):A.status==="inactive"?(f("Your account is inactive. Please contact admin."),{error:"Your account is inactive. Please contact admin."}):(await v.from("vendor_users").update({last_login_at:new Date().toISOString()}).eq("id",A.id),await v.from("vendor_auditlogs").insert({user_type:"vendor",user_id:A.id,action_type:"vendor_login",entity_type:"vendor",entity_id:A.id,description:"Vendor logged in"}),localStorage.setItem("vendor_session",A.id),h(A),await r(A.id),{error:null})}catch(P){console.error("Sign in error:",P);const A="An error occurred during sign in";return f(A),{error:A}}finally{N(!1)}}async function C(){localStorage.removeItem("vendor_session"),h(null),j(null),f(null)}async function i(){if(d)try{const{data:_,error:y}=await v.from("vendor_users").select("*").eq("id",d.id).single();!y&&_&&h(_)}catch(_){console.error("Error refreshing vendor:",_)}}async function l(){d&&await r(d.id)}async function a(_){if(!d)return{error:"Not authenticated"};try{const{error:y}=await v.from("vendor_users").update(_).eq("id",d.id);return y?{error:y.message}:(await i(),{error:null})}catch(y){return console.error("Error updating profile:",y),{error:"Failed to update profile"}}}async function k(_){if(!d)return{error:"Not authenticated"};try{const{error:y}=await v.from("vendor_users").update(_).eq("id",d.id);return y?{error:y.message}:(await v.from("vendor_auditlogs").insert({user_type:"vendor",user_id:d.id,action_type:"vendor_updated",entity_type:"vendor",entity_id:d.id,description:"Vendor updated bank details"}),await i(),{error:null})}catch(y){return console.error("Error updating bank details:",y),{error:"Failed to update bank details"}}}const b={vendor:d,wallet:g,loading:m,error:n,isAuthenticated:!!d&&d.status==="active",signIn:w,signOut:C,refreshVendor:i,refreshWallet:l,updateProfile:a,updateBankDetail
1s:k};return e.jsx(Ee.Provider,{value:b,children:s})}function O(){const s=o.useContext(Ee);if(s===void 0)throw new Error("useVendorAuth must be used within a VendorAuthProvider");return s}function cs(){const s=B(),{signIn:d,loading:h,error:g}=O(),[j,m]=o.useState(""),[N,n]=o.useState(""),[f,p]=o.useState(!1),[r,w]=o.useState(null),C=async i=>{if(i.preventDefault(),w(null),!j||!N){w("Please fill in all fields");return}(await d(j,N)).error||s("/vendormanagement/dashboard")};return e.jsxs("div",{className:"min-h-screen bg-slate-50 flex items-center justify-center p-4 transition-colors duration-300 relative overflow-hidden",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[e.jsx("div",{className:"absolute -top-40 -right-40 w-96 h-96 bg-primary-500/10 rounded-full blur-[100px] animate-pulse"}),e.jsx("div",{className:"absolute -bottom-40 -left-40 w-96 h-96 bg-secondary-500/10 rounded-full blur-[100px] animate-pulse delay-1000"})]}),e.jsxs("div",{className:"relative z-10 w-full max-w-md",children:[e.jsxs("button",{onClick:()=>s("/vendormanagement"),className:"mb-8 inline-flex items-center gap-2 text-slate-500 hover:text-slate-900 font-bold text-sm transition-colors group",children:[e.jsx(M,{className:"w-4 h-4 transform group-hover:-translate-x-1 transition-transform"}),"Back to Portal Selection"]}),e.jsxs("div",{className:"bg-white/80 backdrop-blur-xl border border-slate-200 rounded-3xl p-8 sm:p-10 shadow-2xl shadow-slate-200/50 transition-all duration-300",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 bg-gradient-to-br from-primary-600 to-secondary-600 rounded-2xl mb-6 shadow-xl shadow-primary-500/30 transform hover:scale-110 transition-transform",children:e.jsx(V,{className:"w-8 h-8 text-white"})}),e.jsx("h1",{className:"text-3xl font-black text-slate-900 mb-2 tracking-tighter",children:"Vendor Access"}),e.jsx("p",{className:"text-slate-500 text-sm font-medium",children:"Continue to your business dashboard"})]}),(g||r)&&e.jsx("div",{className:"mb-6 p-4 bg-red-50 border border-red-100 rounded-xl animate-in shake duration-300",children:e.jsxs("p",{className:"text-red-600 text-xs font-bold flex items-center gap-2",children:[e.jsx($,{className:"w-4 h-4"})," ",g||r]})}),e.jsxs("form",{onSubmit:C,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-black text-slate-500 uppercase tracking-widest mb-2 ml-1",children:"Email Address"}),e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none",children:e.jsx(ve,{className:"w-5 h-5 text-slate-400 group-focus-within:text-primary-500 transition-colors"})}),e.jsx("input",{type:"email",value:j,onChange:i=>m(i.target.value),placeholder:"[email protected]",className:"w-full pl-12 pr-4 py-4 bg-slate-50 border border-slate-200 rounded-2xl text-slate-900 placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-primary-500/50 focus:border-primary-500 transition-all font-medium"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-black text-slate-500 uppercase tracking-widest mb-2 ml-1",children:"Account Password"}),e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none",children:e.jsx(le,{className:"w-5 h-5 text-slate-400 group-focus-within:text-primary-500 transition-colors"})}),e.jsx("input",{type:f?"text":"password",value:N,onChange:i=>n(i.target.value),placeholder:"••••••••",className:"w-full pl-12 pr-12 py-4 bg-slate-50 border border-slate-200 rounded-2xl text-slate-900 placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-primary-500/50 focus:border-primary-500 transition-all font-medium"}),e.jsx("button",{type:"button",onClick:()=>
1p(!f),className:"absolute inset-y-0 right-0 pr-4 flex items-center text-slate-400 hover:text-slate-900 transition-colors",children:f?e.jsx(Ne,{className:"w-5 h-5"}):e.jsx(ne,{className:"w-5 h-5"})})]})]}),e.jsx("button",{type:"submit",disabled:h,className:"w-full py-4 bg-gradient-to-r from-primary-600 to-secondary-600 hover:from-primary-500 hover:to-secondary-500 text-white font-black uppercase tracking-widest rounded-2xl shadow-xl shadow-primary-500/30 hover:shadow-primary-500/50 transition-all active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:h?e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-5 h-5 animate-spin"}),"Authenticating..."]}):"Sign In to Dashboard"})]}),e.jsx("div",{className:"mt-10 text-center",children:e.jsxs("p",{className:"text-slate-500 text-[11px] font-bold uppercase tracking-wider",children:["Don't have an account yet?"," ",e.jsx("button",{onClick:()=>s("/vendormanagement/register"),className:"text-primary-600 hover:underline cursor-pointer",children:"Become a Vendor"})]})})]})]})]})}function ms(){const s=B(),[d,h]=o.useState(!1),[g,j]=o.useState(!1),[m,N]=o.useState(null),[n,f]=o.useState({full_name:"",email:"",password:"",company_name:"",phone:"",country_code:"+91"}),[p,r]=o.useState(!1);async function w(i){const a=new TextEncoder().encode(i),k=await crypto.subtle.digest("SHA-256",a);return Array.from(new Uint8Array(k)).map(_=>_.toString(16).padStart(2,"0")).join("")}const C=async i=>{i.preventDefault(),N(null),h(!0);try{if(!n.email||!n.password||!n.full_name||!n.phone)throw new Error("Please fill in all required fields");if(n.password.length<6)throw new Error("Password must be at least 6 characters long");const{data:l}=await v.from("vendor_users").select("id").eq("email",n.email.toLowerCase()).single();if(l)throw new Error("Email already registered");const a=await w(n.password),{error:k}=await v.from("vendor_users").insert({email:n.email.toLowerCase(),password_hash:a,full_name:n.full_name,phone:n.phone,country_code:n.country_code,company_name:n.company_name||null,status:"pending"});if(k)throw k;j(!0)}catch(l){console.error("Registration error:",l),N(l.message||"Failed to register. Please try again.")}finally{h(!1)}};return g?e.jsx("div",{className:"min-h-screen bg-slate-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white max-w-md w-full rounded-3xl p-8 shadow-xl text-center",children:[e.jsx("div",{className:"w-20 h-20 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-6",children:e.jsx(ce,{className:"w-10 h-10 text-green-600"})}),e.jsx("h2",{className:"text-2xl font-bold text-slate-900 mb-2",children:"Application Submitted!"}),e.jsx("p",{className:"text-slate-600 mb-8",children:"Thank you for your interest in becoming a vendor. Your application has been submitted successfully and is pending admin approval. We will notify you once your account is activated."}),e.jsx("button",{onClick:()=>s("/vendormanagement"),className:"w-full py-3 bg-slate-900 text-white font-bold rounded-xl hover:bg-slate-800 transition-colors",children:"Back to Home"}),e.jsx("button",{onClick:()=>s("/vendormanagement/vendor-login"),className:"w-full mt-3 py-3 text-slate-600 font-bold rounded-xl hover:bg-slate-50 transition-colors",children:"Go to Login"})]})}):e.jsxs("div",{className:"min-h-screen bg-slate-50 flex items-center justify-center p-4 relative overflow-hidden",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[e.jsx("div",{className:"absolute -top-40 -right-40 w-96 h-96 bg-primary-500/10 rounded-full blur-[60px] animate-pulse"}),e.jsx("div",{className:"absolute -bottom-40 -left-40 w-96 h-96 bg-secondary-500/10 rounded-full blur-[60px] animate-pulse delay-1000"})]}),e.jsxs("div",{className:"relative z-10 w-full max-w-lg",children:[e.jsxs("button",{onClick:()=>s("/vendormanagement"),className:"mb-8 inline-flex items-center gap-2 text-slate-500 hover:text-slate-900 font-bold text-sm transition-colors group",children:[e.jsx(M,{className:"w-4 h-4 transform group-hover:-translate-x-1 transition-transform"}),"Back"]}),e.jsxs("div",{className:"bg-white/95 border border-slate-200 rounded-3xl p-8 shadow-2xl",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 bg-gradient-to-br from-secondary-600 to-primary-600 rounded-2xl mb-4 shadow-lg shadow-secondary-500/20",children:e.jsx(V,{className:"w-8 h-8 text-white"})}),e.jsx("h1",{className:"text-3xl font-black text-slate-900 mb-2",children:"Become a Vendor"}),e.jsx("p",{className:"text-slate-500 text-sm",children:"Join our network of service providers"})]}),m&&e.jsxs("div",{className:"mb-6 p-4 bg-red-50 border border-red-100 rounded-xl flex items-center gap-3 text-red-600 text-sm font-bold",children:[e.jsx($,{className:"w-5 h-5 flex-shrink-0"}),m]}),e.jsxs("form",{onSubmit:C,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 uppercase tracking-wider mb-2 ml-1",children:"Full Name"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none",children:e.jsx(W,{className:"w-5 h-5 text-slate-400"})}),e.jsx("input",{type:"text",value:n.full_name,onChange:i=>f({...n,full_name:i.target.value}),className:"w-full pl-12 pr-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-secondary-500/50 focus:border-secondary-500 text-slate-900 transition-all font-medium",placeholder:"John Doe",required:!0})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 uppercase tracking-wider mb-2 ml-1",children:"Phone"}),e.jsx(ze,{value:n.phone,countryCode:n.country_code,onChange:(i,l)=>
1f({...n,phone:i,country_code:l}),placeholder:"9876543210"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 uppercase tracking-wider mb-2 ml-1",children:"Company Name (Optional)"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none",children:e.jsx(Ye,{className:"w-5 h-5 text-slate-400"})}),e.jsx("input",{type:"text",value:n.company_name,onChange:i=>f({...n,company_name:i.target.value}),className:"w-full pl-12 pr-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-secondary-500/50 focus:border-secondary-500 text-slate-900 transition-all font-medium",placeholder:"Your Business Name"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 uppercase tracking-wider mb-2 ml-1",children:"Email Address"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none",children:e.jsx(ve,{className:"w-5 h-5 text-slate-400"})}),e.jsx("input",{type:"email",value:n.email,onChange:i=>f({...n,email:i.target.value}),className:"w-full pl-12 pr-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-secondary-500/50 focus:border-secondary-500 text-slate-900 transition-all font-medium",placeholder:"[email protected]",required:!0})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-slate-500 uppercase tracking-wider mb-2 ml-1",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none",children:e.jsx(le,{className:"w-5 h-5 text-slate-400"})}),e.jsx("input",{type:p?"text":"password",value:n.password,onChange:i=>f({...n,password:i.target.value}),className:"w-full pl-12 pr-12 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-secondary-500/50 focus:border-secondary-500 text-slate-900 transition-all font-medium",placeholder:"••••••••",required:!0,minLength:6}),e.jsx("button",{type:"button",onClick:()=>r(!p),className:"absolute inset-y-0 right-0 pr-4 flex items-center text-slate-400 hover:text-slate-900",children:p?e.jsx(Ne,{className:"w-5 h-5"}):e.jsx(ne,{className:"w-5 h-5"})})]}),e.jsx("p",{className:"text-xs text-slate-400 mt-1 ml-1",children:"Must be at least 6 characters"})]}),e.jsx("button",{type:"submit",disabled:d,className:"w-full py-4 mt-4 bg-gradient-to-r from-secondary-600 to-primary-600 hover:from-secondary-500 hover:to-primary-500 text-white font-black uppercase tracking-widest rounded-2xl shadow-xl shadow-secondary-500/30 hover:shadow-secondary-500/50 transition-all active:scale-95 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:d?e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-5 h-5 animate-spin"}),"Submitting..."]}):"Submit Application"})]}),e.jsx("div",{className:"mt-8 text-center border-t border-slate-100 pt-6",children:e.jsxs("p",{className:"text-slate-500 text-xs font-bold uppercase tracking-wider",children:["Already have an account?"," ",e.jsx("button",{onClick:()=>s("/vendormanagement/vendor-login"),className:"text-secondary-600 hover:underline",children:"Login Here"})]})})]})]})]})}const K=s=>s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");function xs({product:s,onClose:d,onSuccess:h}){const{vendor:g}
1=O(),[j,m]=o.useState(!1),[N,n]=o.useState([]),[f,p]=o.useState([]),[r,w]=o.useState(!1),[C,i]=o.useState("details"),[l,a]=o.useState({name:"",slug:"",description:"",full_description:"",category_id:"",price:0,discount_price:0,mrp:0,stock:100,pricing_unit_id:"",is_active:!0,image_url:"",meta_title:"",meta_description:"",meta_keywords:""}),[k,b]=o.useState([""]),[_,y]=o.useState([]),[P,A]=o.useState([]),[E,c]=o.useState([]);o.useEffect(()=>{R(),s&&ee()},[s]);const R=async()=>{try{const[t,u]=await Promise.all([v.from("categories").select("id, name").eq("is_active",!0).order("name"),v.from("pricing_units").select("id, name, short_label, is_default").eq("is_active",!0).order("display_order")]);t.data&&n(t.data),u.data&&p(u.data)}catch(t){console.error("Error fetching data:",t)}},ee=()=>{if(!s)return;a({name:s.name||"",slug:s.slug||"",description:s.description||"",full_description:s.full_description||"",category_id:s.category_id||"",price:s.price||0,discount_price:s.discount_price||0,mrp:s.mrp||0,stock:s.stock||100,pricing_unit_id:s.pricing_unit_id||"",is_active:s.is_active!==!1,image_url:s.image_url||"",meta_title:s.meta_title||"",meta_description:s.meta_description||"",meta_keywords:s.meta_keywords||""});const t=s.gallery_images||[];b(Array.isArray(t)&&t.length>0?t:[""]),y(s.attributes||[]),A(s.variants||[]),c(s.addons||[])},qe="https://image.a2zworkhub.com/media/api/api.php",xe=async(t,u)=>{const x=t.target.files?.[0];if(!x)return;if(!["image/jpeg","image/png","image/gif","image/webp"].includes(x.type)){alert("Please upload a valid image (JPG, PNG, GIF, WebP)");return}if(x.size>10*1024*1024){alert("File size must be less than 10MB");return}w(!0);try{const F=new FormData;F.append("folder","vendor-products"),F.append("file",x);const pe=await fetch(`${qe}/upload.php`,{method:"POST",body:F}),he=await pe.json();if(!pe.ok)throw new Error(he.error||"Upload failed");const se=he.file?.url;if(!se)throw new Error("No URL returned from upload");if(u!==void 0){const H=[...k];H[u]=se,b(H)}else a(H=>({...H,image_url:se}))}catch(F){console.error("Upload error:",F),alert("Error uploading image: "+(F.message||"Unknown error"))}finally{w(!1)}},Oe=()=>b([...k,""]),Fe=t=>{k.length===1?b([""]):b(k.filter((u,x)=>x!==t))},Le=(t,u)=>{const x=[...k];x[t]=u,b(x)},Ie=()=>{y([..._,{attribute_name:"",attribute_value:"",display_order:_.length}])},ue=(t,u,x)=>{const S=[..._];S[t]={...S[t],[u]:x},y(S)},Re=t=>{y(_.filter((u,x)=>x!==t))},Ve=()=>{A([...P,{variant_type:"",variant_name:"",price_modifier:0,is_default:!1,is_active:!0,display_order:P.length}])},T=(t,u,x)=>{const S=[...P];S[t]={...S[t],[u]:x},A(S)},Ue=t=>{A(P.filter((u,x)=>x!==t))},Me=()=>{c([...E,{addon_name:"",addon_description:"",addon_price:0,is_required:!1,max_quantity:1,is_active:!0,display_order:E.length}])},G=(t,u,x)=>{const S=[...E];S[t]={...S[t],[u]:x},c(S)},Be=t=>{c(E.filter((u,x)=>x!==t))},Te=async t=>{if(t.preventDefault(),!l.name.trim()){alert("Please enter a product name");return}if(!l.category_id){alert("Please select a category");return}if(l.price<=0){alert("Please enter a valid price");return}m(!0);try{const u=k.filter(S=>
1S.trim()),x={vendor_id:g?.id,name:l.name,slug:l.slug||K(l.name),description:l.description,category_id:l.category_id,price:l.price,discount_price:l.discount_price||null,mrp:l.mrp||null,stock:l.stock,pricing_unit_id:l.pricing_unit_id||null,is_active:l.is_active,image_url:l.image_url,meta_title:l.meta_title,meta_description:l.meta_description,meta_keywords:l.meta_keywords,gallery_images:u,attributes:_.filter(S=>S.attribute_name&&S.attribute_value),variants:P.filter(S=>S.variant_type&&S.variant_name),addons:E.filter(S=>S.addon_name),status:"pending",approved_product_id:null,admin_notes:null,reviewed_at:null};if(s?.id){if(s.status==="approved"&&s.approved_product_id){console.log("Deleting approved product from main table:",s.approved_product_id),await v.from("product_images").delete().eq("product_id",s.approved_product_id),await v.from("product_attributes").delete().eq("product_id",s.approved_product_id),await v.from("product_variants").delete().eq("product_id",s.approved_product_id),await v.from("product_addons").delete().eq("product_id",s.approved_product_id);const{error:F}=await v.from("products").delete().eq("id",s.approved_product_id);F&&console.error("Error deleting approved product:",F)}const{error:S}=await v.from("pending_vendor_products").update(x).eq("id",s.id);if(S)throw S;alert("✅ Product updated and sent for re-approval! The previous approved version has been removed.")}else{const{error:S}=await v.from("pending_vendor_products").insert(x);if(S)throw S;alert("✅ Product submitted for approval!")}h(),d()}catch(u){console.error("Submit error:",u),alert("Error submitting product")}finally{m(!1)}},We=[{id:"details",label:"Product Details"},{id:"gallery",label:"Gallery"},{id:"attributes",label:"Attributes"},{id:"variants",label:"Variants"},{id:"addons",label:"Add-ons"}];return e.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center p-4 z-50 overflow-y-auto backdrop-blur-sm",children:e.jsxs("div",{className:"bg-white rounded-2xl w-full max-w-6xl my-8 max-h-[90vh] overflow-y-auto shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between p-6 border-b border-gray-200 sticky top-0 bg-white z-10",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900",children:s?"Edit Product Submission":"Submit New Product"}),e.jsx("p",{className:"text-gray-500 text-sm mt-1",children:"Products will be reviewed by admin before going live"})]}),e.jsx("button",{onClick:d,className:"p-2 hover:bg-gray-100 rounded-xl transition-colors",children:e.jsx(ie,{className:"w-6 h-6 text-gray-600"})})]}),e.jsx("div",{className:"mx-6 mt-6",children:e.jsxs("div",{className:"flex items-start gap-3 p-4 bg-blue-50 border border-blue-200 rounded-xl",children:[e.jsx($,{className:"w-5 h-5 text-blue-600 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-blue-800 font-medium",children:"Admin Approval Required"}),e.jsx("p",{className:"text-blue-600 text-sm",children:"Your product will be reviewed by an admin before it appears in the catalog."})]})]})}),e.jsx("div",{className:"flex border-b border-gray-200 mx-6 mt-6 overflow-x-auto",children:We.map(t=>e.jsx("button",{onClick:()=>i(t.id),className:`px-4 py-3 font-medium text-sm capitalize transition-colors border-b-2 -mb-px whitespace-nowrap ${C===t.id?"border-purple-500 text-purple-600":"border-transparent text-gray-500 hover:text-gray-700"}`,children:t.label},t.id))}),e.jsxs("form",{onSubmit:Te,className:"p-6",children:[C==="details"&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:["Product Name ",e.jsx("span",{className:"text-red-500",children:"*"}),s?.id&&e.jsx("span",{className:"ml-2 text-xs text-orange-500 font-normal",children:"(Cannot be changed)"})]}),e.jsx("input",{required:!0,type:"text",value:l.name,onChange:t=>{if(s?.id)return;const u=t.target.value,x=K(u),S=!l.slug||K(l.name)===l.slug;a({...l,name:u,slug:S?x:l.slug})},disabled:!!s?.id,className:`w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500 ${s?.id?"bg-gray-100 cursor-not-allowed opacity-70":""}`,placeholder:"Enter product name"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:["Slug (URL)",s?.id&&e.jsx("span",{className:"ml-2 text-xs text-orange-500 font-normal",children:"(Cannot be changed)"})]}),e.jsx("input",{type:"text",value:l.slug,onChange:t=>{s?.id||a({...l,slug:K(t.target.value)})},disabled:!!s?.id,className:`w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500 ${s?.id?"bg-gray-100 cursor-not-allowed opacity-70":""}`,placeholder:"product-url-slug"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:["Category ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("select",{required:!0,value:l.category_id,onChange:t=>a({...l,category_id:t.target.value}),className:"w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500",children:[e.jsx("option",{value:"",children:"Select category"}),N.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:"Main Image URL"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"url",value:l.image_url,onChange:t=>a({...l,image_url:t.target.value}),className:"flex-1 px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500",placeholder:"https://..."}),e.jsxs("label",{className:"px-4 py-3 bg-purple-50 text-purple-600 rounded-xl font-medium cursor-pointer hover:bg-purple-100 transition-colors flex items-center gap-2",children:[e.jsx(fe,{className:"w-4 h-4"}),r?e.jsx(z,{className:"w-4 h-4 animate-spin"}):"Upload",e.jsx("input",{type:"file",accept:"image/*",onChange:t=>xe(t),className:"hidden",disabled:r})]})]}),l.image_url&&e.jsx("img",{src:l.image_url,alt:"Preview",className:"mt-2 w-20 h-20 object-cover rounded-lg"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:["Price (₹) ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{required:!0,type:"number",step:"0.01",value:l.price,onChange:t=>a({...l,price:parseFloat(t.target.value)||0}),className:"w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:"Discount Price (₹)"}),e.jsx("input",{type:"number",step:"0.01",value:l.discount_price,onChange:t=>a({...l,discount_price:parseFloat(t.target.value)||0}),className:"w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:"Pricing Unit"}),e.jsxs("select",{value:l.pricing_unit_id,onChange:t=>a({...l,pricing_unit_id:t.target.value}),className:"w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500",children:[e.jsx("option",{value:"",children:"Select pricing unit"}),f.map(t=>e.jsxs("option",{value:t.id,children:[t.name," (₹",l.price||"0",t.short_label,")",t.is_default?" - Default":""]},t.id))]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"How the price will be displayed (e.g., ₹99/kg, ₹129/month)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:"Stock"}),e.jsx("input",{type:"number",value:l.stock,onChange:t=>a({...l,stock:parseInt(t.target.value)||0}),className:"w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500"})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:"Short Description"}),e.jsx("textarea",{value:l.description,onChange:t=>a({...l,description:t.target.value}),className:"w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500",rows:3,placeholder:"Brief product description..."})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:"Full Description"}),e.jsx("textarea",{value:l.full_description,onChange:t=>a({...l,full_description:t.target.value}),className:"w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500",rows:5,placeholder:"Detailed product description..."})]}),e.jsx("div",{className:"md:col-span-2 flex items-center gap-4 p-4 bg-gray-50 rounded-xl",children:e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:l.is_active,onChange:t=>a({...l,is_active:t.target.checked}),className:"w-5 h-5 rounded border-gray-300 text-purple-600 focus:ring-purple-500"}),e.jsx("span",{className:"text-gray-700 font-medium",children:"Active Product"})]})}),e.jsxs("div",{className:"md:col-span-2 border-t border-gray-200 pt-6 mt-4",children:[e.jsx("h4",{className:"text-lg font-bold text-gray-900 mb-4",children:"SEO Settings (Optional)"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:"Meta Title"}),e.jsx("input",{type:"text",value:l.meta_title,onChange:t=>a({...l,meta_title:t.target.value}),className:"w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500",placeholder:"SEO title for search engines"})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:"Meta Description"}),e.jsx("textarea",{value:l.meta_description,onChange:t=>a({...l,meta_description:t.target.value}),className:"w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500",rows:2,placeholder:"Brief description for search results"})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx("label",{className:"block text-sm font-semibold text-gray-700 mb-2",children:"Meta Keywords"}),e.jsx("input",{type:"text",value:l.meta_keywords,onChange:t=>a({...l,meta_keywords:t.target.value}),className:"w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-purple-500",placeholder:"keyword1, keyword2, keyword3"})]})]})]})]}),C==="gallery"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-lg font-bold text-gray-900",children:"Product Gallery"}),e.jsx("p",{className:"text-sm text-gray-500",children:"Add multiple images for your product"})]}),e.jsxs("button",{type:"button",onClick:Oe,className:"px-4 py-2 bg-purple-50 text-purple-600 rounded-xl font-medium hover:bg-purple-100 transition-colors flex items-center gap-2",children:[e.jsx(U,{className:"w-4 h-4"})," Add Image"]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:k.map((t,u)=>e.jsxs("div",{className:"flex gap-3 items-start p-4 bg-gray-50 rounded-xl",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"url",value:t,onChange:x=>Le(u,x.target.value),placeholder:"Image URL...",className:"flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 text-sm"}),e.jsxs("label",{className:"px-3 py-2 bg-purple-100 text-purple-600 rounded-lg cursor-pointer hover:bg-purple-200 transition-colors flex items-center",children:[e.jsx(fe,{className:"w-4 h-4"}),e.jsx("input",{type:"file",accept:"image/*",onChange:x=>xe(x,u),className:"hidden",disabled:r})]})]}),t&&e.jsx("img",{src:t,alt:`Gallery ${u+1}`,className:"w-full h-32 object-cover rounded-lg"})]}),e.jsx("button",{type:"button",onClick:()=>Fe(u),className:"p-2 text-red-500 hover:bg-red-50 rounded-lg",children:e.jsx(J,{className:"w-4 h-4"})})]},u))})]}),C==="attributes"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-lg font-bold text-gray-900",children:"Product Attributes"}),e.jsx("p",{className:"text-sm text-gray-500",children:"Add specifications like Size, Color, Material etc."})]}),e.jsxs("button",{type:"button",onClick:Ie,className:"px-4 py-2 bg-purple-50 text-purple-600 rounded-xl font-medium hover:bg-purple-100 transition-colors flex items-center gap-2",children:[e.jsx(U,{className:"w-4 h-4"})," Add Attribute"]})]}),_.length===0?e.jsx("div",{className:"text-center py-8 text-gray-500",children:'No attributes added yet. Click "Add Attribute" to get started.'}):e.jsx("div",{className:"space-y-3",children:_.map((t,u)=>e.jsxs("div",{className:"flex items-center gap-3 p-4 bg-gray-50 rounded-xl",children:[e.jsx(Ge,{className:"w-5 h-5 text-gray-400"}),e.jsx("input",{type:"text",value:t.attribute_name,onChange:x=>ue(u,"attribute_name",x.target.value),placeholder:"Attribute Name (e.g. Color)",className:"flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 text-sm"}),e.jsx("input",{type:"text",value:t.attribute_value,onChange:x=>ue(u,"attribute_value",x.target.value),placeholder:"Value (e.g. Blue)",className:"flex-1 px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 text-sm"}),e.jsx("button",{type:"button",onClick:()=>Re(u),className:"p-2 text-red-500 hover:bg-red-50 rounded-lg",children:e.jsx(J,{className:"w-4 h-4"})})]},u))})]}),C==="variants"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-lg font-bold text-gray-900",children:"Product Variants"}),e.jsx("p",{className:"text-sm text-gray-500",children:"Add size, color or other variants with price modifiers"})]}),e.jsxs("button",{type:"button",onClick:Ve,className:"px-4 py-2 bg-purple-50 text-purple-600 rounded-xl font-medium hover:bg-purple-100 transition-colors flex items-center gap-2",children:[e.jsx(U,{className:"w-4 h-4"})," Add Variant"]})]}),P.length===0?e.jsx("div",{className:"text-center py-8 text-gray-500",children:'No variants added yet. Click "Add Variant" to get started.'}):e.jsx("div",{className:"space-y-3",children:P.map((t,u)=>e.jsxs("div",{className:"grid grid-cols-6 gap-3 items-center p-4 bg-gray-50 rounded-xl",children:[e.jsx("input",{type:"text",value:t.variant_type,onCh
1ange:x=>T(u,"variant_type",x.target.value),placeholder:"Type (e.g. Size)",className:"col-span-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 text-sm"}),e.jsx("input",{type:"text",value:t.variant_name,onChange:x=>T(u,"variant_name",x.target.value),placeholder:"Name (e.g. Large)",className:"col-span-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 text-sm"}),e.jsx("input",{type:"number",value:t.price_modifier,onChange:x=>T(u,"price_modifier",parseFloat(x.target.value)||0),placeholder:"Price +/-",className:"col-span-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 text-sm"}),e.jsxs("label",{className:"col-span-1 flex items-center gap-2 text-sm text-gray-600",children:[e.jsx("input",{type:"checkbox",checked:t.is_default,onChange:x=>T(u,"is_default",x.target.checked),className:"rounded border-gray-300 text-purple-600 focus:ring-purple-500"}),"Default"]}),e.jsxs("label",{className:"col-span-1 flex items-center gap-2 text-sm text-gray-600",children:[e.jsx("input",{type:"checkbox",checked:t.is_active,onChange:x=>T(u,"is_active",x.target.checked),className:"rounded border-gray-300 text-purple-600 focus:ring-purple-500"}),"Active"]}),e.jsx("button",{type:"button",onClick:()=>Ue(u),className:"col-span-1 p-2 text-red-500 hover:bg-red-50 rounded-lg justify-self-end",children:e.jsx(J,{className:"w-4 h-4"})})]},u))})]}),C==="addons"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-lg font-bold text-gray-900",children:"Product Add-ons"}),e.jsx("p",{className:"text-sm text-gray-500",children:"Add optional extras customers can purchase"})]}),e.jsxs("button",{type:"button",onClick:Me,className:"px-4 py-2 bg-purple-50 text-purple-600 rounded-xl font-medium hover:bg-purple-100 transition-colors flex items-center gap-2",children:[e.jsx(U,{className:"w-4 h-4"})," Add Add-on"]})]}),E.length===0?e.jsx("div",{className:"text-center py-8 text-gray-500",children:'No add-ons added yet. Click "Add Add-on" to get started.'}):e.jsx("div",{className:"space-y-3",children:E.map((t,u)=>e.jsxs("div",{className:"grid grid-cols-6 gap-3 items-center p-4 bg-gray-50 rounded-xl",children:[e.jsx("input",{type:"text",value:t.addon_name,onChange:x=>G(u,"addon_name",x.target.value),placeholder:"Add-on Name",className:"col-span-2 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 text-sm"}),e.jsx("input",{type:"number",value:t.addon_price,onChange:x=>G(u,"addon_price",parseFloat(x.target.value)||0),placeholder:"Price",className:"col-span-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 text-sm"}),e.jsx("input",{type:"number",value:t.max_quantity,onChange:x=>G(u,"max_quantity",parseInt(x.target.value)||1),placeholder:"Max Qty",className:"col-span-1 px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 text-sm"}),e.jsxs("label",{className:"col-span-1 flex items-center gap-2 text-sm text-gray-600",children:[e.jsx("input",{type:"checkbox",checked:t.is_required,onChange:x=>G(u,"is_required",x.target.checked),className:"rounded border-gray-300 text-purple-600 focus:ring-purple-500"}),"Required"]}),e.jsx("button",{type:"button",onClick:()=>Be(u),className:"col-span-1 p-2 text-red-500 hover:bg-red-50 rounded-lg justify-self-end",children:e.jsx(J,{className:"w-4 h-4"})})]},u))})]}),e.jsxs("div",{className:"flex gap-4 pt-6 mt-6 border-t border-gray-200",children:[e.jsx("button",{type:"button",onClick:d,className:"flex-1 py-3 border border-gray-300 text-gray-700 rounded-xl font-semibold hover:bg-gray-50 transition-colors",children:"Cancel"}),e.jsxs("button",{type:"submit",disabled:j,className:"flex-1 py-3 bg-gradient-to-r from-purple-600 to-blue-600 text-white rounded-xl font-semibold hover:shadow-lg transition-all flex items-center justify-center gap-2 disabled:opacity-50",children:[j?e.jsx(z,{className:"w-5 h-5 animate-spin"}):e.jsx(re,{className:"w-5 h-5"}),j?"Submitting...":s?"Update Submission":"Submit for Approval"]})]})]})]})})}function us(){const{vendor:s}
1=O(),[d,h]=o.useState([]),[g,j]=o.useState(!0),[m,N]=o.useState(!1),[n,f]=o.useState(!1),[p,r]=o.useState(!1),[w,C]=o.useState(null),[i,l]=o.useState(null),[a,k]=o.useState("all"),b=m&&n;o.useEffect(()=>{_(),s&&y()},[s,a]);const _=async()=>{const{data:c}=await v.from("vendor_settings").select("setting_value").eq("setting_key","vendor_product_submission").single();if(c?.setting_value&&N(c.setting_value.enabled||!1),s?.id){const{data:R}=await v.from("vendor_users").select("can_add_products").eq("id",s.id).single();R&&f(R.can_add_products||!1)}},y=async()=>{if(!s)return;j(!0);let c=v.from("pending_vendor_products").select("*, categories(name)").eq("vendor_id",s.id).order("created_at",{ascending:!1});a!=="all"&&(c=c.eq("status",a));const{data:R,error:ee}=await c;!ee&&R&&h(R),j(!1)},P=()=>{r(!1),C(null)},A=()=>{y()},E={pending:d.filter(c=>c.status==="pending").length,approved:d.filter(c=>c.status==="approved").length,rejected:d.filter(c=>c.status==="rejected").length};return!g&&!m?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[e.jsx("div",{className:"w-20 h-20 bg-slate-100 rounded-full flex items-center justify-center mb-6",children:e.jsx(le,{className:"w-10 h-10 text-slate-400"})}),e.jsx("h2",{className:"text-2xl font-bold text-slate-900 mb-2",children:"Product Submission Disabled"}),e.jsx("p",{className:"text-slate-500 text-center max-w-md",children:"Product submission is currently disabled system-wide. Please contact the administrator if you need to add products."})]}):!g&&m&&!n?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[e.jsx("div",{className:"w-20 h-20 bg-orange-100 rounded-full flex items-center justify-center mb-6",children:e.jsx($,{className:"w-10 h-10 text-orange-500"})}),e.jsx("h2",{className:"text-2xl font-bold text-slate-900 mb-2",children:"Access Not Enabled"}),e.jsx("p",{className:"text-slate-500 text-center max-w-md",children:"Your account is not authorized to submit products. Please contact the administrator to request access."}),d.length>0&&e.jsxs("div",{className:"mt-8 w-full max-w-2xl",children:[e.jsx("h3",{className:"text-lg font-bold text-slate-900 mb-4",children:"Your Previous Submissions"}),e.jsx("div",{className:"space-y-3",children:d.slice(0,5).map(c=>e.jsx("div",{className:"bg-white p-4 rounded-xl border border-slate-200 shadow-sm",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium text-slate-900",children:c.name}),e.jsx("span",{className:`px-2 py-1 rounded-full text-xs font-bold ${c.status==="pending"?"bg-yellow-100 text-yellow-700":c.status==="approved"?"bg-green-100 text-green-700":"bg-red-100 text-red-700"}`,children:c.status.toUpperCase()})]})},c.id))})]})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-black text-slate-900 tracking-tight",children:"My Products"}),e.jsx("p",{className:"text-slate-500 text-sm mt-1",children:"Submit products for admin approval"})]}),b&&e.jsxs("button",{onClick:()=>r(!0),className:"px-6 py-3 bg-gradient-to-r from-purple-600 to-blue-600 text-white rounded-xl font-bold shadow-lg shadow-purple-500/25 hover:shadow-xl hover:shadow-purple-500/30 transition-all flex items-center gap-2",children:[e.jsx(U,{className:"w-5 h-5"}),"Submit New Product"]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:["all","pending","approved","rejected"].map(c=>e.jsxs("button",{onClick:()=>k(c),className:`px-4 py-2.5 rounded-xl font-semibold text-sm transition-all ${a===c?c==="pending"?"bg-gradient-to-r from-yellow-500 to-orange-500 text-white shadow-lg":c==="approved"?"bg-gradient-to-r from-green-500 to-emerald-600 text-white shadow-lg":c==="rejected"?"bg-gradient-to-r from-red-500 to-rose-600 text-white shadow-lg":"bg-gradient-to-r from-purple-600 to-blue-600 text-white shadow-lg":"bg-slate-100 text-slate-600 hover:bg-slate-200"}`,children:[c==="all"?"All":c.charAt(0).toUpperCase()+c.slice(1),c!=="all"&&e.jsx("span",{className:"ml-2 px-1.5 py-0.5 bg-white/20 rounded text-xs",children:E[c]})]},c))}),g?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(z,{className:"w-10 h-10 animate-spin text-purple-600"})}):d.length===0?e.jsxs("div",{className:"text-center py-16 bg-white rounded-2xl border border-slate-200 shadow-sm",children:[e.jsx(q,{className:"w-16 h-16 text-slate-300 mx-auto mb-4"}),e.jsx("p",{className:"text-slate-900 font-semibold text-lg",children:a==="all"?"No products submitted yet":`No ${a} products`}),e.jsx("p",{className:"text-slate-500 text-sm mt-1",children:'Click "Submit New Product" to get started'})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:d.map(c=>e.jsxs("div",{className:"bg-white border border-slate-200 rounded-2xl overflow-hidden shadow-sm hover:shadow-xl transition-all duration-300 group",children:[e.jsxs("div",{className:"aspect-video bg-slate-100 relative overflow-hidden",children:[c.image_url?e.jsx("img",{src:c.image_url,alt:c.name,className:"w-full h-full object-cover group-hover:scale-105 transition-transform duration-500"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx(q,{className:"w-12 h-12 text-slate-300"})}),e.jsx("div",{className:"absolute top-3 right-3",children:e.jsxs("span",{className:`px-3 py-1.5 rounded-full text-xs font-bold flex items-center gap-1.5 shadow-lg ${c.status==="pending"?"bg-yellow-500 text-white":c.status==="approved"?"bg-green-500 text-white":"bg-red-500 text-white"}`,children:[c.status==="pending"&&e.jsx(Z,{className:"w-3 h-3"}),c.status==="approved"&&e.jsx(ce,{className:"w-3 h-3"}),c.status==="rejected"&&e.jsx(je,{className:"w-3 h-3"}),c.status.toUpperCase()]})})]}),e.jsxs("div",{className:"p-5",children:[e.jsx("h3",{className:"font-bold text-slate-900 text-lg mb-1 line-clamp-1",children:c.name}),e.jsx("p",{className:"text-slate-500 text-sm mb-4",children:c.categories?.name||"No category"}),e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsx("div",{children:c.discount_price&&c.discount_price<c.price?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xl font-black text-green-600",children:["₹",c.discount_price.toLocaleStr
1ing("en-IN")]}),e.jsxs("span",{className:"text-sm text-slate-400 line-through",children:["₹",c.price.toLocaleString("en-IN")]})]}):e.jsxs("span",{className:"text-xl font-black text-slate-900",children:["₹",c.price.toLocaleString("en-IN")]})})}),e.jsx("div",{className:"mb-4",children:c.status==="rejected"&&c.admin_notes&&e.jsxs("div",{className:"p-3 bg-red-50 border border-red-200 rounded-xl",children:[e.jsx("p",{className:"text-xs font-bold text-red-700 mb-1 uppercase tracking-wide",children:"Rejection Reason"}),e.jsx("p",{className:"text-sm text-red-600",children:c.admin_notes})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>l(c),className:"flex-1 py-2.5 bg-slate-100 text-slate-700 rounded-xl font-semibold text-sm hover:bg-slate-200 transition-colors flex items-center justify-center gap-1.5",children:[e.jsx(ne,{className:"w-4 h-4"}),"View"]}),c.status==="pending"&&b&&e.jsxs("button",{onClick:()=>{C(c),r(!0)},className:"flex-1 py-2.5 bg-purple-50 text-purple-600 rounded-xl font-semibold text-sm hover:bg-purple-100 transition-colors flex items-center justify-center gap-1.5",children:[e.jsx(te,{className:"w-4 h-4"}),"Edit"]}),c.status==="approved"&&b&&e.jsxs("button",{onClick:()=>{confirm("Editing an approved product will remove it from the catalog until re-approved. Continue?")&&(C(c),r(!0))},className:"flex-1 py-2.5 bg-green-50 text-green-600 rounded-xl font-semibold text-sm hover:bg-green-100 transition-colors flex items-center justify-center gap-1.5",children:[e.jsx(te,{className:"w-4 h-4"}),"Update"]}),c.status==="rejected"&&b&&e.jsxs("button",{onClick:()=>{C(c),r(!0)},className:"flex-1 py-2.5 bg-blue-50 text-blue-600 rounded-xl font-semibold text-sm hover:bg-blue-100 transition-colors flex items-center justify-center gap-1.5",children:[e.jsx(te,{className:"w-4 h-4"}),"Resubmit"]})]}),e.jsxs("p",{className:"text-[10px] text-slate-400 mt-4 text-center font-semibold uppercase tracking-widest",children:["Submitted: ",new Date(c.created_at).toLocaleDateString("en-IN",{day:"2-digit",month:"short",year:"numeric"})]})]})]},c.id))}),p&&e.jsx(xs,{product:w,onClose:P,onSuccess:A}),i&&e.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center p-4 z-50 backdrop-blur-sm",children:e.jsxs("div",{className:"bg-white rounded-2xl w-full max-w-2xl max-h-[90vh] overflow-y-auto shadow-2xl",children:[e.jsx("div",{className:"p-6 border-b border-slate-200 sticky top-0 bg-white z-10",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-bold text-slate-900",children:"Product Details"}),e.jsx("button",{onClick:()=>l(null),className:"p-2 hover:bg-slate-100 rounded-xl transition-colors",children:e.jsx(je,{className:"w-5 h-5 text-slate-500"})})]})}),e.jsxs("div",{className:"p-6 space-y-6",children:[i.image_url&&e.jsx("img",{src:i.image_url,alt:i.name,className:"w-full h-48 object-cover rounded-xl"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-bold text-slate-900",children:i.name}),e.jsx("p",{className:"text-slate-500",children:i.categories?.name})]}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("span",{className:`px-3 py-1.5 rounded-full text-sm font-bold ${i.status==="pending"?"bg-yellow-100 text-yellow-700":i.status==="approved"?"bg-green-100 text-green-700":"bg-red-100 text-red-700"}`,children:i.status.toUpperCase()})}),i.description&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700 mb-2",children:"Description"}),e.jsx("p",{className:"text-slate-600",children:i.description})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-slate-50 p-4 rounded-xl",children:[e.jsx("p",{className:"text-xs text-slate-500 mb-1 uppercase font-semibold tracking-wide",children:"Price"}),e.jsxs("p",{className:"text-2xl font-black text-slate-900",children:["₹",i.price.toLocaleString("en-IN")]})]}),i.discount_price&&e.jsxs("div",{className:"bg-green-50 p-4 rounded-xl",children:[e.jsx("p",{className:"text-xs text-green-600 mb-1 uppercase font-semibold tracking-wide",children:"Discount Price"}),e.jsxs("p",{className:"text-2xl font-black text-green-600",children:["₹",i.discount_price.toLocaleStr
1ing("en-IN")]})]})]}),i.admin_notes&&e.jsxs("div",{className:`p-4 rounded-xl ${i.status==="rejected"?"bg-red-50 border border-red-200":"bg-blue-50 border border-blue-200"}`,children:[e.jsx("p",{className:`text-xs font-bold mb-2 uppercase tracking-wide ${i.status==="rejected"?"text-red-700":"text-blue-700"}`,children:"Admin Notes"}),e.jsx("p",{className:`${i.status==="rejected"?"text-red-600":"text-blue-600"}`,children:i.admin_notes})]})]})]})})]})}function ps(){const{vendor:s,wallet:d}=O(),[h,g]=o.useState({totalOrders:0,pendingOrders:0,completedOrders:0}),[j,m]=o.useState([]),[N,n]=o.useState(!0);o.useEffect(()=>{s&&f()},[s]);async function f(){try{n(!0);const{data:p}=await v.from("vendor_orderassignments").select("*, orders (id, order_number, final_amount, status, created_at, order_items (id, quantity, price, discount_price, products (name, image_url)))").eq("vendor_id",s?.id).order("created_at",{ascending:!1}).limit(6);p&&(m(p),g({totalOrders:p.length,pendingOrders:p.filter(r=>["assigned","accepted","in_progress"].includes(r.status)).length,completedOrders:p.filter(r=>["completed","admin_approved","payment_released"].includes(r.status)).length}))}catch(p){console.error("Error:",p)}finally{n(!1)}}return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-gradient-to-r from-primary-600/10 to-secondary-600/10 border border-primary-100 rounded-2xl p-6 shadow-sm",children:[e.jsxs("h2",{className:"text-xl font-bold text-slate-900 mb-1",children:["Welcome back, ",s?.full_name,"! 👋"]}),e.jsx("p",{className:"text-slate-500 text-sm",children:"Here's what's happening with your orders today."})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(I,{title:"Total Orders",value:h.totalOrders.toString(),icon:Ae,color:"blue"}),e.jsx(I,{title:"Pending",value:h.pendingOrders.toString(),icon:Z,color:"orange"}),e.jsx(I,{title:"Completed",value:h.completedOrders.toString(),icon:ce,color:"green"}),e.jsx(I,{title:"Wallet Bal.",value:`₹${d?.balance?.toFixed(2)||"0.00"}`,icon:we,color:"purple"})]}),e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("h3",{className:"text-lg font-bold text-slate-900",children:"Recent Orders"})}),N?e.jsx(Y,{}):j.length===0?e.jsx(Se,{icon:q,message:"No orders assigned yet",subMessage:"Orders will appear here once assigned by admin"}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:j.map(p=>e.jsxs("div",{className:"bg-white border border-slate-200 rounded-xl p-5 shadow-sm hover:shadow-md transition-shadow",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-slate-900 font-bold text-sm tracking-tight",children:["Order #",p.orders?.order_number]}),e.jsx("p",{className:"text-slate-400 text-[10px] uppercase font-semibold mt-0.5",children:new Date(p.created_at).toLocaleDateString()})]}),e.jsx(X,{status:p.status})]}),e.jsxs("div",{className:"space-y-2 py-3 border-t border-b border-slate-50 my-3",children:[e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-slate-500",children:"Order Amount"}),e.jsxs("span",{className:"text-slate-900 font-bold",children:["₹",p.order_amount?.toFixed(2)]})]}),e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-slate-500",children:"Your Payout"}),e.jsxs("span",{className:"text-green-600 font-bold",children:["₹",p.vendor_payout?.toFixed(2)]})]})]}),e.jsxs("div",{className:"flex gap-1.5 overflow-hidden",children:[p.orders?.order_items?.slice(0,3).map((r,w)=>e.jsx("div",{className:"w-8 h-8 rounded-lg bg-slate-100 flex-shrink-0 overflow-hidden border border-slate-200",children:r.products?.image_url?e.jsx("img",{src:r.products.image_url,alt:"",className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx(q,{className:"w-4 h-4 text-slate-400"})})},w)),p.orders?.order_items?.length>3&&e.jsxs("div",{className:"w-8 h-8 rounded-lg bg-slate-100 flex items-center justify-center text-[10px] font-bold text-slate-500",children:["+",p.orders?.order_items?.length-3]})]})]}
1,p.id))})]})}function hs(){const{vendor:s}=O(),[d,h]=o.useState([]),[g,j]=o.useState(!0),[m,N]=o.useState("all");o.useEffect(()=>{s&&n()},[s,m]);async function n(){try{j(!0);let a=v.from("vendor_orderassignments").select("*, orders (id, order_number, final_amount, status, created_at, delivery_address, profiles (full_name, email, phone), order_items (id, quantity, price, discount_price, products (name, image_url)))").eq("vendor_id",s?.id).order("created_at",{ascending:!1});m!=="all"&&(a=a.eq("status",m));const{data:k}=await a;h(k||[])}catch(a){console.error("Error:",a)}finally{j(!1)}}async function f(a,k){if(confirm(`Update order status to ${k.replace("_"," ")}?`)){j(!0);try{await v.from("vendor_orderassignments").update({status:k}).eq("id",a),n()}catch(b){console.error("Update status error:",b)}finally{j(!1)}}}const p=[{value:"all",label:"All"},{value:"assigned",label:"Assigned"},{value:"in_progress",label:"In Progress"},{value:"completed",label:"Completed"}],[r,w]=o.useState(null),[C,i]=o.useState(!1);function l(a){w(a),i(!0)}return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsx("h2",{className:"text-xl font-bold text-slate-900",children:"My Orders"}),e.jsx("div",{className:"flex gap-1 overflow-x-auto pb-2 md:pb-0 scrollbar-hide",children:p.map(a=>e.jsx("button",{onClick:()=>N(a.value),className:`px-4 py-1.5 rounded-lg text-xs font-semibold whitespace-nowrap transition-all ${m===a.value?"bg-primary-600 text-white shadow-lg shadow-primary-500/25":"bg-slate-100 text-slate-600 hover:text-slate-900"}`,children:a.label},a.value))})]}),g?e.jsx(Y,{}):d.length===0?e.jsx(Se,{icon:q,message:"No orders found"}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-1 gap-4",children:d.map(a=>e.jsx("div",{className:"bg-white border border-slate-200 rounded-xl p-4 sm:p-5 shadow-sm hover:shadow-md transition-all group",children:e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsxs("div",{className:"px-2 py-1 bg-slate-100 rounded text-[10px] font-bold text-slate-500",children:["#",a.orders?.order_number]}),e.jsx(X,{status:a.status})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-4 mb-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-slate-900 font-bold text-base truncate",children:a.customer_name||a.orders?.profiles?.full_name}),(a.customer_phone||a.orders?.profiles?.phone)&&e.jsxs("p",{className:"text-secondary-600 text-xs font-medium mt-0.5",children:["📞 ",a.customer_phone||a.orders?.profiles?.phone]})]}),e.jsxs("div",{className:"flex-1 sm:border-l border-slate-100 sm:pl-4",children:[a.service_date&&e.jsxs("p",{className:"text-slate-600 text-xs font-medium flex items-center gap-1.5",children:["📅 ",new Date(a.service_date).toLocaleDateString(),a.service_time&&e.jsxs("span",{className:"text-slate-400",children:["• ",a.service_time]})]}),a.service_address&&e.jsxs("p",{className:"text-slate-500 text-[11px] mt-1 line-clamp-1",children:["📍 ",a.service_address]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[a.orders?.order_items?.slice(0,4).map(k=>e.jsxs("div",{className:"flex items-center gap-2 bg-slate-50 border border-slate-100 rounded-lg p-1.5 pr-3",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-white overflow-hidden flex-shrink-0",children:k.products?.image_url?e.jsx("img",{src:k.products.image_url,alt:"",className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx(q,{className:"w-3 h-3 text-slate-500"})})}),e.jsxs("p",{className:"text-[10px] font-medium text-slate-700 whitespace-nowrap",children:[k.products?.name," ",e.jsxs("span",{className:"text-slate-400",children:["x",k.quantity]})]})]},k.id)),a.orders?.order_items?.length>4&&e.jsxs("div",{className:"h-9 px-3 flex items-center bg-slate-50 border border-slate-100 rounded-lg text-[10px] font-bold text-slate-500",children:["+",a.orders?.order_items?.length-4," more"]})]})]}),e.jsxs("div",{className:"flex flex-row lg:flex-col items-center lg:items-end justify-between lg:justify-center gap-4 lg:min-w-[140px] pt-4 lg:pt-0 border-t lg:border-t-0 lg:border-l border-slate-100",children:[e.jsxs("div",{className:"text-left lg:text-right",children:[e.jsxs("p",{className:"text-xl font-black text-slate-900 leading-none",children:["₹",a.vendor_payout?.toFixed(2)]}),e.jsx("p",{className:"text-[10px] font-bold text-green-600 uppercase tracking-wider mt-1",children:"Payout Amount"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>l(a),className:"px-3 py-1.5 bg-slate-100 hover:bg-slate-200 text-slate-700 rounded-lg text-xs font-bold transition-all",children:"Details"}),a.status==="assigned"&&e.jsx("button",{onClick:()=>f(a.id,"in_progress"),className:"px-4 py-1.5 bg-secondary-600 hover:bg-secondary-500 text-white rounded-lg text-xs font-bold shadow-lg shadow-secondary-500/25 transition-all",children:"Start"}),a.status==="in_progress"&&e.jsx("button",{onClick:()=>f(a.id,"completed"),className:"px-4 py-1.5 bg-green-600 hover:bg-green-500 text-white rounded-lg text-xs font-bold shadow-lg shadow-green-500/25 transition-all",children:"Complete"})]})]})]})},a.id))}),e.jsx(Ce,{isOpen:C,onClose:()=>i(!1),title:"Order Details",children:r&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-4 bg-slate-50 rounded-xl border border-slate-100",children:[e.jsxs("p",{className:"text-slate-500 text-xs",children:["Order #",r.orders?.order_number]}),e.jsxs("p",{className:"text-2xl font-black text-slate-900",children:["₹",r.order_amount?.toFixed(2)]}),e.jsxs("p",{className:"text-green-600 text-sm font-bold mt-1",children:["Your Payout: ₹",r.vend
1or_payout?.toFixed(2)]})]}),e.jsxs("div",{className:"border-t border-slate-100 pt-4",children:[e.jsxs("h4",{className:"text-slate-900 font-bold mb-3 text-sm flex items-center gap-2",children:[e.jsx(q,{className:"w-4 h-4 text-primary-500"})," Order Items"]}),e.jsx("div",{className:"space-y-3",children:r.orders?.order_items?.map(a=>e.jsxs("div",{className:"flex items-center gap-3 bg-slate-50/50 p-2 rounded-lg border border-slate-100",children:[e.jsx("div",{className:"w-10 h-10 bg-white rounded-lg flex-shrink-0 overflow-hidden border border-slate-200",children:a.products?.image_url?e.jsx("img",{src:a.products.image_url,alt:"",className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx(q,{className:"w-5 h-5 text-slate-400"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-bold text-slate-900 truncate",children:a.products?.name}),e.jsxs("p",{className:"text-[10px] text-slate-500 font-medium",children:["₹",a.discount_price||a.price," x ",a.quantity]})]}),e.jsxs("p",{className:"text-sm font-black text-slate-900",children:["₹",((a.discount_price||a.price)*a.quantity).toFixed(2)]})]},a.id))})]}),e.jsxs("div",{className:"border-t border-slate-100 pt-4",children:[e.jsxs("h4",{className:"text-slate-900 font-bold mb-2 text-sm flex items-center gap-2",children:[e.jsx(W,{className:"w-4 h-4 text-secondary-500"})," Customer Information"]}),e.jsxs("div",{className:"bg-slate-50 p-3 rounded-lg border border-slate-100",children:[e.jsx("p",{className:"text-slate-900 font-bold text-sm",children:r.customer_name||r.orders?.profiles?.full_name}),(r.customer_phone||r.orders?.profiles?.phone)&&e.jsxs("p",{className:"text-blue-600 text-xs font-bold mt-1 cursor-pointer hover:underline",children:["📞 ",r.customer_phone||r.orders?.profiles?.phone]}),r.customer_email&&e.jsx("p",{className:"text-slate-500 text-xs mt-0.5",children:r.customer_email})]})]}),(r.service_date||r.service_address)&&e.jsxs("div",{className:"border-t border-slate-100 pt-4",children:[e.jsxs("h4",{className:"text-slate-900 font-bold mb-2 text-sm flex items-center gap-2",children:[e.jsx(Z,{className:"w-4 h-4 text-orange-500"})," Service Slot"]}),e.jsxs("div",{className:"space-y-2",children:[r.service_date&&e.jsxs("div",{className:"flex items-center gap-2 text-slate-700 text-xs font-medium bg-orange-50 p-2 rounded-lg border border-orange-100",children:[e.jsxs("span",{children:["📅 ",new Date(r.service_date).toLocaleDateString()]}),r.service_time&&e.jsxs("span",{children:["at ",r.service_time]})]}),r.service_address&&e.jsxs("div",{className:"bg-slate-50 p-3 rounded-lg border border-slate-100",children:[e.jsx("p",{className:"text-slate-400 text-[10px] uppercase font-bold mb-1",children:"Service Address"}),e.jsx("p",{className:"text-slate-700 text-xs leading-relaxed font-medium",children:r.service_address})]})]})]}),r.admin_notes&&e.jsxs("div",{className:"border-t border-slate-100 pt-4",children:[e.jsx("h4",{className:"text-slate-900 font-bold mb-2 text-sm",children:"📝 Admin Notes"}),e.jsx("p",{className:"text-slate-600 bg-slate-50 p-3 rounded-xl text-xs italic font-medium leading-relaxed",children:r.admin_notes})]}),r.special_instructions&&e.jsxs("div",{className:"border-t border-slate-100 pt-4",children:[e.jsx("h4",{className:"text-yellow-600 font-bold mb-2 text-sm",children:"⚠️ Special Instructions"}),e.jsx("p",{className:"text-slate-700 bg-yellow-50 border border-yellow-200 p-3 rounded-xl text-xs font-bold leading-relaxed",children:r.special_instructions})]})]})})]})}function gs(){const{vendor:s}=O(),[d,h]=o.useState([]),[g,j]=o.useState([]),[m,N]=o.useState(!0);o.useEffect(()=>{s&&n()},[s]);async function n(){try{N(!0);const[r,w]=await Promise.all([v.from("categories").select("id, name, icon").order("name"),v.from("vendor_categories").select("*, categories (name)").eq("vendor_id",s?.id)]);h(r.data||[]),j(w.data||[])}catch(r){console.error("Error:",r)}finally{N(!1)}}async function f(r){g.find(C=>C.category_id===r)||(N(!0),await v.from("vendor_categories").insert({vendor_id:s?.id,category_id:r,status:"pending"}),n())}const p=g.map(r=>r.category_id);return e.jsxs("div",{className:"space-y-8",children:[e.jsx("h2",{className:"text-2xl font-black text-slate-900 tracking-tight",children:"Service Categories"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-1 h-6 bg-primary-600 rounded-full"}),e.jsx("h3",{className:"text-lg font-bold text-slate-800",children:"My Subscriptions"})]}),g.length===0?e.jsxs("div",{className:"bg-white border border-slate-200 rounded-2xl p-8 text-center shadow-sm",children:[e.jsx("div",{className:"w-16 h-16 bg-slate-50 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(me,{className:"w-8 h-8 text-slate-300"})}),e.jsx("p",{className:"text-slate-500 font-medium",children:"You haven't requested any categories yet"}),e.jsx("p",{className:"text-slate-400 text-xs mt-1",children:"Select from available categories below to start receiving orders."})]}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:g.map(r=>e.jsxs("div",{className:"bg-white border border-slate-200 rounded-xl p-4 flex items-center justify-between shadow-sm group hover:border-primary-200 transition-all",children:[e.jsx("span",{className:"text-slate-900 font-bold text-sm",children:r.categories?.name}),e.jsx(X,{status:r.status})]},r.id))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-1 h-6 bg-secondary-600 rounded-full"}),e.jsx("h3",{className:"text-lg font-bold text-slate-800",children:"Available Areas"})]}),m?e.jsx(Y,{}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 ga
1p-3",children:d.filter(r=>!p.includes(r.id)).map(r=>e.jsxs("button",{onClick:()=>f(r.id),className:"bg-white border border-slate-200 hover:bg-slate-50 hover:border-primary-500/50 rounded-xl p-4 text-left transition-all shadow-sm group",children:[e.jsx("p",{className:"text-slate-900 font-bold text-sm group-hover:text-primary-600 transition-colors uppercase tracking-tight",children:r.name}),e.jsxs("p",{className:"text-primary-600 text-[10px] font-black mt-3 flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx(U,{className:"w-3 h-3"})," REQUEST ACCESS"]})]},r.id))})]})]})}function bs(){const{vendor:s,wallet:d}=O(),[h,g]=o.useState([]),[j,m]=o.useState(!0),[N,n]=o.useState(!1),[f,p]=o.useState(""),[r,w]=o.useState(!1);o.useEffect(()=>{s&&C()},[s]);async function C(){try{m(!0);const{data:b}=await v.from("vendor_wallettransactions").select("*").eq("vendor_id",s?.id).order("created_at",{ascending:!1}).limit(20);g(b||[])}catch(b){console.error("Error:",b)}finally{m(!1)}}async function i(b){b.preventDefault();const _=parseFloat(f);if(!_||_<=0||_>(d?.balance||0)){alert("Invalid amount or insufficient balance");return}if(!s?.bank_name&&!s?.upi_id){alert("Please add bank details in Settings first");return}if(!d?.id){alert("Wallet not found. Please contact admin.");return}try{w(!0);const{data:y}=await v.from("vendor_withdrawrequests").select("id").eq("vendor_id",s?.id).eq("status","pending").maybeSingle();if(y){alert("You already have a pending withdrawal request."),w(!1);return}const{error:P}=await v.from("vendor_withdrawrequests").insert({wallet_id:d?.id,vendor_id:s?.id,amount:_,status:"pending",payment_method:s?.upi_id?"upi":"bank_transfer"});if(P)throw P;n(!1),p(""),alert("✅ Withdrawal request submitted successfully!"),C(),k()}catch(y){console.error("Error:",y),alert("An error occurred.")}finally{w(!1)}}const[l,a]=o.useState([]);o.useEffect(()=>{s&&k()},[s]);async function k(){const{data:b}=await v.from("vendor_withdrawrequests").select("*").eq("vendor_id",s?.id).order("created_at",{ascending:!1});a(b||[])}return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-gradient-to-br from-primary-600 via-primary-500 to-secondary-600 rounded-3xl p-6 sm:p-8 shadow-2xl relative overflow-hidden group",children:[e.jsx("div",{className:"absolute -right-10 -top-10 w-40 h-40 bg-white/10 rounded-full blur-3xl group-hover:bg-white/20 transition-all duration-700"}),e.jsxs("div",{className:"relative z-10",children:[e.jsx("p",{className:"text-orange-100/80 text-xs font-black uppercase tracking-widest mb-2",children:"Available for Withdrawal"}),e.jsxs("p",{className:"text-5xl font-black text-white mb-8 tracking-tighter",children:["₹",d?.balance?.toFixed(2)||"0.00"]}),e.jsxs("div",{className:"grid grid-cols-3 gap-6 pt-6 border-t border-white/10",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-orange-200/60 text-[10px] font-bold uppercase mb-1",children:"Pending"}),e.jsxs("p",{className:"text-white font-black text-sm",children:["₹",d?.pending_balance?.toFixed(2)||"0.00"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-orange-200/60 text-[10px] font-bold uppercase mb-1",children:"Total Earned"}),e.jsxs("p",{className:"text-white font-black text-sm",children:["₹",d?.total_earned?.toFixed(2)||"0.00"]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-orange-200/60 text-[10px] font-bold uppercase mb-1",children:"Withdrawn"}),e.jsxs("p",{className:"text-white font-black text-sm",children:["₹",d?.total_withdrawn?.toFixed(2)||"0.00"]})]})]})]})]}),e.jsx("button",{onClick:()=>n(!0),disabled:!d?.balance||d.balance<=0,className:"w-full py-4 bg-emerald-600 hover:bg-emerald-500 text-white font-black uppercase tracking-widest rounded-2xl shadow-xl shadow-emerald-500/20 disabled:opacity-50 transition-all active:scale-95",children:"Request Payout"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-1 h-6 bg-orange-500 rounded-full"}),e.jsx("h3",{className:"text-lg font-bold text-slate-800",children:"Payout Requests"})]}),l.length===0?e.jsx("div",{className:"bg-white border border-slate-100 rounded-2xl p-6 text-center",children:e.jsx("p",{className:"text-slate-400 text-sm",children:"No payout history found"})}):e.jsx("div",{className:"space-y-3",children:l.map(b=>e.jsxs("div",{className:"bg-white border border-slate-200 rounded-2xl p-4 shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("p",{className:"text-2xl font-black text-slate-900 leading-none",children:["₹",b.amount?.toFixed(2)]}),e.jsx(X,{status:b.status})]}),e.jsxs("div",{className:"flex items-center justify-between text-[10px] font-bold",children:[e.jsx("p",{className:"text-slate-400 uppercase tracking-wider",children:new Date(b.created_at).toLocaleDateString()}),b.reviewed_at&&e.jsxs("p",{className:"text-slate-500",children:["PROCESSED: ",new Date(b.reviewed_at).toLocaleDateString()]})]})]},b.id))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("div",{className:"w-1 h-6 bg-secondary-500 rounded-full"}),e.jsx("h3",{className:"text-lg font-bold text-slate-800",children:"Recent Transactions"})]}),j?e.jsx(Y,{}):h.length===0?e.jsx("div",{className:"bg-white border border-slate-100 rounded-2xl p-6 text-center",children:e.jsx("p",{className:"text-slate-400 text-sm",children:"No transactions yet"})}):e.jsx("div",{className:"space-y-2",children:h.map(b=>e.jsxs("div",{className:"bg-white border border-slate-100 rounded-xl p-3 flex items-center justify-between hover:bg-slate-50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center ${b.type==="credit"?"bg-green-50":"bg-red-50"}`,children:b.type==="credit"?e.jsx(es,{className:"w-4 h-4 text-green-600"}):e.jsx(ss,{className:"w-4 h-4 text-red-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-slate-900 text-xs font-bold leading-tight",children:b.description}),e.jsx("p",{className:"text-slate-400 text-[10px] font-medium mt
1-0.5",children:new Date(b.created_at).toLocaleDateString()})]})]}),e.jsxs("p",{className:`text-sm font-black ${b.type==="credit"?"text-green-600":"text-red-600"}`,children:[b.type==="credit"?"+":"-","₹",b.amount?.toFixed(2)]})]},b.id))})]})]}),e.jsx(Ce,{isOpen:N,onClose:()=>n(!1),title:"Request Payout",children:e.jsxs("form",{onSubmit:i,className:"space-y-4",children:[e.jsxs("div",{className:"bg-slate-50 p-4 rounded-xl border border-slate-100",children:[e.jsx("p",{className:"text-slate-400 text-[10px] font-bold uppercase mb-1",children:"Maximum Withdrawable"}),e.jsxs("p",{className:"text-3xl font-black text-slate-900 leading-none",children:["₹",d?.balance?.toFixed(2)||"0.00"]})]}),e.jsx(L,{label:"Amount to Withdraw",type:"number",value:f,onChange:p,placeholder:"Enter amount (e.g. 500)",required:!0}),!s?.bank_name&&!s?.upi_id&&e.jsxs("div",{className:"flex items-start gap-2 p-3 bg-red-50 border border-red-100 rounded-xl",children:[e.jsx($,{className:"w-4 h-4 text-red-500 flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-red-600 text-xs font-bold",children:"Please add bank details in Settings first to receive payouts."})]}),e.jsxs("div",{className:"flex gap-3 pt-4 border-t border-slate-100",children:[e.jsx("button",{type:"button",onClick:()=>n(!1),className:"flex-1 py-2.5 border border-slate-200 text-slate-600 rounded-xl text-xs font-bold",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:r||!s?.bank_name&&!s?.upi_id,className:"flex-1 py-2.5 bg-emerald-600 text-white rounded-xl disabled:opacity-50 text-xs font-bold shadow-lg shadow-emerald-500/20",children:r?"Submitting...":"Confirm Payout"})]})]})})]})}function fs(){const{vendor:s,updateProfile:d,updateBankDetails:h,signOut:g}=O(),j=B(),[m,N]=o.useState(!1),[n,f]=o.useState({full_name:s?.full_name||"",phone:s?.phone||"",company_name:s?.company_name||"",address:s?.address||""}),[p,r]=o.useState({bank_name:s?.bank_name||"",bank_account_number:s?.bank_account_number||"",bank_ifsc:s?.bank_ifsc||"",upi_id:s?.upi_id||""});async function w(){try{N(!0),await d(n),alert("Profile updated!")}catch(i){console.error(i)}finally{N(!1)}}async function C(){try{N(!0),await h(p),alert("Bank details updated!")}catch(i){console.error(i)}finally{N(!1)}}return e.jsxs("div",{className:"max-w-4xl mx-auto space-y-8",children:[e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-black text-slate-900 tracking-tight",children:"Settings"}),e.jsx("p",{className:"text-slate-500 text-sm font-medium",children:"Manage your profile and business details"})]})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-8",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-1 h-6 bg-primary-600 rounded-full"}),e.jsx("h3",{className:"text-lg font-bold text-slate-800",children:"Personal Info"})]}),e.jsxs("div",{className:"bg-white border border-slate-200 rounded-2xl p-6 shadow-sm space-y-4",children:[e.jsx(L,{label:"Full Name",value:n.full_name,onChange:i=>f({...n,full_name:i}),placeholder:"Enter your full name"}),e.jsx(L,{label:"Phone Number",value:n.phone,onChange:i=>f({...n,phone:i}),placeholder:"Enter phone number"}),e.jsx(L,{label:"Business Name",value:n.company_name,onChange:i=>f({...n,company_name:i}),placeholder:"Enter business name"}),e.jsx(L,{label:"Business Address",value:n.address,onChange:i=>f({...n,address:i}),placeholder:"Enter business address"}),e.jsxs("button",{onClick:w,disabled:m,className:"w-full py-2.5 bg-primary-600 hover:bg-primary-500 text-white rounded-xl text-xs font-bold shadow-lg shadow-primary-500/25 transition-all flex items-center justify-center gap-2",children:[e.jsx(re,{className:"w-4 h-4"})," ",m?"Saving...":"Save Profile"]})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-1 h-6 bg-emerald-600 rounded-full"}),e.jsx("h3",{className:"text-lg font-bold text-slate-800",children:"Payout Details"})]}),e.jsxs("div",{className:"bg-white border border-slate-200 rounded-2xl p-6 shadow-sm space-y-4",children:[e.jsx(L,{label:"UPI ID (Recommended)",value:p.upi_id,onChange:i=>r({...p,upi_id:i}
1),placeholder:"example@upi"}),e.jsxs("div",{className:"relative py-4",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t border-slate-100"})}),e.jsx("div",{className:"relative flex justify-center text-[10px] uppercase font-bold text-slate-400",children:e.jsx("span",{className:"px-2 bg-white",children:"OR BANK TRANSFER"})})]}),e.jsx(L,{label:"Bank Name",value:p.bank_name,onChange:i=>r({...p,bank_name:i}),placeholder:"e.g. HDFC Bank"}),e.jsx(L,{label:"Account Number",value:p.bank_account_number,onChange:i=>r({...p,bank_account_number:i}),placeholder:"Enter account number"}),e.jsx(L,{label:"IFSC Code",value:p.bank_ifsc,onChange:i=>r({...p,bank_ifsc:i}),placeholder:"Enter IFSC code"}),e.jsxs("button",{onClick:C,disabled:m,className:"w-full py-2.5 bg-emerald-600 hover:bg-emerald-500 text-white rounded-xl text-xs font-bold shadow-lg shadow-emerald-500/25 transition-all flex items-center justify-center gap-2",children:[e.jsx(re,{className:"w-4 h-4"})," ",m?"Saving...":"Save Payout Details"]})]})]})]}),e.jsx("div",{className:"pt-8 border-t border-slate-100",children:e.jsxs("button",{onClick:()=>{g(),j("/vendormanagement")},className:"w-full sm:w-auto px-8 py-3 bg-red-50 text-red-600 border border-red-100 font-bold rounded-xl flex items-center justify-center gap-2 transition-all hover:bg-red-100",children:[e.jsx(ae,{className:"w-5 h-5"})," Logout from Session"]})})]})}function js(){const{vendor:s,signOut:d}=O(),h=B(),g=ye(),[j,m]=o.useState(!1),N=[{icon:Pe,label:"Dashboard",path:"/vendormanagement/dashboard"},{icon:Ae,label:"Orders",path:"/vendormanagement/dashboard/orders"},{icon:q,label:"Products",path:"/vendormanagement/dashboard/products"},{icon:me,label:"Categories",path:"/vendormanagement/dashboard/categories"},{icon:we,label:"Wallet",path:"/vendormanagement/dashboard/wallet"},{icon:$e,label:"Settings",path:"/vendormanagement/dashboard/settings"}];return e.jsxs("div",{className:"min-h-screen bg-slate-50 flex",children:[e.jsxs("aside",{className:"hidden lg:flex flex-col fixed inset-y-0 w-64 bg-white border-r border-slate-200 z-40 transition-colors duration-300",children:[e.jsx("div",{className:"p-6 border-b border-slate-100",children:e.jsxs("div",{className:"flex items-center gap-3 px-2",children:[e.jsx("div",{className:"w-10 h-10 bg-primary-600 rounded-xl flex items-center justify-center shadow-lg shadow-primary-500/30",children:e.jsx(ge,{className:"w-6 h-6 text-white"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-slate-900 font-black text-xl tracking-tighter uppercase",children:be.appName}),e.jsx("p",{className:"text-[10px] font-bold text-primary-600 uppercase tracking-widest -mt-1",children:"Vendor Portal"})]})]})}),e.jsx("div",{className:"p-4 border-b border-slate-100",children:e.jsxs("div",{className:"flex items-center gap-3 bg-slate-50 p-3 rounded-2xl border border-slate-100",children:[e.jsx("div",{className:"w-10 h-10 bg-primary-600 rounded-full flex items-center justify-center border-2 border-white shadow-sm flex-shrink-0",children:e.jsx(W,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{className:"overflow-hidden",children:[e.jsx("p",{className:"text-slate-900 font-bold text-sm truncate",children:s?.full_name}),e.jsx("p",{className:"text-slate-500 text-[10px] font-medium truncate",children:s?.email})]})]})}),e.jsx("nav",{className:"flex-1 px-4 py-6 space-y-1",children:N.map(n=>e.jsx(Q,{icon:n.icon,label:n.label,active:g.pathname===n.path||n.path==="/vendormanagement/dashboard"&&g.pathname==="/vendormanagement/dashboard",onClick:()=>h(n.path)},n.path))}),e.jsx("div",{className:"p-4 border-t border-slate-100",children:e.jsxs("button",{onClick:()=>{d(),h("/vendormanagement")},className:"w-full flex items-center gap-3 px-4 py-3 text-red-600 hover:bg-red-50 rounded-xl transition-all font-bold text-sm",children:[e.jsx(ae,{className:"w-5 h-5"})," Logout"]})})]}),j&&e.jsxs("div",{className:"lg:hidden fixed inset-0 z-[100] flex",children:[e.jsx("div",{className:"fixed inset-0 bg-slate-900/60 backdrop-blur-sm",onClick:()=>m(!1)}),e.jsxs("aside",{className:"relative w-80 max-w-[85%] bg-white h-full flex flex-col animate-in slide-in-from-left duration-300 shadow-2xl",children:[e.jsxs("div",{className:"p-6 flex items-center justify-between border-b border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-primary-600 rounded-xl flex items-center justify-center shadow-lg",children:e.jsx(ge,{className:"w-6 h-6 text-white"})}),e.jsx("p",{className:"text-slate-900 font-black text-xl tracking-tighter uppercase",children:be.appName})]}),e.jsx("button",{onClick:()=>m(!1),className:"p-2 text-slate-400 hover:text-slate-900",children:e.jsx(ie,{className:"w-6 h-6"})})]}),e.jsx("nav",{className:"flex-1 p-4 py-6 space-y-1",children:N.map(n=>e.jsx(Q,{icon:n.icon,label:n.label,active:g.pathname===n.path,onClick:()=>{h(n.path),m(!1)}},n.path))}),e.jsxs("div",{className:"p-6 border-t border-slate-100 bg-slate-50",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6 px-2",children:[e.jsx("div",{className:"w-10 h-10 bg-purple-600 rounded-full flex items-center justify-center shadow-sm",children:e.jsx(W,{className:"w-5 h-5 text-white"})}),e.jsxs("div",{className:"overflow-hidden text-left",children:[e.jsx("p",{className:"text-slate-900 font-bold text-sm truncate",children:s?.full_name}),e.jsx("p",{className:"text-slate-500 text-[10px] font-medium truncate",children:s?.email})]})]}),e.jsxs("button",{onClick:()=>{d(),h("/vendormanagement")},className:"w-full flex items-center justify-center gap-3 px-4 py-3 bg-red-600 text-white rounded-xl font-bold text-sm shadow-lg shadow-red-500/20",children:[e.jsx(ae,{className:"w-5 h-5"})," Logout"]})]})]})]}),e.jsxs("main",{className:"flex-1 lg:ml-64 pt-16 lg:pt-0 min-h-screen flex flex-col",children:[e.jsxs("header",{className:"lg:hidden fixed top-0 left-0 right-0 z-50 bg-white/90 backdrop-blur-md border-b border-slate-200 px-4 h-16 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>m(!0),className:"p-2 -ml-2 text-slate-600",children:e.jsx(De,{className:"w-6 h-6"})}),e.jsx("p",{className:"text-slate-900 font-black text-xl tracking-tighter",children:"A2Z WORK
1HUB"})]}),e.jsx("div",{className:"w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center border-2 border-white shadow-sm",children:e.jsx(W,{className:"w-5 h-5 text-purple-600"})})]}),e.jsx("div",{className:"flex-1 p-4 sm:p-6 lg:p-8 max-w-7xl mx-auto w-full",children:e.jsxs(oe,{children:[e.jsx(D,{path:"/",element:e.jsx(ps,{})}),e.jsx(D,{path:"/orders",element:e.jsx(hs,{})}),e.jsx(D,{path:"/products",element:e.jsx(us,{})}),e.jsx(D,{path:"/categories",element:e.jsx(gs,{})}),e.jsx(D,{path:"/wallet",element:e.jsx(bs,{})}),e.jsx(D,{path:"/settings",element:e.jsx(fs,{})})]})})]})]})}function vs(){const[s,d]=o.useState({vendors:0,pendingOrders:0,pendingWithdrawals:0,totalPayout:0}),[h,g]=o.useState(!0);o.useEffect(()=>{j()},[]);async function j(){try{g(!0);const[m,N,n]=await Promise.all([v.from("vendor_users").select("id, status"),v.from("vendor_orderassignments").select("id, status, vendor_payout"),v.from("vendor_withdrawrequests").select("id, status, amount")]),f=m.data||[],p=N.data||[],r=n.data||[];d({vendors:f.filter(w=>w.status==="active").length,pendingOrders:p.filter(w=>["assigned","accepted","in_progress","completed"].includes(w.status)).length,pendingWithdrawals:r.filter(w=>w.status==="pending").length,totalPayout:p.filter(w=>w.status==="payment_released").reduce((w,C)=>w+(C.vendor_payout||0),0)})}catch(m){console.error("Error:",m)}finally{g(!1)}}return h?e.jsx(Y,{}):e.jsxs("div",{className:"space-y-6",children:[e.jsx("h2",{className:"text-2xl font-bold text-slate-900",children:"Dashboard Overview"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(I,{title:"Active Vendors",value:s.vendors.toString(),icon:_e,color:"blue"}),e.jsx(I,{title:"Pending Orders",value:s.pendingOrders.toString(),icon:q,color:"orange"}),e.jsx(I,{title:"Pending Payouts",value:s.pendingWithdrawals.toString(),icon:Z,color:"purple"}),e.jsx(I,{title:"Total Payouts",value:`₹${s.totalPayout.toFixed(2)}`,icon:ls,color:"green"})]})]})}function Ns(){const s=B(),d=ye(),[h,g]=o.useState(!1),j=[{icon:Pe,label:"Dashboard",path:"/vendormanagement/admin"},{icon:_e,label:"Vendors",path:"/vendormanagement/admin/vendors"},{icon:me,label:"Categories",path:"/vendormanagement/admin/categories"},{icon:q,label:"Orders",path:"/vendormanagement/admin/orders"},{icon:ts,label:"Withdrawals",path:"/vendormanagement/admin/withdrawals"},{icon:as,label:"Commissions",path:"/vendormanagement/admin/commissions"},{icon:rs,label:"Audit Logs",path:"/vendormanagement/admin/logs"}];return e.jsxs("div",{className:"min-h-screen bg-slate-50 transition-colors duration-300",children:[e.jsxs("div",{className:"lg:hidden fixed top-0 left-0 right-0 z-50 bg-white/80 backdrop-blur-md border-b border-slate-200 px-4 py-3 flex items-center justify-between",children:[e.jsx("button",{onClick:()=>g(!0),className:"text-slate-600 p-2 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(De,{className:"w-6 h-6"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 bg-gradient-to-br from-blue-600 to-purple-600 rounded-lg flex items-center justify-center",children:e.jsx(V,{className:"w-4 h-4 text-white"})}),e.jsxs("h1",{className:"text-slate-900 font-bold text-sm tracking-tight",children:["Admin ",e.jsx("span",{className:"text-blue-600",children:"Panel"})]})]}),e.jsx("div",{className:"w-10"})]}),e.jsxs("aside",{className:"hidden lg:flex lg:flex-col lg:fixed lg:inset-y-0 lg:w-64 bg-white border-r border-slate-200 transition-colors duration-300 shadow-xl",children:[e.jsx("div",{className:"p-6 border-b border-slate-100",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 bg-gradient-to-br from-blue-600 to-purple-600 rounded-xl flex items-center justify-center shadow-lg shadow-blue-500/20",children:e.jsx(V,{className:"w-6 h-6 text-white"})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-slate-900 font-bold text-lg leading-tight",children:["Admin ",e.jsx("span",{className:"text-blue-600",children:"Panel"})]}),e.jsx("p",{className:"text-slate-400 text-[10px] font-medium uppercase tracking-widest mt-0.5",children:"Vendor Hub"})]})]})}),e.jsx("nav",{className:"flex-1 p-4 space-y-1 overflow-y-auto",children:j.map(m=>e.jsx(Q,{icon:m.icon,label:m.label,active:d.pathname===m.path,onClick:()=>s(m.path)},m.path))}),e.jsx("div",{className:"p-4 border-t border-slate-100 bg-slate-50/50",children:e.jsxs("button",{onClick:()=>s("/"),className:"w-full flex items-center gap-3 px-4 py-3 text-slate-500 hover:text-slate-900 hover:bg-white rounded-xl transition-all border border-transparent hover:border-slate-200 group",children:[e.jsx(M,{className:"w-5 h-5 group-hover:-translate-x-1 transition-transform"}),e.jsx("span",{className:"font-medium text-sm",children:"Back to Site"})]})})]}),h&&e.jsxs("div",{className:"lg:hidden fixed inset-0 z-[100]",children:[e.jsx("div",{className:"absolute inset-0 bg-slate-900/60 backdrop-blur-sm transition-opacity",onClick:()=>g(!1)}),e.jsxs("aside",{className:"absolute left-0 top-0 bottom-0 w-72 bg-white border-r border-slate-200 shadow-2xl animate-in slide-in-from-left duration-300 flex flex-col",children:[e.jsxs("div",{className:"p-5 flex justify-between items-center border-b border-slate-100 bg-slate-50/50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-blue-600 to-purple-600 rounded-lg flex items-center justify-center shadow-lg",children:e.jsx(V,{className:"w-5 h-5 text-white"})}),e.jsx("h1",{className:"text-slate-900 font-bold",children:"Admin Hub"})]}),e.jsx("button",{onClick:()=>g(!1),className:"p-2 text-slate-400 hover:text-slate-600 hover:bg-slate-100 rounded-lg transition-colors",children:e.jsx(ie,{className:"w-5 h-5"})})]}),e.jsx("nav",{className:"flex-1 p-4 space-y-1 overflow-y-auto",children:j.map(m=>e.jsx(Q,{icon:m.icon,label:m.label,active:d.pathname===m.path,onClick:()=>{s(m.path),g(!1)}},m.path))}),e.jsx("div",{className:"p-4 border-t border-slate-100",children:e.jsxs("button",{onClick:()=>s("/"),className:"w-full flex items-center gap-3 px-4 py-3 text-slate-600 hover:bg-slate-50 rounded-xl transition-all",children:[e.jsx(M,{className:"w-5 h-5"}),e.jsx("span",{className:"font-medium",children:"Exit Admin"})]})})]})]}),e.jsx("main",{className:"lg:pl-64 pt-16 lg:pt-0 transition-all duration-300",children:e.jsx("div",{className:"p-4 lg:p-10 max-w-7xl mx-auto",children:e.jsx("div",{className:"",children:e.jsxs(oe,{children:[e.jsx(D,{path:"/",element:e.jsx(vs,{})}),e.jsx(D,{path:"/vendors",element:e.jsx(He,{})}),e.jsx(D,{path:"/categories",element:e.jsx(Je,{})}),e.jsx(D,{path:"/orders",element:e.jsx(Ke,{})}),e.jsx(D,{path:"/withdrawals",element:e.jsx(Qe,{})}),e.jsx(D,{path:"/commissions",element:e.jsx(Xe,{})}),e.jsx(D,{path:"/logs",element:e.jsx(Ze,{})})]})})})})]})}function ys(){const s=B(),{profile:d}=ke();return d?.role,e.jsxs("div",{className:"min-h-screen bg-slate-50 flex items-center justify-center p-4 transition-colors duration-300 overflow-hidden relative",children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden pointer-events-none",children:[e.jsx("div",{className:"absolute -top-40 -right-40 w-96 h-96 bg-primary-500/10 rounded-full blur-[100px] animate-pulse"}),e.jsx("div",{className:"absolute -bottom-40 -left-40 w-96 h-96 bg-secondary-500/10 rounded-full blur-[100px] animate-pulse delay-1000"})]}),e.jsxs("div",{className:"relative z-10 w-full max-w-md",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-20 h-20 bg-gradient-to-br from-primary-600 to-secondary-600 rounded-2xl mb-6 shadow-xl shadow-primary-500/30 transform hover:scale-110 transition-transform duration-300",children:e.jsx(V,{className:"w-10 h-10 text-white"})}),e.jsx("h1",{className:"text-4xl font-black text-slate-900 mb-2 tracking-tighter",children:"Vendor Management"}),e.jsx("p",{className:"text-slate-600 font-medium tracking-tight",children:"Enterprise Service Provider Portal"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("button",{onClick:()=>
1s("/vendormanagement/vendor-login"),className:"w-full group relative overflow-hidden bg-white border border-slate-200 hover:border-primary-500 rounded-2xl p-5 flex items-center gap-4 transition-all duration-300 shadow-sm hover:shadow-xl hover:shadow-primary-500/10",children:[e.jsx("div",{className:"w-12 h-12 bg-primary-600 rounded-xl flex items-center justify-center text-white shadow-lg shadow-primary-500/30 group-hover:scale-110 transition-transform duration-300",children:e.jsx(V,{className:"w-6 h-6"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("h3",{className:"font-bold text-lg text-slate-900 leading-tight",children:"Vendor Portal"}),e.jsx("p",{className:"text-sm text-slate-500",children:"Manage orders & wallet"})]}),e.jsx(ns,{className:"w-5 h-5 ml-auto text-slate-300 group-hover:text-primary-500 transform group-hover:translate-x-1 transition-all"})]}),e.jsxs("button",{onClick:()=>s("/vendormanagement/register"),className:"w-full group relative overflow-hidden bg-white border border-slate-200 hover:border-secondary-500 rounded-2xl p-5 flex items-center gap-4 transition-all duration-300 shadow-sm hover:shadow-xl hover:shadow-secondary-500/10",children:[e.jsx("div",{className:"w-12 h-12 bg-secondary-600 rounded-xl flex items-center justify-center text-white shadow-lg shadow-secondary-500/30 group-hover:scale-110 transition-transform duration-300",children:e.jsx(is,{className:"w-6 h-6"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("h3",{className:"font-bold text-lg text-slate-900 leading-tight",children:"Become a Vendor"}),e.jsx("p",{className:"text-sm text-slate-500",children:"Register as a partner"})]}),e.jsx(M,{className:"w-5 h-5 ml-auto text-slate-300 group-hover:text-secondary-500 transform rotate-180 group-hover:translate-x-1 transition-all"})]})]}),e.jsx("div",{className:"mt-6 text-center",children:e.jsxs("button",{onClick:()=>s("/"),className:"inline-flex items-center gap-2 text-slate-500 hover:text-slate-900 font-bold text-sm transition-colors",children:[e.jsx(M,{className:"w-4 h-4"}),"Back to Marketplace"]})})]})]})}function ws({children:s}){const{user:d,profile:h,loading:g}=ke();return g?e.jsx("div",{className:"min-h-screen bg-slate-900 flex items-center justify-center",children:e.jsx("div",{className:"animate-spin w-8 h-8 border-4 border-primary-500 border-t-transparent rounded-full"})}):!d||h?.role!=="admin"?e.jsx(de,{to:"/vendormanagement",replace:!0}):e.jsx(e.Fragment,{children:s})}function _s({children:s}){const{isAuthenticated:d,loading:h}=O();return h?e.jsx("div",{className:"min-h-screen bg-slate-900 flex items-center justify-center",children:e.jsx("div",{className:"animate-spin w-8 h-8 border-4 border-primary-500 border-t-transparent rounded-full"})}):d?e.jsx(e.Fragment,{children:s}):e.jsx(de,{to:"/vendormanagement/vendor-login",replace:!0})}function ks(){return e.jsxs(oe,{children:[e.jsx(D,{path:"/",element:e.jsx(ys,{})}),e.jsx(D,{path:"/register",element:e.jsx(ms,{})}),e.jsx(D,{path:"/admin/*",element:e.jsx(ws,{children:e.jsx(Ns,{})})}),e.jsx(D,{path:"/vendor-login",element:e.jsx(cs,{})}),e.jsx(D,{path:"/dashboard/*",element:e.jsx(_s,{children:e.jsx(js,{})})}),e.jsx(D,{path:"*",element:e.jsx(de,{to:"/vendormanagement",replace:!0})})]})}function Hs(){return e.jsx(ds,{children:e.jsx(ks,{})})}export{Hs as VendorManagementPage,Hs 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.