import{r as i,j as t}from"./query-Bw69rE6b.js";import{c as d,p as R,C as I,X as P}from"./index-CoUu6FiM.js";import{P as q}from"./pencil-ByuKsEO5.js";function T({value:s,onSave:w,emptyLabel:E="Click to add description",multiline:a=!1,placeholder:N="",className:p,readOnly:n,italicEmpty:C,actions:D}){const[f,r]=i.useState(!1),[m,c]=i.useState(s??""),[o,b]=i.useState(!1),[g,l]=i.useState(null),u=i.useRef(null);i.useEffect(()=>{c(s??"")},[s]),i.useEffect(()=>{f&&requestAnimationFrame(()=>{u.current?.focus();const e=u.current;e&&"value"in e&&e.setSelectionRange(e.value.length,e.value.length)})},[f]);const h=(m??"").trim(),S=(s??"").trim(),v=h!==S;function y(){n||(c(s??""),l(null),r(!0))}function k(){c(s??""),l(null),r(!1)}async function x(){if(!v){r(!1);return}b(!0),l(null);try{await w(h),r(!1)}catch(e){l(e instanceof Error?e.message:"Save failed.")}finally{b(!1)}}function z(e){e.key==="Escape"?(e.preventDefault(),k()):(e.key==="Enter"&&(e.metaKey||e.ctrlKey)||e.key==="Enter"&&!a)&&(e.preventDefault(),x())}if(f){const e=a?"textarea":"input";return t.jsxs("div",{className:d("flex flex-col gap-1.5",p),children:[t.jsx(e,{ref:u,value:m,onChange:K=>c(K.target.value),onKeyDown:z,placeholder:N,disabled:o,rows:a?3:void 0,className:d("w-full rounded-md border border-accent bg-surface-raised px-2.5 py-1.5 text-sm text-ink","focus:outline-none focus:ring-2 focus:ring-accent/30","disabled:cursor-not-allowed disabled:opacity-60",a&&"resize-y min-h-[64px]")}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("button",{type:"button",onClick:x,disabled:o||!v,className:"inline-flex h-7 items-center gap-1.5 rounded-md bg-accent px-2.5 text-xs font-medium text-white shadow-xs transition hover:bg-accent-ink disabled:cursor-not-allowed disabled:opacity-50",children:[o?t.jsx(R,{size:11,className:"animate-spin"}):t.jsx(I,{size:11}),"Save"]}),t.jsxs("button",{type:"button",onClick:k,disabled:o,className:"inline-flex h-7 items-center gap-1.5 rounded-md border border-border bg-surface-raised px-2.5 text-xs text-ink-muted transition hover:bg-surface-subtle hover:text-ink disabled:cursor-not-allowed disabled:opacity-50",children:[t.jsx(P,{size:11}),"Cancel"]}),t.jsx("span",{className:"ml-1 text-[10px] text-ink-dim",children:a?"⌘↵ save · esc cancel":"↵ save · esc cancel"})]}),g&&t.jsx("p",{className:"text-xs text-critical",children:g})]})}const j=!s||!s.trim();return t.jsxs("div",{className:d("group inline-flex max-w-full items-start gap-1.5",!n&&"cursor-text",p),onClick:y,role:n?void 0:"button",tabIndex:n?void 0:0,onKeyDown:e=>{n||(e.key==="Enter"||e.key===" ")&&(e.preventDefault(),y())},children:[t.jsx("span",{className:d("min-w-0 flex-1 whitespace-pre-wrap break-words",j&&C?"italic text-ink-dim":"text-ink"),children:j?E:s}),!n&&t.jsxs("span",{className:"mt-0.5 inline-flex items-center gap-1 opacity-0 transition-opacity duration-fast group-hover:opacity-100 focus-visible:opacity-100",children:[D,t.jsx(q,{size:11,className:"text-ink-dim"})]})]})}export{T as I};
