1import{a as L,r as u,m as A,j as e,I as C,B as o,D as B,q as E,t as H,v as I,w as K,d as q,K as O,L as R,ai as c,aK as $,C as V,H as M,J as S,b1 as Z,s as D,p as g}from"./index-Cbf19BJ2.js";import{A as J}from"./AdminLayout-BO09t3h9.js";import{C as Q,c as U}from"./card-DgudV2Qs.js";import{T as G,a as W,b as f,c as d,d as X,e as i}from"./table-D7xTN4Xt.js";import{S as Y}from"./search-BLo06ZQ6.js";import{P as ee}from"./plus-BhsMqakM.js";import{E as se}from"./eye-Bp1ggn78.js";import{S as ae}from"./square-pen-CZ4v3j6_.js";import{B as te}from"./book-open-CNcPEnxv.js";import"./wallet-DiTxM8js.js";import"./list-D4zz6wAQ.js";import"./users-Xzu6q5UA.js";import"./zap-bic735yl.js";import"./shopping-cart-J9DiLkwU.js";import"./package-C0aFhqOE.js";import"./circle-dot-BggEKS0Q.js";import"./truck-CiBM9Qd9.js";import"./mic-B7DTX7IA.js";import"./upload-C7UHHK-4.js";import"./code-cui-3nIF.js";import"./file-code-Dc3Knbwk.js";import"./refresh-cw-jn-MXuPZ.js";import"./shield-CfgkgLd3.js";import"./credit-card-u85TQkWj.js";import"./globe-CgQQH_HA.js";import"./ticket-G16NpKMh.js";const ie={1:e.jsx($,{className:"w-4 h-4"}),2:e.jsx(Z,{className:"w-4 h-4"}),3:e.jsx(te,{className:"w-4 h-4"})},re={1:"Film",2:"Seriál",3:"Kniha"};function Te(){var z,k;const v=L(),[m,F]=u.useState(""),[r,y]=u.useState(0),[T,h]=u.useState(!1),[j,_]=u.useState(""),[p,N]=u.useState(!1),x=20,{data:t,isLoading:P}=A({queryKey:["admin-library",m,r],queryFn:async()=>{let s=D.from("oz1_films").select("film_id, film_nazev, film_nazev_druhy, film_typ_id, film_rok, film_rate, fr_url, film_status_id, film_poster, film_token",{count:"exact"}).order("film_rok",{ascending:!1});m.trim()&&(s=s.or(`film_nazev.ilike.%${m.trim()}%,film_nazev_druhy.ilike.%${m.trim()}%`));const{data:a,error:l,count:n}=await s.range(r*x,(r+1)*x-1);if(l)throw l;return{films:a||[],count:n}}}),w=async()=>{var s;if(j.trim()){N(!0);try{const{data:a,error:l}=await D.functions.invoke("scrape-csfd",{body:{csfd_url:j.trim()}});if(l)throw l;if(a!=null&&a.error){if(a.existing_id){g.info("Titul již existuje, pÅesmÄrovávám..."),v(`/oza/knihovna/${a.existing_id}`),h(!1);return}throw new Error(a.error)}const n=a.data;g.success(`VytvoÅeno: ${n.name} (${n.year||"?"}) | ${((s=n.genres)==null?void 0:s.join(", "))||"bez žánru"} | Poster: ${n.posterDownloaded?"â":"â"}`),h(!1),_(""),v(`/oza/knihovna/${n.film_id}`)}catch(a){g.error("Chyba: "+(a.message||"Neznámá chyba"))}finally{N(!1)}}},b=Math.ceil(((t==null?void 0:t.count)||0)/x);return e.jsx(J,{title:"Knihovna",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 items-start sm:items-center justify-between",children:[e.jsxs("div",{className:"relative flex-1 max-w-md",children:[e.jsx(Y,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(C,{placeholder:"Hledat v knihovnÄ...",value:m,onChange:s=>{F(s.target.value),y(0)},className:"pl-9"})]}),e.jsxs(o,{onClick:()=>h(!0),children:[e.jsx(ee,{className:"w-4 h-4 mr-2"}),"PÅidat titul"]})]}),e.jsx(B,{open:T,onOpenChange:h,children:e.jsxs(E,{children:[e.jsxs(H,{
1children:[e.jsx(I,{children:"PÅidat titul z ÄSFD"}),e.jsx(K,{children:"Vlož odkaz na ÄSFD stránku filmu nebo seriálu. Automaticky se stáhnou vÅ¡echna data."})]}),e.jsx("div",{className:"space-y-4 py-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{htmlFor:"csfd-url",children:"ÄSFD odkaz nebo ID"}),e.jsx(C,{id:"csfd-url",placeholder:"https://www.csfd.cz/film/12345-nazev/ nebo 12345",value:j,onChange:s=>_(s.target.value),onKeyDown:s=>{s.key==="Enter"&&!p&&w()}})]})}),e.jsxs(O,{children:[e.jsx(o,{variant:"outline",onClick:()=>h(!1),disabled:p,children:"ZruÅ¡it"}),e.jsx(o,{onClick:w,disabled:p||!j.trim(),children:p?e.jsxs(e.Fragment,{children:[e.jsx(R,{className:"w-4 h-4 mr-2 animate-spin"}),"Stahuji z ÄSFD..."]}):"VytvoÅit"})]})]})}),e.jsx(Q,{children:e.jsx(U,{className:"p-0",children:e.jsxs(G,{children:[e.jsx(W,{children:e.jsxs(f,{children:[e.jsx(d,{className:"w-14"}),e.jsx(d,{children:"Název"}),e.jsx(d,{className:"w-24",children:"Typ"}),e.jsx(d,{className:"w-20 text-center",children:"Rok"}),e.jsx(d,{className:"w-24 text-center",children:"HodnocenÃ"}),e.jsx(d,{className:"w-24 text-right",children:"Akce"})]})}),e.jsx(X,{children:P?[...Array(10)].map((s,a)=>e.jsxs(f,{children:[e.jsx(i,{children:e.jsx(c,{className:"h-10 w-7 rounded"})}),e.jsx(i,{children:e.jsx(c,{className:"h-4 w-64"})}),e.jsx(i,{children:e.jsx(c,{className:"h-5 w-16"})}),e.jsx(i,{children:e.jsx(c,{className:"h-4 w-12 mx-auto"})}),e.jsx(i,{children:e.jsx(c,{className:"h-4 w-12 mx-auto"})}),e.jsx(i,{children:e.jsx(c,{className:"h-8 w-20 ml-auto"})})]},a)):((z=t==null?void 0:t.films)==null?void 0:z.length)===0?e.jsx(f,{children:e.jsx(i,{colSpan:6,className:"text-center py-8 text-muted-foreground",children:"Žádné tituly nenalezeny"})}):(k=t==null?void 0:t.films)==null?void 0:k.map(s=>{var l;const a=s.film_token?`https://caswyrmvzhzcecoabwfw.supabase.co/storage/v1/object/public/film-posters/${s.film_id}/${((l=s.film_poster)==null?void 0:l.split("_")[0])||"cs"}_${s.film_token}.jpg`:null;return e.jsxs(f,{children:[e.jsx(i,{className:"pr-0",children:a?e.jsx("img",{src:a,alt:"",className:"h-10 w-7 rounded object-cover bg-muted",loading:"lazy"}):e.jsx("div",{className:"h-10 w-7 rounded bg-muted flex items-center justify-center",children:e.jsx($,{className:"w-3 h-3 text-muted-foreground"})})}),e.jsx(i,{children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.film_nazev}),s.film_nazev_druhy&&e.jsx("div",{className:"text-sm text-muted-foreground",children:s.film_nazev_druhy})]})}),e.jsx(i,{children:e.jsxs(V,{variant:"outline",className:"gap-1",children:[s.film_typ_id&&ie[s.film_typ_id],s.film_typ_id?re[s.film_typ_id]||"Neznámý":"-"]})}),e.jsx(i,{className:"text-center font-mono",children:s.film_rok||"-"}),e.jsx(i,{className:"text-center",children:s.film_rate?e.jsxs("div",{className:"flex items-center justify-center gap-1",children:[e.jsx(M,{className:"w-3 h-3 text-yellow-500 fill-yellow-500"}),Number(s.film_rate).toFixed(1)]}):"-"}),e.jsx(i,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx(o,{variant:"ghost",size:"icon",asChild:!0,children:e.jsx(S,{to:`/titul/${s.fr_url}`,target:"_blank",children:e.jsx(se,{className:"w-4 h-4"})})}),e.jsx(o,{variant:"ghost",size:"icon",asChild:!0,children:e.jsx(S,{to:`/oza/knihovna/${s.film_id}`,children:e.jsx(ae,{className:"w-4 h-4"})})})]})})]},s.film_id)})})]})})}),b>1&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Zobrazeno ",r*x+1,"-",Math.min((r+1)*x,(t==null?void 0:t.count)||0)," z ",t==null?void 0:t.count," titulů"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o,{variant:"outline",size:"sm",disabled:r===0,onClick:()=>y(r-1),children:"PÅedchozÃ"}),e.jsx(o,{variant:"outline",size:"sm",disabled:r>=b-1,onClick:()=>y(r+1),children:"DalÅ¡Ã"})]})]})]})})}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.