import{r as i,j as e,ak as g,ad as w,f as _,ao as j,d as b,t as h}from"./vendor-laZsiqLO.js";import{C as N,a as k,b as C,c as y,d as v}from"./card-BKDXjfy_.js";import{I as F}from"./input-CT5MkJwj.js";import{B as L}from"./button-B8f8jW4H.js";import{L as u}from"./label-BDbCc0wv.js";import{S}from"./switch-52dk8qnh.js";import{T as A}from"./textarea-B6YN8A27.js";import{u as U}from"./useTranslation-BW0o-tkY.js";import"./utils-RgT4yCq8.js";function Q({onFetchSuccess:f}){const{t:s}=U(),[a,l]=i.useState(""),[r,o]=i.useState(!1),[c,n]=i.useState(""),[m,d]=i.useState(!1),x=async()=>{if(a){d(!0);try{const p=(await b.post("/api/user/posts/fetch-url",{url:a,rewrite:r,prompt:r&&c.trim()!==""?c:null})).data;h.success(p.message||s("_article_fetched_success","Article fetched successfully!")),f(p),l(""),n(""),o(!1)}catch(t){h.error(t.response?.data?.message||s("_fetch_failed","Failed to fetch article."))}finally{d(!1)}}};return e.jsxs(N,{className:"shadow-sm mb-6 border-primary/20 bg-primary/5 animate-in fade-in slide-in-from-top-4",children:[e.jsxs(k,{className:"pb-3",children:[e.jsxs(C,{className:"flex items-center gap-2 text-lg text-primary",children:[e.jsx(g,{className:"w-5 h-5"})," ",s("_quick_fetch_article","Quick Fetch Article")]}),e.jsx(y,{children:s("_quick_fetch_desc","Paste a news URL to automatically extract the headline, content, and cover image.")})]}),e.jsx(v,{children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 items-start sm:items-center",children:[e.jsx(F,{placeholder:s("_news_url_placeholder","https://example.com/news-article"),value:a,onChange:t=>l(t.target.value),className:"flex-1 bg-background"}),e.jsxs("div",{className:"flex items-center gap-4 w-full sm:w-auto justify-between sm:justify-start shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{id:"ai-rewrite",checked:r,onCheckedChange:o}),e.jsxs(u,{htmlFor:"ai-rewrite",className:"cursor-pointer flex items-center gap-1 font-semibold text-purple-600",children:[e.jsx(w,{className:"w-4 h-4"})," ",s("_ai_rewrite","AI Rewrite")]})]}),e.jsxs(L,{type:"button",onClick:x,disabled:m||!a,children:[m?e.jsx(_,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(j,{className:"w-4 h-4 mr-2"}),s("_fetch","Fetch")]})]})]}),r&&e.jsxs("div",{className:"animate-in fade-in slide-in-from-top-2 pt-2 border-t border-primary/10 mt-2",children:[e.jsx(u,{className:"text-purple-700 dark:text-purple-400 mb-2 block",children:s("_custom_ai_prompt","Custom AI Prompt (Optional)")}),e.jsx(A,{placeholder:s("_custom_prompt_placeholder","E.g., Rewrite this in a sarcastic tone, focusing on the main points... Ensure you output the result in HTML <p> tags."),value:c,onChange:t=>n(t.target.value),className:"h-24 bg-background/50 resize-y font-mono text-sm shadow-inner"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s("_custom_prompt_helper","Leave blank to use the system's default professional news rewriting prompt.")})]})]})})]})}export{Q as default};
