import{a as L,r as l}from"./vendor-react-CTtPmzVP.js";import{j as e,I as q,bV as U,Q,cG as $,O as J,P as V,ai as Y,o as Z,M as ee,W as t,z as te,ak as d,a6 as se,by as ne,aj as ae,F as re,cH as le}from"./vendor-mui-core-DnR6WYuU.js";import{b2 as oe}from"./vendor-ux-DMZIE6wA.js";import{R as ie}from"./required-BQln5OcV.js";import{F as ce}from"./form-wrapper-PT5ZzMQy.js";import{e as ue}from"./edit.svg-RRSklUg-.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(U,{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(V,{children:e.jsx(Y,{onClickAway:i,children:e.jsx(Z,{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:S=[],formatterBeforeSubmit:z=null,directEditing:x=!1,autoFocus:M=!0,errorTips:F="",...b}){const[E,k]=l.useState(x),[g,T]=l.useState(!1),{t:O}=l.useContext(oe),[_,D]=l.useState(""),[f,N]=l.useState(i&&a==="__encrypted__"?null:a),[c,m]=l.useState(f),[y,j]=l.useState(!1),[A,v]=l.useState(!1),R=async()=>{if(b.validate&&typeof b.validate=="function"){const s=b.validate(c);if(s){D(s);return}}D(""),T(!0);try{if(await I(c)===!1)m(f);else{let w=c;typeof z=="function"&&(w=z(c)),m(w),N(w),j(!1)}}catch{m(f)}finally{T(!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)},W=s=>{s.key==="Enter"&&R()},X=l.useCallback(()=>{v(!0),setTimeout(()=>{v(!1)},500)},[]),G=()=>{if(x&&!n&&!g){R();return}y&&X(),!y&&!n&&!g&&(k(!1),j(!1))},H=E||x?e.jsx(te,{style:{flex:1},fullWidth:!0,value:c,onChange:s=>{K(s.target.value)},autoFocus:M,size:"small",variant:"outlined",placeholder:u,onKeyDown:W,onBlur:G,disabled:n,error:!!F,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:O("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:H}),e.jsx(d,{className:"form-item-action",style:{marginLeft:!S.length||x?0:12},children:E&&!x?e.jsxs(e.Fragment,{children:[y?e.jsx(q,{"data-cy":"schema-form-item-confirm",onClick:R,disabled:n||g||!y,sx:{animation:A?`${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:S.length?e.jsx(P,{triggers:S,disabled:n}):null})})]}),(F||_)&&e.jsx(re,{error:!0,children:F||_})]})})}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};
