1import{aM as d,bG as v,bE as b,r as o,j as e,aD as w,aE as C,aF as S,aG as E,bN as P}from"./index-495Gbj5S.js";import{l as R,u as _,d as q,s as D}from"./link-juicer.functions-CrfZlAq7.js";import{P as T}from"./plus-BuxM8Eij.js";import{T as M}from"./trash-2-COOlAnl2.js";const F={source_content_id:null,source_path_pattern:"",is_enabled:!0,max_links_per_page:8,max_links_per_paragraph:2,exclude_link_target_types:[],exclude_blocks:["heading","table_header","code","blockquote","figcaption","figure_caption"],prefer_same_cluster:!0};function Y(){const l=d(R);d(_);const i=d(q),u=v(),{data:c}=b({queryKey:["lj-rules"],queryFn:()=>l()}),[x,s]=o.useState(null),n=()=>u.invalidateQueries({queryKey:["lj-rules"]});async function a(r){confirm("Delete this rule?")&&(await i({data:{id:r}}),n())}return e.jsxs("div",{children:[e.jsxs("header",{className:"mb-6 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Source rules"}),e.jsx("p",{className:"mt-1 text-sm text-fg-muted",children:"Per-page or path-pattern rules that control how Link Juicer renders links on each source."})]}),e.jsxs("button",{onClick:()=>s({...F}),className:"inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-sm font-medium text-fg-on-accent",children:[e.jsx(T,{className:"h-3.5 w-3.5"})," New rule"]})]}),e.jsx("div",{className:"overflow-x-auto rounded-md border border-border-strong",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-bg-elevated text-xs uppercase tracking-wide text-fg-muted",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left",children:"Scope"}),e.jsx("th",{className:"px-3 py-2 text-center",children:"On"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Max/page"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Max/para"}),e.jsx("th",{className:"px-3 py-2 text-left",children:"Exclude targets"}),e.jsx("th",{className:"px-3 py-2 text-center",children:"Cluster"}),e.jsx("th",{className:"px-3 py-2"})]})}),e.jsxs("tbody",{children:[(c??[]).map(r=>e.jsxs("tr",{className:"border-t border-border-strong hover:bg-bg-elevated/50",children:[e.jsx("td",{className:"px-3 py-2",children:r._content?e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:r._content.title}),e.jsx("div",{className:"font-mono text-xs text-fg-muted",children:r._content.path})]}):e.jsx("div",{className:"font-mono text-xs",children:r.source_path_pattern})}),e.jsx("td",{className:"px-3 py-2 text-center",children:r.is_enabled?"â":"-"}),e.jsx("td",{className:"px-3 py-2 text-right",children:r.max_links_per_page}),e.jsx("td",{className:"px-3 py-2 text-right",children:r.max_links_per_paragraph}),e.jsx("td",{className:"px-3 py-2 text-xs text-fg-muted",children:(r.exclude_link_target_types??[]).join(", ")||"-"}),e.jsx("td",{className:"px-3 py-2 text-center",children:r.prefer_same_cluster?"â":"-"}),e.jsxs("td",{className:"px-3 py-2 text-right",children:[e.jsx("button",{onClick:()=>s(r),className:"mr-2 text-fg-muted hover:text-fg",children:"Edit"}),e.jsx("button",{onClick:()=>a(r.id),className:"text-fg-muted hover:text-red-600",children:e.jsx(M,{className:"inline h-3.5 w-3.5"})})]})]},r.id)),(!c||c.length===0)&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-3 py-8 text-center text-fg-muted",children:"No rules yet."})})]})]})}),x&&e.jsx($,{rule:x,onClose:()=>s(null),onSaved:()=>{s(null),n()}})]})}const Q=["post","category","product_type","production_country","download","supplier","static"];function $({rule:l,onClose:i,onSaved:u}){const c=d(_),x=d(D),[s,n]=o.useState(l),[a,r]=o.useState(l.source_content_id?"content":"pattern"),[h,j]=o.useState(""),[m,g]=o.useState(null),{data:f}=b({queryKey:["lj-rule-content-search",h],queryFn:()=>x({data:{q:h||void 0,limit:20}}),enabled:a==="content"});async function y(){g(null);try{const t={...s,source_content_id:a==="content"?s.source_content_id:null,
1source_path_pattern:a==="pattern"?s.source_path_pattern:null};if(a==="content"&&!t.source_content_id)throw new Error("Pick a content item");if(a==="pattern"&&!t.source_path_pattern)throw new Error("Provide a path pattern");await c({data:t}),u()}catch(t){g(t instanceof Error?t.message:String(t))}}function N(t){n(p=>({...p,exclude_link_target_types:p.exclude_link_target_types.includes(t)?p.exclude_link_target_types.filter(k=>k!==t):[...p.exclude_link_target_types,t]}))}return e.jsx(w,{open:!0,onOpenChange:t=>!t&&i(),children:e.jsxs(C,{className:"max-w-xl",children:[e.jsx(S,{children:e.jsx(E,{children:l.id?"Edit rule":"New rule"})}),e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{className:"flex gap-2 text-xs",children:[e.jsx("button",{onClick:()=>r("pattern"),className:`rounded border px-3 py-1 ${a==="pattern"?"border-accent bg-accent/10":"border-border-strong"}`,children:"Path pattern"}),e.jsx("button",{onClick:()=>r("content"),className:`rounded border px-3 py-1 ${a==="content"?"border-accent bg-accent/10":"border-border-strong"}`,children:"Specific content"})]}),a==="pattern"&&e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-fg-muted",children:"Path pattern (use trailing /* for prefix, or exact path)"}),e.jsx("input",{value:s.source_path_pattern??"",onChange:t=>n({...s,source_path_pattern:t.target.value}),placeholder:"/magazine/*",className:"mt-1 w-full rounded border border-border-strong bg-bg-elevated px-2 py-1.5 font-mono text-xs"})]}),a==="content"&&e.jsxs("div",{children:[e.jsx("input",{value:h,onChange:t=>j(t.target.value),placeholder:"Search contentâ¦",className:"w-full rounded border border-border-strong bg-bg-elevated px-2 py-1.5"}),e.jsx("div",{className:"mt-2 max-h-48 overflow-y-auto rounded border border-border-strong",children:(f??[]).map(t=>e.jsxs("button",{onClick:()=>n({...s,source_content_id:t.id}),className:`flex w-full items-center justify-between border-b border-border-strong px-2 py-1 text-left text-xs last:border-b-0 hover:bg-bg-elevated ${s.source_content_id===t.id?"bg-accent/10":""}`,children:[e.jsx("span",{className:"truncate",children:t.title}),e.jsx("span",{className:"ml-2 shrink-0 font-mono text-fg-muted",children:t.path})]},t.id))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-fg-muted",children:"Max links per page"}),e.jsx("input",{type:"number",value:s.max_links_per_page,onChange:t=>n({...s,max_links_per_page:parseInt(t.target.value||"0",10)}),className:"mt-1 w-full rounded border border-border-strong bg-bg-elevated px-2 py-1"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs text-fg-muted",children:"Max links per paragraph"}),e.jsx("input",{type:"number",value:s.max_links_per_paragraph,onChange:t=>n({...s,max_links_per_paragraph:parseInt(t.target.value||"0",10)}),className:"mt-1 w-full rounded border border-border-strong bg-bg-elevated px-2 py-1"})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-xs text-fg-muted",children:"Exclude target types"}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:Q.map(t=>e.jsx("button",{onClick:()=>N(t),className:`rounded border px-2 py-0.5 text-xs ${s.exclude_link_target_types.includes(t)?"border-accent bg-accent/10":"border-border-strong"}`,children:t},t))})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:s.is_enabled,onChange:t=>n({...s,is_enabled:t.target.checked})}),e.jsx("span",{children:"Enabled"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:s.prefer_same_cluster,onChange:t=>n({...s,prefer_same_cluster:t.target.checked})}),e.jsx("span",{children:"Prefer same cluster"})]}),m&&e.jsx("div",{className:"text-xs text-red-600",children:m})]}),e.jsxs(P,{children:[e.jsx("button",{onClick:i,className:"rounded border border-border-strong px-3 py-1.5 text-sm",children:"Cancel"}),e.jsx("button",{onClick:y,className:"rounded bg-accent px-3 py-1.5 text-sm font-medium text-fg-on-accent",children:"Save"})]})]})})}export{Y as component};
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.