1import{r as l,j as e}from"./vendor-react-Dqm4a0k5.js";import{u as Y,B as N,c as I,s as x}from"./index-BR-ShKyk.js";import{a as K,b as X,c as Q,D as A,f as L}from"./useOwnedToolCount-wyv1Fa3v.js";import{T as f}from"./placeholderStyles-DBHPcRYS.js";import{I as S}from"./validation-DfDrtHjz.js";import{L as n}from"./useSupportTickets-CNr_YXIK.js";import{S as Z,a as ee,b as se,c as ae,d as v}from"./categories-DVobXU6A.js";import{u as te,a as re}from"./use-toast-DL6cPnZQ.js";import{l as ie,m as le,n as oe}from"./FullShell-D8umUy0n.js";import{am as P,aw as ne,an as ce,ax as de,X as me,L as ue,ay as pe}from"./vendor-icons-Dv6Y7wXg.js";import"./vendor-supabase-RijQlDjE.js";import"./vendor-utils-KLhAiGEE.js";import"./vendor-query-BQV4-hhd.js";import"./radix-react-slot-CrO6XSQS.js";import"./radix-react-compose-refs-IIetlP92.js";import"./vendor-radix-DFc8vCWX.js";import"./MobilePageTransitionAnimated-lpTtBr8f.js";import"./vendor-motion-uI1IlCbt.js";import"./useDebounce-JJj-9H3L.js";function Ie({trigger:C}){const[D,j]=l.useState(!1),[F,B]=l.useState(!1),[u,b]=l.useState([]),[U,y]=l.useState(!1),[o,T]=l.useState({}),R=l.useRef(null),{user:h}=Y(),[i,w]=l.useState({name:"",email:"",subject:"",description:"",severity:"medium",stepsToReproduce:"",expectedBehavior:"",actualBehavior:""}),{toast:p}=re(),k=te();l.useEffect(()=>{h&&w(s=>({...s,name:s.name||h.user_metadata?.full_name||h.user_metadata?.name||"",email:s.email||h.email||""}))},[h]);const c=(s,a)=>{w(t=>({...t,[s]:a})),o[s]&&T(t=>({...t,[s]:void 0}))},z=s=>({file:s,preview:URL.createObjectURL(s),id:Math.random().toString(36).substring(7)}),E=s=>["image/jpeg","image/jpg","image/png","image/gif","image/webp"].includes(s.type),$=s=>s.size<=10485760,g=l.useCallback(s=>{const a=Array.from(s),t=[];a.forEach(r=>{if(!E(r)){p({title:"Invalid File Type",description:`${r.name}: Only image files (JPG, PNG, GIF, WebP) are allowed.`,variant:"destructive"});return}if(!$(r)){p({title:"File Too Large",description:`${r.name}: File size must be less than 10MB.`,variant:"destructive"});return}t.push(z(r))}),t.length>0&&(b(r=>[...r,...t]),p({title:"Files Added",description:`${t.length} screenshot(s) added successfully.`}))},[p]),W=l.useCallback(s=>{s.preventDefault(),y(!0)},[]),G=l.useCallback(s=>{s.preventDefault(),y(!1)},[]),M=l.useCallback(s=>{s.preventDefault(),y(!1);const a=Array.from(s.dataTransfer.files);g(a)},[g]),H=l.useCallback(async s=>{const t=Array.from(s.clipboardData.items).filter(d=>d.type.startsWith("image/"));if(t.length===0)return;const r=[];for(const d of t){const m=d.getAsFile();m&&r.push(m)}r.length>0&&g(r)},[g]),_=s=>{b(a=>{const t=a.find(r=>r.id===s);return t&&URL.revokeObjectURL(t.preview),a.filter(r=>r.id!==s)})},q=async()=>{if(u.length===0)return[];const s=u.map(async a=>{const r=`${`${Date.now()}-${a.id}.${a.file.name.split(".").pop()}`}`,{error:d}=await x.storage.from("bug-reports").upload(r,a.file);if(d)throw console.error("Upload error:",d),new Error(`Failed to upload ${a.file.name}`);const{data:m}=x.storage.from("bug-reports").getPublicUrl(r);return m.publicUrl});return Promise.all(s)},V=async s=>{s.preventDefault();const a={};if(i.email.trim()?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(i.email.trim())||(a.email="Please enter a valid email address"):a.email="Email is required",i.subject.trim()||(a.subject="Bug summary is required"),i.description.trim()||(a.description="Description is required"),Object.keys(a).length>0){T(a);return}B(!0);try{const{data:{user:t}}=await x.auth.getUser(),r=await q(),d={userAgent:navigator.userAgent,language:navigator.language,platform:navigator.platform,screenWidth:window.screen.width,screenHeight:window.screen.height,windowWidth:window.innerWidth,windowHeight:window.innerHeight},{error:m}=await x.functions.invoke("report-bug",{body:{...i,attachments:r,pageUrl:window.location.href,browserInfo:d,userId:t?.id||null}});if(m)throw m;p({title:"Bug Report Submitted",description:"Thank you for your report! We'll look into this issue."}),w({name:t?.user_metadata?.full_name||t?.user_metadata?.name||"",email:t?.email||"",subject:"",description:"",severity:"medium",stepsToReproduce:"",expectedBehavior:"",actualBehavior:""}),u.forEach(J=>URL.revokeObjectURL(J.preview)),b([]),j(!1)}catch(t){console.error("Error submitting bug report:",t),p({title:"Submission Failed",description:"There was an error submitting your bug report. Please try again.",variant:"destructive"})}finally{B(!1)}},O=e.jsxs(K,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",onPaste:H,children:[e.jsxs(X,{children:[e.jsxs(Q,{className:"flex items-center gap-2 text-xl",children:[e.jsx(P,{className:"h-6 w-6 text-primary"}),"Report a Bug"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"Help us improve DealKeep by reporting bugs you encounter. Include screenshots for faster resolution."})]}),e.jsxs("form",{onSubmit:V,className:"space-y-6 mt-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{htmlFor:"name",children:"Name (Optional)"}),e.jsx(S,{id:"name",value:i.name,onChange:s=>c("name",s.target.value),placeholder:"Your name"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{htmlFor:"email",children:"Email *"}),e.jsx(S,{id:"email",type:"email",value:i.email,onChange:s=>c("email",s.target.value),placeholder:"[email protected]","aria-invalid":!!o.email}),o.email&&e.jsx("p",{className:"text-sm text-destructive",children:o.email})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{htmlFor:"subject",children:"Bug Summary *"}),e.jsx(S,{id:"subject",value:i.subject,onChange:s=>c("subject",s.target.value),placeholder:"Brief description of the issue","aria-invalid":!!o.subject}),o.subject&&e.jsx("p",{className:"text-sm text-destructive",children:o.subject})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{htmlFor:"severity",children:"Severity"}),e.jsxs(Z,{value:i.severity,onValueChange:s=>c("severity",s),children:[e.jsx(ee,{children:e.jsx(se,{placeholder:"Select severity"})}),e.jsxs(ae,{children:[e.jsx(v,{value:"low",children:"Low â Minor cosmetic issue"}),e.jsx(v,{value:"medium",children:"Medium â Feature works but has issues"}),e.jsx(v,{value:"high",children:"High â Feature is broken or unusable"}),e.jsx(v,{value:"critical",children:"Critical â Data loss or security issue"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{htmlFor:"description",children:"Detailed Description *"}),e.jsx(f,{id:"description",value:i.description,onChange:s=>c("description",s.target.value),placeholder:"Describe the bug in detail...",className:"min-h-[100px] resize-y","aria-invalid":!!o.description}),o.description&&e.jsx("p",{className:"text-sm text-destructive",children:o.description})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{htmlFor:"stepsToReproduce",children:"Steps to Reproduce (Optional)"}
1),e.jsx(f,{id:"stepsToReproduce",value:i.stepsToReproduce,onChange:s=>c("stepsToReproduce",s.target.value),placeholder:`1. Go to... 22. Click on... 33. See error`,className:"min-h-[80px] resize-y"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{htmlFor:"expectedBehavior",children:"Expected Behavior (Optional)"}),e.jsx(f,{id:"expectedBehavior",value:i.expectedBehavior,onChange:s=>c("expectedBehavior",s.target.value),placeholder:"What should happen...",className:"min-h-[80px] resize-y"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{htmlFor:"actualBehavior",children:"Actual Behavior (Optional)"}),e.jsx(f,{id:"actualBehavior",value:i.actualBehavior,onChange:s=>c("actualBehavior",s.target.value),placeholder:"What actually happens...",className:"min-h-[80px] resize-y"})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(n,{className:"text-base font-medium",children:"Screenshots (Optional)"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Add screenshots to help us understand the issue better. You can drag & drop images, paste from clipboard (Ctrl+V), or click to select files."}),e.jsxs("div",{className:`border-2 border-dashed rounded-lg p-6 text-center transition-colors ${U?"border-primary bg-primary/5":"border-border hover:border-primary/50"}`,onDragOver:W,onDragLeave:G,onDrop:M,onClick:()=>R.current?.click(),children:[e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(ne,{className:"h-5 w-5"}),e.jsx(ce,{className:"h-5 w-5"}),e.jsx(de,{className:"h-5 w-5"})]}),e.jsx("div",{className:"text-sm font-medium",children:"Drop images here, paste from clipboard, or click to select"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Supports JPG, PNG, GIF, WebP up to 10MB each"})]}),e.jsx("input",{ref:R,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:s=>s.target.files&&g(s.target.files)})]}),u.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(n,{className:"text-sm font-medium",children:["Attached Screenshots (",u.length,")"]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:u.map(s=>e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"aspect-video rounded-lg overflow-hidden border bg-muted",children:e.jsx("img",{src:s.preview,alt:"Screenshot preview",className:"w-full h-full object-cover"})}),e.jsx(N,{type:"button",variant:"destructive",size:"icon",className:"absolute -top-2 -right-2 h-6 w-6 rounded-full opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>_(s.id),children:e.jsx(me,{className:"h-3 w-3"})}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground truncate",children:s.file.name})]},s.id))})]})]}),e.jsx("div",{className:"flex justify-end pt-4",children:e.jsx(N,{type:"submit",disabled:F,className:"min-w-[120px]",children:F?e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"h-4 w-4 mr-2 animate-spin"}),"Submitting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"h-4 w-4 mr-2"}),"Submit Report"]})})})]})]});return C?e.jsxs(A,{open:D,onOpenChange:j,children:[e.jsx(L,{asChild:!0,children:C}),O]}):e.jsx("div",{className:I("fixed z-50",k?"bottom-20 right-3":"bottom-6 right-6"),children:e.jsxs(A,{open:D,onOpenChange:j,children:[e.jsxs(ie,{children:[e.jsx(le,{asChild:!0,children:e.jsx(L,{asChild:!0,children:e.jsx(N,{size:"icon",className:I("rounded-full shadow-lg hover:shadow-xl transition-all duration-200 group touch-manipulation",k?"h-9 w-9":"h-8 w-8"),variant:"outline","aria-label":"Report a bug",children:e.jsx(P,{className:"h-3 w-3 group-hover:animate-pulse"})})})}),e.jsx(oe,{side:"left",sideOffset:8,children:"Report a bug"})]}),O]})})}export{Ie as BugReportButton};
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.