1import{o as Ae}from"./rolldown-runtime-BPhFYGVA.js";import{$ as L,D as ie,Ft as B,Gn as O,Ot as q,P as oe,Wt as J,_r as Re,dn as F,ft as Ie,or as U}from"./lucide-BwEzwYFm.js";import{t}from"./toastManager-BrpyqxRK.js";import{s as Ge}from"./motion-CmZprGEZ.js";import{t as ae}from"./utils-fWthLaoR.js";import{i as W,n as $,t as M}from"./tooltip-CSKaVKF1.js";import{t as j}from"./logger-D_d3dKmL.js";import{d as Pe,f as Oe,u as We}from"./dropdown-menu-DNbBY8dE.js";import{a as $e,f as Me,h as Fe,i as ze,n as De,o as Ke,p as Le,r as Be,u as qe}from"./episodeService-Blcds3SM.js";import{t as y}from"./button-BDmWPil6.js";import{a as Je,i as Ue,n as re,t as te}from"./card-B26qP8jk.js";import{o as ne}from"./designTokens-Bl-CGHOR.js";import{t as He}from"./nb-DKVh5uNc.js";import{C as _,D as Qe,St as Ve,hn as Xe,jt as m,q as Ye,t as Ze}from"./index-OLcA6JxB.js";import{t as es}from"./AITagSuggestionsWidget-G0-N7_Yr.js";import{t as ss}from"./BatchProcessingPanel-OUMWg01L.js";import{t as as}from"./useRealtimeChannel-sXZOKv-V.js";import{t as rs}from"./ChapterEditor-CWMdG_gV.js";import{t as ts}from"./TagEditor-9sSZ81zR.js";import{t as ns}from"./AdminLayout-B9A2VA90.js";import{a as is,n as os,r as cs}from"./DeleteConfirmDialog-DRbd2JVy.js";import{t as ls}from"./useWaveformGenerator-Dlj0Von3.js";var c=Ae(Re(),1),e=Ge();function ds({transcriptStatus:a}){const p=a?.status,h=a?.hasSummary,n=[];switch(p){case"completed":n.push((0,e.jsxs)(m,{variant:"default",className:"gap-1 bg-green-500",children:[(0,e.jsx)(F,{className:"h-3 w-3"}),"Transkribert"]},"transcript")),h&&n.push((0,e.jsxs)(m,{variant:"outline",className:"gap-1 border-primary/50 text-primary",children:[(0,e.jsx)(oe,{className:"h-3 w-3"}),"Oppsummert"]},"summary")),a?.hasAiChapters&&(a.transcriptSyncedAt?n.push((0,e.jsxs)(m,{variant:"outline",className:"gap-1 border-green-500/50 text-green-600",children:[(0,e.jsx)(B,{className:"h-3 w-3"}),"Synkronisert"]},"synced")):n.push((0,e.jsxs)(m,{variant:"outline",className:"gap-1 border-amber-500/50 text-amber-600",children:[(0,e.jsx)(B,{className:"h-3 w-3"}),"Ikke synkronisert"]},"unsynced")));break;case"processing":n.push((0,e.jsxs)(m,{variant:"default",className:"gap-1",children:[(0,e.jsx)(q,{className:"h-3 w-3 animate-spin"}),"Prosesserer"]},"processing"));break;case"pending":n.push((0,e.jsxs)(m,{variant:"secondary",className:"gap-1",children:[(0,e.jsx)(F,{className:"h-3 w-3"}),"I kø"]},"pending"));break;case"failed":n.push((0,e.jsxs)(m,{variant:"destructive",className:"gap-1",children:[(0,e.jsx)(F,{className:"h-3 w-3"}),"Feilet"]},"failed"));break}return n.length>0?(0,e.jsx)(e.Fragment,{children:n}):null}function ms({episode:a,isMobile:p,allTags:h,transcriptStatus:n,transcribingEpisode:g,syncingEpisode:d,generatingOgImage:b,generatingWaveform:N,onUpdateTags:w,onTranscribe:E,onSyncTranscript:T,onRegenerateOgImage:z,onGenerateWaveform:A,onDelete:D,onRefresh:R}){const u=n?.status,v=!!a.waveform_data;return(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsxs)("div",{className:"flex gap-1.5 flex-wrap",children:[(0,e.jsx)(rs,{episodeId:a.id,chapters:a.chapters||[],onUpdate:R}),(0,e.jsxs)(We,{children:[(0,e.jsx)(Oe,{asChild:!0,children:(0,e.jsxs)(y,{size:"sm",variant:"outline",className:"gap-1.5 min-h-[36px] h-auto px-2.5 text-xs",children:[(0,e.jsx)(ie,{className:"h-3.5 w-3.5","aria-hidden":"true"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:"Emneord"})]})}),(0,e.jsx)(Pe,{className:"w-80",align:p?"center":"start",children:(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("h4",{className:"font-medium text-sm",children:"Rediger emneord"}),(0,e.jsx)(ts,{tags:a.tags||[],onChange:I=>w(a.id,I),suggestions:h})]})})]}),(0,e.jsx)("div",{className:"hidden sm:block w-px h-6 bg-border self-center mx-1"}),(0,e.jsx)(cs,{episodeId:a.id,episodeTitle:a.title,hasTranscript:u==="completed"}),(0,e.jsxs)(M,{children:[(0,e.jsx)(W,{asChild:!0,children:(0,e.jsx)(y,{size:"sm",variant:u==="completed"?"ghost":"secondary",className:"gap-1 min-h-[36px] min-w-[36px] h-auto px-2.5",onClick:()=>E(a.id),disabled:g===a.id||u==="processing"||u==="pending",children:g===a.id||u==="processing"?(0,e.jsx)(q,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":"true"}):u==="completed"?(0,e.jsx)(O,{className:"h-3.5 w-3.5 text-green-500","aria-hidden":"true"}):(0,e.jsx)(F,{className:"h-3.5 w-3.5","aria-hidden":"true"})})}),(0,e.jsx)($,{children:u==="completed"?"Re-transkriber":u==="processing"?"Transkriberer...":u==="pending"?"I transkriberingskø":"Transkriber episode"})]}
1),n?.hasAiChapters&&(0,e.jsxs)(M,{children:[(0,e.jsx)(W,{asChild:!0,children:(0,e.jsx)(y,{size:"sm",variant:n.transcriptSyncedAt?"ghost":"secondary",className:"gap-1 min-h-[36px] min-w-[36px] h-auto px-2.5",onClick:()=>T(a.id),disabled:d===a.id,children:d===a.id?(0,e.jsx)(q,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":"true"}):n.transcriptSyncedAt?(0,e.jsx)(O,{className:"h-3.5 w-3.5 text-green-500","aria-hidden":"true"}):(0,e.jsx)(B,{className:"h-3.5 w-3.5","aria-hidden":"true"})})}),(0,e.jsx)($,{children:n.transcriptSyncedAt?"Re-synk fra transkript":"Synk kapitler fra transkript"})]})]}),(0,e.jsxs)("div",{className:"flex gap-1.5 flex-wrap items-center",children:[(0,e.jsxs)(M,{children:[(0,e.jsx)(W,{asChild:!0,children:(0,e.jsx)(y,{size:"sm",variant:a.og_image_url?"ghost":"outline",className:"gap-1 min-h-[36px] min-w-[36px] h-auto px-2.5",onClick:()=>z(a.id,!!a.og_image_url),disabled:b===a.id,children:b===a.id?(0,e.jsx)(L,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":"true"}):a.og_image_url?(0,e.jsx)(O,{className:"h-3.5 w-3.5 text-green-500","aria-hidden":"true"}):(0,e.jsx)(J,{className:"h-3.5 w-3.5","aria-hidden":"true"})})}),(0,e.jsx)($,{children:a.og_image_url?"Regenerer OG-bilde":"Generer OG-bilde"})]}),(0,e.jsxs)(M,{children:[(0,e.jsx)(W,{asChild:!0,children:(0,e.jsx)(y,{size:"sm",variant:v?"ghost":"outline",className:"gap-1 min-h-[36px] min-w-[36px] h-auto px-2.5",onClick:()=>A(a.id,a.audio_url),disabled:N===a.id,children:N===a.id?(0,e.jsx)(L,{className:"h-3.5 w-3.5 animate-spin","aria-hidden":"true"}):v?(0,e.jsx)(O,{className:"h-3.5 w-3.5 text-green-500","aria-hidden":"true"}):(0,e.jsx)(U,{className:"h-3.5 w-3.5","aria-hidden":"true"})})}),(0,e.jsx)($,{children:v?"Regenerer waveform":"Generer waveform"})]}),(0,e.jsx)("div",{className:"flex-1"}),(0,e.jsx)(os,{title:"Slett episode?",description:`Er du sikker på at du vil slette "${a.title}"? Alle tilhørende kommentarer og vurderinger vil også bli slettet.`,onConfirm:()=>D(a.id),variant:"button"})]})]})}function hs({episodesWithoutWaveform:a,episodesWithoutOg:p,generatingWaveform:h,isBatchGenerating:n,isAutoTagging:g,isSyncing:d,onBatchGenerateWaveforms:b,onBatchGenerateOgImages:N,onAutoTagEpisodes:w,onSyncRSS:E}){return(0,e.jsxs)("div",{className:"flex flex-wrap justify-end gap-2 sm:gap-3 mb-6",children:[a>0&&(0,e.jsxs)(y,{onClick:b,disabled:!!h,variant:"outline",size:"sm",className:"gap-2 touch-target min-h-[44px]",isLoading:!!h,children:[!h&&(0,e.jsx)(U,{className:"h-4 w-4","aria-hidden":"true"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:h?"Genererer...":`Waveforms (${a})`}),(0,e.jsx)("span",{className:"sm:hidden",children:h?"...":`Wave (${a})`})]}),p>0&&(0,e.jsxs)(y,{onClick:N,disabled:n,variant:"outline",size:"sm",className:"gap-2 touch-target min-h-[44px]",isLoading:n,children:[!n&&(0,e.jsx)(J,{className:"h-4 w-4","aria-hidden":"true"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:n?"Genererer...":`OG-bilder (${p})`}),(0,e.jsx)("span",{className:"sm:hidden",children:n?"...":`OG (${p})`})]}),(0,e.jsxs)(y,{onClick:w,disabled:g,variant:"outline",size:"sm",className:"gap-2 touch-target min-h-[44px]",isLoading:g,children:[!g&&(0,e.jsx)(oe,{className:"h-4 w-4","aria-hidden":"true"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:g?"Analyserer...":"Analyser med AI"}),(0,e.jsx)("span",{className:"sm:hidden",children:g?"AI...":"AI"})]}),(0,e.jsxs)(y,{onClick:E,disabled:d,size:"sm",className:"gap-2 touch-target min-h-[44px]",isLoading:d,children:[!d&&(0,e.jsx)(L,{className:"h-4 w-4","aria-hidden":"true"}),(0,e.jsx)("span",{className:"hidden sm:inline",children:d?"Synkroniserer...":"Synkroniser RSS"}),(0,e.jsx)("span",{className:"sm:hidden",children:d?"...":"Synk"})]})]})}var C=12;function Ws(){const a=Ve(),[p,h]=(0,c.useState)([]),[n,g]=(0,c.useState)(new Map),[d,b]=(0,c.useState)(0),[N,w]=(0,c.useState)(!0),[E,T]=(0,c.useState)(!1),[z,A]=(0,c.useState)(!1),[D,R]=(0,c.useState)(!1),[u,v]=(0,c.useState)(null),[I,G]=(0,c.useState)(null),[ce,H]=(0,c.useState)(null),[le,Q]=(0,c.useState)(null),[K,de]=(0,c.useState)(1),[me,he]=(0,c.useState)(0),[ue,pe]=(0,c.useState)(0),{allTags:ge}=Xe(),{generateAndSave:V,state:us}=ls(),o=(0,c.useCallback)(async()=>{w(!0);const s=(K-1)*C,r=s+C-1,i=await De();i.ok?b(i.data):j.error("Failed to count episodes",void 0,{error:String(i.error)});const x=await Be();x.ok&&he(x.data);const S=await ze();S.ok&&pe(S.data);const Z=await Le(s,r);
1if(!Z.ok){t.error("Kunne ikke hente episoder"),w(!1);return}const ee=Z.data.map(k=>({...k,chapters:k.chapters?JSON.parse(JSON.stringify(k.chapters)):[]}));h(ee);const se=ee.map(k=>k.id);if(se.length>0){const k=await qe(se);if(k.ok){const{transcripts:_e,episodeSyncData:Ee,queueItems:Ce}=k.data,Te=new Map(Ee.map(l=>[l.id,l.transcript_synced_at])),P=new Map;_e.forEach(l=>{const f=l.ai_chapters;P.set(l.episode_id,{episode_id:l.episode_id,status:l.status,hasSummary:!!l.summary,hasAiChapters:Array.isArray(f)&&f.length>0,transcriptSyncedAt:Te.get(l.episode_id)||null})}),Ce.forEach(l=>{const f=P.get(l.episode_id);(!f||f.status!=="completed")&&P.set(l.episode_id,{episode_id:l.episode_id,status:l.status==="processing"?"processing":l.status==="pending"?"pending":f?.status||"none",hasSummary:f?.hasSummary||!1,hasAiChapters:f?.hasAiChapters||!1,transcriptSyncedAt:f?.transcriptSyncedAt||null})}),g(P)}}w(!1)},[K]);(0,c.useEffect)(()=>{o()},[o]),as("episodes-changes:page",[{event:"*",table:"episodes",onPayload:()=>o()}]);const X=async()=>{T(!0);try{const s=await _("sync-rss");if(!s.ok)throw s.error;t.success("RSS feed synkronisert"),o()}catch(s){j.apiError("sync_rss",s),t.error("Kunne ikke synkronisere RSS feed")}finally{T(!1)}},xe=async s=>{if(!(await $e(s)).ok){t.error("Kunne ikke slette episode");return}t.success("Episode slettet"),o()},fe=async(s,r)=>{if(!(await Fe(s,r)).ok){t.error("Kunne ikke oppdatere emneord");return}t.success("Emneord oppdatert"),o()},je=async()=>{A(!0);try{const s=await _("auto-tag-episodes");if(!s.ok)throw s.error;const r=s.data;(r?.tagged??0)>0?(t.success(`${r.tagged} episoder tagget med AI`),o()):t.info("Ingen episoder trengte tagging")}catch(s){j.apiError("auto_tag_episodes",s),t.error("Kunne ikke auto-tagge episoder")}finally{A(!1)}},ye=async()=>{R(!0);try{const s=await _("batch-generate-og-images",{body:{limit:5,delayMs:3e3}});if(!s.ok)throw s.error;const r=s.data;(r?.processed??0)>0?(t.success(`${r.succeeded}/${r.processed} OG-bilder generert. ${r.remaining} gjenstår.`),o()):t.info("Alle episoder har OG-bilder")}catch(s){j.apiError("batch_generate_og",s),t.error("Kunne ikke generere OG-bilder")}finally{R(!1)}},ke=async(s,r=!0)=>{v(s);try{const i=await _("generate-share-image",{body:{episodeId:s,forceRegenerate:r}});if(!i.ok)throw i.error;const x=i.data;x?.success&&(t.success(x.cached?"OG-bilde lastet":"OG-bilde generert"),o())}catch(i){j.apiError("generate_og_image",i),t.error("Kunne ikke generere OG-bilde")}finally{v(null)}},Ne=async(s,r)=>{G(s);try{await V(s,r)?(t.success("Waveform generert og lagret"),o()):t.error("Kunne ikke generere waveform")}catch(i){j.apiError("generate_waveform",i),t.error("Kunne ikke generere waveform")}finally{G(null)}},we=async()=>{const s=await Me(5),r=s.ok?s.data:[];if(r.length===0){t.info("Alle episoder har waveform-data");return}let i=0;for(const x of r){G(x.id);try{await V(x.id,x.audio_url)&&i++,await new Promise(S=>setTimeout(S,500))}catch(S){j.apiError("batch_waveform",S)}}G(null),i>0&&(t.success(`${i}/${r.length} waveforms generert`),o())},be=Math.ceil(d/C),ve=async s=>{H(s);try{await Ke(s);const r=await _("admin-process-transcription-queue",{body:{batchSize:1}});if(!r.ok)throw r.error;t.success("Transkribering startet"),o()}catch(r){j.apiError("transcribe_episode",r),t.error("Kunne ikke starte transkribering")}finally{H(null)}},Se=async s=>{Q(s);try{const r=await _("sync-transcript-to-episode",{body:{episodeId:s,syncChapters:!0,syncDescription:!1,syncTags:!1,overwrite:!1}});if(!r.ok)throw r.error;const i=r.data?.syncedFields??[];i.length>0?t.success(`Synkroniserte: ${i.join(", ")}`):t.info("Ingen felt å synkronisere"),o()}catch(r){j.apiError("sync_transcript_to_episode",r),t.error("Kunne ikke synkronisere transkript")}finally{Q(null)}},Y=(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"mb-6",children:(0,e.jsx)(ss,{onRefresh:o})}),(0,e.jsx)("div",{className:"mb-6",children:(0,e.jsx)(es,{onRefresh:o})}),(0,e.jsx)(hs,{episodesWithoutWaveform:ue,episodesWithoutOg:me,generatingWaveform:I,isBatchGenerating:D,isAutoTagging:z,isSyncing:E,onBatchGenerateWaveforms:we,onBatchGenerateOgImages:ye,onAutoTagEpisodes:je,onSyncRSS:X}),(0,e.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 sm:gap-6",children:N?(0,e.jsx)(te,{className:ae("col-span-full",ne.card),children:(0,e.jsx)(re,{className:"py-12 text-center text-muted-foreground",children:"Laster episoder..."})}):p.length===0?(0,e.jsx)("div",{className:"col-span-full",children:(0,e.jsx)(Ze,{icon:Ie,title:"Ingen episoder funnet",description:"Ingen episoder er lastet inn ennå. Bruk 'Synkroniser RSS' knappen for å hente episoder.",action:{label:"Synkroniser RSS",onClick:X}})}):(0,e.jsx)(e.Fragment,{children:p.map(s=>(0,e.jsxs)(te,{className:ae("overflow-hidden border border-border",ne.card),children:[s.image_url&&(0,e.jsxs)("div",{className:"aspect-video relative",children:[(0,e.jsx)("img",{src:s.image_url,alt:s.title,className:"w-full h-full object-cover",loading:"lazy",decoding:"async"}),s.episode_number&&(0,e.jsxs)(m,{className:"absolute top-2 right-2",children:["#",s.episode_number]})]}),(0,e.jsxs)(Ue,{className:"pb-2",children:[(0,e.jsx)(Je,{className:"text-base sm:text-lg line-clamp-2",title:s.title,children:s.title}),(0,e.jsxs)("p",{className:"text-xs sm:text-sm text-muted-foreground",children:[Ye(new Date(s.publish_date),"PPP",{locale:He}),s.duration&&` ⢠${Math.floor(s.duration/60)} min`]})]}),(0,e.jsxs)(re,{className:"pt-0",children:[(0,e.jsx)("p",{className:"text-xs sm:text-sm text-muted-foreground line-clamp-2 sm:line-clamp-3 mb-3",children:s.description}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-1.5 mb-4",children:[(0,e.jsx)(ds,{transcriptStatus:n.get(s.id)}),s.og_image_url&&(0,e.jsxs)(m,{variant:"outline",className:"gap-1 text-xs border-green-500/30 text-green-600",children:[(0,e.jsx)(J,{className:"h-2.5 w-2.5","aria-hidden":"true"}),"OG"]}),!!s.waveform_data&&(0,e.jsxs)(m,{variant:"outline",className:"gap-1 text-xs border-green-500/30 text-green-600",children:[(0,e.jsx)(U,{className:"h-2.5 w-2.5","aria-hidden":"true"}),"Wave"]})]}),s.tags&&s.tags.length>0&&(0,e.jsxs)("div",{className:"flex flex-wrap gap-1 mb-4",children:[s.tags.slice(0,4).map(r=>(0,e.jsxs)(m,{variant:"secondary",className:"text-xs",children:[(0,e.jsx)(ie,{className:"h-2.5 w-2.5 mr-1","aria-hidden":"true"}),r]},r)),s.tags.length>4&&(0,e.jsxs)(m,{variant:"secondary",className:"text-xs",children:["+",s.tags.length-4]})]}),(0,e.jsx)(ms,{episode:s,isMobile:a,allTags:ge,transcriptStatus:n.get(s.id),transcribingEpisode:ce,syncingEpisode:le,generatingOgImage:u,generatingWaveform:I,onUpdateTags:fe,onTranscribe:ve,onSyncTranscript:Se,onRegenerateOgImage:ke,onGenerateWaveform:Ne,onDelete:xe,onRefresh:o})]})]},s.id))})}),!N&&d>C&&(0,e.jsx)("div",{className:"mt-6 sm:mt-8",children:(0,e.jsx)(is,{currentPage:K,totalPages:be,onPageChange:de,totalItems:d,itemsPerPage:C})})]});return(0,e.jsx)(ns,{title:"Episoder",description:"Administrer podcast-episoder",children:a?(0,e.jsx)(Qe,{onRefresh:o,children:Y}):Y})}export{Ws 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.