1import{i as A,r as a,j as e,L as P}from"./vendor-react-PtCE6zzk.js";import{u as R,i as U,y as _,n as B,P as F,q as V,B as f,S as $,F as M}from"./index-Dx1RQjBj.js";import{u as O}from"./useDocumentTitle-BkoG-C1v.js";import{u as z}from"./useWizardState-gc2CGPyN.js";import{T as g}from"./triangle-alert-DLirsOPX.js";import{U as W}from"./upload-y_2Doz9c.js";import{C as L}from"./circle-check-CyBDmAm-.js";import"./vendor-radix-DCv5VfO_.js";import"./vendor-supabase-Bcw6FzAw.js";import"./vendor-recharts-DzKtGs7j.js";function te(){var k;O("Import content - Opedd");const{getAccessToken:y}=R(),C=z(),{toast:n}=U(),m=A(),p=a.useRef(null),[l,j]=a.useState(!1),[o,N]=a.useState(null),[v,w]=a.useState(null),i=a.useCallback(async r=>{if(!l){j(!0),w(null),N(null);try{if(r.size>200*1024*1024)throw new Error("File exceeds 200MB limit. Split into multiple files or use scripts/ migration tooling.");const t=await y();if(!t)throw new Error("Not signed in.");const s=await fetch(`${_}/functions/v1/substack-upload`,{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"text/csv"},body:r}),x=await s.json().catch(()=>({}));if(!s.ok)throw new Error(x.error||`Upload failed with HTTP ${s.status}`);const d=x.data??x,u=typeof d.imported=="number"?d.imported:0,h=typeof d.skipped=="number"?d.skipped:0,b=Array.isArray(d.errors)?d.errors.filter(E=>typeof E=="string"):[];N({imported:u,skipped:h,errors:b});const D=u+h+b.length;n(D===0?{title:"No rows found",description:"We received your file but found no data rows. Check that your CSV has a header row plus at least one data row."}:{title:"Import complete",description:`${u} imported, ${h} skipped, ${b.length} errors.`})}catch(t){B(t,{tags:{surface:"dashboard-import"}});const s=t instanceof Error?t.message:"Upload failed.";w(s),n({title:"Import failed",description:s,variant:"destructive"})}finally{j(!1)}}},[y,l,n]),S=a.useCallback(r=>{var s;const t=(s=r.target.files)==null?void 0:s[0];t&&i(t)},[i]),I=a.useCallback(r=>{var s;r.preventDefault();const t=(s=r.dataTransfer.files)==null?void 0:s[0];t&&i(t)},[i]),c=(k=C.setupData)==null?void 0:k.platform,T=c==="api"||!c;return e.jsx(F,{title:"Bring your writing in",headerActions:e.jsx(e.Fragment,{}),children:e.jsxs("div",{className:`p-4 sm:p-8 ${V.narrow} w-full mx-auto space-y-6`,children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.12em] text-gray-500",children:"Import"}),e.jsx("h2",{className:"text-[30px] font-semibold tracking-tight text-navy-deep leading-tight mt-1.5",children:"Import content"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-2xl leading-relaxed mt-2",children:"Upload a CSV of your articles to ingest them into Opedd. Each row becomes a licensable article."})]}),!T&&e.jsxs("div",{className:"bg-amber-50 border border-amber-200 rounded-xl p-4 flex items-start gap-3",children:[e.jsx(g,{className:"w-5 h-5 text-amber-700 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-amber-900",children:[e.jsxs("p",{className:"font-medium",children:["You're on the ",c," platform."]}),e.jsxs("p",{className:"mt-1",children:["Your content syncs automatically via the ",c," connector. The CSV import is for Custom API publishers only."]}),e.jsx(f,{variant:"link",className:"px-0 mt-1 text-amber-900 underline",onClick:()=>m("/dashboard"),children:"Return to Dashboard"})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-surface-border shadow-card p-6 sm:p-8",children:[e.jsx("h2",{className:"text-base font-semibold text-navy-deep mb-2",children:"CSV file"}),e.jsxs("p",{className:"text-sm text-gray-600 mb-4 leading-relaxed",children:[e.jsx("strong",{className:"font-medium text-navy-deep",children:"Required columns:"})," ",e.jsx("code",{className:"font-mono text-xs bg-gray-50 border border-border rounded px-1.5 py-0.5 text-navy-deep",children:"title"}),", ",e.jsx("code",{className:"font-mono text-xs bg-gray-50 border border-border rounded px-1.5 py-0.5 text-navy-deep",children:"url"}),", ",e.jsx("code",{className:"font-mono text-xs bg-gray-50 border border-border rounded px-1.5 py-0.5 text-navy-deep",children:"published_at"})," (ISO 8601).",e.jsx("br",{}),e.jsx("strong",{className:"font-medium text-navy-deep",children:"Optional columns:"})," ",e.jsx("code",{className:"font-mono text-xs bg-gray-50 border border-border rounded px-1.5 py-0.5 text-navy-deep",children:"description"}),", ",e.jsx("code",{className:"font-mono text-xs bg-gray-50 border border-border rounded px-1.5 py-0.5 text-navy-deep",children:"html_body"}),", ",e.jsx("code",{className:"font-mono text-xs bg-gray-50 border border-border rounded px-1.5 py-0.5 text-navy-deep",children:"author"}),", ",e.jsx("code",{className:"font-mono text-xs bg-gray-50 border border-border rounded px-1.5 py-0.5 text-navy-deep",children:"language"}),", ",e.jsx("code",{className:"font-mono text-xs bg-gray-50 border border-border rounded px-1.5 py-0.5 text-navy-deep",children:"tags"})," (semicolon-separated), ",e.jsx("code",{className:"font-mono text-xs bg-gray-50 border border-border rounded px-1.5 py-0.5 text-navy-deep",children:"image_urls"})," (semicolon-separated), ",e.jsx("code",{className:"font-mono text-xs bg-gray-50 border border-border rounded px-1.5 py-0.5 text-navy-deep",children:"canonical_url"}),", ",e.jsx("code",{className:"font-mono text-xs bg-gray-50 border border-border rounded px-1.5 py-0.5 text-navy-deep",children:"is_paid"})," (true/false).",e.jsx("br",{}),e.jsx("strong",{className:"font-medium text-navy-deep",children:"Limits:"})," 5,000 rows per file. 200MB max. For larger archives, split into multiple files or use"," ",e.jsx(P,{to:"/dashboard",className:"text-oxford font-medium hover:underline underline-offset-4",children:"the canonical Custom API"}),"."]}),e.jsxs("div",{role:"button",tabIndex:0,"aria-label":"Upload CSV file",onDrop:I,onDragOver:r=>r.preventDefault(),onClick:()=>{var r;return(r=p.current)==null?void 0:r.click()},onKeyDown:r=>{var t;(r.key==="Enter"||r.key===" ")&&(r.preventDefault(),(t=p.current)==null||t.click())},className:"border-2 border-dashed border-border bg-gray-50 rounded-xl p-10 text-center cursor-pointer hover:border-oxford hover:bg-oxford-light transition-colors",children:[e.jsx("input",{ref:p,type:"file",accept:".csv,text/csv",onChange:S,className:"hidden",disabled:l}),l?e.jsxs("div",{className:"flex flex-col items-center gap-3 text-gray-600",children:[e.jsx($,{size:"lg"}),e.jsx("p",{className:"text-sm font-medium",children:"Uploading..."})]}):e.jsxs("div",{className:"flex flex-col items-center gap-3 text-gray-600",children:[e.jsx(W,{className:"w-8 h-8"}),e.jsx("p",{className:"text-sm font-medium",children:"Drop your CSV here, or click to browse"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:".csv up to 200MB"})]})]})]}),o&&(o.imported+o.skipped+o.errors.length===0?e.jsxs("div",{"data-testid":"import-result-banner-empty",className:"bg-amber-50 border border-amber-200 rounded-xl p-4 flex items-start gap-3",children:[e.jsx(g,{className:"w-5 h-5 text-amber-700 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-amber-900",children:[e.jsx("p",{className:"font-medium",children:"No rows found"}),e.jsx("p",{className:"mt-1",children:"We received your file but found no data rows to import. Check that your CSV has a header row plus at least one data row."}),e.jsx(f,{variant:"link",className:"px-0 mt-1 text-amber-900 underline",onClick:()=>
1m("/dashboard"),children:"Return to Dashboard"})]})]}):e.jsxs("div",{"data-testid":"import-result-banner-complete",className:"bg-emerald-50 border border-emerald-200 rounded-xl p-4 flex items-start gap-3",children:[e.jsx(L,{className:"w-5 h-5 text-emerald-700 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-emerald-900",children:[e.jsx("p",{className:"font-medium",children:"Import complete"}),e.jsxs("p",{className:"mt-1",children:[e.jsx("strong",{children:o.imported})," imported,"," ",e.jsx("strong",{children:o.skipped})," skipped,"," ",e.jsx("strong",{children:o.errors.length})," errors."]}),o.errors.length>0&&e.jsx("ul",{"data-testid":"import-result-errors-list",className:"mt-2 list-disc pl-5 text-xs text-emerald-800 space-y-0.5 max-h-40 overflow-y-auto",children:o.errors.map((t,s)=>e.jsx("li",{children:t},s))}),e.jsx(f,{variant:"link",className:"px-0 mt-1 text-emerald-900 underline",onClick:()=>m("/dashboard"),children:"Return to Dashboard"})]})]})),v&&e.jsxs("div",{className:"bg-red-50 border border-red-200 rounded-xl p-4 flex items-start gap-3",children:[e.jsx(g,{className:"w-5 h-5 text-red-700 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-red-900",children:[e.jsx("p",{className:"font-medium",children:"Import failed"}),e.jsx("p",{className:"mt-1",children:v})]})]}),e.jsx("div",{className:"bg-white rounded-xl border border-surface-border shadow-card p-6 sm:p-8 text-sm text-gray-700",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(M,{className:"w-4 h-4 mt-0.5 text-muted-foreground shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-navy-deep",children:"Need to import more than 5,000 articles?"}),e.jsxs("p",{className:"mt-1",children:["For larger migrations (e.g., 50K+ Rebel Mouse articles), email"," ",e.jsx("a",{href:"mailto:[email protected]",className:"text-oxford font-medium hover:underline underline-offset-4",children:"[email protected]"})," ","- we'll run a migration script directly. See the"," ",e.jsx("a",{href:"https://docs.opedd.com/publishers",target:"_blank",rel:"noopener noreferrer",className:"text-oxford font-medium hover:underline underline-offset-4",children:"managed ingestion direction"})," ","for full options."]})]})]})})]})})}export{te 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.