import{d as e}from"./objectSpread2-DtFdQpqy.js";import{a as t,n}from"./preload-helper-EQ20WQt-.js";import{c as r,l as i,o as a}from"./prop-types-DdDwMzX7.js";import{ft as o}from"./poll-D7UTo6nN.js";import{Do as s,Eo as c,Jt as l,ja as u}from"./time-BE5vfriQ.js";import"./modal_container-BxVy7jyR.js";import{E as d}from"./compose_form_container-CpVH13U8.js";import{p as f}from"./form_fields-BFfmILJg.js";import{t as p}from"./callout-DN5SLZLr.js";import{t as m}from"./styles.module-DaF9IQcd.js";var h=e(t()),g=n(),_=r({newTitle:{id:`account.node_modal.title`,defaultMessage:`Add a personal note`},editTitle:{id:`account.node_modal.edit_title`,defaultMessage:`Edit personal note`},save:{id:`account.node_modal.save`,defaultMessage:`Save`},fieldLabel:{id:`account.node_modal.field_label`,defaultMessage:`Personal Note`},errorUnknown:{id:`account.node_modal.error_unknown`,defaultMessage:`Could not save the note`}}),v=({accountId:e,onClose:t})=>{let n=s(t=>t.relationships.get(e)),r=c();return(0,h.useEffect)(()=>{n||r(u([e]))},[e,r,n]),n?(0,g.jsx)(y,{relationship:n,accountId:e,onClose:t}):(0,g.jsx)(o,{})},y=({relationship:e,accountId:t,onClose:n})=>{let r=e.note,[o,s]=(0,h.useState)(r),[u,v]=(0,h.useState)(``),[y,b]=(0,h.useState)(`idle`),x=o!==r,S=(0,h.useCallback)(e=>{y!==`saving`&&s(e.target.value)},[y]),C=i(),w=(0,h.useRef)(new AbortController),T=c(),E=(0,h.useCallback)(()=>{y===`saving`||!x||(b(`saving`),T(l({accountId:t,note:o},{signal:w.current.signal})).then(()=>{b(`idle`),n()}).catch(e=>{b(`error`),e instanceof Error?v(e.message):v(C.formatMessage(_.errorUnknown))}))},[t,T,C,x,o,n,y]),D=(0,h.useCallback)(()=>{w.current.abort(),n()},[n]);return(0,g.jsx)(d,{title:r?C.formatMessage(_.editTitle):C.formatMessage(_.newTitle),extraContent:(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(p,{className:m.noteCallout,children:(0,g.jsx)(a,{id:`account.node_modal.callout`,defaultMessage:`Personal notes are visible only to you.`})}),(0,g.jsx)(f,{value:o,onChange:S,label:C.formatMessage(_.fieldLabel),className:m.noteInput,status:y===`error`?{variant:`error`,message:u}:void 0,autoFocus:!0})]}),onClose:D,confirm:C.formatMessage(_.save),onConfirm:E,updating:y===`saving`,disabled:!x,noCloseOnConfirm:!0,noFocusButton:!0})};export{v as AccountNoteModal};
//# sourceMappingURL=note_modal-BqJaXy57.js.map