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,d as S,f as C,ft as w,ht as T,i as ee,jt as E,m as D,mt as O,ot as te,pt as k,r as ne,s as A,st as j,t as M,tt as N,u as P,wt as F,x as re,yt as I}from"../chunks/BA99CCI5.js";import{a as ie}from"../chunks/DP37y6wO.js";import{t as L}from"../chunks/BJ4akexL.js";import"../chunks/xihTtKlq.js";import"../chunks/DGo8yE5j.js";import{n as R,t as z}from"../chunks/DC11RaJ72.js";import{t as B}from"../chunks/D7OHFWTL2.js";import{t as V}from"../chunks/BtIghOBA.js";import{t as H}from"../chunks/SEZzcS_o.js";import{t as ae}from"../chunks/CmTUQ0et.js";import{t as U}from"../chunks/DYf5Ixhg.js";import{n as oe,t as W}from"../chunks/B66v-P2b.js";import{t as se}from"../chunks/Aq-7zSc_.js";import{n as ce,r as le}from"../chunks/Da9e11Mg.js";import{i as ue,n as de,r as fe,t as pe}from"../chunks/C_LFCSMn.js";import{t as me}from"../chunks/DLVOwqGo.js";import{t as G}from"../chunks/Cut3gr1-.js";import{t as K}from"../chunks/BfBgZfCV2.js";import{t as q}from"../chunks/BBtCGbx62.js";import{t as J}from"../chunks/Dat55klv2.js";import"../chunks/BymfG72d2.js";import{t as Y}from"../chunks/DxZIQ_tr2.js";import{t as he}from"../chunks/DSmeX4VS2.js";import{t as X}from"../chunks/CT9uUPGn.js";import{n as Z}from"../chunks/DsOfWPM4.js";import{t as ge}from"../chunks/vB0UVZBU.js";import{t as _e}from"../chunks/CNfB0kJd.js";import{t as ve}from"../chunks/BTzQwcpc.js";import{t as ye}from"../chunks/DGICnufN.js";import{t as be}from"../chunks/DCohNkHF.js";import{t as Q}from"../chunks/Cme17KJK.js";import{t as xe}from"../chunks/BWZVzKif.js";import{n as Se}from"../chunks/CWc174af.js";import{t as Ce}from"../chunks/DYe9q02k2.js";import{c as $}from"../chunks/DK-GnTaC2.js";import{t as we}from"../chunks/VZQaB9P52.js";var Te=_(`<div class="flex items-center justify-end gap-0.5"><!> <!></div>`);function Ee(n,r){l(r,!1);let a=()=>F(K,`$page`,s),[s,c]=t(),u=T(),f=A(r,`formats`,8),p=M();function m(e){return`/custom-formats/${d(u)}/${e.id}`}function h(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#039;`)}function g(e){return e?Z(X.parse(e)):``}let _=[{key:`name`,header:`Name`,headerIcon:G,align:`left`,sortable:!0,width:`w-48`,cell:e=>({html:`
					<div>
						<div class="font-medium">${h(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">
										${h(e.name)}
									</span>
								`).join(``)}
							</div>
						`:``}
					</div>
				`})},{key:`description`,header:`Description`,headerIcon:V,align:`left`,cell:e=>({html:e.description?`<span class="text-sm text-neutral-600 dark:text-neutral-400 prose-inline">${g(e.description)}</span>`:`<span class="text-neutral-400">-</span>`})},{key:`conditions`,header:`Conditions`,headerIcon:U,align:`left`,cell:e=>({html:e.conditions.length>0?`<div class="flex flex-wrap gap-1">${$(e.conditions).map(e=>{let t;return t=e.required&&e.negate?`bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200`:e.required?`bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200`:e.negate?`bg-amber-100 text-amber-800 dark:bg-amber-900 dark:text-amber-200`:`bg-neutral-100 text-neutral-700 dark:bg-neutral-800 dark:text-neutral-300`,`<span class="inline-flex items-center px-1.5 py-0.5 rounded font-mono text-[10px] font-medium ${t}">${h(e.name)}</span>`}).join(``)}</div>`:`<span class="text-neutral-400 text-xs">None</span>`})},{key:`testCount`,header:`Tests`,headerIcon:H,align:`center`,width:`w-20`,sortable:!0,cell:e=>({html:e.testCount>0?`<span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-neutral-100 text-neutral-700 dark:bg-neutral-800 dark:text-neutral-300">${e.testCount}</span>`:`<span class="text-neutral-400 text-xs">-</span>`})}];x(()=>a(),()=>{b(u,a().params.databaseId)}),te(),S(),Q(n,{get data(){return f()},get columns(){return _},emptyMessage:`No custom formats found`,hoverable:!0,compact:!1,rowHref:m,pageSize:50,$$slots:{actions:(t,n)=>{let a=I(()=>n.row);var s=Te(),c=w(s),l=e=>{W(e,{get icon(){return B},size:`xs`,variant:`ghost`,tooltip:`Export`,$$events:{click:()=>p(`export`,{name:d(a).name})}})};e(c,e=>{y(Y),N(()=>Y.importExport)&&e(l)});var u=O(c,2);W(u,{get icon(){return R},size:`xs`,variant:`secondary`,tooltip:`Clone`,$$events:{click:()=>p(`clone`,{name:d(a).name})}}),o(s),v(`click`,s,D(function(e){P.call(this,r,e)})),i(t,s)}}}),E(),c()}var De=_(`<div class="flex flex-wrap gap-1"></div>`),Oe=_(`<div class="prose-inline line-clamp-3 text-xs text-neutral-600 dark:text-neutral-400"></div>`),ke=_(`<div class="text-xs text-neutral-400 italic dark:text-neutral-500">No description</div>`),Ae=_(`<div class="text-xs text-neutral-400">None</div>`),je=_(`<div class="space-y-3"><!> <!> <!></div>`),Me=_(`<div class="flex items-center gap-1 rounded bg-neutral-100 px-1.5 py-0.5 text-xs text-neutral-600 dark:bg-neutral-800 dark:text-neutral-400"><!> <span> </span></div>`),Ne=_(`<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>`),Pe=_(`<!> <div></div>`,1);function Fe(n,p){l(p,!1);let m=()=>F(K,`$page`,ee),_=()=>F(ae,`$visibleCount`,ee),[ee,ne]=t(),ie=T(),L=T(),z=A(p,`formats`,8),V=M(),{visibleCount:ae,sentinel:U,reset:oe,setTotalCount:se}=ge({pageSize:30});function ce(e){return e?Z(X.parse(e)):``}function le(e){return e.required&&e.negate?`danger`:e.required?`success`:e.negate?`warning`:`secondary`}x(()=>m(),()=>{b(ie,m().params.databaseId)}),x(()=>y(z()),()=>{se(z().length)}),x(()=>y(z()),()=>{z(),oe()}),x(()=>(y(z()),_()),()=>{b(L,z().slice(0,_()))}),te(),S();var ue=Pe(),de=k(ue);xe(de,{flush:!0,children:(t,n)=>{var l=h(),u=k(l);c(u,1,()=>d(L),f,(t,n)=>{J(t,{get href(){return`/custom-formats/${d(ie)??``}/${d(n),N(()=>d(n).id)??``}`},hoverable:!0,children:(t,l)=>{var u=je(),p=w(u),m=e=>{var t=De();c(t,5,()=>(d(n),N(()=>d(n).tags)),f,(e,t)=>{q(e,{variant:`info`,size:`sm`,rounded:`md`,children:(e,n)=>{r();var a=s();j(()=>g(a,(d(t),N(()=>d(t).name)))),i(e,a)},$$slots:{default:!0}})}),o(t),i(e,t)};e(p,e=>{d(n),N(()=>d(n).tags.length>0)&&e(m)});var h=O(p,2),_=e=>{var t=Oe();a(t,()=>(d(n),N(()=>ce(d(n).description))),!0),o(t),i(e,t)},v=e=>{var t=ke();i(e,t)};e(h,e=>{d(n),N(()=>d(n).description)?e(_):e(v,-1)});var b=O(h,2),x=e=>{var t=De();c(t,5,()=>(y($),d(n),N(()=>$(d(n).conditions))),f,(e,t)=>{{let n=I(()=>(d(t),N(()=>le(d(t)))));q(e,{get variant(){return d(n)},size:`sm`,rounded:`md`,mono:!0,children:(e,n)=>{r();var a=s();j(()=>g(a,(d(t),N(()=>d(t).name)))),i(e,a)},$$slots:{default:!0}})}}),o(t),i(e,t)},S=e=>{var t=Ae();i(e,t)};e(b,e=>{d(n),N(()=>d(n).conditions.length>0)?e(x):e(S,-1)}),o(u),i(t,u)},$$slots:{default:!0,header:(t,r)=>{var a=Ne(),s=w(a),c=w(s,!0);o(s);var l=O(s,2),u=w(l),f=e=>{var t=Me(),r=w(t);H(r,{size:12});var a=O(r,2),s=w(a,!0);o(a),o(t),j(()=>{re(t,`title`,`${d(n),N(()=>d(n).testCount)??``} test${d(n),N(()=>d(n).testCount===1?``:`s`)??``}`),g(s,(d(n),N(()=>d(n).testCount)))}),i(e,t)};e(u,e=>{d(n),N(()=>d(n).testCount>0)&&e(f)});var m=O(u,2),h=e=>{W(e,{get icon(){return B},size:`xs`,variant:`ghost`,tooltip:`Export`,$$events:{click:()=>V(`export`,{name:d(n).name})}})};e(m,e=>{y(Y),N(()=>Y.importExport)&&e(h)});var _=O(m,2);W(_,{get icon(){return R},size:`xs`,variant:`ghost`,tooltip:`Clone`,$$events:{click:()=>V(`clone`,{name:d(n).name})}}),o(l),o(a),j(()=>g(c,(d(n),N(()=>d(n).name)))),v(`click`,l,C(D(function(e){P.call(this,p,e)}))),i(t,a)}}})}),i(t,l)},$$slots:{default:!0}});var fe=O(de,2);u(fe,e=>U?.(e)),i(n,ue),E(),ne()}var Ie=_(`<!> <!> <!> <!> <!>`,1),Le=_(`<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>`),Re=_(`<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 custom formats match the current filters</p></div>`),ze=_(`<div class="space-y-4 text-sm text-neutral-700 dark:text-neutral-300"><section><h3 class="mb-2 font-semibold text-neutral-900 dark:text-neutral-100">What Are Custom Formats?</h3> <p>Custom formats identify specific release characteristics &mdash; codec, resolution, source,
				release group, and more. When a release matches a format's conditions, quality profiles use
				its score to decide which releases are preferred.</p></section> <section><h3 class="mb-2 font-semibold text-neutral-900 dark:text-neutral-100">Conditions</h3> <p>Each custom format has one or more conditions grouped by type (Release Title, Release Group,
				Source, Resolution, etc.). Conditions use AND logic between types and OR logic within a
				type, with <strong>Required</strong> and <strong>Negate</strong> modifiers to change this behavior.
				Each condition type is explained in detail on the conditions tab when editing a format.</p></section> <section><h3 class="mb-2 font-semibold text-neutral-900 dark:text-neutral-100">Regular Expressions in Profilarr</h3> <p>Release Title conditions use regular expressions (regex) to match patterns in release names.
				In Profilarr, regex patterns are managed as their own reusable entity &mdash; a single
				pattern can be shared across multiple custom formats. When a pattern is updated, every
				format using it gets the change automatically.</p> <p class="mt-2">You can browse and manage patterns on the <a class="font-medium text-accent-600 underline hover:text-accent-500 dark:text-accent-400 dark:hover:text-accent-300">Regular Expressions</a> page.</p></section></div>`),Be=_(`<!> <div class="space-y-6 px-4 pb-8 md:px-8"><!> <!> <div class="mt-6"><!></div></div> <!> <!>`,1);function Ve(a,s){l(s,!1);let c=()=>F(d(v),`$simpleSearchStore`,h),u=()=>F(pe,`$filterMode`,h),f=()=>F(X,`$viewMode`,h),[h,_]=t(),v=T(),C=T(),D=T(),M=T(),P=T(),R=A(s,`data`,8),B=T(!1),V=T(!1),H=T(``);function U(e){b(H,e.detail.name),b(V,!0)}async function W(e){let{name:t}=e.detail;try{let e=new URLSearchParams({entityType:`custom_format`,name:t}),n=await fetch(`/databases/${R().currentDatabase.id}/export?${e}`),r=await n.json();if(!n.ok){L.add(`error`,r.error||`Export failed`);return}if(!await z(JSON.stringify(r,null,2))){L.add(`error`,`Failed to copy to clipboard`);return}L.add(`success`,`Copied "${t}" to clipboard`)}catch{L.add(`error`,`Export failed`)}}let G=T([]),K=[{key:`all`,label:`All`,description:`Name, tags, description and conditions`,type:`text`,accessor:we},{key:`name`,label:`Name`,description:`Custom format 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:`referenced`,label:`Referenced`,description:`Whether a quality profile uses it`,type:`text`,accessor:e=>e.referenceCount>0?`yes`:`no`,suggestions:()=>[`yes`,`no`]},{key:`description`,label:`Description`,description:`Custom format description`,type:`text`,accessor:e=>e.description??null},{key:`condition`,label:`Condition`,description:`Condition names`,type:`text`,accessor:e=>e.conditions.map(e=>e.name),suggestions:e=>[...new Set(e.flatMap(e=>e.conditions.map(e=>e.name)))].sort()},{key:`tests`,label:`Tests`,description:`Number of configured test cases`,type:`number`,accessor:e=>e.testCount}],q=T(!1),J=null;ee(()=>{typeof window<`u`&&(J=window.matchMedia(`(max-width: 767px)`),b(q,J.matches),J.addEventListener(`change`,Y))}),ne(()=>{J&&J.removeEventListener(`change`,Y)});function Y(e){b(q,e.matches)}let X=Se({storageKey:`customFormatsView`});x(()=>y(R()),()=>{n(b(v,ce(`cfSearch:${R().currentDatabase.id}`,{debounceMs:150})),`$simpleSearchStore`,h)}),x(()=>c(),()=>{b(C,c().query)}),x(()=>(d(q),u()),()=>{b(D,d(q)||u()===`simple`)}),x(()=>(d(D),d(C),y(R()),d(G)),()=>{b(M,(()=>{if(d(D)){if(!d(C))return R().customFormats;let e=d(C).toLowerCase();return R().customFormats.filter(t=>t.name.toLowerCase().includes(e))}return ue(R().customFormats,d(G),K)})())}),x(()=>y(R()),()=>{b(P,R().databases.map(e=>({label:e.name,href:`/custom-formats/${e.id}`,active:e.id===R().currentDatabase.id})))}),te(),S();var Z=Be(),ge=k(Z);{let e=I(()=>(y(R()),N(()=>`${R().currentDatabase.name} · Custom Formats`)));be(ge,{get title(){return d(e)}})}var Q=O(ge,2),xe=w(Q);he(xe,{get tabs(){return d(P)},responsive:!0});var $=O(xe,2);_e($,{children:(t,n)=>{var r=Ie(),a=k(r),o=e=>{le(e,{get searchStore(){return d(v)},placeholder:`Search custom formats...`,responsive:!0})},s=e=>{{let t=I(()=>(y(R()),N(()=>`smartFilter:customFormats:${R().currentDatabase.id}`)));de(e,{get fields(){return K},get items(){return y(R()),N(()=>R().customFormats)},get storageKey(){return d(t)},placeholder:`Filter custom formats...`,get tags(){return d(G)},set tags(e){b(G,e)},$$legacy:!0})}};e(a,e=>{d(D)?e(o):e(s,-1)});var c=O(a,2);oe(c,{text:`New`,children:(e,t)=>{ve(e,{get icon(){return se},$$events:{click:()=>ie(`/custom-formats/${R().currentDatabase.id}/new`)}})},$$slots:{default:!0}});var l=O(c,2),h=e=>{fe(e,{get value(){return p(),u()},set value(e){m(pe,e)},$$legacy:!0})};e(l,e=>{d(q)||e(h)});var g=O(l,2);me(g,{get value(){return p(),f()},set value(e){m(X,e)},$$legacy:!0});var _=O(g,2);ve(_,{get icon(){return ae},$$events:{click:()=>b(B,!0)}}),i(t,r)},$$slots:{default:!0}});var Te=O($,2),De=w(Te),Oe=e=>{var t=Le(),n=w(t),r=w(n);o(n),o(t),j(()=>g(r,`No custom formats found for ${y(R()),N(()=>R().currentDatabase?.name)??``}`)),i(e,t)},ke=e=>{var t=Re();i(e,t)},Ae=e=>{Ee(e,{get formats(){return d(M)},$$events:{clone:U,export:W}})},je=e=>{Fe(e,{get formats(){return d(M)},$$events:{clone:U,export:W}})};e(De,e=>{y(R()),N(()=>R().customFormats.length===0)?e(Oe):(d(M),N(()=>d(M).length===0)?e(ke,1):f()===`table`?e(Ae,2):e(je,-1))}),o(Te),o(Q);var Me=O(Q,2);ye(Me,{header:`About Custom Formats`,get open(){return d(B)},set open(e){b(B,e)},children:(e,t)=>{var n=ze(),a=O(w(n),4),s=O(w(a),4),c=O(w(s));r(),o(s),o(a),o(n),j(()=>re(c,`href`,`/regular-expressions/${y(R()),N(()=>R().currentDatabase.id)??``}`)),i(e,n)},$$slots:{default:!0},$$legacy:!0});var Ne=O(Me,2);{let e=I(()=>(y(R()),N(()=>R().customFormats.map(e=>e.name))));Ce(Ne,{get databaseId(){return y(R()),N(()=>R().currentDatabase.id)},entityType:`custom_format`,get sourceName(){return d(H)},get existingNames(){return d(e)},get canWriteToBase(){return y(R()),N(()=>R().canWriteToBase)},get open(){return d(V)},set open(e){b(V,e)},$$legacy:!0})}i(a,Z),E(),_()}export{Ve as component};