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