1import{j as e,C as t,aL as s,aX as a,aY as n,aZ as r,a_ as i,a$ as l,b0 as o,aT as c,b1 as d,b2 as m,b3 as x,b4 as u,b5 as f,b6 as h,b7 as g,b8 as p,b9 as j,aU as N,ba as b,aQ as v,v as w,aM as y,aV as T,as as C,bb as k,bc as _,bd as S,X as R,r as E}from"./ui-vendor-B6qDrwDU.js";import{a as F,u as I,j as z}from"./react-vendor-CWdWklYc.js";import{D as K}from"./DashboardLayout-DnCA3ayu.js";import{u as L,e as $,f as A,g as D,C as V,b as M,c as B,d as U,h as O,a as H,I as q,B as X,l as Y,L as Q,T as P,i as W,j as G,k as Z,S as J,m as ee,n as te,o as se,p as ae,q as ne,A as re,r as ie,s as le,t as oe}from"./index-lqK706Ou.js";import{C as ce,a as de,b as me,u as xe,g as ue,c as fe}from"./helpers-BW4r8qfI.js";import{c as he}from"./loading-overlay-DqCJoqDT.js";import{u as ge,Q as pe}from"./useUsageQuota-O583bigr.js";import"./clerk-auth.service-DFa_3oME.js";import"./clerk-vendor-D3H2MyHf.js";import"./mode-toggle-D4o8gWHn.js";import"./convex-vendor-CExL1t8U.js";const je=F.memo(function({transformationId:r,originalText:i,currentResult:l,tone:o,onRefinementComplete:c,initialOpen:d=!1,onOpened:m}){const{t:x}=L("transformation"),[u,f]=F.useState(d),[h,g]=F.useState(""),[p,j]=F.useState(!1),[N,b]=F.useState(null),v=F.useRef(null),w=$(A.refinements.refineTransformation),y=D(A.refinements.getRefinements,{transformationId:r});F.useEffect(()=>{d&&(f(!0),m?.(),setTimeout(()=>v.current?.focus(),100))},[d,m]);const T=async()=>{if(h.trim()){j(!0),b(null);try{const e=await w({transformationId:r,instruction:h.trim()});c(e.refinedText),g("")}catch(e){const t=e instanceof Error?e.message:"Failed to refine";b(t),Y.error("Refinement failed",e instanceof Error?e:void 0)}finally{j(!1)}}},C=y?.length||0;return e.jsx(V,{className:"border",children:e.jsxs(ce,{open:u,onOpenChange:f,children:[e.jsx(de,{asChild:!0,children:e.jsx(M,{className:"cursor-pointer transition-colors hover:bg-muted/50",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx(B,{className:"text-lg",children:x("refinement.historyTitle")}),e.jsx(U,{children:C>0?`${C} ${1===C?"refinement":"refinements"}`:x("refinement.placeholder")})]}),e.jsx(t,{className:O("h-5 w-5 text-muted-foreground transition-transform",u&&"rotate-180")})]})})}),e.jsx(me,{children:e.jsxs(H,{className:"space-y-4 border-t pt-4",children:[C>0&&e.jsx("div",{className:"space-y-3",children:y?.map((t,s)=>e.jsxs("div",{className:O("rounded-md border p-3",s===y.length-1&&"border-foreground"),children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-medium",children:["â",t.instruction,"â"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(t.createdAt).toLocaleTimeString()})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t.refinedText})]},t._id))}),e.jsxs("div",{className:"space-y-2",children:[N&&e.jsx("p",{className:"text-sm text-destructive",children:N}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(s,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(q,{ref:v,value:h,onChange:e=>g(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),T())},placeholder:x("refinement.placeholder"),disabled:p,className:"pl-9"})]}),e.jsx(X,{onClick:()=>{T()},disabled:p||!h.trim(),children:p?e.jsx(a,{className:"h-4 w-4 animate-spin"}):e.jsx(n,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:x("refinement.creditNote")})]})]})})]})})}),Ne={professional:g,friendly:h,casual:f,empathetic:u,concise:x,assertive:m,diplomatic:d,urgent:c,enthusiastic:o,formal:l,confident:i,neutral:r},be=F.memo(function({value:t,onChange:s,disabled:a=!1}){const{t:n}=L("transformation"),r=xe(),i=void 0===r;return F.useEffect(()=>{!t&&r&&r.length>0&&s(r[0].slug)},[t,s,r]),i?e.jsx("div",{className:"flex gap-2",children:[...Array(6)].map((t,s)=>e.jsx("div",{className:"h-10 w-28 shrink-0 animate-pulse rounded-md bg-muted"},s))}):e.jsx("div",{id:"tone-selector",className:"flex flex-wrap gap-2",children:r?.map(r=>{const i=t===r.slug,l=(c=r.slug,Ne[c]||o);var c;return e.jsxs("button",{type:"button",onClick:()=>s(r.slug),disabled:a,className:O("flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-all","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",i?"border-foreground bg-foreground text-background":"border-border bg-background text-foreground hover:border-foreground hover:shadow-sm",a&&"cursor-not-allowed opacity-50"),children:[e.jsx(l,{className:"h-4 w-4"}),e.jsx("span",{children:ue(r.slug,n)})]},r.slug)})})}),ve={briefcase:g,"message-circle":f,heart:u,sparkles:o,"file-text":x,target:m,smile:h,"shield-check":i,"graduation-cap":l,scale:r},we=t=>{if(!t)return null;const s=ve[t];return s?e.jsx(s,{className:"h-4 w-4"}):null},ye=F.memo(function({value:t,onChange:s,disabled:a=!1,showDescription:n=!1,showLabel:r=!1,showTooltip:i=!1,showAllOption:l=!1,className:o="",id:c="tone"}){const{t:d}=L("transformation"),m=xe(),x=void 0===m;F.useEffect(()=>{!t&&m&&m.length>0&&!l&&s(m[0].slug)},[t,s,l,m]);const u=m?.find(e=>e.slug===t);return e.jsxs(e.Fragment,{children:[r&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{htmlFor:c,className:"text-sm",children:d("form.targetTone")}),i&&e.jsx(P,{children:e.jsxs(W,{children:[e.jsx(G,{asChild:!0,children:e.jsx("button",{type:"button",className:"text-muted-foreground transition-colors hover:text-foreground",children:e.jsx(p,{className:"h-3.5 w-3.5"})})}),e.jsx(Z,{children:e.jsx("p",{className:"max-w-xs text-xs",children:d("form.tooltipText")})})]})})]}),e.jsxs(J,{value:t,onValueChange:s,disabled:a||x,children:[e.jsx(ee,{id:c,className:`h-9 ${o}`,children:e.jsx(te,{placeholder:d("form.selectTone"),children:"all"===t&&l?d("toneSelector.allTones",{defaultValue:"All Tones"}):u&&e.jsxs("div",{className:"flex items-center gap-2",children:[we(u.icon),e.jsx("span",{className:"text-sm",children:ue(u.slug,d)})]})})}),e.jsxs(se,{children:[l&&e.jsx(ae,{value:"all",children:d("toneSelector.allTones",{defaultValue:"All Tones"})}),m?.map(t=>e.jsx(ae,{value:t.slug,children:e.jsxs("div",{className:"flex items-center gap-2",children:[we(t.icon),e.jsx("span",{className:"text-sm",children:ue(t.slug,d)})]})},t.slug))]})]}),n&&u&&"all"!==t&&e.jsx("p",{className:"text-xs text-muted-foreground",children:fe(u.slug,d)})]})});F.memo(function({onTransform:t,isLoading:a,initialText:n="",initialTone:r="",focusRequestId:i=0,onUpgradeClick:l}){const{t:o}=L(["transformation","common"]),[c,d]=F.useState(n),[m,x]=F.useState(r),u=F.useRef(null),f=D(A.usage.getCurrentQuota),h=void 0===f,g=f?{remaining_transformations:f.remaining,limit:f.limit,character_limit:f.characterLimit,can_transform:f.canTransform,tier:f.tier}:null;F.useEffect(()=>{n&&d(n)},[n]),F.useEffect(()=>{r&&x(r)}
1,[r]),F.useEffect(()=>{i>0&&u.current&&u.current.focus()},[i]);const p=c.length,j=g?.character_limit||1e3,N=p>j,b=p/j*100,v=!!g&&("free"===g.tier||"personal"===g.tier),w=c.trim().length>0&&m&&!N&&!a&&g?.can_transform;return e.jsxs(V,{className:"border",children:[e.jsx(M,{className:"pb-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(B,{className:"text-lg",children:o("form.title")}),g&&e.jsx(U,{className:"text-xs",children:o("form.remainingUsage",{remaining:g.remaining_transformations,limit:g.limit})})]}),e.jsx(s,{className:"h-5 w-5 text-muted-foreground"})]})}),e.jsx(H,{children:e.jsxs("form",{onSubmit:e=>{(async e=>{e.preventDefault(),c.trim()&&m&&!a&&await t(c,m)})(e)},className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Q,{htmlFor:"text",className:"text-sm",children:o("form.yourText")}),e.jsx(ne,{ref:u,id:"text",placeholder:o("form.placeholder"),value:c,onChange:e=>d(e.target.value),disabled:a||h,rows:6,className:"resize-none"}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:N?"text-destructive":b>=90?"text-orange-600":b>=60?"text-yellow-600":"text-muted-foreground",children:o("form.characterCount",{count:p,limit:j})}),N&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-destructive",children:o("form.characterLimitExceeded")}),v&&l&&e.jsx(X,{size:"sm",variant:"ghost",onClick:l,children:o("usage.upgradeButton",{ns:"common"})})]})]})]}),e.jsx("div",{className:"space-y-2",children:e.jsx(ye,{value:m,onChange:x,disabled:a||h,showDescription:!0,showLabel:!0,showTooltip:!0})}),!g?.can_transform&&g&&e.jsxs("div",{className:"rounded-md border bg-muted/30 p-3 text-sm",children:[e.jsx("p",{className:"font-medium text-foreground",children:o("form.dailyLimitReached")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:o("form.upgradeMessage")}),v&&l&&e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:e.jsx(X,{size:"sm",onClick:l,children:o("usage.upgradeButton",{ns:"common"})})})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx(X,{type:"submit",disabled:!w,className:"flex-1",children:a?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"mr-2 h-4 w-4 animate-spin",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),o("form.transforming")]}):o("form.transform")}),c&&e.jsx(X,{type:"button",variant:"outline",onClick:()=>d(""),disabled:a,children:o("form.clear")})]})]})})]})});const Te=F.memo(function({value:t,onChange:s,onTransform:n,isLoading:r,disabled:i=!1,characterLimit:l,error:o}){const{t:c}=L("transformation"),d=t.length,m=d>l,x=t.trim().length>0&&!m&&!i;return e.jsxs(V,{className:"border",children:[e.jsx(M,{children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx(B,{className:"text-lg",children:c("form.title")}),e.jsx(U,{children:c("form.placeholder")})]}),e.jsx(j,{className:"h-5 w-5 text-muted-foreground"})]})}
1),e.jsxs(H,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(ne,{value:t,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"===e.key&&e.metaKey&&x&&!r&&(e.preventDefault(),n())},placeholder:c("form.placeholder"),disabled:r,rows:6,className:"resize-none"}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx("span",{className:O(m&&"text-destructive font-medium"),children:c("form.characterCount",{count:d,limit:l})}),m&&e.jsx("span",{className:"text-destructive",children:c("form.characterLimitExceeded")})]})]}),o&&e.jsxs(re,{variant:"destructive",children:[e.jsx(N,{className:"h-4 w-4"}),e.jsx(ie,{children:o})]}),e.jsx(X,{id:"transform-button",onClick:n,disabled:!x||r,className:"w-full",children:r?e.jsxs(e.Fragment,{children:[e.jsx(a,{className:"mr-2 h-4 w-4 animate-spin"}),c("form.transforming")]}):c("form.transform")})]})]})}),Ce=F.memo(function({result:t,currentText:s,onUseAsInput:a,selectedTone:n}){const{t:r}=L("transformation"),[i,l]=F.useState(!1),[c,d]=F.useState(!1),m=le(A.transformations.toggleFavorite),x=t&&s;return e.jsxs(V,{className:"border",children:[e.jsx(M,{children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx(B,{className:"text-lg",children:r("result.title")}),e.jsx(U,{children:x?`${ue(t.target_tone,r)} · ${(t.processing_time_ms/1e3).toFixed(1)}s`:r(n?"output.placeholder":"output.selectTone")})]}),e.jsx(o,{className:"h-5 w-5 text-muted-foreground"})]})}),e.jsx(H,{children:x?e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-md border bg-muted/30 p-4",children:e.jsx("p",{className:"whitespace-pre-wrap text-sm leading-relaxed",children:s})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:[s.length," ",r("result.characterCountResult",{count:s.length})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[a&&e.jsx(X,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>a(s),title:r("result.useTransformedText"),children:e.jsx(b,{className:"h-4 w-4"})}),e.jsx(X,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>{(async()=>{if(!t)return;const e=!i;try{await m({transformationId:t.id}),l(e),e?oe.favoriteAdded(t.id):oe.favoriteRemoved(t.id)}catch(s){Y.error("Failed to toggle favorite",s instanceof Error?s:void 0)}})()},title:r(i?"actions.unfavorite":"actions.favorite"),children:e.jsx(v,{className:O("h-4 w-4",i&&"fill-foreground")})}),e.jsx(X,{variant:"outline",size:"sm",className:"h-8",onClick:()=>{(async()=>{if(!s)return;await he(s)&&(d(!0),setTimeout(()=>d(!1),2e3))})()},children:c?e.jsxs(e.Fragment,{children:[e.jsx(w,{className:"mr-1.5 h-3.5 w-3.5"}),r("result.copySuccess")]}):e.jsxs(e.Fragment,{children:[e.jsx(y,{className:"mr-1.5 h-3.5 w-3.5"}),r("actions.copy")]})})]})]})]}):e.jsx("div",{className:"flex h-40 items-center justify-center rounded-md border border-dashed",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:r(n?"output.placeholder":"output.selectTone")})})})]})}),ke=F.memo(function({transformationId:n,originalText:r,currentResult:i,tone:l,onRefinementComplete:o,autoFocus:c=!1,onFocused:d}){const{t:m}=L("transformation"),[x,u]=F.useState(""),[f,h]=F.useState(!1),[g,p]=F.useState(null),[j,N]=F.useState(!1),b=F.useRef(null);F.useEffect(()=>{if(c&&b.current){const e=setTimeout(()=>{b.current?.focus(),d?.()},100);return()=>clearTimeout(e)}},[c,d]);const v=$(A.refinements.refineTransformation),w=D(A.refinements.getRefinements,{transformationId:n}),y=async()=>{if(x.trim()){h(!0),p(null);try{const e=await v({transformationId:n,instruction:x.trim()});o(e.refinedText),u("")}catch(e){const t=e instanceof Error?e.message:"Failed to refine transformation";p(t),Y.error("Refinement failed",e instanceof Error?e:void 0,{transformationId:n})}finally{h(!1)}}};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(q,{ref:b,value:x,onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),y())},placeholder:m("refinement.placeholder",{defaultValue:"How would you like to adjust this?"}),disabled:f,className:"flex-1"}),e.jsx(X,{onClick:()=>{y()},disabled:f||!x.trim(),size:"default",children:f?e.jsxs(e.Fragment,{children:[e.jsx(a,{className:"mr-2 h-4 w-4 animate-spin"}),m("refinement.refining",{defaultValue:"Refining..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(s,{className:"mr-2 h-4 w-4"}),m("refinement.refine",{defaultValue:"Refine"})]})})]}),g&&e.jsx("p",{className:"text-sm text-destructive",children:g}),w&&w.length>0&&e.jsxs("div",{children:[e.jsxs(X,{variant:"ghost",size:"sm",className:"w-full justify-between",onClick:()=>N(!j),children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"h-4 w-4"}),m("refinement.historyTitle",{defaultValue:"Refinement History"}),e.jsx("span",{className:"rounded-full bg-muted px-2 py-0.5 text-xs",children:w.length})]}),j?e.jsx(C,{className:"h-4 w-4"}):e.jsx(t,{className:"h-4 w-4"})]}),j&&e.jsx("div",{className:"mt-2 space-y-2",children:w.map(t=>
1e.jsx(V,{className:"border-muted",children:e.jsxs(H,{className:"p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:m("refinement.iteration",{defaultValue:"Iteration {{number}}",number:t.iteration})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(t.createdAt).toLocaleString()})]}),e.jsxs("p",{className:"mb-2 text-xs italic text-muted-foreground",children:["â",t.instruction,"â"]}),e.jsx("p",{className:"text-sm",children:t.refinedText})]})},t._id))})]})]})});F.memo(function({result:t,onUpdate:a,onTransformAgain:n,highlight:r=!1,initialShowRefinement:i=!1,onRefinementShown:l}){const{t:o}=L("transformation"),[c,d]=F.useState(!1),[m,x]=F.useState(null),[u,f]=F.useState(!1),[h,g]=F.useState(i),[p,j]=F.useState(i),[N,b]=F.useState(t.transformed_text);F.useEffect(()=>{i&&(g(!0),j(!0),l?.())},[i,l]);const T=le(A.transformations.toggleFavorite),C=le(A.transformations.rateTransformation),R=async e=>{try{await C({transformationId:t.id,rating:e}),x(e),a?.()}catch(s){Y.error("Failed to rate transformation",s instanceof Error?s:void 0,{id:t.id})}},E=(e=!1)=>{n&&n({text:e?N:t.original_text,tone:t.target_tone})};return e.jsxs(V,{className:"border transition-shadow "+(r?"ring-2 ring-primary/40 shadow-lg":""),children:[e.jsx(M,{className:"pb-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(B,{className:"text-lg",children:"Result"}),e.jsx("span",{className:"sr-only",children:"result-card"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Processed in ",(t.processing_time_ms/1e3).toFixed(2),"s"]})]}),e.jsx(X,{variant:"ghost",size:"icon",onClick:()=>{(async()=>{const e=!c;try{await T({transformationId:t.id}),d(e),a?.(),e?oe.favoriteAdded(t.id):oe.favoriteRemoved(t.id)}catch(s){Y.error("Failed to toggle favorite",s instanceof Error?s:void 0,{id:t.id})}})()},title:c?"Remove from favorites":"Add to favorites",className:"h-8 w-8",children:e.jsx(v,{className:"h-4 w-4 transition-colors "+(c?"fill-foreground text-foreground":"text-muted-foreground hover:text-foreground")})})]})}
1),e.jsxs(H,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"flex h-full flex-col space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground",children:"Original"}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.input_language&&e.jsx("span",{className:"rounded-md border bg-background px-1.5 py-0.5 text-xs uppercase text-muted-foreground",children:t.input_language}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[t.character_count," chars"]})]})]}),e.jsx("div",{className:"flex-1 rounded-md border bg-muted/30 p-3",children:e.jsx("p",{className:"whitespace-pre-wrap text-sm leading-relaxed",children:t.original_text})}),n&&e.jsx("div",{className:"flex items-center justify-end gap-2 pt-1",children:e.jsx(X,{variant:"ghost",size:"icon",className:"h-8 w-8",title:o("result.useOriginalText"),onClick:()=>E(!1),children:e.jsx(k,{className:"h-4 w-4"})})})]}),e.jsxs("div",{className:"flex h-full flex-col space-y-2",children:[e.jsx("div",{className:"flex items-center justify-between gap-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("h4",{className:"text-xs font-medium text-muted-foreground",children:[ue(t.target_tone,o)," ",o("result.toneLabel")]}),t.output_language&&e.jsx("span",{className:"rounded-md border bg-background px-1.5 py-0.5 text-xs uppercase text-muted-foreground",children:t.output_language})]})}),e.jsx("div",{className:"flex-1 rounded-md border bg-background p-3",children:e.jsx("p",{className:"whitespace-pre-wrap text-sm leading-relaxed",children:N})}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[n&&e.jsx(X,{variant:"ghost",size:"icon",className:"h-8 w-8",title:o("result.useTransformedText"),onClick:()=>E(!0),children:e.jsx(k,{className:"h-4 w-4"})}),e.jsxs(X,{variant:"outline",size:"sm",className:"h-8",onClick:()=>g(!h),children:[e.jsx(s,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:o("refinement.button",{defaultValue:"Refine"})})]}),e.jsx(X,{variant:"default",size:"sm",className:"h-8",onClick:()=>{(async()=>{await he(N)&&(f(!0),setTimeout(()=>f(!1),2e3))})()},disabled:u,children:u?e.jsxs(e.Fragment,{children:[e.jsx(w,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:o("messages.copied",{ns:"common"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(y,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:o("actions.copy",{ns:"common"})})]})})]})]})]}),h&&e.jsx("div",{className:"border-t pt-4",children:e.jsx(ke,{transformationId:t.id,originalText:t.original_text,currentResult:N,tone:t.target_tone,onRefinementComplete:e=>{b(e),a?.()},autoFocus:p,onFocused:()=>j(!1)})}),e.jsxs("div",{className:"flex items-center justify-center gap-3 border-t pt-3",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"How was this?"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(X,{variant:1===m?"default":"outline",size:"sm",className:"h-7",onClick:()=>{R(1)},children:[e.jsx(_,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:"Good"})]}),e.jsxs(X,{variant:-1===m?"destructive":"outline",size:"sm",className:"h-7",onClick:()=>{R(-1)},children:[e.jsx(S,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:"Needs work"})]})]})]})]})]})});const _e=[{id:"welcome",titleKey:"onboarding.welcome.title",descriptionKey:"onboarding.welcome.description",position:"center"},{id:"enter-text",titleKey:"onboarding.enterText.title",descriptionKey:"onboarding.enterText.description",targetElement:"textarea",position:"bottom"},{id:"select-tone",titleKey:"onboarding.selectTone.title",descriptionKey:"onboarding.selectTone.description",targetElement:"#tone-selector",position:"bottom"},{id:"transform",titleKey:"onboarding.transform.title",descriptionKey:"onboarding.transform.description",targetElement:"#transform-button",position:"top"},{id:"copy-result",titleKey:"onboarding.copyResult.title",descriptionKey:"onboarding.copyResult.description",position:"center"},{id:"explore",titleKey:"onboarding.explore.title",descriptionKey:"onboarding.explore.description",position:"center"}];function Se({onComplete:t,onSkip:s}){const{t:a}=L("common"),[n,r]=F.useState(0),[i,l]=F.useState(null),o=_e[n],c=n===_e.length-1,d=(n+1)/_e.length*100;F.useEffect(()=>{if(o.targetElement){const e=document.querySelector(o.targetElement);e&&(l(e),e.scrollIntoView({behavior:"smooth",block:"center"}))}else l(null);return()=>{l(null)}},[n,o.targetElement]);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm",style:{zIndex:1e4},"aria-hidden":"true"}),i&&e.jsx("div",{className:"pointer-events-none fixed",style:{zIndex:1e4,top:i.getBoundingClientRect().top-8,left:i.getBoundingClientRect().left-8,width:i.getBoundingClientRect().width+16,height:i.getBoundingClientRect().height+16,boxShadow:"0 0 0 4px rgba(59, 130, 246, 0.5), 0 0 0 9999px rgba(0, 0, 0, 0.6)",borderRadius:"8px",transition:"all 0.3s ease-in-out"},"aria-hidden":"true"}
1),e.jsxs(V,{className:"w-full max-w-md shadow-2xl",style:(()=>{if("center"===o.position||!i)return{position:"fixed",top:"50%",left:"50%",transform:"translate(-50%, -50%)",zIndex:10001,maxHeight:"calc(100vh - 32px)",overflowY:"auto"};const e=i.getBoundingClientRect(),t={position:"fixed",zIndex:10001,maxHeight:"calc(100vh - 32px)",overflowY:"auto"},s=400,a=window.innerHeight,n=a-e.bottom,r=e.top;switch(o.position){case"bottom":n<s&&r>n?(t.bottom=a-e.top+16+"px",t.left=`${e.left+e.width/2}px`,t.transform="translateX(-50%)"):(t.top=`${Math.min(e.bottom+16,a-s-16)}px`,t.left=`${e.left+e.width/2}px`,t.transform="translateX(-50%)");break;case"top":r<s&&n>r?(t.top=`${e.bottom+16}px`,t.left=`${e.left+e.width/2}px`,t.transform="translateX(-50%)"):(t.bottom=`${Math.max(a-e.top+16,16)}px`,t.left=`${e.left+e.width/2}px`,t.transform="translateX(-50%)");break;case"left":t.top=`${Math.max(16,Math.min(e.top+e.height/2,a-200-16))}px`,t.right=window.innerWidth-e.left+16+"px",t.transform="translateY(-50%)";break;case"right":t.top=`${Math.max(16,Math.min(e.top+e.height/2,a-200-16))}px`,t.left=`${e.right+16}px`,t.transform="translateY(-50%)"}return t})(),children:[e.jsx(M,{children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(B,{className:"text-xl",children:a(o.titleKey)}),e.jsx(U,{className:"mt-2",children:a(o.descriptionKey)})]}),e.jsx(X,{variant:"ghost",size:"icon",onClick:s,className:"-mt-1 ml-2","aria-label":a("onboarding.skipTutorial"),children:e.jsx(R,{className:"h-4 w-4"})})]})}
1),e.jsxs(H,{children:[e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:a("onboarding.stepProgress",{current:n+1,total:_e.length})}),e.jsxs("span",{children:[Math.round(d),"%"]})]}),e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-primary transition-all duration-300",style:{width:`${d}%`}})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[n>0?e.jsx(X,{variant:"outline",onClick:()=>{n>0&&r(e=>e-1)},className:"flex-1",children:a("onboarding.previous")}):e.jsx(X,{variant:"ghost",onClick:s,className:"flex-1",children:a("onboarding.skipTutorial")}),e.jsx(X,{onClick:()=>{c?t():r(e=>e+1)},className:"flex-1",children:c?e.jsxs(e.Fragment,{children:[e.jsx(w,{className:"mr-2 h-4 w-4"}),a("onboarding.getStarted")]}):e.jsxs(e.Fragment,{children:[a("onboarding.next"),e.jsx(E,{className:"ml-2 h-4 w-4"})]})})]}),e.jsx("div",{className:"mt-4 flex items-center justify-center gap-1.5",children:_e.map((t,s)=>e.jsx("button",{onClick:()=>r(s),className:"h-2 rounded-full transition-all "+(s===n?"w-6 bg-primary":s<n?"bg-primary/60 w-2":"w-2 bg-muted"),"aria-label":a("onboarding.goToStep",{step:s+1,title:a(t.titleKey)}),"aria-current":s===n?"step":void 0},t.id))})]})]})]})}const Re="tonesmith-tutorial-completed";function Ee(){const{t:t}=L(["transformation","common"]),s=I(),a=z(),[n,r]=F.useState(null),[i,l]=F.useState(null),o=ge(),c=void 0===o,[d,m]=F.useState(""),[x,u]=F.useState(""),[f,h]=F.useState(!1),[g,p]=F.useState(!1),[j,N]=F.useState(!1),[b,v]=F.useState(""),w=F.useRef(null),{runTransformation:y}=function(){const e=$(A.transformations.transformTone);return{runTransformation:async t=>{try{const s=Y.generateCorrelationId();Y.info("Creating transformation",{target_tone:t.target_tone,character_count:t.original_text.length,correlation_id:s});const a=await e({originalText:t.original_text,targetTone:t.target_tone,userLanguage:t.user_language});return Y.info("Transformation successful",{correlation_id:s}),{success:!0,data:{id:a.id,original_text:a.originalText,transformed_text:a.transformedText,target_tone:a.targetTone,character_count:a.characterCount,processing_time_ms:a.processingTimeMs,input_language:a.inputLanguage,output_language:a.outputLanguage,quota:a.quota}}}catch(i){const t=i instanceof Error?i.message:"Failed to transform text";return Y.error("Transformation failed",i instanceof Error?i:void 0,{error:t}),{success:!1,error:t}}}}}();F.useEffect(()=>{if(!localStorage.getItem(Re)){const e=setTimeout(()=>h(!0),500);return()=>clearTimeout(e)}},[]),F.useEffect(()=>{const e=s.state;(e?.originalText||e?.targetTone||e?.transformationResult||e?.showRefinement)&&(e.originalText&&u(e.originalText),e.targetTone&&m(e.targetTone),e.transformationResult&&(r(e.transformationResult),v(e.transformationResult.transformed_text)),e.showRefinement&&N(!0),a(s.pathname,{replace:!0,state:null}))},[s.state,a,s.pathname]),F.useEffect(()=>{n&&v(n.transformed_text)},[n]);const T=F.useCallback(async()=>{if(!x.trim()||!d||g)return;const e={original_text:x,target_tone:d};l(null),p(!0);try{const t=await y(e);t.success&&t.data?(r(t.data),v(t.data.transformed_text),oe.transformationCompleted(t.data.target_tone,t.data.character_count,t.data.processing_time_ms),setTimeout(()=>{w.current?.scrollIntoView({behavior:"smooth",block:"center"})},100)):(l(t.error||"Failed to transform text"),oe.transformationFailed(d,t.error||"Failed"))}catch(t){const e=t instanceof Error?t.message:"Failed to transform text";l(e),oe.transformationFailed(d,e)}finally{p(!1)}},[x,d,g,y]),C=F.useCallback(()=>a("/upgrade"),[a]),k=F.useCallback(()=>{localStorage.setItem(Re,"true"),h(!1)},[]),_=F.useCallback(e=>v(e),[]),S=F.useCallback(e=>u(e),[]),R=F.useCallback(()=>N(!1),[]),E=o?.character_limit||1e3;return e.jsxs(K,{children:[f&&e.jsx(Se,{onComplete:k,onSkip:k}),e.jsxs("div",{className:"mx-auto w-full max-w-5xl space-y-6",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:t("page.title")}),!c&&o&&e.jsx("p",{className:"text-sm text-muted-foreground",children:t("form.remainingUsage",{remaining:o.remaining_transformations,limit:o.limit})})]}),e.jsx(pe,{quota:o,onUpgrade:C}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-sm font-medium",children:t("form.targetTone")}),e.jsx(be,{value:d,onChange:m,disabled:g})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(Te,{value:x,onChange:u,onTransform:T,isLoading:g,disabled:!d||c||o&&!o.can_transform,characterLimit:E,error:i,selectedTone:d}),e.jsx("div",{ref:w,children:e.jsx(Ce,{result:n,currentText:b,onUseAsInput:S,selectedTone:d})})]}),n&&e.jsx(je,{transformationId:n.id,originalText:n.original_text,currentResult:b,tone:n.target_tone,onRefinementComplete:_,initialOpen:j,onOpened:R})]})]})}export{Ee as TransformPage}; 2//# sourceMappingURL=TransformPage-CWr-Ewng.js.map
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.