1import{o as fs,u as js,n as vs,ad as bs,q as ys,w as ae,aQ as ws,r as o,ab as Ns,j as e,ai as Ss,R as Cs,l as j,aT as ks,T as Ps,b as Fs,e as Ls,_ as b,aZ as As,a8 as Es,Y as Rs,b3 as ke,bb as Us,ao as Ms,aL as Ds,E as Os,al as _s,v as Pe}from"./index-CE18-tb0.js";import{S as T,a as $,b as B,c as V,d as I}from"./select-B_VNVb2N.js";import{E as zs}from"./exceljs.min-BxJGa8ry.js";import{c as Ts,t as $s,a as Bs,v as Vs,e as Is,b as Gs}from"./xmp-DXfE_oow.js";import{L as Ws}from"./LargeBatchDialog-Ca_GPXAE.js";import{U as Xs}from"./upload-BTbSUZ_s.js";import{F as Hs}from"./folder-open-Cfxotgap.js";import{S as Js}from"./settings-2-BTcLzLG2.js";import{C as Zs}from"./chevron-up-4Uu7HJ9z.js";import{C as Ys}from"./circle-x-DpjNHquW.js";import{F as Fe}from"./file-text-BiI4ahgV.js";import"./vendor-Y7T1HomI.js";import"./supabase-BwgEV_BN.js";import"./index-BdQq_4o_.js";import"./_commonjs-dynamic-modules-TDtrdbi3.js";import"./jszip.min-CUneog-9.js";function Le(h){return h.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)+/g,"").slice(0,120)}function Z(h,v,u){return h.split(v).join(u)}function Y(h){const u=String(h||"").trim().toLowerCase(),S=u.replace(/\.[^.]+$/,""),U=S.replace(/[^a-z0-9]+/g,"");return[u,S,U]}function qs(){const h=o.useRef(new Set);return o.useEffect(()=>()=>{h.current.forEach(v=>URL.revokeObjectURL(v)),h.current.clear()},[]),v=>{const u=URL.createObjectURL(v);return h.current.add(u),u}}function Ks(){const[h,v]=o.useState(!1);return o.useEffect(()=>{v(typeof window.showDirectoryPicker=="function")},[]),h}const Qs="JPG, PNG, WEBP, MP4, MOV, SVG",Ae=[{id:"adobe_safe",label:"Adobe safe",pattern:"{index}_{title_slug}",maxLength:30,example:"001_city-skyline.jpg"},{id:"title_slug",label:"Title slug",pattern:"{title_slug}",maxLength:0,example:"city-skyline-at-sunset.jpg"},{id:"original_index",label:"Original + counter",pattern:"{original}_{index}",maxLength:0,example:"DSC001_001.jpg"},{id:"prefix_index",label:"Custom prefix",pattern:"{customPrefix}_{index}",maxLength:0,example:"stock_001.jpg"}];function jt(){const{user:h,profile:v}=fs(),{toast:u}=js(),S=qs(),U=vs(),[q]=bs(),{credits:et}=ys(),Ee=ae(s=>s.addFiles),Re=ae(s=>s.clearFiles),M=q.get("return")==="dashboard",k=ws(v),[y,P]=o.useState(1),[c,f]=o.useState([]),[F,re]=o.useState("zip"),D=Ks(),[K,Ue]=o.useState(null),[Me,G]=o.useState(!1),[De,le]=o.useState(!1),[Oe,_e]=o.useState(!1),ze=o.useCallback(s=>{const r=s.filter(a=>a.type.startsWith("image/")||a.type.startsWith("video/")||a.type==="image/svg+xml");if(!r.length)return;const t=r.map((a,i)=>({id:`${Date.now()}-${i}-${a.name}`,file:a,url:S(a),size:a.size,title:"",keywords:"",description:"",status:"Not processed",newName:a.name,selected:!1,exportState:"idle"}));f(t)},[S]),{getRootProps:Te,getInputProps:$e,isDragActive:Be,open:Ve}=Ns({onDrop:ze,multiple:!0,noClick:!0}),[p,O]=o.useState(""),[Ie,Ge]=o.useState([]),[C,We]=o.useState(""),[Xe,ne]=o.useState(!1),[d,L]=o.useState({columns:[],rows:[]}),[ie,oe]=o.useState([]),[ce,He]=o.useState(""),[de,Je]=o.useState(""),[me,Ze]=o.useState(""),[xe,Ye]=o.useState(""),[_,qe]=o.useState(!1),[pe,Ke]=o.useState(!0),[W,Q]=o.useState("{title_slug}"),[A,ee]=o.useState(0),[X,Qe]=o.useState("");o.useEffect(()=>{const s=q.get("preset"),r=Ae.find(t=>t.id===s);r&&(Q(r.pattern),ee(r.maxLength))},[q]),o.useEffect(()=>{if(!M||c.length>0)return;const s=ae.getState().getRawFiles();if(!Array.isArray(s)||s.length===0)return;const r=s.map((t,a)=>({id:`handoff-${Date.now()}-${a}-${t.name}`,file:t,url:S(t),size:t.size,title:"",keywords:"",description:"",status:"Not processed",newName:t.name,selected:!0,exportState:"idle"}));f(r),P(3)},[M,c.length,S]);const[se,ue]=o.useState(!1),[es,he]=o.useState(0),[E,H]=o.useState("idle"),[ss,ge]=o.useState(0),[ts,fe]=o.useState(0),[je,ve]=o.useState(0),be=o.useRef(null);o.useEffect(()=>{if(!h?.id||p!=="session")return;let s=!1;return(async()=>{ne(!0);try{const{data:t,error:a}=await Pe.getUserSessions(h.id,1,50,!1,{includePreview:!1});if(a)throw a;if(!s){const i=Array.isArray(t)?t:[];Ge(i.map(l=>({id:l.id,title:l.title||"Untitled",created_at:l.created_at,image_count:l.image_count||l.total_images||0})))}}catch(t){console.error("[FileRenamer] Failed to load sessions list",t),s||u({title:"Error loading sessions",de
1scription:"Could not fetch your recent sessions. Please try again.",variant:"destructive"})}finally{s||ne(!1)}})(),()=>{s=!0}},[p,h?.id,u]);const as=c.length>0,rs=o.useMemo(()=>c.length?p==="session"?!!C:p==="csv"?d.columns.length>0&&!!d.fileNameCol:p==="clear"||p==="generate"||p==="fake":!1,[c.length,p,C,d.columns.length,d.fileNameCol]);function z(s,r){const t=s.original.includes(".")?s.original.replace(/^.*(\.[^.]+)$/i,"$1"):"",a=s.original.replace(/\.[^.]+$/,""),i=s.title?Le(s.title):"",l=String(r+1).padStart(3,"0");let n=W||"{original}";if(n=Z(n,"{title_slug}",i||Le(a)),n=Z(n,"{original}",a),n=Z(n,"{index}",l),n=Z(n,"{customPrefix}",X||""),n=n.replace(/[\\/:*?"<>|]+/g,"-").replace(/(^\.|\.$)/g,""),A>0){const x=t.toLowerCase(),m=Math.max(1,A-x.length);return n=n.slice(0,m).replace(/[-_\s.]+$/g,""),`${n||l}${x}`}return(n||a)+t.toLowerCase()}async function ls(s){try{if(s.name.toLowerCase().endsWith(".xlsx")||s.name.toLowerCase().endsWith(".xls")){const r=await s.arrayBuffer(),t=new zs.Workbook;await t.xlsx.load(r);const a=t.worksheets[0],i=[],l=[];a.getRow(1).eachCell((n,x)=>{i[x-1]=String(n.value??"").trim()}),a.eachRow((n,x)=>{if(x===1)return;const m={};n.eachCell((w,g)=>{m[i[g-1]||`Col${g}`]=String(w.value??"").trim()}),l.push(m)}),L({columns:i.filter(Boolean),rows:l}),oe(l.slice(0,3));return}if(s.name.toLowerCase().endsWith(".csv")){const t=(await s.text()).split(/\r?\n/).filter(l=>l.length>0);if(!t.length)throw new Error("Empty CSV");const a=t[0].split(",").map(l=>l.trim()),i=[];for(let l=1;l<t.length;l++){const n=t[l].split(","),x={};a.forEach((m,w)=>{x[m]=(n[w]||"").trim()}),i.push(x)}L({columns:a.filter(Boolean),rows:i}),oe(i.slice(0,3));return}u({title:"Unsupported file",description:"Please upload CSV or Excel (.xlsx) file",variant:"destructive"})}catch(r){u({title:"CSV/Excel parse error",description:r?.message||"Failed to parse file",variant:"destructive"})}}async function ns(s){const r=new Map;let t=1;for(;t<=10;){const{images:a}=await Pe.getSession(s,t,1e3);if(!a?.length)break;for(const i of a){const l=String(i.original_filename||i.filename||"").trim();if(!l)continue;const n=i.metadata||i.meta_json||{},x=String(i.title??n.title??"").trim(),m=String(i.description??n.description??"").trim(),w=Array.isArray(i.keywords)?i.keywords:Array.isArray(n.keywords)?n.keywords:String(i.keywords??n.keywords??"").split(",").map(N=>String(N).trim()).filter(Boolean),g=Array.isArray(w)?w.join(", "):String(w||"");for(const N of Y(l))r.has(N)||r.set(N,{title:x,keywords:g,description:m})}t+=1}return r}function ye(s,r){const t=c.map((a,i)=>{let l=a.title,n=a.keywords,x=a.description,m=a.status;if(s==="session"){let g;const N=Y(a.file.name);if(r)for(const R of N){const J=r.get(R);if(J){g=J;break}}g&&(g.title||g.keywords||g.description)?(l=g.title||l,n=g.keywords||n,x=g.description||x,m="Matched from session"):m="Unmatched"}else if(s==="csv"){const g=d.fileNameCol||"",N=Y(a.file.name),R=d.rows.find(J=>{const Ce=String(J[g]||"").trim();if(!Ce)return!1;const hs=Y(Ce);return N.some(gs=>hs.includes(gs))});R?(l=String(d.titleCol&&R[d.titleCol]||l),n=String(d.keywordsCol&&R[d.keywordsCol]||n),x=String(d.descriptionCol&&R[d.descriptionCol]||x),m="From CSV"):m="Unmatched"}else s==="clear"?(l="",n="",x="",m="Cleared"):s==="generate"?m="Generated":s==="fake"&&(m="Fake");const w=z({title:l,original:a.file.name},i);return{...a,title:l,keywords:n,description:x,status:m,newName:w}});f(t)}async function is(){if(p==="session"&&C){const s=await ns(C);ye("session",s)}else ye(p);P(3)}const te=o.useMemo(()=>{const s=c.filter(a=>a.status==="Matched from session"||a.status==="From CSV"||a.status==="Generated"||a.status==="Cleared"||a.status==="Fake").length,r=c.filter(a=>a.status==="Unmatched").length;return{matched:s,unmatched:r,renamedOnly:r}},[c]);function we(s){const r=/\.([^.]+)$/i.exec(s);return r?r[1].toLowerCase():""}async function os(s,r){try{const t=we(s.newName)||we(s.file.name)||"jpg";let a=s.file;const i=(s.keywords||"").split(/[,;\n]/).map(m=>m.trim()).filter(Boolean),l=p!=="clear"?{title:s.title,description:s.description,keywords:i,creator:_?ce:void 0,rights:_?de:void 0,website:_?me:void 0,location:_?xe:void 0}:{title:"",description:"",keywords:[]},n=!!(l.title||l.description||(l.keywords?.length??0)||l.creator||l.rights||l.website||l.location);if(s.file.type==="image/jpeg"||t==="jpg"||t==="jpeg"){if(a=await Bs(s.file,l),n&&
1!await Vs(a))return{ok:!1,error:"XMP verification failed (JPEG)"}}else if((s.file.type==="image/png"||t==="png")&&(a=await Is(s.file,l),n&&!await Gs(a)))return{ok:!1,error:"XMP verification failed (PNG)"};return{ok:!0,path:s.newName||s.file.name,blob:a}}catch(t){return{ok:!1,error:t?.message||"Failed"}}}async function cs(){if(!k){G(!0),u({title:"Upgrade required",description:"Downloading renamed files with embedded metadata is available on paid plans. Free users can use CSV export from Review Editor."});return}try{ue(!0),he(0),ge(0),fe(0),ve(0),H("processing"),u({title:"Export started",description:`${c.length} file(s)`}),be.current?.scrollIntoView({behavior:"smooth",block:"center"}),await new Promise(t=>setTimeout(t,16));const s=c,r=[];for(let t=0;t<s.length;t++){const a=s[t];f(l=>l.map(n=>n.id===a.id?{...n,exportState:"processing",exportError:void 0}:n));const i=await os(a,t);i.ok&&i.path&&i.blob?(r.push({path:i.path,blob:i.blob}),f(l=>l.map(n=>n.id===a.id?{...n,exportState:"done"}:n)),fe(l=>l+1)):(ve(l=>l+1),f(l=>l.map(n=>n.id===a.id?{...n,exportState:"failed",exportError:i.error||"Failed"}:n))),he(Math.round((t+1)/s.length*100)),await new Promise(l=>setTimeout(l,16))}if(F==="zip"){H("zipping");const t=await Ts(r,a=>{ge(Math.round(a.percent||0))});$s(t,"renamed.zip")}else if(F==="fs"&&D&&K){H("writing");for(const t of r){const i=await(await K.getFileHandle(t.path,{create:!0})).createWritable();await i.write(t.blob),await i.close()}}H("done"),u({title:"Export complete",description:`Processed ${r.length} file(s)`})}catch(s){u({title:"Export error",description:s?.message||"Failed to export",variant:"destructive"})}finally{ue(!1)}}const ds=c.some(s=>s.selected),ms=s=>f(r=>r.map(t=>({...t,selected:s}))),xs=(s,r)=>f(t=>t.map(a=>a.id===s?{...a,selected:r}:a)),ps=s=>{s.preventDefault(),s.stopPropagation(),Ve()};function Ne(){f(s=>s.map((r,t)=>({...r,newName:z({title:r.title,original:r.file.name},t)})))}function Se(){const s=c.map((r,t)=>{const a=r.newName&&r.newName!==r.file.name?r.newName:z({title:r.title,original:r.file.name},t);return new File([r.file],a,{type:r.file.type,lastModified:r.file.lastModified})});Re(),Ee(s),u({title:"Files renamed",description:"Renamed files were sent back to the upload flow. You can continue metadata generation from Dashboard."}),U("/dashboard?renamed=1")}async function us(){try{const s=await window.showDirectoryPicker();Ue(s)}catch{}}return e.jsxs("div",{className:"cs-page",children:[e.jsx(Ss,{onUploadClick:()=>U("/dashboard"),onPurchaseOpen:()=>G(!0),onAccountOpen:()=>le(!0)}),e.jsxs("div",{className:"max-w-[1200px] mx-auto px-5 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsx("div",{children:e.jsx("h2",{className:"text-[20px] font-bold tracking-tight mb-0.5",style:{color:"var(--cs-text-primary)",letterSpacing:"-0.02em"},children:"File Renamer"})}),e.jsx("div",{className:"flex items-center gap-2",children:[{num:1,label:"Upload"},{num:2,label:"Metadata"},{num:3,label:"Review & Export"}].map((s,r)=>e.jsxs(Cs.Fragment,{children:[r>0&&e.jsx("div",{className:"w-6 h-px",style:{background:y>=s.num?"var(--cs-primary, hsl(var(--primary)))":"var(--cs-border)"}}),e.jsxs("button",{type:"button",onClick:()=>{s.num<y&&P(s.num)},disabled:s.num>y,className:`flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded-full transition-colors ${s.num===y?"bg-primary text-primary-foreground":s.num<y?"bg-primary/10 text-primary cursor-pointer hover:bg-primary/20":"text-muted-foreground bg-muted/50 cursor-default"}`,children:[e.jsx("span",{className:"w-4 h-4 rounded-full flex items-center justify-center text-[10px] font-bold border border-current/20",children:s.num<y?"â":s.num}),e.jsx("span",{className:"hidden sm:inline",children:s.label})]})]},s.num))})]}),y===1&&e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"rounded-xl p-8",style:{background:"var(--cs-bg-card)",border:"1px solid var(--cs-border)",boxShadow:"var(--cs-shadow-card)"},children:[e.jsxs("div",{...Te(),className:`border-2 border-dashed rounded-xl p-10 text-center ${Be?"border-primary bg-primary/5":"border-muted-foreground
1/20 hover:border-primary/50"}`,children:[e.jsx("input",{...$e()}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"mx-auto w-16 h-16 rounded-full bg-primary/10 flex items-center justify-center",children:e.jsx(Xs,{className:"h-8 w-8 text-primary"})}),e.jsx("div",{className:"text-lg",children:"Drop your files here"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"or browse files manually"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Supported: ",Qs]}),e.jsx(j,{type:"button",variant:"outline",className:"mt-2",onClick:ps,children:"Browse Files"})]})]}),e.jsx("div",{className:"mt-6 text-xs text-muted-foreground",children:"You can change filenames and metadata later â this step is only about which files to process and where to save results."})]}),c.length>0&&e.jsxs("div",{className:"rounded-xl p-6",style:{background:"var(--cs-bg-card)",border:"1px solid var(--cs-border)",boxShadow:"var(--cs-shadow-card)"},children:[e.jsxs("div",{className:"mb-4 font-medium",children:[c.length," file(s) selected"]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-muted-foreground",children:[e.jsx("th",{className:"w-16",children:"Preview"}),e.jsx("th",{children:"Original file name"}),e.jsx("th",{className:"w-32",children:"Size"}),e.jsx("th",{className:"w-40",children:"Status"})]})}),e.jsx("tbody",{children:c.map(s=>e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"py-2",children:e.jsx("img",{src:s.url,alt:"thumb",className:"w-12 h-12 object-cover rounded"})}),e.jsx("td",{className:"py-2",children:s.file.name}),e.jsxs("td",{className:"py-2",children:[(s.size/1024/1024).toFixed(2)," MB"]}),e.jsx("td",{className:"py-2 text-muted-foreground",children:"Not processed"})]},s.id))})]})})]}),e.jsxs("div",{className:"rounded-xl p-6",style:{background:"var(--cs-bg-card)",border:"1px solid var(--cs-border)",boxShadow:"var(--cs-shadow-card)"},children:[e.jsx("div",{className:"font-medium mb-4",style:{color:"var(--cs-text-primary)"},children:"Output destination"}),e.jsxs("div",{className:"flex items-center gap-8",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:"out",value:"zip",checked:F==="zip",onChange:()=>re("zip")}),e.jsx("span",{children:"Download as ZIP (recommended)"})]}),e.jsx(ks,{children:e.jsxs(Ps,{children:[e.jsx(Fs,{asChild:!0,children:e.jsxs("label",{className:`flex items-center gap-2 ${D?"":"opacity-50"}`,children:[e.jsx("input",{type:"radio",name:"out",value:"fs",disabled:!D,checked:F==="fs",onChange:()=>re("fs")}),e.jsx("span",{children:"Save back to original folder (where supported)"})]})}),!D&&e.jsx(Ls,{children:"Available in Chrome / Edge only"})]})}),F==="fs"&&D&&e.jsxs(j,{variant:"outline",size:"sm",onClick:us,children:[e.jsx(Hs,{className:"h-4 w-4 mr-2"}),"Choose folder"]})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(j,{disabled:!as,onClick:()=>P(2),children:"Next: Metadata source"})})]}),y===2&&e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"rounded-xl p-6",style:{background:"var(--cs-bg-card)",border:"1px solid var(--cs-border)",boxShadow:"var(--cs-shadow-card)"},children:[e.jsx("div",{className:"font-medium mb-2",children:"How do you want to handle metadata?"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"flex items-start gap-3",children:[e.jsx("input",{type:"radio",name:"src",checked:p==="session",onChange:()=>O("session")}),e.jsxs("div",{children:[e.jsx("div",{children:"Use existing CyberStock session"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"We match files by original filename. Unmatched files will be labeled on the next step."})]})]}),e.jsxs("label",{className:"flex items-start gap-3",children:[e.jsx("input",{type:"radio",name:"src",checked:p==="csv",onChange:()=>O("csv")}),e.jsxs("div",{children:[e.jsx("div",{children:"Import from CSV / Excel"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Upload a CSV/XLSX and map columns for File name, Title, Ke
1ywords, Description."})]})]}),e.jsxs("label",{className:"flex items-start gap-3",children:[e.jsx("input",{type:"radio",name:"src",checked:p==="generate",onChange:()=>O("generate")}),e.jsxs("div",{children:[e.jsx("div",{children:"Generate new metadata with CyberStock"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"UI only for now. Will create a session and use it as the source later."})]})]}),e.jsxs("label",{className:"flex items-start gap-3",children:[e.jsx("input",{type:"radio",name:"src",checked:p==="clear",onChange:()=>O("clear")}),e.jsxs("div",{children:[e.jsx("div",{children:"Clear metadata"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Removes Title/Keywords/Description in XMP for JPEG; other formats will be renamed only."})]})]}),e.jsxs("label",{className:"flex items-start gap-3",children:[e.jsx("input",{type:"radio",name:"src",checked:p==="fake",onChange:()=>O("fake")}),e.jsxs("div",{children:[e.jsx("div",{children:"Generate fake metadata"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"UI only in this version."})]})]})]})]}),p==="session"&&e.jsxs("div",{className:"rounded-xl p-6",style:{background:"var(--cs-bg-card)",border:"1px solid var(--cs-border)",boxShadow:"var(--cs-shadow-card)"},children:[e.jsx("div",{className:"mb-3",children:"Choose session"}),e.jsxs("div",{className:"flex gap-3 items-center",children:[e.jsxs(T,{onValueChange:We,value:C,children:[e.jsx($,{className:"w-[360px]",children:e.jsx(B,{placeholder:Xe?"Loading sessionsâ¦":"Select a session"})}),e.jsx(V,{children:Ie.map(s=>e.jsxs(I,{value:s.id,children:[s.title," · ",new Date(s.created_at).toLocaleDateString()," · ",s.image_count||0," files"]},s.id))})]}),C&&e.jsx("a",{className:"text-sm text-primary",href:`/sessions/${C}/review-edit`,target:"_blank",rel:"noreferrer",children:"View session details"})]})]}),p==="csv"&&e.jsxs("div",{className:"rounded-xl p-6 space-y-4",style:{background:"var(--cs-bg-card)",border:"1px solid var(--cs-border)",boxShadow:"var(--cs-shadow-card)"},children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsx(b,{type:"file",accept:".csv,.xlsx,.xls",onChange:s=>s.target.files&&s.target.files[0]&&ls(s.target.files[0])})}),d.columns.length>0&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm mb-1",children:"File name"}),e.jsxs(T,{onValueChange:s=>L(r=>({...r,fileNameCol:s})),value:d.fileNameCol,children:[e.jsx($,{children:e.jsx(B,{placeholder:"Choose column"})}),e.jsx(V,{children:d.columns.map(s=>e.jsx(I,{value:s,children:s},s))})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm mb-1",children:"Title"}),e.jsxs(T,{onValueChange:s=>L(r=>({...r,titleCol:s})),value:d.titleCol,children:[e.jsx($,{children:e.jsx(B,{placeholder:"Choose column"})}),e.jsx(V,{children:d.columns.map(s=>e.jsx(I,{value:s,children:s},s))})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm mb-1",children:"Keywords"}),e.jsxs(T,{onValueChange:s=>L(r=>({...r,keywordsCol:s})),value:d.keywordsCol,children:[e.jsx($,{children:e.jsx(B,{placeholder:"Choose column"})}),e.jsx(V,{children:d.columns.map(s=>e.jsx(I,{value:s,children:s},s))})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm mb-1",children:"Description"}),e.jsxs(T,{onValueChange:s=>L(r=>({...r,descriptionCol:s})),value:d.descriptionCol,children:[e.jsx($,{children:e.jsx(B,{placeholder:"Choose column"})}),e.jsx(V,{children:d.columns.map(s=>e.jsx(I,{value:s,children:s},s))})]})]})]}),ie.length>0&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Preview rows: ",JSON.stringify(ie)]})]}),e.jsxs("div",{className:"rounded-xl p-6 space-y-4",style:{background:"var(--cs-bg-card)",border:"1px solid var(--cs-border)",boxShadow:"var(--cs-shadow-card)"},children:[e.jsx("div",{className:"font-medium",style:{color:"var(--cs-text-primary)"},children:"Global metadata template"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm mb-1",children:"Photographer / Author"}),e.jsx(b,{value:ce,onChange:s=>He(s.target.value),placeholder:"Your name"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm mb-1",children:"Copyright / Website"}),e.jsx(b,{value:de,onChange:s=>Je(s.target.value),placeholder:" 2026 Your Name"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm mb-1",children:"Website"}),e.jsx(b,{value:me,onChange:s=>Ze(s.target.value),placeholder:"https://..."})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm mb-1",children:"Location"}),e.jsx(b,{value:xe,onChange:s=>Ye(s.target.value),placeholder:"City, Country"})]})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:_,onChange:s=>qe(s.target.checked)}),e.jsx("span",{children:"Apply to all files"})]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx(j,{variant:"outline",onClick:()=>P(1),children:"Back"}),e.jsx(j,{disabled:!rs,onClick:is,children:"Next: Review & export"})]})]}),y===3&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"rounded-xl overflow-hidden",style:{background:"var(--cs-bg-card)",border:"1px solid var(--cs-border)",boxShadow:"var(--cs-shadow-card)"},children:[e.jsxs("button",{type:"button",onClick:()=>Ke(s=>!s),className:"w-full flex items-center justify-between px-5 py-4 text-left hover:bg-primary/5 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(Js,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold",style:{color:"var(--cs-text-primary)"},children:"Rename & Metadata Settings"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Pattern: ",e.jsx("span",{className:"font-mono text-foreground",children:W}),A>0&&e.jsxs(e.Fragment,{children:[" · Max ",A," chars"]}),X&&e.jsxs(e.Fragment,{children:[" · Prefix: ",X]})]})]})]}),pe?e.jsx(Zs,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(As,{className:"h-4 w-4 text-muted-foreground"})]}),pe&&e.jsxs("div",{className:"px-5 pb-5 space-y-5 border-t",style:{borderColor:"var(--cs-border)"},children:[e.jsxs("div",{className:"pt-4",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider mb-3",children:"Rename templates"}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2",children:Ae.map(s=>e.jsxs("button",{type:"button",onClick:()=>{Q(s.pattern),ee(s.maxLength),Ne()},className:`rounded-lg border p-3 text-left text-sm transition ${W===s.pattern&&A===s.maxLength?"border-primary bg-primary/10 ring-1 ring-primary/30":"hover:border-primary/50 hover:bg-primary/5"}`,children:[e.jsx("div",{className:"font-medium text-xs",style:{color:"var(--cs-text-primary)"},children:s.label}),e.jsx("div",{className:"text-[11px] text-muted-foreground font-mono mt-0.5",children:s.pattern}),e.jsxs("div",{className:"mt-1.5 text-[10px] text-muted-foreground",children:["e.g. ",s.example]})]},s.id))})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1.5",children:"Filename pattern"}),e.jsx(b,{value:W,onChange:s=>Q(s.target.value),placeholder:"{title_slug}",className:"text-sm"}),e.jsxs("div",{className:"text-[11px] text-muted-foreground mt-1",children:["Variables: ","{title_slug}"," ","{original}"," ","{index}"," ","{customPrefix}"]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1.5",children:"Max filename length"}),e.jsx(b,{type:"number",min:0,value:A||"",onChange:s=>ee(Math.max(0,Number(s.target.value||0))),placeholder:"0 = no limit, 30 = Adobe safe",className:"text-sm"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground mb-1.5",children:"Custom prefix"}),e.jsx(b,{value:X,onChange:s=>Qe(s.target.value),placeholder:"stock",className:"text-sm"})]})]}),c.length>0&&e.jsxs("div",{className:"rounded-lg p-3 text-xs",style:{background:"var(--cs-bg-secondary, rgba(255,255,255,0.03))",border:"1px solid var(--cs-border)"},children:[e.jsx("div",{className:"font-medium text-muted-foreground uppercase tracking-wider mb-2 text-[10px]",children:"Live preview"}),c.slice(0,3).map((s,r)=>{const t=z({title:s.title,original:s.file.name},r);return e.jsxs("div",{className:"flex items-center gap-2 py-0.5 truncate",children:[e.jsx("span",{className:"text-muted-foreground truncate max-w-[200px]",children:s.file.name}),e.jsx(Es,{className:"h-3 w-3 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-foreground font-medium truncate",children:t}),e.jsxs("span",{className:"text-muted-foreground flex-shrink-0",children:["(",t.length,")"]})]},s.id)})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(j,{size:"sm",onClick:Ne,children:"Apply to all files"})})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 px-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-emerald-500"}),e.jsx("span",{className:"text-muted-foreground",children:"Matched:"}),e.jsx("span",{className:"font-medium",style:{color:"var(--cs-text-primary)"},children:te.matched})]}),te.unmatched>0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-amber-500"}),e.jsx("span",{className:"text-muted-foreground",children:"Unmatched:"}),e.jsx("span",{className:"font-medium",style:{color:"var(--cs-text-primary)"},children:te.unmatched})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-500"}),e.jsx("span",{className:"text-muted-foreground",children:"Total files:"}),e.jsx("span",{className:"font-medium",style:{color:"var(--cs-text-primary)"},children:c.length})]})]}),e.jsxs("div",{className:"rounded-xl overflow-hidden",style:{background:"var(--cs-bg-card)",border:"1px solid var(--cs-border)",boxShadow:"var(--cs-shadow-card)"},children:[e.jsx("div",{className:"flex items-center justify-between px-5 py-3 border-b",style:{borderColor:"var(--cs-border)"},children:e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:ds,onChange:s=>ms(s.target.checked),className:"rounded"}),e.jsxs("span",{className:"text-muted-foreground",children:["Select all (",c.length,")"]})]})}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:[e.jsx("th",{className:"w-10 px-5 py-2.5"}),e.jsx("th",{className:"w-14 py-2.5",children:"Preview"}),e.jsx("th",{className:"py-2.5 px-3",children:"New file name"}),e.jsx("th",{className:"py-2.5 px-3",children:"Title"}),e.jsx("th",{className:"py-2.5 px-3",children:"Keywords"}),e.jsx("th",{className:"w-36 py-2.5 px-3",children:"Status"})]})}),e.jsx("tbody",{children:c.map((s,r)=>e.jsxs("tr",{className:"border-t transition-colors hover:bg-primary/[0.02]",style:{borderColor:"var(--cs-border)"},children:[e.jsx("td",{className:"py-2.5 px-5",children:e.jsx("input",{type:"checkbox",checked:s.selected,onChange:t=>xs(s.id,t.target.checked),className:"rounded"})}),e.jsx("td",{className:"py-2.5",children:e.jsx("img",{src:s.url,alt:"",className:"w-10 h-10 object-cover rounded-md"})}),e.jsx("td",{className:"py-2.5 px-3",children:e.jsx("span",{className:"font-mono text-xs",style:{color:"var(--cs-text-primary)"},children:s.newName})}),e.jsx("td",{className:"py-2.5 px-3",children:e.jsx(b,{value:s.title,onChange:t=>f(a=>a.map(i=>i.id===s.id?{...i,title:t.target.value,newName:z({title:t.target.value,original:i.file.name},r)}:i)),className:"h-8 text-xs",placeholder:"Title"})}),e.jsx("td",{className:"py-2.5 px-3",children:e.jsx(b,{value:s.keywords,onChange:t=>f(a=>a.map(i=>i.id===s.id?{...i,keywords:t.target.value}:i)),className:"h-8 text-xs",placeholder:"Keywords"})}),e.jsx("td",{className:"py-2.5 px-3",children:se&&s.exportState!=="idle"?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs",children:[s.exportState==="processing"&&e.jsxs(e.Fragment,{children:[e.jsx(Rs,{className:"h-3.5 w-3.5 animate-spin text-primary"}),e.jsx("span",{className:"text-muted-foreground",children:"Processing"})]}),s.exportState==="done"&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{className:"h-3.5 w-3.5 text-emerald-500"}),e.jsx("span",{className:"text-emerald-500",children:"Done"})]}),s.exportState==="failed"&&e.jsxs(e.Fragment,{children:[e.jsx(Ys,{className:"h-3.5 w-3.5 text-destructive"}),e.jsx("span",{className:"text-destructive",children:"Failed"})]})]}):e.jsx("span",{className:`text-[11px] px-2 py-1 rounded-full border inline-block ${s.status==="Matched from session"||s.status==="From CSV"?"border-emerald-500/30 text-emerald-500 bg-emerald-500/10":s.status==="Unmatched"?"border-amber-500/30 text-amber-500 bg-amber-500/10":s.status==="Cleared"?"border-blue-500/30 text-blue-500 bg-blue-500/10":"border-muted-foreground
1/20 text-muted-foreground"}`,children:s.status})})]},s.id))})]})})]}),e.jsx("div",{ref:be,className:"rounded-xl p-5",style:{background:"var(--cs-bg-card)",border:"1px solid var(--cs-border)",boxShadow:"var(--cs-shadow-card)"},children:se?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"text-sm font-medium",style:{color:"var(--cs-text-primary)"},children:[E==="processing"&&"Embedding metadataâ¦",E==="zipping"&&"Creating ZIP archiveâ¦",E==="writing"&&"Writing filesâ¦",E==="done"&&"Export complete"]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[ts,"/",c.length," files ",je>0&&e.jsxs("span",{className:"text-destructive",children:["· ",je," failed"]})]})]}),e.jsx(Us,{value:E==="zipping"?ss:es,className:"h-2"}),E==="done"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-emerald-500",children:[e.jsx(ke,{className:"h-4 w-4"}),e.jsx("span",{children:"All files exported successfully"})]}),e.jsx("div",{className:"flex flex-wrap items-center gap-2 pt-1",children:M?e.jsx(j,{onClick:Se,disabled:c.length===0,className:"bg-emerald-600 hover:bg-emerald-500 text-white font-semibold shadow",children:"Continue Processing"}):e.jsx(j,{variant:"outline",size:"sm",onClick:()=>U("/dashboard"),children:"Return to Dashboard"})})]})]}):e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(Fe,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",style:{color:"var(--cs-text-primary)"},children:"Ready to export"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[c.length," file(s) · Output: ",F==="zip"?"ZIP download":K?"Selected folder":"Local folder"]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[!M&&e.jsx(j,{variant:"outline",size:"sm",onClick:()=>P(2),children:"Back"}),e.jsxs(j,{variant:k?"outline":"default",size:"sm",onClick:cs,disabled:se||c.length===0,className:k?void 0:"bg-amber-500 text-white hover:bg-amber-600",children:[k?e.jsx(Fe,{className:"mr-2 h-4 w-4"}):e.jsx(Ms,{className:"mr-2 h-4 w-4"}),k?"Download":"Upgrade to download",!k&&e.jsx(Ds,{className:"ml-2 h-3.5 w-3.5"})]}),M&&e.jsx(j,{onClick:Se,disabled:c.length===0,className:"bg-emerald-600 hover:bg-emerald-500 text-white font-semibold shadow",children:"Continue Processing"})]})]})})]})]}),e.jsx(Os,{open:Me,onOpenChange:G,initialTab:"unlimited"}),e.jsx(_s,{open:De,onOpenChange:le,onUpgrade:()=>G(!0)}),e.jsx(Ws,{open:Oe,onOpenChange:_e})]})}export{jt 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.