1import{by as Ke,r as o,g as We,i as R,j as e,bU as Te,G as h,bD as O,d5 as Ae,b0 as ze,J as U,bO as te,U as S,d4 as q,bW as Me,c2 as re,aL as Qe,K as F,e as He,c4 as Ve,a1 as Ye,bL as Be}from"./vendor-B3bqREfz.js";import{u as Ge,f as C,C as g,a as j,b as f,d as N,c as k,B as m,g as A,I as _e}from"./index-BHZdkTHk.js";import{A as Je}from"./AdminLayout-C31anzfd.js";import{P as K}from"./progress-D7PltSAm.js";import{S as Xe,a as Ze,b as es,c as ss,d as ae}from"./select-CdK0CD7c.js";import{A as ts,a as rs,b as as,c as ls,d as is,e as ds,f as ns,g as cs}from"./alert-dialog-Cfg8Q-r-.js";import"./harbor-shoppers-logo-BwiOLETu.js";import"./textarea-BFtGXtJd.js";function Ns(){var fe,Ne,be,ve,ye,we,Ce,ke,Pe,Ie,Se;const{toast:n}=Ge(),v=Ke(),[x,Ue]=o.useState(null),[t,W]=o.useState({status:"idle",currentPage:0,totalPages:0,totalProducts:0,imported:0,skipped:0,errors:[],newlyImportedWcIds:[]}),[b,Fe]=o.useState("none"),[$e,z]=o.useState(!1),[le,ie]=o.useState(!1),T=o.useRef(!1),[$,Ee]=o.useState(""),[c,E]=o.useState(null),[de,ne]=o.useState(!1),[L,ce]=o.useState(!1),[oe,Q]=o.useState(null);o.useState(!1);const{data:i,isLoading:D,refetch:os}=We({queryKey:["/api/admin/sync/stats"]}),{data:l,isLoading:Le,refetch:me}=We({queryKey:["/api/admin/sync/products/gaps"],refetchInterval:!1}),[a,H]=o.useState(null),P=o.useRef(null),De=o.useCallback(async()=>{try{await C("POST","/api/admin/sync/customers/cancel"),n({title:"Cancel Requested",description:"The import will stop after finishing the current batch."})}catch{}},[n]),V=o.useCallback(()=>{P.current||(P.current=setInterval(async()=>{try{const s=await fetch("/api/admin/sync/customers/progress",{credentials:"include"});if(!s.ok)return;const r=await s.json();H(r),(r.status==="completed"||r.status==="failed"||r.status==="cancelled")&&(P.current&&clearInterval(P.current),P.current=null,v.invalidateQueries({queryKey:["/api/admin/sync/stats"]}),r.status==="completed"?(Ue({imported:r.imported,updated:r.updated,skipped:r.skipped,errors:r.errors,newlyImportedWcIds:[]}),n({title:"Customer Import Complete",description:`Imported ${r.imported}, updated ${r.updated}, skipped ${r.skipped}`})):r.status==="cancelled"&&n({title:"Import Cancelled",description:`Stopped after importing ${r.imported} customers.`}))}catch{}},2e3))},[v,n]);o.useEffect(()=>(fetch("/api/admin/sync/customers/progress",{credentials:"include"}).then(s=>s.ok?s.json():null).then(s=>{s&&s.status==="running"&&(H(s),V())}).catch(()=>{}),()=>{P.current&&clearInterval(P.current)}),[V]);const xe=R({mutationFn:async()=>(await C("POST","/api/admin/sync/customers")).json(),onSuccess:s=>{s.status==="running"&&(H({status:"running",imported:0,updated:0,skipped:0,errors:[],total:0,processed:0,percent:0}),V())},onError:()=>{n({title:"Import Failed",description:"Failed to start customer import. Please try again.",variant:"destructive"})}}),Y=R({mutationFn:async()=>(await C("POST","/api/admin/sync/products")).json(),onSuccess:s=>{v.invalidateQueries({queryKey:["/api/admin/sync/stats"]}),v.invalidateQueries({queryKey:["/api/products"]}),n({title:"Product Sync Complete",description:s.message||`Synced ${s.synced} products`})},onError:s=>{n({title:"Sync Failed",description:(s==null?void 0:s.message)||"Failed to sync products. Please try again.",variant:"destructive"})}}),[d,B]=o.useState(null),I=o.useRef(null),Re=o.useCallback(async()=>{try{await C("POST","/api/admin/sync/wp-users/cancel"),n({title:"Cancel Requested",description:"The WP user import will stop after finishing the current batch."})}catch{}},[n]),G=o.useCallback(()=>{I.current||(I.current=setInterval(async()=>{try{const s=await fetch("/api/admin/sync/wp-users/progress",{credentials:"include"});if(!s.ok)return;const r=await s.json();B(r),(r.status==="completed"||r.status==="failed"||r.status==="cancelled")&&(I.current&&clearInterval(I.current),I.current=null,v.invalidateQueries({queryKey:["/api/admin/sync/stats"]}),r.status==="completed"?n({title:"WordPress User Import Complete",description:`Imported ${r.imported}, updated ${r.updated}, skipped ${r.skipped}`}):r.status==="cancelled"&&n({title:"WP Import Cancelled",description:`Stopped after importing ${r.imported} users.`}))}catch{}},2e3))},[v,n]);o.useEffect(()=>(fetch("/api/admin/sync/wp-users/progress",{credentials:"include"}).then(s=>s.ok?s.json():null).then(s=>{s&&s.status==="running"&&(B(s),G())}).catch(()=>{}),()=>
1{I.current&&clearInterval(I.current)}),[G]);const ue=R({mutationFn:async()=>(await C("POST","/api/admin/sync/wp-users")).json(),onSuccess:s=>{s.status==="running"&&(B({status:"running",imported:0,updated:0,skipped:0,errors:[],total:0,processed:0,percent:0}),G())},onError:()=>{n({title:"Import Failed",description:"Failed to start WordPress user import. Please try again.",variant:"destructive"})}}),_=R({mutationFn:async()=>(await C("POST","/api/admin/sync/products/migrate-remaining")).json(),onSuccess:s=>{n({title:s.migrated===0?"Already Complete":`Migrated ${s.migrated} Products`,description:s.message}),me(),v.invalidateQueries({queryKey:["/api/admin/sync/products/gaps"]})},onError:()=>{n({title:"Migration Failed",description:"Could not migrate remaining products. Check server logs.",variant:"destructive"})}}),J=o.useCallback(async s=>{T.current=!1;const r=s||1,p=!!s;W(p?M=>({...M,status:"running"}):{status:"running",currentPage:0,totalPages:0,totalProducts:0,imported:0,skipped:0,errors:[],newlyImportedWcIds:[]});let u=r,y=r,X=p?t.imported:0,Z=p?t.skipped:0,ee=p?[...t.errors]:[],se=p?[...t.newlyImportedWcIds]:[];try{for(;u<=y&&!T.current;){const w=await(await C("POST","/api/admin/sync/products/migrate-page",{page:u,perPage:25})).json();y=w.totalPages,X+=w.imported,Z+=w.skipped,ee=[...ee,...w.errors],se=[...se,...w.newlyImportedWcIds],W({status:T.current?"paused":"running",currentPage:u,totalPages:w.totalPages,totalProducts:w.total,imported:X,skipped:Z,errors:ee,newlyImportedWcIds:se}),u++}W(M=>({...M,status:T.current?"paused":"completed"})),T.current||(v.invalidateQueries({queryKey:["/api/admin/sync/stats"]}),n({title:"Migration Complete",description:`Imported ${X} products, skipped ${Z} duplicates`}))}catch{W(w=>({...w,status:"error"})),n({title:"Migration Error",description:"An error occurred during migration. You can resume where it stopped.",variant:"destructive"})}},[n,v,t]),Oe=()=>{T.current=!0},qe=async()=>{if(t.newlyImportedWcIds.length!==0){z(!1),ie(!0);try{const r=t.newlyImportedWcIds;let p=0;for(let u=0;u<r.length;u+=25){const y=r.slice(u,u+25);b==="draft"?await C("POST","/api/admin/sync/products/wc-batch-status",{productIds:y,status:"draft"}):b==="delete"&&await C("POST","/api/admin/sync/products/wc-batch-delete",{productIds:y}),p+=y.length}n({title:"Cleanup Complete",description:`${b==="draft"?"Drafted":"Removed"} ${p} products from WooCommerce`})}catch{n({title:"Cleanup Error",description:"Some products may not have been updated. Check WooCommerce.",variant:"destructive"})}finally{ie(!1)}}},pe=xe.isPending||Y.isPending,he=t.totalPages>0?Math.round(t.currentPage/t.totalPages*100):0,ge=async()=>{if($.trim()){ne(!0),Q(null),E(null);try{const s=encodeURIComponent($.trim()),r=await fetch(`/api/admin/wc/product-preview/${s}`,{credentials:"include"}),p=await r.json();if(!r.ok)throw new Error(p.message||"Preview failed");E(p)}catch(s){Q(s.message)}finally{ne(!1)}}},je=async(s=!1)=>{if(c){ce(!0);try{const r=`/api/admin/wc/import-product/${c.wcId}${s?"?forceUpdate=true":""}`,p=await fetch(r,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"}}),u=await p.json();if(!p.ok)throw new Error(u.message||"Import failed");n({title:u.updated?"Product Re-synced":u.alreadyExisted?"Already Imported":"Product Imported",description:u.message}),E(y=>y&&{...y,alreadyImported:!0,localId:u.productId}),v.invalidateQueries({queryKey:["/api/admin/sync/stats"]})}catch(r){n({title:"Import Failed",description:r.message,variant:"destructive"})}finally{ce(!1)}}};return e.jsxs(Je,{children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"Data Sync & Migration"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Import and migrate data from your WooCommerce store (harborshoppers.com)"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[e.jsxs(g,{children:[e.jsxs(j,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(f,{className:"text-sm font-medium",children:"WooCommerce Products"}),e.jsx(Te,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(N,{children:[e.jsx("div",{className:"text-2xl font-bold",children:D?e.jsx(h,{className:"h-4 w-4 animate-spin"}):typeof(i==null?void 0:i.woocommerce.products)=="number"?i.woocommerce.products.toLocaleStr
1ing():"â"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"On harborshoppers.com"})]})]}),e.jsxs(g,{children:[e.jsxs(j,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(f,{className:"text-sm font-medium",children:"WooCommerce Customers"}),e.jsx(O,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(N,{children:[e.jsx("div",{className:"text-2xl font-bold",children:D?e.jsx(h,{className:"h-4 w-4 animate-spin"}):typeof(i==null?void 0:i.woocommerce.customers)=="number"?i.woocommerce.customers.toLocaleString():"â"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Available to import"})]})]}),e.jsxs(g,{children:[e.jsxs(j,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(f,{className:"text-sm font-medium",children:"Local Products"}),e.jsx(Ae,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(N,{children:[e.jsx("div",{className:"text-2xl font-bold",children:D?e.jsx(h,{className:"h-4 w-4 animate-spin"}):(i==null?void 0:i.local.products)||0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"In this platform's database"})]})]}),e.jsxs(g,{children:[e.jsxs(j,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(f,{className:"text-sm font-medium",children:"Local Users"}),e.jsx(O,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(N,{children:[e.jsx("div",{className:"text-2xl font-bold",children:D?e.jsx(h,{className:"h-4 w-4 animate-spin"}):(i==null?void 0:i.local.totalUsers)||0}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(i==null?void 0:i.local.syncedUsers)||0," synced from WooCommerce"]})]})]})]}),e.jsxs(g,{className:`border-2 ${(l==null?void 0:l.gap)===0?"border-green-200 bg-green-50/30":l!=null&&l.gap&&l.gap>0?"border-amber-200 bg-amber-50/30":"border-slate-200"}`,children:[e.jsxs(j,{className:"pb-3",children:[e.jsxs(f,{className:"flex items-center gap-2 text-lg",children:[e.jsx(ze,{className:`h-5 w-5 ${(l==null?void 0:l.gap)===0?"text-green-600":"text-amber-600"}`}),"Migration Coverage"]}),e.jsx(k,{children:"How many WooCommerce listings are in this platform â dropship products are imported but flagged separately."})]}),e.jsx(N,{className:"space-y-4",children:Le?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(h,{className:"h-4 w-4 animate-spin"})," Checking coverageâ¦"]}):l?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 text-sm",children:[e.jsxs("div",{className:"bg-white border rounded-lg p-3",children:[e.jsx("div",{className:"text-2xl font-bold text-slate-800",children:((fe=l.wcTotal)==null?void 0:fe.toLocaleString())??"â"}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:"Published on WC"})]}),e.jsxs("div",{className:"bg-white border rounded-lg p-3",children:[e.jsx("div",{className:"text-2xl font-bold text-blue-700",children:l.hs3NonDropship.toLocaleString()}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:"In HS3 (non-dropship)"})]}),e.jsxs("div",{className:"bg-white border rounded-lg p-3",children:[e.jsx("div",{className:"text-2xl font-bold text-slate-500",children:l.hs3Dropship.toLocaleString()}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:"Dropship (flagged)"})]}),e.jsxs("div",{className:`border rounded-lg p-3 ${l.gap===0?"bg-green-50":"bg-amber-50"}`,children:[e.jsx("div",{className:`text-2xl font-bold ${l.gap===0?"text-green-700":"text-amber-700"}`,children:l.gap===0?"Complete":l.gap!==null?`~${l.gap} missing`:"â"}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:l.coveragePercent!==null?`${l.coveragePercent}% coverage`:"Gap status"})]})]}),l.coveragePercent!==null&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground mb-1",children:[e.jsx("span",{children:"Coverage"}),e.jsxs("span",{children:[l.coveragePercent,"%"]})]}),e.jsx("div",{className:"h-2 bg-slate-100 rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${l.coveragePercent>=100?"bg-green-500":l.coveragePercent>=90?"bg-blue-500":"bg-amber-500"}`,style:{width:`${Math.min(100,l.coveragePercent)}%`}})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[l.gap===0?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-green-700 bg-green-50 border border-green-200 rounded-lg px-3 py-2",children:[e.jsx(U,{className:"h-4 w-4"}),"All WooCommerce products are in the local database."]}):l.gap&&l.gap>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-amber-700 bg-amber-50 border border-amber-200 rounded-lg px-3 py-2",children:[e.jsx(te,{className:"h-4 w-4 shrink-0"}),l.gap," products are in WooCommerce but not yet in the local database."]}),e.jsx(m,{size:"sm",onClick:()=>_.mutate(),disabled:_.isPending,className:"bg-amber-600 hover:bg-amber-700 text-white shrink-0",children:_.isPending?e.jsxs(e.Fragment,{children:[e.jsx(S,{className:"h-3.5 w-3.5 mr-1 animate-spin"})," Migratingâ¦"]}):e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"h-3.5 w-3.5 mr-1"})," Migrate All ",l.gap," Now"]})})]}):null,e.jsxs(m,{variant:"ghost",size:"sm",onClick:()=>me(),className:"shrink-0",children:[e.jsx(S,{className:"h-3.5 w-3.5 mr-1"})," Refresh"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Coverage count uses ",e.jsx("code",{children:"external_id"})," matching. A small gap is normal if some products were initially imported with a barcode as the external ID â the migration deduplication now also checks by URL slug to prevent duplicates."]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Could not load gap data."})})]}),e.jsxs(g,{className:"border-2 border-blue-200 bg-blue-50/30",children:[e.jsxs(j,{children:[e.jsxs(f,{className:"flex items-center gap-2 text-xl",children:[e.jsx(Me,{className:"h-6 w-6 text-blue-600"}),"Full Product Migration"]}),e.jsx(k,{className:"text-base",children:"Transfer all your WooCommerce products to this platform's database. Products are imported page by page (25 at a time) with full progress tracking. After migration, you can optionally draft or remove them from WooCommerce."})]}),e.jsxs(N,{className:"space-y-6",children:[t.status==="idle"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-lg p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(te,{className:"h-5 w-5 text-amber-600 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-sm text-amber-800",children:[e.jsx("strong",{className:"block mb-1",children:"Before you begin:"}),e.jsxs("ul",{className:"list-disc ml-4 space-y-1",children:[e.jsx("li",{children:"This will copy all published products from WooCommerce into this platform"}),e.jsx("li",{children:"Existing products (already imported) will be skipped automatically"}),e.jsx("li",{children:"Images, categories, metadata, and all product details are preserved"}),e.jsx("li",{children:"You can pause and resume the migration at any time"}),e.jsx("li",{children:"After migration, you'll have the option to draft or remove WooCommerce listings"})]})]})]})}),e.jsxs(m,{onClick:()=>J(),size:"lg",className:"w-full md:w-auto",children:[e.jsx(q,{className:"h-5 w-5 mr-2"}),"Start Full Migration"]})]}),t.status==="running"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"h-5 w-5 animate-spin text-blue-600"}),e.jsx("span",{className:"font-medium",children:"Migration in progress..."})]}),e.jsx(m,{variant:"outline",size:"sm",onClick:Oe,children:"Pause"})]}),e.jsx(K,{value:he,className:"h-3"}
1),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-3 text-center",children:[e.jsxs("div",{className:"bg-white rounded-lg p-3 border",children:[e.jsxs("p",{className:"text-2xl font-bold text-blue-600",children:[t.currentPage,"/",t.totalPages]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Pages"})]}),e.jsxs("div",{className:"bg-white rounded-lg p-3 border",children:[e.jsx("p",{className:"text-2xl font-bold",children:t.totalProducts.toLocaleString()}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Products"})]}),e.jsxs("div",{className:"bg-white rounded-lg p-3 border",children:[e.jsx("p",{className:"text-2xl font-bold text-green-600",children:t.imported}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Imported"})]}),e.jsxs("div",{className:"bg-white rounded-lg p-3 border",children:[e.jsx("p",{className:"text-2xl font-bold text-yellow-600",children:t.skipped}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Skipped"})]}),e.jsxs("div",{className:"bg-white rounded-lg p-3 border",children:[e.jsx("p",{className:"text-2xl font-bold text-red-600",children:t.errors.length}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Errors"})]})]})]}),t.status==="paused"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-yellow-600",children:[e.jsx(re,{className:"h-5 w-5"}),e.jsxs("span",{className:"font-medium",children:["Migration paused at page ",t.currentPage," of ",t.totalPages]})]}),e.jsx(K,{value:he,className:"h-3"}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 text-center",children:[e.jsxs("div",{className:"bg-white rounded-lg p-3 border",children:[e.jsx("p",{className:"text-xl font-bold text-green-600",children:t.imported}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Imported"})]}),e.jsxs("div",{className:"bg-white rounded-lg p-3 border",children:[e.jsx("p",{className:"text-xl font-bold text-yellow-600",children:t.skipped}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Skipped"})]}),e.jsxs("div",{className:"bg-white rounded-lg p-3 border",children:[e.jsx("p",{className:"text-xl font-bold text-red-600",children:t.errors.length}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Errors"})]})]}),e.jsxs(m,{onClick:()=>J(t.currentPage+1),children:[e.jsx(S,{className:"h-4 w-4 mr-2"}),"Resume Migration (Page ",t.currentPage+1,")"]})]}),t.status==="completed"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-2 text-green-600",children:[e.jsx(U,{className:"h-6 w-6"}),e.jsx("span",{className:"text-lg font-semibold",children:"Migration Complete!"})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 text-center",children:[e.jsxs("div",{className:"bg-green-50 rounded-lg p-3 border border-green-200",children:[e.jsx("p",{className:"text-2xl font-bold text-green-700",children:t.imported}),e.jsx("p",{className:"text-xs text-green-600",children:"Products Imported"})]}),e.jsxs("div",{className:"bg-yellow-50 rounded-lg p-3 border border-yellow-200",children:[e.jsx("p",{className:"text-2xl font-bold text-yellow-700",children:t.skipped}),e.jsx("p",{className:"text-xs text-yellow-600",children:"Already Existed"})]}),e.jsxs("div",{className:"bg-blue-50 rounded-lg p-3 border border-blue-200",children:[e.jsx("p",{className:"text-2xl font-bold text-blue-700",children:t.newlyImportedWcIds.length}),e.jsx("p",{className:"text-xs text-blue-600",children:"Total Processed"})]}),e.jsxs("div",{className:"bg-red-50 rounded-lg p-3 border border-red-200",children:[e.jsx("p",{className:"text-2xl font-bold text-red-700",children:t.errors.length}),e.jsx("p",{className:"text-xs text-red-600",children:"Errors"})]})]}),t.errors.length>0&&e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-lg p-4 max-h-40 overflow-y-auto",children:[e.jsx("h4",{className:"font-medium text-red-800 mb-2",children:"Errors:"}),e.jsx("ul",{className:"text-xs text-red-700 space-y-1",children:t.errors.map((s,r)=>e.jsx("li",{children:s},r))})]}),t.newlyImportedWcIds.length>0&&e.jsxs(g,{children:[e.jsxs(j,{className:"pb-3",children:[e.jsx(f,{className:"text-base",children:"Post-Migration: WooCommerce Cleanup"}),e.jsx(k,{children:"Now that products are in this platform, what would you like to do with the WooCommerce copies?"})]}),e.jsxs(N,{className:"space-y-4",children:[e.jsxs(Xe,{value:b,onValueChange:s=>Fe(s),children:[e.jsx(Ze,{className:"w-full md:w-[300px]",children:e.jsx(es,{})}),e.jsxs(ss,{children:[e.jsx(ae,{value:"none",children:"Keep them on WooCommerce (no action)"}),e.jsx(ae,{value:"draft",children:"Set to Draft on WooCommerce (hide from store)"}),e.jsx(ae,{value:"delete",children:"Move to Trash on WooCommerce (can be restored)"})]})]}),b!=="none"&&e.jsx(m,{variant:b==="delete"?"destructive":"default",onClick:()=>z(!0),disabled:le,children:le?e.jsxs(e.Fragment,{children:[e.jsx(h,{className:"h-4 w-4 mr-2 animate-spin"}),"Processing..."]}):b==="draft"?e.jsxs(e.Fragment,{children:[e.jsx(Me,{className:"h-4 w-4 mr-2"}),"Draft ",t.newlyImportedWcIds.length," WooCommerce Products"]}):e.jsxs(e.Fragment,{children:[e.jsx(Qe,{className:"h-4 w-4 mr-2"}),"Remove ",t.newlyImportedWcIds.length," WooCommerce Products"]})})]})]}),e.jsx(m,{variant:"outline",onClick:()=>W({status:"idle",currentPage:0,totalPages:0,totalProducts:0,imported:0,skipped:0,errors:[],newlyImportedWcIds:[]}),children:"Reset Migration Tool"})]}),t.status==="error"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-red-600",children:[e.jsx(F,{className:"h-5 w-5"}),e.jsx("span",{className:"font-medium",children:"Migration encountered an error"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[t.imported," products were imported before the error. You can try again."]}),e.jsxs(m,{onClick:()=>J(t.currentPage>0?t.currentPage:void 0),children:[e.jsx(S,{className:"h-4 w-4 mr-2"}),"Retry Migration",t.currentPage>0?` (from Page ${t.currentPage})`:""]})]})]})]}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs(g,{children:[e.jsxs(j,{children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(O,{className:"h-5 w-5"}),"Customer Import"]}),e.jsx(k,{children:"Import all customers from harborshoppers.com into this platform. Runs in the background â you can close this page and come back."})]}),e.jsxs(N,{className:"space-y-4",children:[e.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-lg p-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(re,{className:"h-4 w-4 text-amber-600 mt-0.5"}),e.jsxs("div",{className:"text-sm text-amber-800",children:[e.jsx("strong",{children:"Note:"}),' Imported users will need to use "Forgot Password" to set a new password for this site.']}
1)]})}),(a==null?void 0:a.status)==="running"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-blue-700",children:[e.jsx(h,{className:"h-4 w-4 animate-spin"}),"Importing customers... ",a.percent,"%"]}),e.jsxs(m,{size:"sm",variant:"destructive",onClick:De,children:[e.jsx(F,{className:"h-3 w-3 mr-1"})," Cancel"]})]}),e.jsx(K,{value:a.percent,className:"h-2"}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-sm",children:[e.jsxs("div",{className:"text-center p-2 bg-green-50 rounded",children:[e.jsx("div",{className:"font-bold text-green-700",children:a.imported}),e.jsx("div",{className:"text-xs text-green-600",children:"Imported"})]}),e.jsxs("div",{className:"text-center p-2 bg-yellow-50 rounded",children:[e.jsx("div",{className:"font-bold text-yellow-700",children:a.skipped}),e.jsx("div",{className:"text-xs text-yellow-600",children:"Skipped"})]}),e.jsxs("div",{className:"text-center p-2 bg-blue-50 rounded",children:[e.jsx("div",{className:"font-bold text-blue-700",children:a.updated}),e.jsx("div",{className:"text-xs text-blue-600",children:"Updated"})]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[a.processed," of ",a.total," customers processed",((Ne=a.errors)==null?void 0:Ne.length)>0&&e.jsxs("span",{className:"text-red-500 ml-2",children:["(",a.errors.length," errors)"]})]}),((be=a.errors)==null?void 0:be.length)>0&&e.jsxs("details",{className:"text-xs",children:[e.jsx("summary",{className:"text-red-600 cursor-pointer",children:"View errors"}),e.jsx("div",{className:"mt-1 max-h-32 overflow-y-auto bg-red-50 rounded p-2 space-y-1",children:a.errors.slice(-10).map((s,r)=>e.jsx("div",{className:"text-red-700",children:s},r))})]})]}):e.jsxs(m,{onClick:()=>xe.mutate(),disabled:pe,className:"w-full",children:[e.jsx(q,{className:"h-4 w-4 mr-2"}),"Import All Customers"]}),(a==null?void 0:a.status)==="failed"&&e.jsx("div",{className:"bg-red-50 border border-red-200 rounded-lg p-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(F,{className:"h-4 w-4 text-red-600 mt-0.5"}),e.jsxs("div",{className:"text-sm text-red-800",children:["Import failed. ",((ve=a.errors)==null?void 0:ve[0])||"Unknown error"]})]})}
1),(x||(a==null?void 0:a.status)==="completed")&&e.jsxs("div",{className:"bg-muted rounded-lg p-4 space-y-2",children:[e.jsxs("h4",{className:"font-medium text-sm flex items-center gap-2",children:[e.jsx(U,{className:"h-4 w-4 text-green-600"}),"Import Complete"]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-sm",children:[e.jsxs("div",{className:"text-center p-2 bg-green-50 rounded",children:[e.jsx("div",{className:"font-bold text-green-700",children:(x==null?void 0:x.imported)??(a==null?void 0:a.imported)??0}),e.jsx("div",{className:"text-xs text-green-600",children:"Imported"})]}),e.jsxs("div",{className:"text-center p-2 bg-yellow-50 rounded",children:[e.jsx("div",{className:"font-bold text-yellow-700",children:(x==null?void 0:x.skipped)??(a==null?void 0:a.skipped)??0}),e.jsx("div",{className:"text-xs text-yellow-600",children:"Skipped"})]}),e.jsxs("div",{className:"text-center p-2 bg-blue-50 rounded",children:[e.jsx("div",{className:"font-bold text-blue-700",children:(x==null?void 0:x.updated)??(a==null?void 0:a.updated)??0}),e.jsx("div",{className:"text-xs text-blue-600",children:"Updated"})]})]}),((((ye=x==null?void 0:x.errors)==null?void 0:ye.length)??0)>0||(((we=a==null?void 0:a.errors)==null?void 0:we.length)??0)>0)&&e.jsxs("div",{className:"text-xs text-red-600 mt-2",children:[((Ce=x==null?void 0:x.errors)==null?void 0:Ce.length)??((ke=a==null?void 0:a.errors)==null?void 0:ke.length)??0," errors occurred"]})]})]})]}),e.jsxs(g,{children:[e.jsxs(j,{children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(Te,{className:"h-5 w-5"}),"Quick Product Sync"]}),e.jsx(k,{children:"Quick sync to update existing products and add new ones. Use Full Migration above for first-time bulk import."})]}),e.jsxs(N,{className:"space-y-4",children:[e.jsx("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(S,{className:"h-4 w-4 text-blue-600 mt-0.5"}),e.jsx("div",{className:"text-sm text-blue-800",children:"Products sync automatically when users browse the shop. Use this to force a full refresh."})]})}),e.jsx(m,{onClick:()=>Y.mutate(),disabled:pe,className:"w-full",variant:"outline",children:Y.isPending?e.jsxs(e.Fragment,{children:[e.jsx(h,{className:"h-4 w-4 mr-2 animate-spin"}),"Syncing Products..."]}):e.jsxs(e.Fragment,{children:[e.jsx(S,{className:"h-4 w-4 mr-2"}),"Sync All Products"]})}),e.jsx("div",{className:"flex items-center justify-center gap-2 py-4",children:e.jsxs(A,{variant:"secondary",children:[(i==null?void 0:i.local.products)||0," products synced"]})})]})]})]}),e.jsxs(g,{children:[e.jsxs(j,{children:[e.jsxs(f,{className:"flex items-center gap-2",children:[e.jsx(O,{className:"h-5 w-5"}),"WordPress Users Import"]}),e.jsx(k,{children:"Import ALL WordPress users (vendors, subscribers, admins, etc.) â not just WooCommerce customers. Runs in the background. Users already imported will have their metadata updated."})]}),e.jsxs(N,{className:"space-y-4",children:[e.jsx("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Ae,{className:"h-4 w-4 text-blue-600 mt-0.5"}),e.jsxs("div",{className:"text-sm text-blue-800",children:[e.jsx("strong",{children:"Tip:"})," Run this after the WooCommerce Customer Import to capture vendors, subscribers, spectators, and other roles missing from the customer-only import."]})]})}),(d==null?void 0:d.status)==="running"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-blue-700",children:[e.jsx(h,{className:"h-4 w-4 animate-spin"}),"Importing WordPress users... ",d.percent,"%"]}),e.jsxs(m,{size:"sm",variant:"destructive",onClick:Re,children:[e.jsx(F,{className:"h-3 w-3 mr-1"})," Cancel"]})]}),e.jsx(K,{value:d.percent,className:"h-2"}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-sm",children:[e.jsxs("div",{className:"text-center p-2 bg-green-50 rounded",children:[e.jsx("div",{className:"font-bold text-green-700",children:d.imported}),e.jsx("div",{className:"text-xs text-green-600",children:"New Users"})]}),e.jsxs("div",{className:"text-center p-2 bg-yellow-50 rounded",children:[e.jsx("div",{className:"font-bold text-yellow-700",children:d.skipped}),e.jsx("div",{className:"text-xs text-yellow-600",children:"Skipped"})]}),e.jsxs("div",{className:"text-center p-2 bg-blue-50 rounded",children:[e.jsx("div",{className:"font-bold text-blue-700",children:d.updated}),e.jsx("div",{className:"text-xs text-blue-600",children:"Updated"})]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[d.processed," of ",d.total," users processed",((Pe=d.errors)==null?void 0:Pe.length)>0&&e.jsxs("span",{className:"text-red-500 ml-2",children:["(",d.errors.length," errors)"]})]}),((Ie=d.errors)==null?void 0:Ie.length)>0&&e.jsxs("details",{className:"text-xs",children:[e.jsx("summary",{className:"text-red-600 cursor-pointer",children:"View errors"}),e.jsx("div",{className:"mt-1 max-h-32 overflow-y-auto bg-red-50 rounded p-2 space-y-1",children:d.errors.slice(-10).map((s,r)=>e.jsx("div",{className:"text-red-700",children:s},r))})]})]}):e.jsxs(m,{onClick:()=>ue.mutate(),disabled:ue.isPending,className:"w-full",children:[e.jsx(q,{className:"h-4 w-4 mr-2"}),"Import All WordPress Users"]}),(d==null?void 0:d.status)==="failed"&&e.jsx("div",{className:"bg-red-50 border border-red-200 rounded-lg p-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(F,{className:"h-4 w-4 text-red-600 mt-0.5"}),e.jsxs("div",{className:"text-sm text-red-800",children:["Import failed. ",((Se=d.errors)==null?void 0:Se[0])||"Unknown error"]})]})}),(d==null?void 0:d.status)==="completed"&&e.jsxs("div",{className:"bg-muted rounded-lg p-4 space-y-2",children:[e.jsxs("h4",{className:"font-medium text-sm flex items-center gap-2",children:[e.jsx(U,{className:"h-4 w-4 text-green-600"}),"WordPress Import Complete"]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-sm",children:[e.jsxs("div",{className:"text-center p-2 bg-green-50 rounded",children:[e.jsx("div",{className:"font-bold text-green-700",children:d.imported}),e.jsx("div",{className:"text-xs text-green-600",children:"New Users"})]}),e.jsxs("div",{className:"text-center p-2 bg-yellow-50 rounded",children:[e.jsx("div",{className:"font-bold text-yellow-700",children:d.skipped}),e.jsx("div",{className:"text-xs text-yellow-600",children:"Skipped"})]}),e.jsxs("div",{className:"text-center p-2 bg-blue-50 rounded",children:[e.jsx("div",{className:"font-bold text-blue-700",children:d.updated}),e.jsx("div",{className:"text-xs text-blue-600",children:"Updated"})]})]}),d.errors.length>0&&e.jsxs("div",{className:"text-xs text-red-600 mt-2",children:[d.errors.length," errors occurred"]})]})]})]}),e.jsxs(g,{children:[e.jsxs(j,{children:[e.jsx(f,{children:"Synced Users"}),e.jsx(k,{children:"Users imported from WooCommerce and WordPress"})]}),e.jsx(N,{children:e.jsx("div",{className:"text-sm text-muted-foreground",children:(i==null?void 0:i.local.syncedUsers)===0?e.jsx("p",{children:'No users have been synced yet. Click "Import All Customers" above to start.'}):e.jsxs("p",{children:[i==null?void 0:i.local.syncedUsers,' users synced from WooCommerce. These users can use "Forgot Password" to access their accounts.']})})})]}),e.jsxs(g,{className:"border-blue-200",children:[e.jsx(j,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(He,{className:"h-5 w-5 text-blue-600"}),e.jsxs("div",{children:[e.jsx(f,{children:"Cherry-Pick Product Import"}),e.jsx(k,{children:"Import a specific product from harborshoppers.com by WooCommerce ID or product URL. Use this to pull hidden or archived products one at a time."})]})]})}),e.jsxs(N,{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(_e,{placeholder:"Enter WC Product ID (e.g. 12345) or URL",value:$,onChange:s=>{Ee(s.target.value),E(null),Q(null)},onKeyDown:s=>s.key==="Enter"&&ge(),className:"flex-1"}),e.jsxs(m,{onClick:ge,disabled:de||!$.trim(),variant:"outline",children:[de?e.jsx(h,{className:"h-4 w-4 animate-spin"}):e.jsx(Ve,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-2",children:"Preview"})]})]}),oe&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-red-600 bg-red-50 border border-red-200 rounded-lg p-3",children:[e.jsx(re,{className:"h-4 w-4 flex-shrink-0"}),oe]}),c&&e.jsxs("div",{className:"border rounded-lg p-4 space-y-3 bg-muted/30",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[c.images[0]&&e.jsx("img",{src:c.images[0],alt:c.name,className:"w-16 h-16 object-cover rounded border flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h4",{className:"font-semibold text-sm leading-tight",children:c.name}),e.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[e.jsxs(A,{variant:"outline",className:"text-xs",children:["WC #",c.wcId]}),c.sku&&e.jsxs(A,{variant:"outline",className:"text-xs",children:["SKU: ",c.sku]}),e.jsx(A,{variant:c.status==="publish"?"default":"secondary",className:"text-xs capitalize",children:c.status}),e.jsx(A,{variant:"outline",className:"text-xs capitalize",children:c.catalogVisibility}),e.jsx(A,{variant:c.stockStatus==="instock"?"default":"secondary",className:"text-xs",children:c.stockStatus==="instock"?"In Stock":"Out of Stock"})]}
1),c.price&&e.jsxs("p",{className:"text-sm font-medium mt-1",children:["$",c.price]}),c.categories.length>0&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:c.categories.join(", ")})]})]}),c.alreadyImported?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 bg-green-50 border border-green-200 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 text-green-700 text-sm",children:[e.jsx(U,{className:"h-4 w-4"}),"Already in HS3 as local product #",c.localId," (",c.localStatus,")"]}),e.jsx(m,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs("a",{href:`/admin/products/${c.localId}`,target:"_blank",rel:"noreferrer",children:[e.jsx(Ye,{className:"h-3 w-3 mr-1"}),"View"]})})]}),e.jsxs(m,{onClick:()=>je(!0),disabled:L,variant:"outline",className:"w-full border-amber-300 text-amber-700 hover:bg-amber-50",children:[L?e.jsx(h,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(S,{className:"h-4 w-4 mr-2"}),"Force Re-sync â Pull Latest Data from Old Site"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This will update the name, price, description, and images from the current legacy listing."})]}):e.jsxs(m,{onClick:()=>je(!1),disabled:L,className:"w-full",children:[L?e.jsx(h,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Be,{className:"h-4 w-4 mr-2"}),"Import This Product into HS3"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Tip: Full migration only imports published, visible products. Use cherry-pick to bring in hidden or archived products individually."})]})]})]}),e.jsx(ts,{open:$e,onOpenChange:z,children:e.jsxs(rs,{children:[e.jsxs(as,{children:[e.jsxs(ls,{className:"flex items-center gap-2",children:[e.jsx(te,{className:"h-5 w-5 text-red-500"}),b==="delete"?"Remove Products from WooCommerce?":"Draft Products on WooCommerce?"]}),e.jsx(is,{children:b==="delete"?e.jsxs(e.Fragment,{children:["This will move ",e.jsxs("strong",{children:[t.newlyImportedWcIds.length," products"]})," to the trash on WooCommerce. They can be restored from the WooCommerce trash within 30 days. Your products are safely stored in this platform's database."]}):e.jsxs(e.Fragment,{children:["This will set ",e.jsxs("strong",{children:[t.newlyImportedWcIds.length," products"]}),` to "Draft" status on WooCommerce, hiding them from the store. They won't be deleted and can be republished anytime.`]})})]}),e.jsxs(ds,{children:[e.jsx(ns,{children:"Cancel"}),e.jsx(cs,{className:b==="delete"?"bg-red-600 hover:bg-red-700":"",onClick:qe,children:b==="delete"?"Yes, Remove from WooCommerce":"Yes, Set to Draft"})]})]})})]})}export{Ns 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.