1import{M as N,N as C,h as T,J as B,r as y,C as A,j as e,y as b,B as v,P as U,Q as z,D as O}from"./main-0mA9R0ha.js";import{u as H,a as q,b as G,C as J}from"./zod-DA4AU65J.js";import{A as D,b as F,a as I}from"./alert-BnfI6jbS.js";import{B as x}from"./badge-jwlJvZgN.js";import{C as Q,a as W,b as X,c as K,d as Y,e as Z}from"./card-CPiRAOUA.js";import{C as ee}from"./checkbox-CBwRLvuD.js";import{S as L}from"./spinner-DrCkCm73.js";import{C as se}from"./circle-alert-DWlw_4Go.js";import{C as te}from"./circle-check-VZjgkP6j.js";import{E as ne}from"./external-link-D9IULTHP.js";import{c as re}from"./createLucideIcon-4vlm1tE4.js";import"./index-DkQxBBIZ.js";import"./index-DzprJ28Q.js";import"./index-BBS4A968.js";import"./check-uGO9KJbG.js";import"./loader-circle-MNFmGwwL.js";(function(){try{var s=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},n=new s.Error().stack;n&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[n]="9d113ac2-1ac2-4c5d-968e-5711da60bf1c",s._sentryDebugIdIdentifier="sentry-dbid-9d113ac2-1ac2-4c5d-968e-5711da60bf1c")}catch{}})();const ie=[["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}],["path",{d:"M10.41 10.41a2 2 0 1 1-2.83-2.83",key:"1bzlo9"}],["line",{x1:"13.5",x2:"6",y1:"13.5",y2:"21",key:"1q0aeu"}],["line",{x1:"18",x2:"21",y1:"12",y2:"15",key:"5mozeu"}],["path",{d:"M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59",key:"mmje98"}],["path",{d:"M21 15V5a2 2 0 0 0-2-2H9",key:"43el77"}]],ae=re("image-off",ie),oe=({sessionId:s,selectedRefs:n})=>C.post(`/v1/external-migrations/${s}/selection`,{selectedRefs:n}).then(({data:o})=>o),ce=(s={})=>N({mutationFn:oe,onError:s.onError,onSuccess:s.onSuccess}),le=s=>C.post("/v1/external-migrations",{manifest:s}).then(({data:n})=>n),de=(s={})=>N({mutationFn:le,onError:s.onError,onSuccess:s.onSuccess}),me=()=>C.post("/v1/external-migrations/resume").then(({data:s})=>s),ue=(s={})=>N({mutationFn:me,onError:s.onError,onSuccess:s.onSuccess}),fe=B("/_withUser/x-site-migration"),he=A({items:U(A({externalRef:O(),matched:z(),selected:z()}))});function xe(s){const[n,o]=s.split(":",2);return!n||!o?s:`${n.charAt(0).toUpperCase()+n.slice(1)} ${o}`}function pe(s){return{items:s.map(n=>({externalRef:n.externalRef,matched:n.matched,selected:n.matched}))}}function ge(s,n){const o=new Map,u=[];s.forEach((l,p)=>{const r=l.groups?.[0];if(!r){u.push(p);return}const d=`${r.key}:${r.label}`,m=o.get(d);m?m.indices.push(p):o.set(d,{key:d,label:r.label,url:r.url,indices:[p]})});const f=[...o.values()];return u.length>0&&f.push({key:"__ungrouped",label:n,indices:u}),f}function je(){const{t:s}=T("externalMigration"),{openerOrigin:n,messageNonce:o,resume:u}=fe.useSearch(),f=y.useCallback(t=>{window.opener?.postMessage({...t,nonce:o},n)},[n,o]),l=H({resolver:q(he),defaultValues:{items:[]}}),{fields:p}=G({control:l.control,name:"items"}),r=de({onSuccess:t=>l.reset(pe(t.matchResults))}),d=ce({onSuccess:({pickupToken:t})=>{r.data&&f({type:"livid_migration_ready",sessionId:r.data.sessionId,pickupToken:t})}}),m=ue({onSuccess:({sessionId:t,pickupToken:i})=>{f({type:"livid_migration_ready",sessionId:t,pickupToken:i})}});y.useEffect(()=>{if(u){m.mutate(void 0);return}const t=i=>{i.origin===n&&i.data?.nonce===o&&i.data?.type==="livid_manifest"&&(window.removeEventListener("message",t),r.mutate(i.data.manifest))};return window.addEventListener("message",t),f({type:"livid_popup_ready"}),()=>window.removeEventListener("message",t)},[u,n,o]);const k=y.useMemo(()=>r.data?.matchResults??[],[r.data?.matchResults]),g=r.data?.matchSummary??{total:0,matched:0,unmatched:0},S=r.data?.sourceContext?.displayName??null,w=l.watch("items"),j=w.filter(t=>t.selected).length,E=w.filter(t=>t.matched).length,M=y.useMemo(()=>ge(k,s("groups.other")),[k,s]),c=r.isError?{kind:"error",message:s("error.create")}:d.isError?{kind:"error",message:s("error.confirm")}:m.isError?{kind:"error",message:s("error.resume")}:d.isSuccess||m.isSuccess?{kind:"done"}:d.isPending?{kind:"submitting"}:r.isSuccess?{kind:"review"}:r.isPending?{kind:"loading",message:s("status.lookingUp")}:m.isPending?{kind:"loading",message:s("status.gettingReady")}:{kind:"loading",message:s("status.waiting")},h=c.kind==="review",V=()=>{const t=j===E;
1w.forEach((i,a)=>{i.matched&&l.setValue(`items.${a}.selected`,!t)})},P=t=>{if(!r.data)return;const i=t.items.filter(a=>a.selected&&a.matched).map(a=>a.externalRef);i.length!==0&&d.mutate({sessionId:r.data.sessionId,selectedRefs:i})};return e.jsxs(e.Fragment,{children:[e.jsx("style",{children:"html, body { overflow: hidden; }"}),e.jsx("div",{className:b("fixed inset-0 z-0 box-border flex w-full min-w-0 flex-col overflow-hidden bg-background p-2 sm:p-3",h?"min-h-0":"items-center justify-center"),children:e.jsxs(Q,{className:b("mx-auto w-full min-w-0 max-w-3xl flex-col",h?"min-h-0 max-h-full flex-1 flex-col overflow-hidden py-3 !gap-0 sm:max-h-full":"shrink-0"),children:[e.jsxs(W,{className:"shrink-0 sm:px-6",children:[e.jsx(X,{className:"text-xl",children:s("page.title")}),e.jsx(K,{children:S?s("page.descriptionWithSource",{name:S}):s("page.descriptionDefault")})]}),e.jsxs(Y,{className:b("min-w-0",h&&"flex min-h-0 flex-1 flex-col !px-6 !pt-0"),children:[c.kind==="loading"&&e.jsx($,{icon:e.jsx(L,{className:"size-5"}),children:c.message}),c.kind==="submitting"&&e.jsx($,{icon:e.jsx(L,{className:"size-5"}),children:s("status.finishing")}),c.kind==="error"&&e.jsxs(D,{variant:"destructive",children:[e.jsx(se,{}),e.jsx(F,{children:s("error.title")}),e.jsx(I,{children:c.message})]}),c.kind==="done"&&e.jsxs(D,{children:[e.jsx(te,{}),e.jsx(F,{children:s("success.title")}),e.jsx(I,{children:s("success.description")})]}),h&&e.jsxs("form",{id:"external-migration-form",className:"flex min-h-0 flex-1 flex-col gap-0",onSubmit:l.handleSubmit(P),children:[e.jsxs("div",{className:"mb-3 flex shrink-0 flex-wrap items-center justify-between gap-2 sm:mb-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap gap-2 sm:gap-3",children:[e.jsx(x,{variant:"secondary",children:s("summary.totalVideos",{count:g.total})}),e.jsx(x,{children:s("summary.inLividLine",{count:g.matched})}),g.unmatched>0&&e.jsx(x,{variant:"outline",children:s("summary.unmatchedLine",{count:g.unmatched})}),e.jsx(x,{variant:"secondary",children:s("summary.postCount",{count:M.length})})]}),e.jsx(v,{type:"button",variant:"ghost",size:"sm",onClick:V,children:s(j===E?"actions.deselectAll":"actions.selectAll")})]}),e.jsx("div",{className:"min-h-0 flex-1 touch-pan-y overflow-y-auto overflow-x-hidden overscroll-contain rounded-md border sm:min-h-0",children:M.map(t=>e.jsxs("div",{children:[e.jsxs("div",{className:"sticky top-0 z-10 flex items-center gap-2 border-b bg-muted/80 px-4 py-2 backdrop-blur-sm",children:[e.jsx("span",{className:"truncate text-xs font-semibold",children:t.label}),e.jsxs("span",{className:"shrink-0 text-xs text-muted-foreground",children:["(",t.indices.length,")"]}),t.url&&e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",className:"shrink-0 text-muted-foreground hover:text-foreground",children:e.jsx(ne,{className:"size-3"})})]}),e.jsx("div",{className:"divide-y",children:t.indices.map(i=>{const a=k[i],_=p[i];return!a||!_?null:e.jsx(J,{control:l.control,name:`items.${i}.selected`,render:({field:R})=>e.jsxs("label",{className:`flex gap-3 px-4 py-3 transition-colors ${a.matched?"cursor-pointer hover:bg-accent/50":"cursor-not-allowed opacity-40"}`,children:[e.jsx("div",{className:"flex shrink-0 items-center",children:e.jsx(ee,{checked:R.value,disabled:!a.matched,onCheckedChange:R.onChange})}),e.jsx("div",{className:"relative h-12 w-20 shrink-0 overflow-hidden rounded bg-muted",children:a.thumbnailUrl?e.jsx("img",{src:a.thumbnailUrl,alt:"",className:"h-full w-full object-cover"}):e.jsx("div",{className:"flex h-full w-full items-center justify-center",children:e.jsx(ae,{className:"size-4 text-muted-foreground"})})}),e.jsx("div",{className:"flex min-w-0 flex-1 flex-col justify-center gap-0.5",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-medium",children:a.lividVideo?.title??xe(a.videoRef)}),a.matched?e.jsx(x,{className:"shrink-0 text-[10px] px-1.5 py-0",children:s("badge.matched")}):e.jsx(x,{variant:"outline",className:"shrink-0 text-[10px] px-1.5 py-0",children:s("badge.unmatched")})]})})]})},_.id)})})]},t.key))})]})]}),e.jsxs(Z,{className:b("shrink-0 border-t !pt-4 justify-end gap-3",h&&"!pb-2"),children:[(c.kind==="error"||c.kind==="done")&&e.jsx(v,{variant:"outline",onClick:()=>window.close(),children:s("actions.close")}),h&&e.jsxs(e.Fragment,{children:[e.jsx(v,{variant:"outline",onClick:()=>window.close(),children:s("actions.cancel")}),e.jsx(v,{type:"submit",form:"external-migration-form",disabled:j===0,children:s("actions.useVideos",{count:j})})]})]})]})})]})}function $({icon:s,children:n}){return e.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s,e.jsx("span",{className:"text-sm",children:n})]})}function Ie(){return e.jsx(je,{})}export{Ie as component};
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.