import{B as e,Ct as t,Et as n,Ft as r,H as i,I as a,It as o,K as s,L as c,Mt as l,O as u,Q as d,R as f,St as p,Tt as m,U as h,V as g,W as _,Y as v,Z as y,_t as b,at as x,c as S,d as C,f as w,ft as T,ht as E,i as ee,jt as te,l as D,m as O,mt as k,ot as ne,pt as A,r as j,s as M,st as N,t as P,tt as F,u as I,wt as L,yt as R}from"../chunks/BA99CCI5.js";import{a as z}from"../chunks/DP37y6wO.js";import{t as B}from"../chunks/BJ4akexL.js";import"../chunks/xihTtKlq.js";import"../chunks/DGo8yE5j.js";import{t as V}from"../chunks/3rupxGJ5.js";import{n as H,t as re}from"../chunks/DC11RaJ72.js";import{t as U}from"../chunks/D7OHFWTL2.js";import{t as W}from"../chunks/CkDZnQpg2.js";import{t as G}from"../chunks/BtIghOBA.js";import{t as K}from"../chunks/DYf5Ixhg.js";import{n as ie,t as q}from"../chunks/B66v-P2b.js";import{t as ae}from"../chunks/Aq-7zSc_.js";import{n as J,r as Y}from"../chunks/Da9e11Mg.js";import{i as oe,n as se,r as ce,t as le}from"../chunks/C_LFCSMn.js";import{t as ue}from"../chunks/DLVOwqGo.js";import{t as de}from"../chunks/Cut3gr1-.js";import{t as X}from"../chunks/BBtCGbx62.js";import{t as fe}from"../chunks/Dat55klv2.js";import"../chunks/BymfG72d2.js";import{t as Z}from"../chunks/DxZIQ_tr2.js";import{t as pe}from"../chunks/DSmeX4VS2.js";import{n as Q,t as $}from"../chunks/DsOfWPM4.js";import{t as me}from"../chunks/vB0UVZBU.js";import{t as he}from"../chunks/CNfB0kJd.js";import{t as ge}from"../chunks/BTzQwcpc.js";import{t as _e}from"../chunks/DCohNkHF.js";import{t as ve}from"../chunks/Cme17KJK.js";import{t as ye}from"../chunks/BWZVzKif.js";import{n as be}from"../chunks/CWc174af.js";import{t as xe}from"../chunks/DYe9q02k2.js";import{n as Se,r as Ce}from"../chunks/VZQaB9P52.js";var we=new Set([`$$slots`,`$$events`,`$$legacy`]);function Te(e,t){let n=S(t,we),r=[[`path`,{d:`M12 5v16`}],[`path`,{d:`M16 13h2`}],[`path`,{d:`M16 9h2`}],[`path`,{d:`M20.001 19A2 2 0 0022 17V5a2 2 0 00-1.999-2L16 3.002A5 5 0 0012 5a5 5 0 00-4-2H4a2 2 0 00-2 2v12a2 2 0 001.999 2H8a5 5 0 014 2 5 5 0 014-2z`}],[`path`,{d:`M6 13h2`}],[`path`,{d:`M6 9h2`}]];V(e,D({name:`book-open-text`},()=>n,{get iconNode(){return r}}))}var Ee=new Set([`$$slots`,`$$events`,`$$legacy`]);function De(e,t){let n=S(t,Ee),r=[[`path`,{d:`m12 14 4-4`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`}]];V(e,D({name:`gauge`},()=>n,{get iconNode(){return r}}))}var Oe=_(`<div class="flex items-center justify-end gap-0.5"><!> <!></div>`);function ke(t,n){l(n,!1);let r=M(n,`profiles`,8),a=M(n,`databaseId`,8),s=P();function c(e){return`/quality-profiles/${a()}/${e.id}/general`}let u=`inline-flex items-center leading-none font-medium font-mono px-2 py-1 text-[10px] rounded-md bg-neutral-100 text-neutral-700 dark:bg-neutral-800 dark:text-neutral-300`,f=[{key:`name`,header:`Name`,headerIcon:de,align:`left`,sortable:!0,cell:e=>({html:`
					<div>
						<div class="font-medium">${$(e.name)}</div>
						${e.tags.length>0?`
							<div class="mt-1 flex flex-wrap gap-1">
								${e.tags.map(e=>`
									<span class="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-medium bg-accent-100 text-accent-800 dark:bg-accent-900 dark:text-accent-200">
										${$(e.name)}
									</span>
								`).join(``)}
							</div>
						`:``}
					</div>
				`})},{key:`description`,header:`Description`,headerIcon:G,align:`left`,cell:e=>({html:e.description?Q(e.description):`<span class="text-neutral-400">No description</span>`})},{key:`qualities`,header:`Qualities`,headerIcon:K,align:`left`,width:`w-48`,cell:e=>({html:`
						<div class="flex flex-wrap gap-1 py-1">
							${e.qualities.map(e=>`
								<span class="${e.is_upgrade_until?`inline-flex items-center leading-none font-medium font-mono px-2.5 py-1 text-xs rounded-md bg-emerald-100 text-emerald-800 dark:bg-emerald-900 dark:text-emerald-200`:`inline-flex items-center leading-none font-medium font-mono px-2.5 py-1 text-xs rounded-md bg-neutral-100 text-neutral-700 dark:bg-neutral-800 dark:text-neutral-300`}">${$(e.name)}</span>
							`).join(``)}
						</div>
					`})},{key:`custom_formats`,header:`Custom Formats`,headerIcon:Te,align:`left`,width:`w-48`,cell:e=>({html:`
					<div class="text-xs space-y-1">
						<div class="flex items-center gap-1.5">All: <span class="${u}">${e.custom_formats.all}</span></div>
						<div class="flex items-center gap-1.5">Radarr: <span class="${u}">${e.custom_formats.radarr}</span></div>
						<div class="flex items-center gap-1.5">Sonarr: <span class="${u}">${e.custom_formats.sonarr}</span></div>
					</div>
				`})},{key:`scores`,header:`Scores`,headerIcon:De,align:`left`,width:`w-52`,cell:e=>({html:`
					<div class="text-xs space-y-1">
						<div class="flex items-center gap-1.5">Minimum: <span class="${u}">${e.minimum_custom_format_score}</span></div>
						${e.upgrades_allowed?`
							<div class="flex items-center gap-1.5">Upgrade Until: <span class="${u}">${e.upgrade_until_score}</span></div>
							<div class="flex items-center gap-1.5">Increment: <span class="${u}">${e.upgrade_score_increment}</span></div>
						`:`
							<div class="text-neutral-500 dark:text-neutral-400">No Upgrades</div>
						`}
					</div>
				`})},{key:`language`,header:`Language`,headerIcon:W,align:`left`,width:`w-40`,cell:e=>({html:`<span class="inline-flex items-center leading-none font-medium px-2 py-1 text-[10px] rounded-md bg-neutral-100 text-neutral-700 dark:bg-neutral-800 dark:text-neutral-300">${e.language?e.language.name===`Original`?`Any`:$(e.language.name):`Any`}</span>`})}];C(),ve(t,{get data(){return r()},get columns(){return f},emptyMessage:`No quality profiles found`,hoverable:!0,compact:!1,rowHref:c,pageSize:50,$$slots:{actions:(t,r)=>{let a=R(()=>r.row);var c=Oe(),l=T(c),u=e=>{q(e,{get icon(){return U},size:`xs`,variant:`ghost`,tooltip:`Export`,$$events:{click:()=>s(`export`,{name:d(a).name})}})};e(l,e=>{y(Z),F(()=>Z.importExport)&&e(u)});var f=k(l,2);q(f,{get icon(){return H},size:`xs`,variant:`secondary`,tooltip:`Clone`,$$events:{click:()=>s(`clone`,{name:d(a).name})}}),o(c),v(`click`,c,O(function(e){I.call(this,n,e)})),i(t,c)}}}),te()}var Ae=_(`<div class="flex flex-wrap gap-1"></div>`),je=_(`<div class="description text-xs text-neutral-600 dark:text-neutral-400 svelte-f4ox4y"></div>`),Me=_(`<span class="text-xs text-neutral-400">›</span>`),Ne=_(`<!> <!>`,1),Pe=_(`<span class="text-xs text-neutral-400">›</span> <!>`,1),Fe=_(`<div class="flex flex-1 flex-col gap-3"><!> <!> <div class="mt-auto flex flex-wrap items-center gap-1"><!> <!></div></div>`),Ie=_(`<div class="flex items-end justify-between gap-2"><h3 class="text-sm font-semibold text-neutral-900 dark:text-neutral-100"> </h3> <div class="flex shrink-0 items-center gap-0.5"><!> <!></div></div>`),Le=_(`<div class="flex items-center gap-3 text-xs"><div class="flex items-center gap-1"><!> <!></div> <div class="flex items-center gap-1"><!> <!></div> <div class="flex items-center gap-1"><!> <!></div></div>`),Re=_(`<!> <div></div>`,1);function ze(n,p){l(p,!1);let m=()=>L(G,`$visibleCount`,_),[_,S]=t(),D=E(),j=E(),z=M(p,`profiles`,8),B=M(p,`databaseId`,8),V=E(!1);ee(()=>{let e=window.matchMedia(`(max-width: 767px)`);b(V,e.matches),e.addEventListener(`change`,e=>b(V,e.matches))});let re=P(),{visibleCount:G,sentinel:K,reset:ie,setTotalCount:ae}=me({pageSize:30});x(()=>d(V),()=>{b(D,d(V)?3:5)}),x(()=>y(z()),()=>{ae(z().length)}),x(()=>y(z()),()=>{z(),ie()}),x(()=>(y(z()),m()),()=>{b(j,z().slice(0,m()))}),ne(),C();var J=Re(),Y=A(J);ye(Y,{flush:!0,children:(t,n)=>{var l=h(),u=A(l);c(u,1,()=>d(j),f,(t,n)=>{let l=R(()=>(d(n),d(D),F(()=>d(n).qualities.slice(0,d(D))))),u=R(()=>(d(n),d(D),F(()=>Math.max(0,d(n).qualities.length-d(D)))));fe(t,{get href(){return`/quality-profiles/${B()??``}/${d(n),F(()=>d(n).id)??``}/general`},hoverable:!0,children:(t,p)=>{var m=Fe(),h=T(m),_=e=>{var t=Ae();c(t,5,()=>(d(n),F(()=>d(n).tags)),f,(e,t)=>{X(e,{variant:`info`,size:`sm`,rounded:`md`,children:(e,n)=>{r();var a=s();N(()=>g(a,(d(t),F(()=>d(t).name)))),i(e,a)},$$slots:{default:!0}})}),o(t),i(e,t)};e(h,e=>{d(n),F(()=>d(n).tags.length>0)&&e(_)});var v=k(h,2),b=e=>{var t=je();a(t,()=>(y(Q),d(n),F(()=>Q(d(n).description))),!0),o(t),i(e,t)};e(v,e=>{d(n),F(()=>d(n).description)&&e(b)});var x=k(v,2),S=T(x);c(S,1,()=>d(l),f,(t,n,a)=>{var o=Ne(),c=A(o),l=e=>{var t=Me();i(e,t)};e(c,e=>{a>0&&e(l)});var u=k(c,2);{let e=R(()=>(d(n),F(()=>d(n).is_upgrade_until?`success`:`secondary`)));X(u,{get variant(){return d(e)},size:`sm`,rounded:`md`,mono:!0,children:(e,t)=>{r();var a=s();N(()=>g(a,(d(n),F(()=>d(n).name)))),i(e,a)},$$slots:{default:!0}})}i(t,o)});var C=k(S,2),w=e=>{var t=Pe(),n=k(A(t),2);X(n,{variant:`secondary`,size:`sm`,rounded:`md`,children:(e,t)=>{r();var n=s();N(()=>g(n,`+${d(u)??``} more`)),i(e,n)},$$slots:{default:!0}}),i(e,t)};e(C,e=>{d(u)>0&&e(w)}),o(x),o(m),i(t,m)},$$slots:{default:!0,header:(t,r)=>{var a=Ie(),s=T(a),c=T(s,!0);o(s);var l=k(s,2),u=T(l),f=e=>{q(e,{get icon(){return U},size:`xs`,variant:`ghost`,tooltip:`Export`,$$events:{click:()=>re(`export`,{name:d(n).name})}})};e(u,e=>{y(Z),F(()=>Z.importExport)&&e(f)});var m=k(u,2);q(m,{get icon(){return H},size:`xs`,variant:`ghost`,tooltip:`Clone`,$$events:{click:()=>re(`clone`,{name:d(n).name})}}),o(l),o(a),N(()=>g(c,(d(n),F(()=>d(n).name)))),v(`click`,l,w(O(function(e){I.call(this,p,e)}))),i(t,a)},footer:(e,t)=>{var a=Le(),c=T(a),l=T(c);Te(l,{size:12,class:`text-neutral-400`});var u=k(l,2);X(u,{variant:`secondary`,size:`sm`,rounded:`md`,mono:!0,children:(e,t)=>{r();var a=s();N(()=>g(a,(d(n),F(()=>d(n).custom_formats.total)))),i(e,a)},$$slots:{default:!0}}),o(c);var f=k(c,2),p=T(f);De(p,{size:12,class:`text-neutral-400`});var m=k(p,2);X(m,{variant:`secondary`,size:`sm`,rounded:`md`,mono:!0,children:(e,t)=>{r();var a=s();N(()=>g(a,(d(n),F(()=>d(n).minimum_custom_format_score)))),i(e,a)},$$slots:{default:!0}}),o(f);var h=k(f,2),_=T(h);W(_,{size:12,class:`text-neutral-400`});var v=k(_,2);X(v,{variant:`secondary`,size:`sm`,rounded:`md`,children:(e,t)=>{r();var a=s();N(()=>g(a,(d(n),F(()=>d(n).language?d(n).language.name:`Any`)))),i(e,a)},$$slots:{default:!0}}),o(h),o(a),i(e,a)}}})}),i(t,l)},$$slots:{default:!0}});var oe=k(Y,2);u(oe,e=>K?.(e)),i(n,J),te(),S()}var Be=_(`<!> <!> <!> <!>`,1),Ve=_(`<div class="rounded-lg border border-neutral-200 bg-white p-8 text-center dark:border-neutral-800 dark:bg-neutral-900"><p class="text-neutral-600 dark:text-neutral-400"> </p></div>`),He=_(`<div class="rounded-lg border border-neutral-200 bg-white p-8 text-center dark:border-neutral-800 dark:bg-neutral-900"><p class="text-neutral-600 dark:text-neutral-400">No quality profiles match the current filters</p></div>`),Ue=_(`<!> <div class="space-y-6 px-4 pb-8 md:px-8"><!> <!> <div class="mt-6"><!></div></div> <!>`,1);function We(r,a){l(a,!1);let s=()=>L(d(_),`$simpleSearchStore`,f),c=()=>L(le,`$filterMode`,f),u=()=>L(de,`$viewMode`,f),[f,h]=t(),_=E(),v=E(),S=E(),w=E(),D=E(),O=M(a,`data`,8),P=E(!1),I=E(``);function V(e){b(I,e.detail.name),b(P,!0)}async function H(e){let{name:t}=e.detail;try{let e=new URLSearchParams({entityType:`quality_profile`,name:t}),n=await fetch(`/databases/${O().currentDatabase.id}/export?${e}`),r=await n.json();if(!n.ok){B.add(`error`,r.error||`Export failed`);return}if(!await re(JSON.stringify(r,null,2))){B.add(`error`,`Failed to copy to clipboard`);return}B.add(`success`,`Copied "${t}" to clipboard`)}catch{B.add(`error`,`Export failed`)}}let U=E([]),W=[{key:`all`,label:`All`,description:`Name, tags, description, language and qualities`,type:`text`,accessor:Ce},{key:`name`,label:`Name`,description:`Quality profile name`,type:`text`,isDefault:!0,accessor:e=>e.name,suggestions:e=>e.map(e=>e.name).sort()},{key:`tag`,label:`Tag`,description:`Assigned tag names`,type:`text`,accessor:e=>e.tags.map(e=>e.name),suggestions:e=>[...new Set(e.flatMap(e=>e.tags.map(e=>e.name)))].sort()},{key:`tagged`,label:`Tagged`,description:`Whether any tags are assigned`,type:`text`,accessor:e=>e.tags.length>0?`yes`:`no`,suggestions:()=>[`yes`,`no`]},{key:`description`,label:`Description`,description:`Quality profile description`,type:`text`,accessor:e=>e.description??null},{key:`language`,label:`Language`,description:`Configured profile language`,type:`text`,accessor:Se,suggestions:e=>[...new Set(e.map(Se))].sort()},{key:`upgrades`,label:`Upgrades`,description:`Whether upgrades are allowed`,type:`text`,accessor:e=>e.upgrades_allowed?`yes`:`no`,suggestions:()=>[`yes`,`no`]},{key:`formats`,label:`Formats`,description:`Number of scored custom formats`,type:`number`,accessor:e=>e.custom_formats.total}],G=E(!1),K=null;ee(()=>{typeof window<`u`&&(K=window.matchMedia(`(max-width: 767px)`),b(G,K.matches),K.addEventListener(`change`,q))}),j(()=>{K&&K.removeEventListener(`change`,q)});function q(e){b(G,e.matches)}let de=be({storageKey:`qualityProfilesView`});x(()=>y(O()),()=>{n(b(_,J(`qpSearch:${O().currentDatabase.id}`,{debounceMs:150})),`$simpleSearchStore`,f)}),x(()=>s(),()=>{b(v,s().query)}),x(()=>(d(G),c()),()=>{b(S,d(G)||c()===`simple`)}),x(()=>(d(S),d(v),y(O()),d(U)),()=>{b(w,(()=>{if(d(S)){if(!d(v))return O().qualityProfiles;let e=d(v).toLowerCase();return O().qualityProfiles.filter(t=>t.name.toLowerCase().includes(e))}return oe(O().qualityProfiles,d(U),W)})())}),x(()=>y(O()),()=>{b(D,O().databases.map(e=>({label:e.name,href:`/quality-profiles/${e.id}`,active:e.id===O().currentDatabase.id})))}),ne(),C();var X=Ue(),fe=A(X);{let e=R(()=>(y(O()),F(()=>`${O().currentDatabase.name} · Quality Profiles`)));_e(fe,{get title(){return d(e)}})}var Z=k(fe,2),Q=T(Z);pe(Q,{get tabs(){return d(D)},responsive:!0});var $=k(Q,2);he($,{children:(t,n)=>{var r=Be(),a=A(r),o=e=>{Y(e,{get searchStore(){return d(_)},placeholder:`Search quality profiles...`,responsive:!0})},s=e=>{{let t=R(()=>(y(O()),F(()=>`smartFilter:qualityProfiles:${O().currentDatabase.id}`)));se(e,{get fields(){return W},get items(){return y(O()),F(()=>O().qualityProfiles)},get storageKey(){return d(t)},placeholder:`Filter quality profiles...`,get tags(){return d(U)},set tags(e){b(U,e)},$$legacy:!0})}};e(a,e=>{d(S)?e(o):e(s,-1)});var l=k(a,2);ie(l,{text:`New`,children:(e,t)=>{ge(e,{get icon(){return ae},$$events:{click:()=>z(`/quality-profiles/${O().currentDatabase.id}/new`)}})},$$slots:{default:!0}});var f=k(l,2),h=e=>{ce(e,{get value(){return p(),c()},set value(e){m(le,e)},$$legacy:!0})};e(f,e=>{d(G)||e(h)});var g=k(f,2);ue(g,{get value(){return p(),u()},set value(e){m(de,e)},$$legacy:!0}),i(t,r)},$$slots:{default:!0}});var me=k($,2),ve=T(me),ye=e=>{var t=Ve(),n=T(t),r=T(n);o(n),o(t),N(()=>g(r,`No quality profiles found for ${y(O()),F(()=>O().currentDatabase?.name)??``}`)),i(e,t)},we=e=>{var t=He();i(e,t)},Te=e=>{ke(e,{get profiles(){return d(w)},get databaseId(){return y(O()),F(()=>O().currentDatabase.id)},$$events:{clone:V,export:H}})},Ee=e=>{ze(e,{get profiles(){return d(w)},get databaseId(){return y(O()),F(()=>O().currentDatabase.id)},$$events:{clone:V,export:H}})};e(ve,e=>{y(O()),F(()=>O().qualityProfiles.length===0)?e(ye):(d(w),F(()=>d(w).length===0)?e(we,1):u()===`table`?e(Te,2):e(Ee,-1))}),o(me),o(Z);var De=k(Z,2);{let e=R(()=>(y(O()),F(()=>O().qualityProfiles.map(e=>e.name))));xe(De,{get databaseId(){return y(O()),F(()=>O().currentDatabase.id)},entityType:`quality_profile`,get sourceName(){return d(I)},get existingNames(){return d(e)},get canWriteToBase(){return y(O()),F(()=>O().canWriteToBase)},get open(){return d(P)},set open(e){b(P,e)},$$legacy:!0})}i(r,X),te(),h()}export{We as component};