1import{al as G,s as L,am as se,o as ie,ej as le,r as j,j as e,_ as ne,aE as _e,aS as Ve,G as Y,aT as Ne,eV as We,gc as ze,aL as ke,c2 as qe,cv as Ge,gd as Je,c4 as Qe,X as Me,bB as Xe,by as Ye,g as Ze,dp as Ke,ge as et}from"./vendor-B3bqREfz.js";import{A as tt}from"./AdminLayout-C31anzfd.js";import{W as Se}from"./WalkthroughVideo-Cui8Vbeg.js";import{B as v,D as at,h as st,j as lt,k as nt,l as rt,I as H,m as it}from"./index-BHZdkTHk.js";import{A as ot,a as dt,b as ct,c as mt,d as ut,e as pt,f as ht,g as xt}from"./alert-dialog-Cfg8Q-r-.js";import{T as ee}from"./textarea-BFtGXtJd.js";import"./harbor-shoppers-logo-BwiOLETu.js";const Ce=["bulklister-walkthrough","bulklister-full-training","staff-cue-walkthrough","speed-session-walkthrough","brand-how-it-works","captain-wizard-walkthrough","vendor-new-listing-wizard"],Ae=["upload","youtube","vimeo"],Ie=["public","authenticated","vendor","staff","captain"],Te=["buyers","sellers","staff"],Ue=["sales_demo","onboarding","support"],M=["harbor_shoppers","shopz","boatz_hub","boatz_pro","yachtz_pro","salvage_shoppers","nautical_trips","hirevi"];G(Ce);const bt=G(Ae),gt=G(Ie),re=G(M),ft=G(Te),wt=G(Ue),we=L().trim().url().max(2048).nullable().optional(),jt=L().trim().max(5e3).nullable().optional(),te=se(L().trim().min(1).max(120)).max(30).optional(),vt=ie({label:L().trim().min(1).max(100),destination:L().trim().min(1).max(300).refine(s=>s.startsWith("/")&&!s.startsWith("//")&&!/[<>"'`\s]/.test(s),"next step destination must be an internal path")});ie({provider:bt.optional(),sourceUrl:L().trim().max(2048).url().nullable().optional(),title:L().trim().max(200).nullable().optional(),description:L().trim().max(5e3).nullable().optional(),summaryText:jt,transcriptText:L().trim().max(5e4).nullable().optional(),transcriptUrl:we,captionUrl:we,topics:te,questionsAnswered:te,intendedAudience:se(ft).max(3).optional(),applicableBrands:se(re).max(M.length).optional(),applicableFeatures:te,purpose:wt.optional(),allowHarborAgentToRecommend:le().optional(),nextStep:vt.nullable().optional(),enabled:le().optional(),brandSlug:re.nullable().optional(),audience:gt.optional()});ie({assignmentId:L().trim().min(1).max(120).optional(),brandSlug:re.nullable().optional(),entryId:L().trim().min(1).max(120).nullable(),enabled:le().optional()});async function E(s,r={}){const x=typeof FormData<"u"&&r.body instanceof FormData,y=await fetch(s,{credentials:"include",...r,headers:{...x?{}:{"Content-Type":"application/json"},...r.headers||{}}});if(!y.ok){let A=`Request failed (${y.status})`;try{const f=await y.json();f!=null&&f.message&&(A=f.message)}catch{try{const f=await y.text();f&&(A=f)}catch{}}throw new Error(A)}if(y.status!==204)return y.json()}function ae(s){return s.split(",").map(r=>r.trim()).filter(Boolean)}function q(s){return(s??[]).join(", ")}function je(s){return s?s.replaceAll("_"," "):"All brands"}function yt(s){return{assignmentId:s==null?void 0:s.assignmentId,entryId:(s==null?void 0:s.entryId)??"",brandSlug:(s==null?void 0:s.brandSlug)??null,enabled:(s==null?void 0:s.enabled)??!0}}function Nt({slots:s,library:r,disabled:x=!1,onChanged:y,onMessage:A}){const[f,$]=j.useState({}),[w,u]=j.useState({}),[_,V]=j.useState(null),I=(a,l)=>`${a}:${l??"new"}`,F=(a,l)=>{const i=I(a,l==null?void 0:l.assignmentId);return w[i]??yt(l)},O=(a,l,i)=>{u(p=>({...p,[I(a,l==null?void 0:l.assignmentId)]:i}))},B=async(a,l,i)=>{V(a);try{await l(),await y(),A(i)}catch(p){A(p instanceof Error?p.message:"Could not update slot assignment.","error")}finally{V(null)}},W=(a,l)=>{const i=F(a,l),p=I(a,l==null?void 0:l.assignmentId);B(p,async()=>{(await E(`/api/admin/walkthrough-videos/slots/${a}/assignments`,{method:"PUT",body:JSON.stringify({assignmentId:i.assignmentId,entryId:i.entryId||null,brandSlug:i.brandSlug,enabled:i.enabled})})).slot&&u(h=>{const c={...h};return delete c[p],c})},"Slot draft saved.")},n=(a,l)=>{var h;const i=new Set((((h=s.find(c=>c.slotKey===a))==null?void 0:h.draft)??[]).map(c=>c.brandSlug));if(l==="all"&&i.has(null)){A("This slot already has an all-brands assignment.","error");return}const p=l==="all"?null:M.find(c=>!i.has(c))??null;if(l==="override"&&!p){A("Every brand already has an override for this slot.","error");return}const d=I(a);B(d,async()=>{await E(`/api/admin/walkthrough-videos/slots/${a}/assignments`,{method:"PUT",body:JSON.stringify({entryId:null,brandSlug:p,enabled:!1})})},l==="all"?"Added all-brands assignment.":p?`Added ${je(p)} override.`:"No unused brand scope is available.")},b=(a,l)=>{const i=F(a,l),p=I(a,l.assignmentId);B(p,async()=>{await E(`/api/admin/walkthrough-videos/slots/${a}/assignments`,{method:"PUT",body:JSON.stringify({assignmentId:i.assignmentId,entryId:i.entryId||null,brandSlug:i.brandSlug,enabled:i.enabled})}),await E(`/api/admin/walkthrough-videos/slots/${a}/assignments/${encodeURIComponent(l.assignmentId)}/publish`,{method:"POST"}),u(d=>{const h={...d};return delete h[p],h})}
1,"Slot assignment published.")},N=(a,l,i)=>{const p={...F(a,l),enabled:i},d=I(a,l.assignmentId);B(d,async()=>{await E(`/api/admin/walkthrough-videos/slots/${a}/assignments`,{method:"PUT",body:JSON.stringify({assignmentId:p.assignmentId,entryId:p.entryId||null,brandSlug:p.brandSlug,enabled:i})}),u(h=>{const c={...h};return delete c[d],c})},i?"Slot assignment enabled in draft.":"Slot assignment disabled in draft.")},k=(a,l,i)=>{const p=I(a,l.assignmentId);B(p,async()=>{await E(`/api/admin/walkthrough-videos/slots/${a}/assignments/${encodeURIComponent(l.assignmentId)}?stage=${i}`,{method:"DELETE"})},i==="published"?"Published assignment withdrawn.":i==="both"?"Slot assignment cleared.":"Draft assignment cleared.")},T=a=>$(l=>({...l,[a]:!(l[a]??!0)}));return e.jsxs("section",{className:"rounded-2xl border border-[#c9d9d2] bg-[#edf4ef] p-5","aria-labelledby":"slot-assignments-heading",children:[e.jsx("div",{className:"mb-4 flex flex-wrap items-start justify-between gap-3",children:e.jsxs("div",{children:[e.jsx("h2",{id:"slot-assignments-heading",className:"font-serif text-2xl text-slate-900",children:"Landing page assignments"}),e.jsx("p",{className:"mt-1 text-sm text-slate-600",children:"Each placement can have an all-brands assignment and brand-specific overrides. Draft changes require explicit publishing."})]})}),e.jsx("div",{className:"grid gap-3",children:Ce.map(a=>{const l=s.find(d=>d.slotKey===a);if(!l)return null;const i=f[a]??!0,p=new Map(l.published.map(d=>[d.assignmentId,d]));return e.jsxs("article",{className:"rounded-xl border border-[#d6e1db] bg-white p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-slate-900",children:l.label}),e.jsxs("p",{className:"text-xs text-slate-500",children:[l.draft.length," draft scope",l.draft.length===1?"":"s"," · ",l.published.length," published"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(v,{type:"button",size:"sm",variant:"outline",disabled:x||_!==null,onClick:()=>n(a,"all"),children:[e.jsx(ne,{className:"h-4 w-4"}),"Add all-brands assignment"]}),e.jsxs(v,{type:"button",size:"sm",variant:"outline",disabled:x||_!==null,onClick:()=>n(a,"override"),children:[e.jsx(ne,{className:"h-4 w-4"}),"Add brand override"]}),e.jsx(v,{type:"button",size:"icon",variant:"ghost","aria-label":`${i?"Collapse":"Expand"} ${l.label}`,onClick:()=>T(a),children:i?e.jsx(_e,{className:"h-4 w-4"}):e.jsx(Ve,{className:"h-4 w-4"})})]})]}),i&&e.jsxs("div",{className:"mt-4 space-y-3",children:[l.draft.length===0&&e.jsx("p",{className:"rounded-lg border border-dashed border-slate-300 p-3 text-sm text-slate-600",children:"No assignment yet. Add an all-brands assignment or a brand override."}),l.draft.map(d=>{const h=F(a,d),c=p.get(d.assignmentId),X=I(a,d.assignmentId),C=_===X,P=r.find(g=>g.entryId===h.entryId);return e.jsxs("div",{className:"rounded-lg border border-slate-200 bg-[#fbfcf8] p-3",children:[e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_13rem_auto]",children:[e.jsxs("label",{className:"text-sm font-semibold text-slate-800",children:["Published library entry",e.jsxs("select",{className:"mt-1 h-10 w-full rounded-md border border-slate-300 bg-white px-3 text-sm",value:h.entryId,disabled:x||C,onChange:g=>O(a,d,{...h,entryId:g.target.value}),children:[e.jsx("option",{value:"",children:"No entry (disabled)"}),r.filter(g=>g.published).map(g=>{var m,J;return e.jsxs("option",{value:g.entryId,children:[((m=g.published)==null?void 0:m.title)||((J=g.draft)==null?void 0:J.title)||"Untitled"," · ",g.entryId.slice(0,8)]},g.entryId)})]}),(P==null?void 0:P.published)&&e.jsx("span",{className:"mt-1 block text-xs text-teal-800",children:"Published version selected"})]}),e.jsxs("label",{className:"text-sm font-semibold text-slate-800",children:["Brand scope",e.jsxs("select",{className:"mt-1 h-10 w-full rounded-md border border-slate-300 bg-white px-3 text-sm",value:h.brandSlug??"",disabled:x||C||!!c,onChange:g=>O(a,d,{...h,brandSlug:g.target.value||null}),children:[e.jsx("option",{value:"",children:"All brands"}),M.map(g=>e.jsx("option",{value:g,children:je(g)},g))]}),c&&e.jsx("span",{className:"mt-1 block text-xs font-normal text-slate-500",children:"Published scope is fixed. Add a new override for another brand."})]}),e.jsxs("label",{className:"flex items-end gap-2 pb-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:h.enabled,disabled:x||C,onChange:g=>O(a,d,{...h,enabled:g.target.checked})}),h.enabled?"Enabled":"Disabled"]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs(v,{type:"button",size:"sm",disabled:x||C,onClick:()=>W(a,d),children:[C?e.jsx(Y,{className:"h-4 w-4 animate-spin"}):e.jsx(Ne,{className:"h-4 w-4"}),"Save draft"]}),e.jsx(v,{type:"button",size:"sm",variant:"outline",disabled:x||C,onClick:()=>N(a,d,!h.enabled),children:h.enabled?"Disable draft":"Enable draft"}),e.jsx(v,{type:"button",size:"sm",variant:"outline",disabled:x||C||!h.entryId,onClick:()=>b(a,d),children:"Publish assignment"}),c&&e.jsxs(v,{type:"button",size:"sm",variant:"outline",disabled:x||C,onClick:()=>k(a,d,"published"),children:[e.jsx(We,{className:"h-4 w-4"}),"Withdraw published"]}),e.jsxs(v,{type:"button",size:"sm",variant:"ghost",className:"text-slate-600",disabled:x||C,onClick:()=>k(a,d,"draft"),children:[e.jsx(ze,{className:"h-4 w-4"}),"Clear draft"]}),e.jsxs(v,{type:"button",size:"sm",variant:"ghost",className:"text-rose-700",disabled:x||C,onClick:()=>k(a,d,"both"),children:[e.jsx(ke,{className:"h-4 w-4"}),"Clear assignment"]}),e.jsxs("span",{className:"ml-auto text-xs text-slate-500",children:["Draft ",d.updatedAt?new Date(d.updatedAt).toLocaleStr
1ing():"not saved",c!=null&&c.updatedAt?` · Published ${new Date(c.updatedAt).toLocaleString()}`:""]})]})]},d.assignmentId)})]})]},a)})})]})}const ve=()=>({provider:"upload",sourceUrl:null,title:"",description:"",summaryText:"",transcriptText:"",transcriptUrl:null,captionUrl:null,topics:[],questionsAnswered:[],intendedAudience:["sellers"],applicableBrands:[],applicableFeatures:[],purpose:"onboarding",allowHarborAgentToRecommend:!1,nextStep:null,enabled:!0,audience:"public",brandSlug:null});function ye(s){if(!s||s==="new")return ve();const r=s.draft??s.published;return r?{provider:r.provider,sourceUrl:r.sourceUrl,title:r.title??"",description:r.description??"",summaryText:r.summaryText??"",transcriptText:r.transcriptText??"",transcriptUrl:r.transcriptUrl,captionUrl:r.captionUrl,topics:r.topics,questionsAnswered:r.questionsAnswered,intendedAudience:r.intendedAudience,applicableBrands:r.applicableBrands,applicableFeatures:r.applicableFeatures,purpose:r.purpose,allowHarborAgentToRecommend:r.allowHarborAgentToRecommend,nextStep:r.nextStep,enabled:r.enabled,audience:r.audience,brandSlug:null}:ve()}function kt(s){return s.replaceAll("_"," ")}function St({entry:s,onOpenChange:r,onSave:x,onPublish:y,onWithdraw:A,onDelete:f,onRefreshEntry:$,onMessage:w}){var me,ue,pe,he,xe,be;const[u,_]=j.useState(()=>ye(s)),[V,I]=j.useState(()=>q(u.topics)),[F,O]=j.useState(()=>q(u.questionsAnswered)),[B,W]=j.useState(()=>q(u.applicableFeatures)),[n,b]=j.useState(s),[N,k]=j.useState(!1),[T,a]=j.useState(null),[l,i]=j.useState(!1),[p,d]=j.useState(null),[h,c]=j.useState(null),X=s==="new"?"new":s?`${s.entryId}:${((me=s.draft)==null?void 0:me.updatedAt)??((ue=s.published)==null?void 0:ue.updatedAt)??""}`:"closed";j.useEffect(()=>{const t=ye(s);_(t),I(q(t.topics)),O(q(t.questionsAnswered)),W(q(t.applicableFeatures)),b(s),c(null),d(null),a(null)},[X]);const C=n==="new",P=n&&n!=="new"?n.entryId:null,g=!!(n&&n!=="new"&&((pe=n.published)!=null&&pe.enabled)),m=N||T!==null,J=P,De=n&&n!=="new"?(he=n.draft??n.published)==null?void 0:he.posterUrl:null,S=(t,o)=>{_(U=>({...U,[t]:o}))},Ee=()=>({...u,topics:ae(V),questionsAnswered:ae(F),applicableFeatures:ae(B),applicableBrands:u.applicableBrands}),oe=async()=>{k(!0),c(null);try{const t=await x(n??"new",Ee());return b(t),w("Draft saved."),t}catch(t){const o=t instanceof Error?t.message:"Could not save walkthrough draft.";return c(o),w(o,"error"),null}finally{k(!1)}},Pe=async()=>{const t=await oe();if(t){k(!0),c(null);try{await y(t.entryId),w("Walkthrough published."),r(!1)}catch(o){const U=o instanceof Error?o.message:"Could not publish walkthrough.";c(U),w(U,"error")}finally{k(!1)}}},$e=async()=>{if(P){k(!0),c(null);try{await A(P),w("Published walkthrough withdrawn."),r(!1)}catch(t){const o=t instanceof Error?t.message:"Could not withdraw walkthrough.";c(o),w(o,"error")}finally{k(!1)}}},Be=async()=>{if(P){k(!0),d(null);try{await f(P),i(!1),w("Walkthrough deleted."),r(!1)}catch(t){const o=t instanceof Error?t.message:"Could not delete walkthrough.";d(o),w(o,"error")}finally{k(!1)}}},de=(t,o)=>{var fe;const U=(fe=t.target.files)==null?void 0:fe[0];if(!U||!P||m)return;const Fe=o==="video"?100*1024*1024:10*1024*1024,He=o==="video"?"100 MB":"10 MB";if(U.size>Fe){const D=`${o==="video"?"Video":"Poster"} files must be ${He} or smaller.`;c(D),w(D,"error"),t.target.value="";return}a({kind:o,percent:0}),c(null);const R=new XMLHttpRequest;R.open("POST",`/api/admin/walkthrough-videos/library/${encodeURIComponent(P)}/${o==="video"?"upload":"poster"}`),R.withCredentials=!0,R.upload.onprogress=D=>{D.lengthComputable&&a({kind:o,percent:Math.round(D.loaded/D.total*100)})},R.onerror=()=>{a(null),c("Upload failed. Check your connection and try again."),w("Upload failed. Check your connection and try again.","error")},R.onabort=()=>{a(null),c("Upload was cancelled before it finished."),w("Upload was cancelled before it finished.","error")},R.onload=async()=>{if(R.status>=200&&R.status<300)try{await $(P),w(`${o==="video"?"Video":"Poster"} upload complete.`)}catch(D){const Q=D instanceof Error?D.message:"Upload completed, but refresh failed.";c(Q),w(Q,"error")}else{let D=`Upload rejected (${R.status}).`;try{const Q=JSON.parse(R.responseText);
1Q.message&&(D=Q.message)}catch{}c(D),w(D,"error")}a(null),t.target.value=""};const ge=new FormData;ge.append(o,U),R.send(ge)},Re=t=>{const o=u.intendedAudience??[];S("intendedAudience",o.includes(t)?o.filter(U=>U!==t):[...o,t])},Le=t=>{const o=u.applicableBrands??[];S("applicableBrands",o.includes(t)?o.filter(U=>U!==t):[...o,t])},Z=((xe=u.nextStep)==null?void 0:xe.label)??"",K=((be=u.nextStep)==null?void 0:be.destination)??"",ce=(t,o)=>{S("nextStep",o||(t==="label"?K:Z)?{label:t==="label"?o:Z||"Continue",destination:t==="destination"?o:K||"/"}:null)},z=n&&n!=="new"?n.draft??n.published:null,Oe=z!=null&&z.updatedAt?`Last updated by admin${z.updatedByUserId?` #${z.updatedByUserId}`:""} on ${new Date(z.updatedAt).toLocaleString()}`:"Not saved yet";return e.jsxs(e.Fragment,{children:[e.jsx(at,{open:!!s,onOpenChange:t=>{!t&&m||r(t)},children:e.jsxs(st,{className:"max-h-[92dvh] max-w-5xl overflow-y-auto bg-[#fbfcf8]",children:[e.jsxs(lt,{children:[e.jsx(nt,{className:"font-serif text-2xl text-slate-900",children:C?"New walkthrough":"Manage walkthrough"}),e.jsx(rt,{children:"Save a draft before publishing. Fields marked as comma-separated lists keep your input until you save."})]}),(h||p)&&e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-rose-200 bg-rose-50 p-3 text-sm text-rose-900",role:"alert",children:[e.jsx(qe,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{children:h??p})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("label",{className:"text-sm font-semibold text-slate-800",children:["Title",e.jsx(H,{className:"mt-1 bg-white",disabled:m,value:u.title??"",onChange:t=>S("title",t.target.value)})]}),e.jsxs("label",{className:"text-sm font-semibold text-slate-800",children:["Purpose",e.jsx("select",{className:"mt-1 h-10 w-full rounded-md border border-input bg-white px-3 text-sm",disabled:m,value:u.purpose,onChange:t=>S("purpose",t.target.value),children:Ue.map(t=>e.jsx("option",{value:t,children:t.replace("_"," ")},t))})]}),e.jsxs("label",{className:"text-sm font-semibold text-slate-800 md:col-span-2",children:["Description",e.jsx(ee,{className:"mt-1 min-h-20 bg-white",disabled:m,value:u.description??"",onChange:t=>S("description",t.target.value)})]}),e.jsxs("label",{className:"text-sm font-semibold text-slate-800",children:["Provider",e.jsx("select",{className:"mt-1 h-10 w-full rounded-md border border-input bg-white px-3 text-sm",disabled:m,value:u.provider,onChange:t=>S("provider",t.target.value),children:Ae.map(t=>e.jsx("option",{value:t,children:t==="upload"?"Harbor upload":t},t))})]}),e.jsxs("label",{className:"text-sm font-semibold text-slate-800",children:["Provider URL",e.jsx(H,{className:"mt-1 bg-white",disabled:u.provider==="upload"||m,placeholder:u.provider==="upload"?"Not needed for uploads":"https://...",value:u.sourceUrl??"",onChange:t=>S("sourceUrl",t.target.value||null)})]}),e.jsxs("label",{className:"text-sm font-semibold text-slate-800",children:["Topics (comma-separated)",e.jsx(H,{className:"mt-1 bg-white",disabled:m,value:V,onChange:t=>I(t.target.value)})]}),e.jsxs("label",{className:"text-sm font-semibold text-slate-800",children:["Questions answered (comma-separated)",e.jsx(H,{className:"mt-1 bg-white",disabled:m,value:F,onChange:t=>O(t.target.value)})]}),e.jsxs("label",{className:"text-sm font-semibold text-slate-800 md:col-span-2",children:["Admin-approved summary",e.jsx(ee,{className:"mt-1 min-h-20 bg-white",disabled:m,value:u.summaryText??"",onChange:t=>S("summaryText",t.target.value)})]}),e.jsxs("label",{className:"text-sm font-semibold text-slate-800 md:col-span-2",children:["Transcript text",e.jsx(ee,{className:"mt-1 min-h-28 bg-white",disabled:m,value:u.transcriptText??"",onChange:t=>S("transcriptText",t.target.value)})]}),e.jsxs("label",{className:"text-sm font-semibold text-slate-800",children:["Transcript URL",e.jsx(H,{className:"mt-1 bg-white",disabled:m,value:u.transcriptUrl??"",onChange:t=>S("transcriptUrl",t.target.value||null)})]}),e.jsxs("label",{className:"text-sm font-semibold text-slate-800",children:["Caption URL",e.jsx(H,{className:"mt-1 bg-white",disabled:m,value:u.captionUrl??"",onChange:t=>S("captionUrl",t.target.value||null)})]}),e.jsxs("label",{className:"text-sm font-semibold text-slate-800",children:["Next-step label",e.jsx(H,{className:"mt-1 bg-white",disabled:m,value:Z,onChange:t=>ce("label",t.target.value)})]}),e.jsxs("label",{className:"text-sm font-semibold text-slate-800",children:["Internal next-step path",e.
1jsx(H,{className:"mt-1 bg-white",disabled:m,placeholder:"/...",value:K,onChange:t=>ce("destination",t.target.value)})]}),e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 bg-white p-3 md:col-span-2",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold",children:"Intended audience"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-x-5 gap-y-2 text-sm",children:Te.map(t=>e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",disabled:m,checked:(u.intendedAudience??[]).includes(t),onChange:()=>Re(t)}),t]},t))})]}),e.jsxs("fieldset",{className:"rounded-lg border border-slate-200 bg-white p-3 md:col-span-2",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold",children:"Applicable brands"}),e.jsx("p",{className:"mb-2 text-xs text-slate-500",children:"Leave every brand unchecked to apply this entry to all brands."}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-4",children:M.map(t=>e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",disabled:m,checked:(u.applicableBrands??[]).includes(t),onChange:()=>Le(t)}),kt(t)]},t))})]}),e.jsxs("label",{className:"text-sm font-semibold text-slate-800 md:col-span-2",children:["Applicable features (comma-separated)",e.jsx(H,{className:"mt-1 bg-white",disabled:m,value:B,onChange:t=>W(t.target.value)})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-5 gap-y-3 rounded-lg bg-[#edf4ef] p-4 text-sm md:col-span-2",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",disabled:m,checked:u.allowHarborAgentToRecommend,onChange:t=>S("allowHarborAgentToRecommend",t.target.checked)}),"Allow Harbor Agent to recommend"]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",disabled:m,checked:u.enabled,onChange:t=>S("enabled",t.target.checked)}),"Entry enabled"]}),e.jsxs("label",{className:"flex items-center gap-2",children:["Authorization",e.jsx("select",{className:"h-8 rounded border border-slate-300 bg-white px-2",disabled:m,value:u.audience,onChange:t=>S("audience",t.target.value),children:Ie.map(t=>e.jsx("option",{value:t,children:t},t))})]})]})]}),e.jsxs("section",{className:"rounded-xl border border-dashed border-teal-300 bg-white p-4","aria-labelledby":"media-upload-heading",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{id:"media-upload-heading",className:"font-semibold text-slate-900",children:"Media"}),e.jsx("p",{className:"mt-1 text-xs text-slate-600",children:"Video: MP4 or WebM up to 100 MB. Poster: JPEG, PNG, or WebP up to 10 MB."})]}),De&&e.jsx("span",{className:"text-xs text-slate-500",children:"Poster uploaded"})]}),C?e.jsx("p",{className:"mt-3 text-sm text-slate-600",children:"Save this entry before uploading media."}):e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs("label",{className:`inline-flex cursor-pointer items-center gap-2 rounded-md bg-teal-800 px-3 py-2 text-sm font-semibold text-white ${m?"pointer-events-none opacity-50":""}`,children:[e.jsx(Ge,{className:"h-4 w-4"}),"Upload video",e.jsx("input",{className:"sr-only",type:"file",accept:"video/mp4,video/webm,.mp4,.webm",disabled:m,onChange:t=>de(t,"video")})]}),e.jsxs("label",{className:`inline-flex cursor-pointer items-center gap-2 rounded-md border border-slate-300 px-3 py-2 text-sm font-semibold ${m?"pointer-events-none opacity-50":""}`,children:[e.jsx(Je,{className:"h-4 w-4"}),"Upload poster",e.jsx("input",{className:"sr-only",type:"file",accept:"image/jpeg,image/png,image/webp,.jpg,.jpeg,.png,.webp",disabled:m,onChange:t=>de(t,"poster")})]})]}),T&&e.jsxs("div",{className:"mt-3",role:"status","aria-live":"polite",children:[e.jsxs("div",{className:"mb-1 flex justify-between text-xs font-semibold text-slate-700",children:[e.jsxs("span",{children:["Uploading ",T.kind]}),e.jsxs("span",{children:[T.percent,"%"]})]}),e.jsx("div",{className:"h-2 overflow-hidden rounded bg-teal-100",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":T.percent,"aria-valuetext":`${T.percent}%`,"aria-label":`${T.kind} upload progress`,children:e.jsx("div",{className:"h-full bg-teal-700 transition-[width]",style:{width:`${T.percent}%`}})})]})]}),J&&e.jsxs("section",{className:"rounded-xl border border-slate-200 bg-white p-4","aria-labelledby":"preview-heading",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(Qe,{className:"h-4 w-4 text-teal-800"}),e.jsx("h3",{id:"preview-heading",className:"font-semibold",children:"Preview"})]}),e.jsx(Se,{videoId:J,preview:!0,className:"mx-auto max-w-2xl"})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-t border-[#d6e1db] pt-4",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:!C&&e.jsxs(e.Fragment,{children:[e.jsxs(v,{type:"button",variant:"ghost",className:"text-rose-700 hover:text-rose-800",disabled:m,onClick:()=>{d(null),i(!0)},children:[e.jsx(ke,{className:"h-4 w-4"}),"Delete"]}),g&&e.jsxs(v,{type:"button",variant:"outline",disabled:m,onClick:$e,children:[e.jsx(Me,{className:"h-4 w-4"}),"Withdraw published"]})]})}),e.jsxs(it,{className:"gap-2 sm:space-x-0",children:[e.jsx(v,{type:"button",variant:"outline",disabled:m,onClick:()=>r(!1),children:"Cancel"}),e.jsxs(v,{type:"button",variant:"outline",disabled:m,onClick:()=>void oe(),children:[N?e.jsx(Y,{className:"h-4 w-4 animate-spin"}):e.jsx(Xe,{className:"h-4 w-4"}),"Save draft"]}),e.jsxs(v,{type:"button",disabled:m,onClick:()=>void Pe(),className:"bg-teal-700 hover:bg-teal-800",children:[N?e.jsx(Y,{className:"h-4 w-4 animate-spin"}):e.jsx(Ne,{className:"h-4 w-4"}),"Save & publish"]})]})]}),e.jsx("p",{className:"text-xs text-slate-500","data-testid":"walkthrough-audit",children:Oe})]},X)}),e.jsx(ot,{open:l,onOpenChange:t=>!N&&i(t),children:e.jsxs(dt,{children:[e.jsxs(ct,{children:[e.jsx(mt,{children:"Delete this walkthrough?"}),e.jsx(ut,{children:"This permanently removes the library entry and cannot be undone. Slot assignments that reference it may need to be cleared."})]}),p&&e.jsx("p",{className:"text-sm text-rose-700",role:"alert",children:p}),e.jsxs(pt,{children:[e.jsx(ht,{disabled:N,children:"Cancel"}),e.jsxs(xt,{className:"bg-rose-700 hover:bg-rose-800",disabled:N,onClick:t=>{t.preventDefault(),Be()},children:[N&&e.jsx(Y,{className:"h-4 w-4 animate-spin"}),"Delete walkthrough"]})]})]})})]})}function Ct(s){const r=s.published??s.draft;return r!=null&&r.updatedAt?`Updated by ${r.updatedByUserId?`admin #${r.updatedByUserId}`:"admin"}
1 · ${new Date(r.updatedAt).toLocaleString()}`:"Not updated yet"}function $t(){var B,W;const s=Ye(),[r,x]=j.useState(null),[y,A]=j.useState(null),f=Ze({queryKey:["/api/admin/walkthrough-videos"],queryFn:()=>E("/api/admin/walkthrough-videos")}),$=async()=>{await s.invalidateQueries({queryKey:["/api/admin/walkthrough-videos"]})},w=(n,b="success")=>{A({message:n,kind:b})},u=async(n,b)=>{const N=n==="new"?await E("/api/admin/walkthrough-videos/library",{method:"POST",body:JSON.stringify(b)}):await E(`/api/admin/walkthrough-videos/library/${encodeURIComponent(n.entryId)}`,{method:"PATCH",body:JSON.stringify(b)});return x(N.entry),await $(),N.entry},_=async n=>{await E(`/api/admin/walkthrough-videos/library/${encodeURIComponent(n)}/publish`,{method:"POST"}),await $()},V=async n=>{await E(`/api/admin/walkthrough-videos/library/${encodeURIComponent(n)}/withdraw`,{method:"POST"}),await $()},I=async n=>{await E(`/api/admin/walkthrough-videos/library/${encodeURIComponent(n)}`,{method:"DELETE"}),await $()},F=async n=>{const b=await E(`/api/admin/walkthrough-videos/library/${encodeURIComponent(n)}`);x(b.entry),await $()},O=((B=f.data)==null?void 0:B.library)??[];return e.jsxs(tt,{children:[e.jsx("main",{className:"min-h-[100dvh] bg-[#f5f8f5] px-4 py-7 md:px-8",children:e.jsxs("div",{className:"mx-auto max-w-7xl",children:[e.jsxs("header",{className:"mb-7 flex flex-wrap items-end justify-between gap-4 border-b border-[#c9d9d2] pb-6",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[.22em] text-teal-800",children:"Harbor media desk"}),e.jsx("h1",{className:"mt-2 font-serif text-4xl text-slate-900",children:"Walkthrough library"}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm text-slate-600",children:"Reusable, reviewed video references for landing pages and Harbor Agent. Uploads are limited to MP4/WebM (100 MB) and poster images (10 MB)."})]}),e.jsxs(v,{type:"button",onClick:()=>x("new"),className:"bg-teal-700 hover:bg-teal-800",children:[e.jsx(ne,{className:"h-4 w-4"}),"Add library video"]})]}),y&&e.jsxs("div",{className:`mb-5 flex items-start justify-between gap-4 rounded-xl border px-4 py-3 text-sm ${y.kind==="error"?"border-rose-200 bg-rose-50 text-rose-950":"border-teal-200 bg-teal-50 text-teal-950"}`,role:y.kind==="error"?"alert":"status",children:[e.jsx("span",{children:y.message}),e.jsx("button",{type:"button",className:"font-semibold underline",onClick:()=>A(null),children:"Dismiss"})]}),e.jsxs("section",{className:"mb-8","aria-labelledby":"library-heading",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(Ke,{className:"h-5 w-5 text-teal-800"}),e.jsx("h2",{id:"library-heading",className:"font-serif text-2xl text-slate-900",children:"Library entries"})]}),f.isLoading?e.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:[1,2,3,4].map(n=>e.jsx("div",{className:"h-40 animate-pulse rounded-2xl bg-[#dfe9e3]"},n))}):f.error?e.jsxs("div",{className:"rounded-xl border border-rose-200 bg-rose-50 p-5 text-sm text-rose-900",role:"alert",children:[e.jsxs("p",{children:["Could not load the walkthrough library: ",f.error instanceof Error?f.error.message:"Request failed."]}),e.jsx("button",{type:"button",className:"mt-2 font-semibold underline",onClick:()=>void $(),children:"Retry"})]}):O.length===0?e.jsxs("div",{className:"rounded-2xl border border-dashed border-[#b8cbc2] bg-white p-12 text-center",children:[e.jsx(et,{className:"mx-auto mb-3 h-8 w-8 text-teal-800"}),e.jsx("h3",{className:"font-serif text-xl text-slate-900",children:"The library is ready."}),e.jsx("p",{className:"mt-2 text-sm text-slate-600",children:"Create the first reusable video; it can then be assigned to any fixed placement."})]}):e.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:O.map(n=>{var T;const b=n.draft??n.published,N=!!n.published,k=!!((T=n.published)!=null&&T.enabled);return e.jsx("article",{className:"rounded-2xl border border-[#d6e1db] bg-white p-4",children:e.jsxs("div",{className:"flex gap-4",children:[e.jsx("div",{className:"w-36 shrink-0",children:e.jsx(Se,{videoId:b==null?void 0:b.entryId,preview:!0})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:`rounded-full px-2 py-0.5 text-[10px] font-bold uppercase ${k?"bg-teal-100 text-teal-800":N?"bg-slate-200 text-slate-700":"bg-amber-100 text-amber-800"}`,children:k?"Published":N?"Published · disabled":"Draft"}),e.jsx("h3",{className:"mt-2 truncate font-semibold text-slate-900",children:(b==null?void 0:b.title)||"Untitled video"}),e.jsx("p",{className:"mt-1 line-clamp-2 text-sm text-slate-600",children:(b==null?void 0:b.description)||"No description"}),e.jsx("p",{className:"mt-3 text-xs text-slate-500",children:Ct(n)}),e.jsx(v,{type:"button",size:"sm",variant:"outline",className:"mt-3",onClick:()=>x(n),children:"Manage"})]})]})},n.entryId)})})]}),e.jsx(Nt,{slots:((W=f.data)==null?void 0:W.slots)??[],library:O,disabled:f.isFetching,onChanged:$,onMessage:w})]})}),e.jsx(St,{entry:r,onOpenChange:n=>{n||x(null)},onSave:u,onPublish:_,onWithdraw:V,onDelete:I,onRefreshEntry:F,onMessage:w})]})}export{$t 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.