import{r as a,a9 as w,c as l,j as s,B as I,aa as T,ab as p}from"./index-ck01-P-l.js";import{c as D,S as z,a as C}from"./common-nfwq9z7Z.js";import{L as R}from"./LinkTable-Ia3zEXas.js";import{T as E}from"./textarea-eX4nx7v5.js";import"./loading-vsHIitu7.js";const Y=()=>{const[r,c]=a.useState(""),[h,f]=a.useState(!0),[g,d]=a.useState(!1),[u,m]=a.useState([]),[j,S]=a.useState(),[L,U]=a.useState(!1);let o=a.useRef(void 0);a.useEffect(()=>(i(),()=>{o.current&&clearTimeout(o.current)}),[]);const i=async()=>{try{const{data:{url_list:e}}=await w();m(e),o.current=D(e,i)}catch(e){l.error(e.message||"Failed to get link list.")}f(!1)},b=async e=>{await T(e),m(t=>t.filter(n=>!e.includes(n.id))),l.success("Deleted successfully")},v=async e=>{await p(u.filter(t=>e.includes(t.id)).map(t=>t.url)),i(),l.success("Updated successfully")},x=(e,t)=>{U(e),S(t)},k=e=>{const t=e.target.value,n=t.split(`
`).filter(N=>N.trim()!=="");n.length>10?(l.error("You can only add up to 10 URLs at a time."),c(n.slice(0,10).join(`
`))):c(t)},y=async()=>{d(!0);try{await p(r.split(`
`).filter(e=>e.trim()!=="")),i(),l.success("Added successfully")}catch(e){l.error(e.message||"Failed to add urls.")}c(""),d(!1)};return s.jsx("div",{className:"mt-[5vh]",children:s.jsxs("div",{className:"mb-10 rounded border border-zinc-200",children:[s.jsx("div",{className:"border-b border-zinc-200 px-5 py-4",children:s.jsx("h3",{className:"text-xl font-semibold leading-6 text-zinc-900 ",children:"IsolatedUrl"})}),s.jsx("div",{className:"p-5",children:s.jsxs("div",{children:[s.jsxs("div",{children:[s.jsx("small",{className:"text-sm font-medium leading-none",children:"Url"}),s.jsx("div",{className:"flex w-full items-center space-x-2 mt-2",children:s.jsx(E,{value:r,onChange:k,rows:10})})]}),s.jsx("p",{className:"mt-5 text-sm text-zinc-500 dark:text-zinc-300",children:"Enter each URL in a new line. This will crawl all the links starting with the URL."}),s.jsx("div",{className:"flex justify-end",children:s.jsx(I,{loading:g,className:"text-xs font-normal h-8",onClick:y,disabled:!r.trim(),children:"Submit"})}),s.jsxs("div",{className:"pt-8",children:[s.jsxs("div",{children:[s.jsx(z,{content:"Included Urls"}),s.jsx(R,{links:u,loading:h,deleteLinks:b,updateLinks:v,onSelectLink:e=>x(!0,e)})]}),s.jsx(C,{open:L,selectedIsolatedUrl:j,onOpenChange:x})]})]})})]})})};export{Y as Urls};
