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,T as m,Tt as h,U as g,V as _,W as v,Y as y,Z as b,_t as x,at as S,d as C,f as w,ft as T,ht as E,i as D,jt as O,m as k,mt as A,ot as j,pt as M,r as ee,s as N,st as P,t as F,tt as I,u as L,wt as R,yt as z}from"../chunks/BA99CCI5.js";import{a as B}from"../chunks/DP37y6wO.js";import{t as V}from"../chunks/BJ4akexL.js";import"../chunks/xihTtKlq.js";import"../chunks/DGo8yE5j.js";import{t as te}from"../chunks/ELQnUoYO.js";import{t as H}from"../chunks/CCK5X2n32.js";import{n as U,t as ne}from"../chunks/DC11RaJ72.js";import{t as W}from"../chunks/D7OHFWTL2.js";import{t as G}from"../chunks/CBPqn9zD2.js";import{t as K}from"../chunks/BtIghOBA.js";import{t as re}from"../chunks/CmTUQ0et.js";import{t as q}from"../chunks/BHkcdQFQ.js";import{t as J}from"../chunks/B66v-P2b.js";import{t as ie}from"../chunks/Aq-7zSc_.js";import{n as ae,r as oe}from"../chunks/Da9e11Mg.js";import{i as se,n as ce,r as le,t as ue}from"../chunks/C_LFCSMn.js";import{t as de}from"../chunks/DLVOwqGo.js";import{t as Y}from"../chunks/Cut3gr1-.js";import{t as fe}from"../chunks/C_Z5Pdot2.js";import{t as X}from"../chunks/BfBgZfCV2.js";import{t as pe}from"../chunks/BBtCGbx62.js";import{t as me}from"../chunks/Dat55klv2.js";import"../chunks/BymfG72d2.js";import{t as Z}from"../chunks/DxZIQ_tr2.js";import{t as he}from"../chunks/C3FImjIr2.js";import{t as ge}from"../chunks/DSmeX4VS2.js";import{t as Q}from"../chunks/CT9uUPGn.js";import{n as $}from"../chunks/DsOfWPM4.js";import{t as _e}from"../chunks/vB0UVZBU.js";import{t as ve}from"../chunks/CNfB0kJd.js";import{t as ye}from"../chunks/BTzQwcpc.js";import{t as be}from"../chunks/BdjudyaY.js";import{t as xe}from"../chunks/DGICnufN.js";import{t as Se}from"../chunks/DCohNkHF.js";import{t as Ce}from"../chunks/Cme17KJK.js";import{t as we}from"../chunks/BWZVzKif.js";import{n as Te}from"../chunks/CWc174af.js";import{t as Ee}from"../chunks/DYe9q02k2.js";import{i as De}from"../chunks/VZQaB9P52.js";var Oe=v(`<div class="flex items-center justify-end gap-0.5"><!> <!></div>`);function ke(n,r){l(r,!1);let a=()=>R(X,`$page`,s),[s,c]=t(),u=E(),f=N(r,`expressions`,8),p=F();function m(e){return`/regular-expressions/${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?$(Q.parse(e)):``}let _=[{key:`name`,header:`Name`,headerIcon:Y,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:`pattern`,header:`Pattern`,headerIcon:H,align:`left`,width:`w-[40%]`,cell:e=>({html:`<code class="font-mono text-xs bg-neutral-100 dark:bg-neutral-800 px-2 py-1 rounded break-all">${h(e.pattern)}</code>`})},{key:`description`,header:`Description`,headerIcon:K,align:`left`,width:`w-[30%]`,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:`regex101_id`,header:`Regex101`,headerIcon:q,align:`left`,width:`w-24`,cell:e=>({html:e.regex101_id?`<a href="https://regex101.com/r/${h(e.regex101_id)}" target="_blank" rel="noopener noreferrer" class="inline-flex items-center gap-1 font-mono text-xs text-accent-600 hover:text-accent-700 dark:text-accent-400 dark:hover:text-accent-300 hover:underline">${h(e.regex101_id)}<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg></a>`:`<span class="text-neutral-400">-</span>`})}];S(()=>a(),()=>{x(u,a().params.databaseId)}),j(),C(),Ce(n,{get data(){return f()},get columns(){return _},emptyMessage:`No regular expressions found`,hoverable:!0,compact:!1,rowHref:m,pageSize:50,$$slots:{actions:(t,n)=>{let a=z(()=>n.row);var s=Oe(),c=T(s),l=e=>{J(e,{get icon(){return W},size:`xs`,variant:`ghost`,tooltip:`Export`,$$events:{click:()=>p(`export`,{name:d(a).name})}})};e(c,e=>{b(Z),I(()=>Z.importExport)&&e(l)});var u=A(c,2);J(u,{get icon(){return U},size:`xs`,variant:`secondary`,tooltip:`Clone`,$$events:{click:()=>p(`clone`,{name:d(a).name})}}),o(s),y(`click`,s,k(function(e){L.call(this,r,e)})),i(t,s)}}}),O(),c()}var Ae=v(`<pre class="rounded bg-neutral-100 p-2 text-xs dark:bg-neutral-800"><code class="block font-mono break-all whitespace-pre-wrap text-neutral-900 dark:text-neutral-100"> </code></pre>`);function je(e,t){let n=N(t,`code`,8),r=N(t,`maxLines`,8,void 0);var a=Ae(),s=T(a),c=T(s,!0);o(s),o(a),P(()=>{m(s,r()?`display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: ${r()}; overflow: hidden;`:``),_(c,n())}),i(e,a)}var Me=v(`<span class="markdown text-xs text-neutral-600 dark:text-neutral-400 svelte-e4di6a"></span>`);function Ne(t,n){l(n,!1);let r=E(),s=N(n,`content`,8,null),c=N(n,`inline`,8,!0),u=N(n,`maxLines`,8,void 0);S(()=>(b(s()),b(c()),Q),()=>{x(r,s()?$(c()?Q.parseInline(s()):Q.parse(s())):``)}),j(),C();var f=g(),p=M(f),h=e=>{var t=Me();a(t,()=>d(r),!0),o(t),P(()=>m(t,u()?`display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: ${u()}; overflow: hidden;`:``)),i(e,t)};e(p,e=>{d(r)&&e(h)}),i(t,f),O()}var Pe=v(`<div class="space-y-3"><!> <!></div>`),Fe=v(`<div class="flex items-end justify-between gap-2"><div class="flex min-w-0 flex-wrap items-center gap-1.5"><h3 class="text-sm font-semibold text-neutral-900 dark:text-neutral-100"> </h3> <!></div> <div class="flex shrink-0 items-center gap-0.5"><!> <!> <!></div></div>`),Ie=v(`<!> <div></div>`,1);function Le(n,a){l(a,!1);let p=()=>R(X,`$page`,h),m=()=>R(V,`$visibleCount`,h),[h,v]=t(),D=E(),ee=E(),z=N(a,`expressions`,8),B=F(),{visibleCount:V,sentinel:te,reset:H,setTotalCount:ne}=_e({pageSize:30});S(()=>p(),()=>{x(D,p().params.databaseId)}),S(()=>b(z()),()=>{ne(z().length)}),S(()=>b(z()),()=>{z(),H()}),S(()=>(b(z()),m()),()=>{x(ee,z().slice(0,m()))}),j(),C();var K=Ie(),re=M(K);we(re,{flush:!0,children:(t,n)=>{var l=g(),u=M(l);c(u,1,()=>d(ee),e=>e.id,(t,n)=>{me(t,{get href(){return`/regular-expressions/${d(D)??``}/${d(n),I(()=>d(n).id)??``}`},hoverable:!0,children:(t,r)=>{var a=Pe(),s=T(a);je(s,{get code(){return d(n),I(()=>d(n).pattern)}});var c=A(s,2),l=e=>{Ne(e,{get content(){return d(n),I(()=>d(n).description)},inline:!1,maxLines:3})};e(c,e=>{d(n),I(()=>d(n).description)&&e(l)}),o(a),i(t,a)},$$slots:{default:!0,header:(t,l)=>{var u=Fe(),p=T(u),m=T(p),h=T(m,!0);o(m);var g=A(m,2);c(g,1,()=>(d(n),I(()=>d(n).tags)),f,(e,t)=>{pe(e,{variant:`info`,size:`sm`,rounded:`md`,children:(e,n)=>{r();var a=s();P(()=>_(a,(d(t),I(()=>d(t).name)))),i(e,a)},$$slots:{default:!0}})}),o(p);var v=A(p,2),x=T(v),S=e=>{J(e,{get icon(){return G},size:`xs`,variant:`ghost`,tooltip:`View on regex101`,$$events:{click:()=>window.open(`https://regex101.com/r/${d(n).regex101_id}`,`_blank`)}})};e(x,e=>{d(n),I(()=>d(n).regex101_id)&&e(S)});var C=A(x,2),E=e=>{J(e,{get icon(){return W},size:`xs`,variant:`ghost`,tooltip:`Export`,$$events:{click:()=>B(`export`,{name:d(n).name})}})};e(C,e=>{b(Z),I(()=>Z.importExport)&&e(E)});var D=A(C,2);J(D,{get icon(){return U},size:`xs`,variant:`ghost`,tooltip:`Clone`,$$events:{click:()=>B(`clone`,{name:d(n).name})}}),o(v),o(u),P(()=>_(h,(d(n),I(()=>d(n).name)))),y(`click`,v,w(k(function(e){L.call(this,a,e)}))),i(t,u)}}})}),i(t,l)},$$slots:{default:!0}});var q=A(re,2);u(q,e=>te?.(e)),i(n,K),O(),v()}var Re=v(`<!> <!> <!>`,1),ze=v(`<!> <!> <!> <!> <!>`,1),Be=v(`<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>`),Ve=v(`<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 regular expressions match the current filters</p></div>`),He=v(`<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">How It Works</h3> <p>Regular expressions in Profilarr are separated from custom formats to make them reusable.
				When multiple custom formats share the same pattern, you only need to update it in one
				place.</p> <p class="mt-2">When custom formats are synced to your Arr instances, Profilarr compiles the referenced
				patterns into the format each Arr expects. The regular expressions themselves are <strong>not</strong> synced directly—only the compiled custom formats are.</p></section> <section><h3 class="mb-2 font-semibold text-neutral-900 dark:text-neutral-100">Regex Flavor</h3> <p>Radarr and Sonarr use the <strong>.NET regex engine</strong> (specifically .NET 6+). Patterns
				are matched case-insensitively by default.</p></section> <section><h3 class="mb-2 font-semibold text-neutral-900 dark:text-neutral-100">Testing Patterns</h3> <p>Use <a href="https://regex101.com" target="_blank" rel="noopener noreferrer" class="text-accent-600 hover:underline dark:text-accent-400">regex101.com</a> to test your patterns. Make sure to select the <strong>.NET</strong> flavor from the dropdown
				for accurate results.</p> <p class="mt-2 text-xs text-neutral-500 dark:text-neutral-400">Tip: When saving a regex101 link, include the version number (e.g., <code class="rounded bg-neutral-100 px-1 dark:bg-neutral-800">ABC123/1</code>) to ensure it always points to your specific version.</p></section></div>`),Ue=v(`<!> <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=()=>R(d(g),`$simpleSearchStore`,f),c=()=>R(ue,`$filterMode`,f),u=()=>R(me,`$viewMode`,f),[f,m]=t(),g=E(),v=E(),y=E(),w=E(),k=E(),F=N(a,`data`,8),L=E(!1),H=E(!1),U=E(``);function W(e){x(U,e.detail.name),x(H,!0)}async function G(e){let{name:t}=e.detail;try{let e=new URLSearchParams({entityType:`regular_expression`,name:t}),n=await fetch(`/databases/${F().currentDatabase.id}/export?${e}`),r=await n.json();if(!n.ok){V.add(`error`,r.error||`Export failed`);return}if(!await ne(JSON.stringify(r,null,2))){V.add(`error`,`Failed to copy to clipboard`);return}V.add(`success`,`Copied "${t}" to clipboard`)}catch{V.add(`error`,`Export failed`)}}let q=E([]),J=[{key:`all`,label:`All`,description:`Name, tags, pattern, description and Regex101 ID`,type:`text`,accessor:De},{key:`name`,label:`Name`,description:`Regular expression 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 custom format uses it`,type:`text`,accessor:e=>e.referenceCount>0?`yes`:`no`,suggestions:()=>[`yes`,`no`]},{key:`pattern`,label:`Pattern`,description:`Regular expression pattern`,type:`text`,accessor:e=>e.pattern},{key:`description`,label:`Description`,description:`Regular expression description`,type:`text`,accessor:e=>e.description??null},{key:`regex101_id`,label:`Regex101 ID`,description:`Linked Regex101 identifier`,type:`text`,accessor:e=>e.regex101_id??null}],Y=E(!1),X=null;D(()=>{typeof window<`u`&&(X=window.matchMedia(`(max-width: 767px)`),x(Y,X.matches),X.addEventListener(`change`,pe))}),ee(()=>{X&&X.removeEventListener(`change`,pe)});function pe(e){x(Y,e.matches)}let me=Te({storageKey:`regularExpressionsView`});S(()=>b(F()),()=>{n(x(g,ae(`reSearch:${F().currentDatabase.id}`,{debounceMs:150})),`$simpleSearchStore`,f)}),S(()=>s(),()=>{x(v,s().query)}),S(()=>(d(Y),c()),()=>{x(y,d(Y)||c()===`simple`)}),S(()=>(d(y),d(v),b(F()),d(q)),()=>{x(w,(()=>{if(d(y)){if(!d(v))return F().regularExpressions;let e=d(v).toLowerCase();return F().regularExpressions.filter(t=>t.name.toLowerCase().includes(e))}return se(F().regularExpressions,d(q),J)})())}),S(()=>b(F()),()=>{x(k,F().databases.map(e=>({label:e.name,href:`/regular-expressions/${e.id}`,active:e.id===F().currentDatabase.id})))}),j(),C();var Z=Ue(),Q=M(Z);{let e=z(()=>(b(F()),I(()=>`${F().currentDatabase.name} · Regular Expressions`)));Se(Q,{get title(){return d(e)}})}var $=A(Q,2),_e=T($);ge(_e,{get tabs(){return d(k)},responsive:!0});var Ce=A(_e,2);ve(Ce,{children:(t,n)=>{var r=ze(),a=M(r),o=e=>{oe(e,{get searchStore(){return d(g)},placeholder:`Search regular expressions...`,responsive:!0})},s=e=>{{let t=z(()=>(b(F()),I(()=>`smartFilter:regularExpressions:${F().currentDatabase.id}`)));ce(e,{get fields(){return J},get items(){return b(F()),I(()=>F().regularExpressions)},get storageKey(){return d(t)},placeholder:`Filter regular expressions...`,get tags(){return d(q)},set tags(e){x(q,e)},$$legacy:!0})}};e(a,e=>{d(y)?e(o):e(s,-1)});var l=A(a,2);ye(l,{get icon(){return ie},hasDropdown:!0,dropdownPosition:`right`,$$slots:{dropdown:(e,t)=>{te(e,{position:`right`,minWidth:`14rem`,children:(e,t)=>{var n=Re(),r=M(n);be(r,{label:`New expression`});var a=A(r,2);he(a,{get icon(){return K},label:`Blank`,$$events:{click:()=>B(`/regular-expressions/${F().currentDatabase.id}/new`)}});var o=A(a,2);he(o,{get icon(){return fe},label:`Release Group`,$$events:{click:()=>B(`/regular-expressions/${F().currentDatabase.id}/new?preset=release-group`)}}),i(e,n)},$$slots:{default:!0}})}}});var f=A(l,2),m=e=>{le(e,{get value(){return p(),c()},set value(e){h(ue,e)},$$legacy:!0})};e(f,e=>{d(Y)||e(m)});var _=A(f,2);de(_,{get value(){return p(),u()},set value(e){h(me,e)},$$legacy:!0});var v=A(_,2);ye(v,{get icon(){return re},$$events:{click:()=>x(L,!0)}}),i(t,r)},$$slots:{default:!0}});var we=A(Ce,2),Oe=T(we),Ae=e=>{var t=Be(),n=T(t),r=T(n);o(n),o(t),P(()=>_(r,`No regular expressions found for ${b(F()),I(()=>F().currentDatabase?.name)??``}`)),i(e,t)},je=e=>{var t=Ve();i(e,t)},Me=e=>{ke(e,{get expressions(){return d(w)},$$events:{clone:W,export:G}})},Ne=e=>{Le(e,{get expressions(){return d(w)},$$events:{clone:W,export:G}})};e(Oe,e=>{b(F()),I(()=>F().regularExpressions.length===0)?e(Ae):(d(w),I(()=>d(w).length===0)?e(je,1):u()===`table`?e(Me,2):e(Ne,-1))}),o(we),o($);var Pe=A($,2);xe(Pe,{header:`About Regular Expressions`,get open(){return d(L)},set open(e){x(L,e)},children:(e,t)=>{var n=He();i(e,n)},$$slots:{default:!0},$$legacy:!0});var Fe=A(Pe,2);{let e=z(()=>(b(F()),I(()=>F().regularExpressions.map(e=>e.name))));Ee(Fe,{get databaseId(){return b(F()),I(()=>F().currentDatabase.id)},entityType:`regular_expression`,get sourceName(){return d(U)},get existingNames(){return d(e)},get canWriteToBase(){return b(F()),I(()=>F().canWriteToBase)},get open(){return d(H)},set open(e){x(H,e)},$$legacy:!0})}i(r,Z),O(),m()}export{We as component};