PIMS/public/build/assets/Show-BND-fsBv.js

2 lines
6.6 KiB
JavaScript

import{d as R,n as z,c as j,r,e as B,p as E,a as o,f as w,u as D,h as O,w as A,b as e,i,o as l,t as d,q as I,v as X,s as Y,F as h,g as M,l as k,T as Z}from"./app-BXYcVHqk.js";import{_ as H}from"./AppLayout.vue_vue_type_script_setup_true_lang-86gE95Fg.js";import{_ as W}from"./_plugin-vue_export-helper-DlAUqK2U.js";import"./AppLogoIcon.vue_vue_type_script_setup_true_lang-BzXwPo6R.js";import"./useForwardExpose-Djbxsgaa.js";import"./VisuallyHidden-BvthYHr5.js";import"./RovingFocusGroup-dmigQ6Dy.js";import"./useArrowNavigation-C6Y-ieo6.js";import"./index-C4J_hXM0.js";import"./createLucideIcon-BlA39rtn.js";const G={class:"flex h-full flex-1 flex-col gap-4 overflow-x-auto rounded-xl p-4"},J={key:0,class:"flex items-center gap-3"},K={class:"flex items-center gap-3"},Q={class:"h-12 w-12 shrink-0 overflow-hidden rounded-full bg-muted"},ee=["src","alt"],te={class:"min-w-0 flex-1"},se={class:"truncate text-lg font-semibold"},ae={class:"flex items-center gap-2"},oe={key:1,class:"rounded-md border border-red-300 bg-red-50 p-3 text-red-800 dark:border-red-800 dark:bg-red-950 dark:text-red-200"},le=["aria-busy"],re=["href"],ne={class:"h-20 w-14 shrink-0 overflow-hidden rounded bg-muted"},ue=["src","alt"],ie={class:"flex min-w-0 flex-1 flex-col"},de={class:"flex items-center justify-between gap-2"},ce={class:"truncate font-medium"},ve={class:"text-xs text-muted-foreground"},fe={class:"mt-1 text-xs text-muted-foreground"},pe={key:0,class:"mr-2 rounded border px-1 py-0.5"},me={key:1},he={class:"mt-2 text-sm text-foreground/90"},ge={key:0,class:"fixed bottom-4 left-1/2 z-50 -translate-x-1/2 rounded bg-foreground px-3 py-2 text-sm text-background shadow-lg"},_e=R({__name:"Show",setup(xe){const N=z(),T=j(()=>N.props.entityId),c=r(""),v=r("title_asc"),f=r([]),C=r(0),P=r(1),g=r(1),u=r(!1),_=r(null),b=r(!1),S=r(""),n=r(null);let $=null;const q=j(()=>g.value<P.value&&!u.value);function L(a,s=50){if(!a)return"";const t=a.split(/\s+/);return t.length<=s?a:t.slice(0,s).join(" ")+"…"}async function x(a=!1){if(!u.value){u.value=!0,_.value=null;try{const s=new URLSearchParams;c.value&&s.set("q",c.value),v.value&&s.set("sort",v.value),s.set("per_page","20"),s.set("page",String(g.value));const t=await fetch(`/api/actors/${T.value}?${s.toString()}`,{headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"},credentials:"same-origin"});if(!t.ok)throw new Error(`Fetch failed: ${t.status}`);const p=await t.json();n.value=p.entity,C.value=p.movies.total,P.value=p.movies.last_page,a?f.value=p.movies.data:f.value=f.value.concat(p.movies.data)}catch(s){_.value=s?.message??"Unexpected error",S.value=_.value,b.value=!0,setTimeout(()=>b.value=!1,2500)}finally{u.value=!1}}}function U(){clearTimeout($),$=setTimeout(()=>{g.value=1,x(!0)},300)}function V(){const a=new URL(window.location.href);c.value?a.searchParams.set("q",c.value):a.searchParams.delete("q"),v.value?a.searchParams.set("sort",v.value):a.searchParams.delete("sort"),window.history.replaceState({},"",a.toString()),g.value=1,x(!0)}async function F(){q.value&&(g.value+=1,await x(!1))}const y=r(null);let m=null;return B(()=>{const a=new URL(window.location.href);c.value=a.searchParams.get("q")??"",v.value=a.searchParams.get("sort")??"title_asc",x(!0),m=new IntersectionObserver(s=>{for(const t of s)t.isIntersecting&&F()},{root:null,rootMargin:"200px",threshold:0}),y.value&&m.observe(y.value)}),E(y,(a,s)=>{s&&m&&m.unobserve(s),a&&m&&m.observe(a)}),(a,s)=>(l(),o(h,null,[w(D(O),{title:n.value?.name?`${n.value.name} · Actor`:"Actor"},null,8,["title"]),w(H,{breadcrumbs:[{title:"Actors",href:"/actors"},{title:n.value?.name??"…",href:`/actors/${T.value}`}]},{default:A(()=>[e("div",G,[!n.value&&u.value?(l(),o("div",J,[...s[2]||(s[2]=[e("div",{class:"h-12 w-12 shrink-0 rounded-full bg-muted animate-pulse"},null,-1),e("div",{class:"h-4 w-40 rounded bg-muted animate-pulse"},null,-1)])])):i("",!0),e("div",K,[e("div",Q,[n.value?.profile_path?(l(),o("img",{key:0,src:n.value.profile_path,alt:n.value?.name?`${n.value.name} profile photo`:"Actor profile photo",loading:"lazy",class:"h-full w-full object-cover"},null,8,ee)):i("",!0)]),e("div",te,[e("h1",se,d(n.value?.name??"…"),1)])]),e("div",ae,[I(e("input",{class:"w-full rounded-md border border-gray-300 bg-background px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-primary",type:"text",placeholder:"Filter movies by title…","aria-label":"Filter movies by title","onUpdate:modelValue":s[0]||(s[0]=t=>c.value=t),onInput:U},null,544),[[X,c.value]]),I(e("select",{"onUpdate:modelValue":s[1]||(s[1]=t=>v.value=t),onChange:V,class:"w-44 shrink-0 rounded-md border px-3 py-2 text-sm","aria-label":"Sort movies"},[...s[3]||(s[3]=[e("option",{value:"title_asc"},"Title A → Z",-1),e("option",{value:"title_desc"},"Title Z → A",-1),e("option",{value:"newest"},"Newest",-1),e("option",{value:"oldest"},"Oldest",-1),e("option",{value:"year_asc"},"Year ↑",-1),e("option",{value:"year_desc"},"Year ↓",-1)])],544),[[Y,v.value]])]),_.value?(l(),o("div",oe,d(_.value),1)):i("",!0),e("ul",{class:"divide-y divide-muted-foreground/20","aria-busy":u.value?"true":"false"},[(l(!0),o(h,null,M(f.value,t=>(l(),o("li",{key:t.id,class:"py-1"},[e("a",{href:`/movies/${t.id}`,class:"flex gap-3 rounded px-2 py-2 hover:bg-muted/40 focus:bg-muted/40 focus:outline-none"},[e("div",ne,[t.poster_url?(l(),o("img",{key:0,src:t.poster_url,alt:`Poster for ${t.title}`,loading:"lazy",class:"h-full w-full object-cover"},null,8,ue)):i("",!0)]),e("div",ie,[e("div",de,[e("div",ce,d(t.title),1),e("div",ve,d(t.year??""),1)]),e("div",fe,[t.rating?(l(),o("span",pe,d(t.rating),1)):i("",!0),t.genres?.length?(l(),o("span",me,d(t.genres.map(p=>p.name).join(", ")),1)):i("",!0)]),e("div",he,d(L(t.description)),1)])],8,re)]))),128)),u.value&&f.value.length===0?(l(),o(h,{key:0},M(5,t=>e("li",{key:`s-${t}`,class:"py-1"},[...s[4]||(s[4]=[e("div",{class:"flex gap-3 rounded px-2 py-2"},[e("div",{class:"h-20 w-14 shrink-0 overflow-hidden rounded bg-muted animate-pulse"}),e("div",{class:"flex min-w-0 flex-1 flex-col gap-2"},[e("div",{class:"h-4 w-1/3 rounded bg-muted animate-pulse"}),e("div",{class:"h-3 w-1/2 rounded bg-muted animate-pulse"}),e("div",{class:"h-3 w-2/3 rounded bg-muted animate-pulse"})])],-1)])])),64)):i("",!0)],8,le),e("div",{ref_key:"sentinel",ref:y,class:"py-6 text-center text-sm text-muted-foreground"},[u.value?(l(),o(h,{key:0},[k("Loading…")],64)):!q.value&&f.value.length>0?(l(),o(h,{key:1},[k("End of results")],64)):!f.value.length&&!u.value?(l(),o(h,{key:2},[k("No results")],64)):i("",!0)],512),w(Z,{name:"fade"},{default:A(()=>[b.value?(l(),o("div",ge,d(S.value),1)):i("",!0)]),_:1})])]),_:1},8,["breadcrumbs"])],64))}}),Ae=W(_e,[["__scopeId","data-v-1101142c"]]);export{Ae as default};