1import{r as n,j as e}from"./vendor-react-0gXkYCUL.js";import{r as E,v as P,w as B,e as F,cT as O,al as C,g as K,B as p,M as Q,av as V,t as H,x as G,y as W,O as X,z as $,E as J,a5 as U,aL as Y,Q as Z,dD as ee}from"./vendor-tanstack-router-CwWCdhsE.js";import{a as S,d as se}from"./vendor-tanstack-query-DqVZj5rf.js";import{t as L}from"./vendor-sonner-ChzV1lY3.js";import{b as te}from"./auth-options-CeJnaZyP.js";import{d as ae,c as q}from"./bc-binding.functions-C6h-yKId.js";import{P as ne}from"./page-header-CHKsD4QT.js";import{E as T}from"./empty-state-DVk1ZZxm.js";import{C as A}from"./combobox-B6dZ-kRd.js";import{C as D,a as M,b as ie,c as le}from"./card-CzZraDhx.js";import{L as R}from"./label-c5fX2FHd.js";import{T as re,s as oe,k as ce,ao as z,L as de}from"./vendor-icons--7QveoRD.js";import"./vendor-styling-Qm4_4bAc.js";import"./vendor-base-ui-BRZMDfCl.js";import"./vendor-floating-ui-DTFm_s_Z.js";import"./vendor-common-KYHg74Dw.js";import"./vendor-utils-CLsYt-LL.js";import"./vendor-zod-CZf_aEfN.js";import"./view-tutorial-link-BL0SuLYb.js";E({method:"GET"}).middleware(P("read")).handler(B("77605d9c0b040fe0b39086ff187e0017e9431045e119c9d2a74eb8eb8810f01b"));const me=E({method:"POST"}).middleware(P("write")).handler(B("bd6fffbe0f0311af7bf8e70166a05f35ef713827969c96606983d651b99772ec"));E({method:"POST"}).middleware(P("write")).handler(B("9b5b2dfb005991d224cf9f5fc700ee18c3d53fd001a65cac6e465061d78b87cd"));function Le(){const t=F(),[i,f]=n.useState(0),[o,b]=n.useState(""),[a,j]=n.useState(1),[h,w]=n.useState(null),y=S({queryKey:["tiktok-auths"],queryFn:()=>ee()}),x=n.useMemo(()=>{const s=y.data;return s?.success?(s.data||[]).filter(u=>u.status==="active"):[]},[y.data]),c=n.useMemo(()=>x.map(s=>te(s,t)),[x,t]);n.useEffect(()=>{i>0||x.length===1&&k(String(x[0].id))},[x]);const r=S({queryKey:["bc-list",i],queryFn:()=>ae({data:{authId:i}}),enabled:i>0}),d=n.useMemo(()=>{const s=r.data;return s?.success?s.data?.list||[]:[]},[r.data]),N=r.data&&!r.data.success?O(r.data):null,v=n.useMemo(()=>d.map(s=>({value:s.bc_info.bc_id,label:`${s.bc_info.name} (${s.bc_info.bc_id})`})),[d]),l=S({queryKey:["bc-assets",o,i,"PIXEL",a],queryFn:()=>q({data:{bcId:o,authId:i,assetType:"PIXEL",page:a}}),enabled:!!o&&i>0}),m=n.useMemo(()=>{const s=l.data;return s?.success?s.data||{list:[],pageInfo:{total_number:0,total_page:0,page:1}}:{list:[],pageInfo:{total_number:0,total_page:0,page:1}}},[l.data]),k=n.useCallback(s=>{f(Number(s)),b(""),j(1)},[]),_=n.useCallback(s=>{b(s),j(1)},[]);return e.jsxs("div",{className:"flex flex-col gap-6 p-6",children:[e.jsx(ne,{title:t("pixel.title"),description:t("pixel.description")}),e.jsx(D,{children:e.jsx(M,{className:"pt-6",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex-1 max-w-xs",children:[e.jsx(R,{className:"mb-2 block text-sm font-medium",children:t("bcBinding.selectAuth")}),y.isLoading?e.jsx(C,{className:"h-10 w-full"}):x.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:t("bcBinding.noAuth")}):e.jsx(A,{options:c,value:i?String(i):"",onValueChange:k,placeholder:t("bcBinding.selectAuthPlaceholder")})]}),i>0&&e.jsxs("div",{className:"flex-1 max-w-xs",children:[e.jsx(R,{className:"mb-2 block text-sm font-medium",children:t("bcBinding.selectBc")}),r.isLoading?e.jsx(C,{className:"h-10 w-full"}):N?e.jsx("p",{className:"text-sm text-destructive",children:N}):e.jsx(A,{options:v,value:o,onValueChange:_,placeholder:t("bcBinding.selectBcPlaceholder")})]})]})})}),o&&i>0&&e.jsxs(D,{children:[e.jsx(ie,{children:e.jsx(le,{className:"text-base",children:t("pixel.list.title")})}),e.jsx(M,{children:l.isLoading?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(s=>e.jsx(C,{className:"h-16 w-full"},s))}):l.isError?e.jsx(T,{icon:re,title:t("common.error")}):m.list.length===0?e.jsx(T,{icon:oe,title:t("pixel.noPixels")}):e.jsxs("div",{className:"space-y-2",children:[m.list.map(s=>e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3 transition-colors hover:bg-muted/30",children:[e.jsxs("div",{className:"space-y-1 min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:s.asset_name||s.asset_id}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[s.pixel_code&&e.jsxs("span",{children:[t("pixel.list.code"),": ",e.jsx("span",{className:"font-mono",children:s.pixel_code})]}),e.jsxs("span",{children:[t("pixel.list.id"),": ",e.jsx("span",{className:"font-mono",children:s.asset_id})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.relation_type&&e.jsx("span",{className:K("inline-flex items-center rounded-full px-2 py-0.5 text-xs font-medium",s.relation_type==="OWNER_BC"?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-violet-100 text-violet-700 dark:bg-violet-900/30 dark:text-violet-400"),children:s.relation_type==="OWNER_BC"?t("pixel.list.ownershipSelf"):t("pixel.list.ownershipShared")}),s.pixel_code&&e.jsxs(p,{size:"sm",variant:"outline",onClick:()=>w(s),children:[e.jsx(ce,{className:"mr-1 h-3.5 w-3.5"}),t("pixel.bind.title")]})]})]},s.asset_id)),m.pageInfo.total_page>1&&e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t("common.pagination.total",{total:String(m.pageInfo.total_number)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(p,{variant:"outline",size:"sm",disabled:a<=1,onClick:()=>j(a-1),children:t("common.pagination.prev")}),e.jsxs("span",{className:"flex items-center text-sm px-2",children:[a," / ",m.pageInfo.total_page]}),e.jsx(p,{variant:"outline",size:"sm",disabled:a>=m.pageInfo.total_page,onClick:()=>j(a+1),children:t("common.pagination.next")})]})]})]})})]}),h&&h.pixel_code&&e.jsx(xe,{bcId:o,authId:i,pixel:h,open:!!h,onOpenChange:s=>{s||w(null)}})]})}function xe({bcId:t,authId:i,pixel:f,open:o,onOpenChange:b}){const a=F(),{user:j}=Q({from:"/_authed"}),[h,w]=n.useState(""),[y,x]=n.useState(""),[c,r]=n.useState(1),[d,N]=n.useState(new Map),v=S({queryKey:["bc-assets-pixel-bind",t,i,"ADVERTISER",y,c],queryFn:()=>q({data:{bcId:t,authId:i,assetType:"ADVERTISER",keyword:y||void 0,page:c}}),enabled:o&&!!t&&i>0}),l=n.useMemo(()=>{const s=v.data;return s?.success?s.data||{list:[],pageInfo:{total_number:0,total_page:0}}:{list:[],pageInfo:{total_number:0,total_page:0}}},[v.data]),m=()=>{x(h),r(1)},k=n.useCallback((s,u)=>{N(I=>{const g=new Map(I);return g.has(s)?g.delete(s):g.set(s,u),g})},[]),_=se({mutationFn:s=>(H({userId:j.id,featureKey:"assets.pixel",actionKey:"manage",stage:"submit",targetType:"pixel",targetId:f.pixel_code,objectCount:s.length}),me({data:{bcId:t,pixelCode:f.pixel_code,advertiserIds:s,action:"LINK",authId:i}})),onSuccess:s=>{const u=s;u.success?(L.success(a("pixel.bind.success")),b(!1),N(new Map)):V(u,a("pixel.error"))},onError:s=>L.error(s.message)});return e.jsx(G,{open:o,onOpenChange:b,children:e.jsxs(W,{className:"sm:max-w-xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(X,{children:[e.jsx($,{children:a("pixel.bind.title")}
1),e.jsxs(J,{children:[f.asset_name," (",f.pixel_code,")"]})]}),e.jsxs("div",{className:"space-y-3 py-3",children:[d.size>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 max-h-16 overflow-y-auto",children:Array.from(d.entries()).map(([s,u])=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-md bg-primary/10 px-2 py-0.5 text-xs",children:[u,e.jsx("button",{type:"button",className:"ml-0.5 hover:text-destructive",onClick:()=>N(I=>{const g=new Map(I);return g.delete(s),g}),children:"Ã"})]},s))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(z,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(U,{className:"pl-9",placeholder:a("bcBinding.assign.searchAccountPlaceholder"),value:h,onChange:s=>w(s.target.value),onKeyDown:s=>s.key==="Enter"&&m()})]}),e.jsx(p,{variant:"outline",size:"icon",onClick:m,"aria-label":"Search",children:e.jsx(z,{className:"h-4 w-4"})})]}),v.isLoading?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(s=>e.jsx(C,{className:"h-10 w-full"},s))}):l.list.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-3 text-center",children:a("bcBinding.account.noData")}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-md border max-h-52 overflow-y-auto",children:l.list.map(s=>e.jsxs("label",{className:K("flex items-center gap-3 px-3 py-2 border-b last:border-0 cursor-pointer transition-colors",d.has(s.asset_id)?"bg-primary/5":"hover:bg-muted/30"),children:[e.jsx(Y,{checked:d.has(s.asset_id),onCheckedChange:()=>k(s.asset_id,s.asset_name||s.asset_id)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm truncate",children:s.asset_name||s.asset_id}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:s.asset_id})]})]},s.asset_id))}),l.pageInfo.total_page>1&&e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:a("common.pagination.total",{total:String(l.pageInfo.total_number)})}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx(p,{variant:"ghost",size:"sm",className:"h-7 text-xs",disabled:c<=1,onClick:()=>r(c-1),children:a("common.pagination.prev")}),e.jsxs("span",{children:[c," / ",l.pageInfo.total_page]}),e.jsx(p,{variant:"ghost",size:"sm",className:"h-7 text-xs",disabled:c>=l.pageInfo.total_page,onClick:()=>r(c+1),children:a("common.pagination.next")})]})]})]})]}),e.jsxs(Z,{children:[e.jsx(p,{variant:"outline",onClick:()=>b(!1),children:a("common.cancel")}),e.jsx(p,{onClick:()=>_.mutate(Array.from(d.keys())),disabled:d.size===0||_.isPending,children:_.isPending?e.jsxs(e.Fragment,{children:[e.jsx(de,{className:"mr-2 h-4 w-4 animate-spin"}),a("pixel.bind.submitting")]}):a("pixel.bind.submit")})]})]})})}export{Le 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.