1import{bw as h,J as B,N as v,aB as g,O as t,b9 as C,M as F,o as z,bM as k,X as A,a9 as I,bQ as S,bX as U,bU as P}from"./B4cWliYT.js";import{r as j}from"./DGq9ti5X.js";const N={class:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50"},$={class:"relative bg-white dark:bg-gray-800 rounded-lg shadow-xl p-6 w-full max-w-2xl mx-4 h-[70vh] md:h-[75vh] max-h-[90vh] flex flex-col overflow-hidden"},W={class:"flex justify-between items-center mb-6"},V=["disabled"],D={class:"mb-6"},T={class:"border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-6 text-center"},E={key:1,class:"text-green-600 dark:text-green-400"},L={class:"font-medium"},R={class:"text-sm text-gray-500 dark:text-gray-400 mt-1"},q={key:0,class:"mb-4 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-md"},G={class:"text-sm text-red-700 dark:text-red-300"},X={class:"mt-auto flex justify-end gap-3"},J=["disabled"],K=["disabled"],O={key:0},Q={key:1,class:"inline-flex items-center"},H={key:1,class:"flex-1 flex flex-col items-center justify-center py-12",role:"status","aria-live":"polite"},Y={__name:"PromptFromFileModal",props:{onUpload:{type:Function,required:!0}},emits:["close","upload"],setup(d,{emit:u}){const n=d,p=u,a=h(null),m=h(null),o=h(null),r=h(!1);function x(s){const e=s.target.files[0];if(!e)return;const l=e.name.toLowerCase();if(!(l.endsWith(".md")||l.endsWith(".pdf")||l.endsWith(".ppt")||l.endsWith(".pptx"))){o.value="Unsupported file type. Use .md, .pdf, .ppt, .pptx";return}if(e.size>10*1024*1024){o.value="File size must be less than 10MB";return}a.value=e,o.value=null;const b=new FileReader;b.onload=_=>{m.value=_.target.result},b.onerror=()=>{o.value="Failed to read file"},b.readAsText(e)}const f=B(()=>!!a.value&&!!m.value);async function c(){var s,e,l;if(!(!f.value||!n.onUpload)){o.value=null,r.value=!0;try{await n.onUpload({filename:(s=a.value)==null?void 0:s.name,content:m.value,file:a.value}),r.value=!1,p("close")}catch(i){o.value=((l=(e=i==null?void 0:i.response)==null?void 0:e.data)==null?void 0:l.message)||(i==null?void 0:i.message)||"Analysis failed",r.value=!1}}}function y(){a.value=null,m.value=null,o.value=null}function M(s){if(s===0)return"0 Bytes";const e=1024,l=["Bytes","KB","MB"],i=Math.floor(Math.log(s)/Math.log(e));return parseFloat((s/Math.pow(e,i)).toFixed(1))+" "+l[i]}return(s,e)=>(g(),v("div",N,[t("div",$,[C(t("div",null,[t("div",W,[e[4]||(e[4]=t("h3",{class:"text-lg font-semibold text-gray-900 dark:text-white"}," Create From File ",-1)),t("button",{onClick:e[0]||(e[0]=l=>s.$emit("close")),disabled:r.value,class:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 disabled:opacity-50 disabled:cursor-not-allowed"},e[3]||(e[3]=[t("svg",{class:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)]),8,V)]),t("div",D,[e[7]||(e[7]=t("p",{class:"text-gray-600 dark:text-gray-400 mb-4"}," Upload a source asset for analysis. We will extract key information and generate a highâquality prompt for your landing page. ",-1)),t("div",T,[t("input",{ref:"fileInput",type:"file",accept:".md,.pdf,.ppt,.pptx",onChange:x,class:"hidden"},null,544),a.value?(g(),v("div",E,[e[6]||(e[6]=t("svg",{class:"w-12 h-12 mx-auto mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})],-1)),t("p",L,k(a.value.name),1),t("p",R,k(M(a.value.size)),1),t("button",{onClick:y,class:"text-sm text-red-600 hover:text-red-800 dark:text-red-400 dark:hover:text-red-300 mt-2"},"Remove file")])):(g(),v("div",{key:0,onClick:e[1]||(e[1]=l=>s.$refs.fileInput.click()),class:"cursor-pointer"},e[5]||(e[5]=[t("svg",{class:"w-12 h-12 mx-auto mb-4 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[t("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"})],-1),t("p",{class:"text-gray-600 dark:text-gray-400"},"Click to upload .md, .pdf, .ppt, .pptx",-1)])))])])],512),[[z,!r.value]]),o.value&&!r.value?(g(),v("div",q,[t("p",G,k(o.value),1)])):F("",!0),C(t("div",X,[t("button",{onClick:e[2]||(e[2]=l=>s.$emit("close")),disabled:r.value,class:"px-4 py-2 text-gray-600 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"},"Cancel",8,J),t("button",{onClick:c,disabled:!f.value||r.value,class:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:bg-gray-300 disabled:cursor-not-allowed transition-colors"},[r.value?(g(),v("span",Q,e[8]||(e[8]=[t("svg",{class:"animate-spin h-5 w-5 mr-2 text-white",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","aria-hidden":"true"},[t("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),t("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})],-1),A(" Analyzing... ")]))):(g(),v("span",O,"Analyze & Generate Prompt"))],8,K)],512),[[z,!r.value]]),r.value?(g(),v("div",H,e[9]||(e[9]=[t("svg",{class:"animate-spin h-10 w-10 text-primary-500 mb-3",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","aria-hidden":"true"},[t("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),t("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})],-1),t("p",{class:"text-sm text-gray-700 dark:text-gray-200"},"Analyzing fileâ¦",-1)]))):F("",!0)])]))}};let w={toast:null};async function re(d){const{action:u,context:n,openModal:p,closeModal:a}=d;switch(u){case"campaign-step:render-buttons":return await Z(n);case"campaign-step:button:prompt-from-file":return ee(n,p,a)}}async function Z(d){return d.currentStep!==1?[]:[{id:"prompt-from-file",title:"Generate a suggested prompt from a file",icon:j,showInMaximized:!1,showInNormal:!0}]}function ee(d,u,n){const{campaignState:p}=d;if(!p){console.warn("PromptFromFile: Missing campaignState");return}u({id:"prompt-from-file",title:"Prompt From File",component:{render(){return I(Y,{onClose:()=>n(),onUpload:a=>te(a,p)})}}})}async function te(d,u){var n,p,a,m;w.toast||(w.toast=P());try{const{file:o}=d||{};if(!o)throw new Error("Please upload a file to analyze");const{$api:r}=S(),x=U(),f=new FormData;f.append("file",o),x.organizationId&&f.append("organizationId",x.organizationId),x.repositoryId&&f.append("repositoryId",x.repositoryId);const c=await r.post("/ai-processing/prompt-from-file",f,{headers:{"Content-Type":"multipart/form-data"}}),y=((n=c==null?void 0:c.data)==null?void 0:n.prompt)||((p=c==null?void 0:c.data)==null?void 0:p.text)||"";if(!y)throw new Error("No prompt generated from analysis");return u.prompt&&(u.prompt.value=y),w.toast.add({title:"Prompt generated",description:"We extracted a prompt from your source. Review and continue.",color:"green"}),!0}catch(o){throw console.error("PromptFromFile analysis error:",o),w.toast.add({title:"Analysis failed",description:((m=(a=o==null?void 0:o.response)==null?void 0:a.data)==null?void 0:m.message)||o.message||"Unexpected error",color:"red"}),o}}export{re as default};
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.