import{a as N,r as o}from"./vendor-react-Dvs43sk9.js";import{j as e,I as w,bi as G,Q as U,bE as H,O as Q,P as $,ai as J,o as Y,M as Z,W as s,z as V,ak as d,a6 as ee,bF as se,aj as te,F as ne,bG as ae}from"./vendor-mui-core-CnXrAOs3.js";import{p as re}from"./vendor-ux-IiQnod3w.js";import{R as le}from"./required-BGaDOGrj.js";import{F as oe}from"./form-wrapper-C8oo_Fdy.js";import{e as ie}from"./edit.svg-DycWG9v3.js";function B({triggers:l=[],onEnterEdit:n,disabled:p}){const a=N.useRef(null),[h,c]=N.useState(!1),k=r=>{c(!1),r()},C=()=>{c(r=>!r)},i=r=>{a.current&&a.current.contains(r.target)||c(!1)};return l.length===0?e.jsx(w,{"data-cy":"schema-form-item-edit",onClick:n,disabled:p,size:"large",children:e.jsx(ie,{})}):e.jsxs(e.Fragment,{children:[e.jsx(G,{variant:"outlined",ref:a,"aria-label":"split button",children:e.jsx(U,{size:"large","aria-controls":h?"split-button-menu":void 0,"aria-expanded":h?"true":void 0,sx:{paddingLeft:"12px",paddingRight:"12px"},onClick:C,children:e.jsx(H,{})})}),e.jsx(Q,{sx:{zIndex:9999},open:h,anchorEl:a.current,role:void 0,placement:"bottom-end",children:e.jsx($,{children:e.jsx(J,{onClickAway:i,children:e.jsx(Y,{id:"split-button-menu",autoFocusItem:!0,children:l.map(r=>e.jsx(Z,{onClick:()=>k(r.handler),children:r.title},r.key))})})})})]})}B.propTypes={triggers:s.arrayOf(s.shape({key:s.string.isRequired,title:s.string.isRequired,handler:s.func.isRequired})),onEnterEdit:s.func.isRequired,disabled:s.bool.isRequired};const L=(l,n,p)=>l===null&&n&&p?"******":l?n?"******":l:"",ce=ae`
  0%, 100% {
    transform: scale(1) translateX(0);
  }
  50% {
    transform: scale(1.05) translateX(-3px);
  }
  25%, 75% {
    transform: scale(1.1) translateX(3px);
  }
`;function ue({label:l="",disabled:n=!1,required:p=!1,initialValue:a="",onChange:h=()=>{},placeholder:c="",style:k={},onSubmit:C=()=>{},secure:i=!1,type:r="",triggers:I=[],formatterBeforeSubmit:q=null,directEditing:x=!1,autoFocus:D=!0,errorTips:F="",...P}){const[z,b]=o.useState(x),[g,E]=o.useState(!1),{t:O}=o.useContext(re),[f,T]=o.useState(i&&a==="__encrypted__"?null:a),[u,m]=o.useState(f),[j,y]=o.useState(!1),[v,_]=o.useState(!1),S=async()=>{E(!0);try{if(await C(u)===!1)m(f);else{let R=u;typeof q=="function"&&(R=q(u)),m(R),T(R),y(!1)}}catch{m(f)}finally{E(!1),b(!1)}};o.useEffect(()=>{const t=i&&a==="__encrypted__"?null:a;t!==f&&(T(t),m(t),y(!1))},[a,i,f]);const A=t=>{y(t!==u),m(t),h(t)},K=t=>{t.key==="Enter"&&S()},M=o.useCallback(()=>{_(!0),setTimeout(()=>{_(!1)},500)},[]),W=()=>{if(x&&!n&&!g){S();return}j&&M(),!j&&!n&&!g&&(b(!1),y(!1))},X=z||x?e.jsx(V,{style:{flex:1},fullWidth:!0,value:u,onChange:t=>{A(t.target.value)},autoFocus:D,size:"small",variant:"outlined",placeholder:c,onKeyDown:K,onBlur:W,disabled:n,error:!!F,multiline:r==="textarea",type:i?"password":r||"text",...P}):e.jsx(d,{"data-cy":"schema-form-item-edit",className:"form-item-input slot",style:{whiteSpace:"pre-wrap",cursor:"text"},onClick:()=>{n||b(!0)},sx:{px:1},children:L(u,i,a)?L(u,i,a):e.jsx("span",{className:"placeholder",children:O("common.requiredInputPlaceholder",{name:c||l})})});return e.jsx(oe,{className:"form",style:k,children:e.jsxs(d,{children:[e.jsxs(d,{className:"form-item-label",children:[l,p&&e.jsx(le,{})]}),e.jsxs(d,{className:"form-item-body",style:{alignItems:"flex-start"},children:[e.jsx(d,{className:"form-item-input",children:X}),e.jsx(d,{className:"form-item-action",style:{marginLeft:!I.length||x?0:12},children:z&&!x?e.jsxs(e.Fragment,{children:[j?e.jsx(w,{"data-cy":"schema-form-item-confirm",onClick:S,disabled:n||g||!j,sx:{animation:v?`${ce} 0.5s linear`:"none"},style:{paddingRight:4},size:"large",children:g?e.jsx(ee,{size:24}):e.jsx(se,{})}):null,e.jsx(w,{"data-cy":"schema-form-item-cancel",onClick:()=>{m(f),b(!1),y(!1)},style:{paddingLeft:j?4:8},disabled:n||g,size:"large",children:e.jsx(te,{})})]}):e.jsx(d,{children:I.length?e.jsx(B,{triggers:I,disabled:n}):null})})]}),F&&e.jsx(ne,{error:!0,children:F})]})})}ue.propTypes={style:s.object,onSubmit:s.func,onChange:s.func,label:s.string,initialValue:s.string,placeholder:s.string,required:s.bool,disabled:s.bool,secure:s.bool,triggers:s.array,formatterBeforeSubmit:s.func,directEditing:s.bool,type:s.string,autoFocus:s.bool,errorTips:s.string};export{ue as F,B as I};
