"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),i=require("react/jsx-runtime"),t=require("../../molecules/Sections/SectionWrapper.js"),n=require("../../atoms/Textarea/Textarea.js"),s=require("../../_svg/ButtonCognitiveIcon.js"),r=require("react"),l=require("lucide-react");exports.TextSection=function(o){var a=o.rows,d=o.value,c=o.errorMessage,g=o.onChange,p=o.placeholder,u=o.title,x=o.isHighlighted,h=o.isOpen,f=o.readOnly,_=o.showCognitiveIcon,y=o.onToggle,m=o.tooltipDescription,v=o.enableInlineEdit,j=o.setSendMessageInChat,C=o.isAiStreaming,I=o.fieldName,w=o.id,E=o.activeEditId,b=o.setActiveEditId,S=o.pendingEditId;o.setPendingEditId;var T=e.__rest(o,["rows","value","errorMessage","onChange","placeholder","title","isHighlighted","isOpen","readOnly","showCognitiveIcon","onToggle","tooltipDescription","enableInlineEdit","setSendMessageInChat","isAiStreaming","fieldName","id","activeEditId","setActiveEditId","pendingEditId","setPendingEditId"]),k=r.useState(null),O=k[0],A=k[1],q=r.useState(!1),M=q[0],z=q[1],D=r.useRef(C);r.useEffect(function(){D.current&&!C&&M&&z(!1),D.current=C},[C,M]);var R=null!==O,W=!!E&&E!==w&&v,P=(null==O?void 0:O.trim())||"",N=P===((null==d?void 0:d.trim())||"")||null!==O&&""===P,B=f||C||v&&!R,H=i.jsx("div",e.__assign({style:{display:"flex",alignItems:"center",width:"100%",justifyContent:"space-between"}},{children:i.jsx("span",{children:u})})),F={display:"flex",alignItems:"center",justifyContent:"center",padding:"8px",border:"1px solid #e5e7eb",borderRadius:"8px",cursor:"pointer",width:"36px",height:"36px",backgroundColor:"#ffffff"},L={cursor:N?"not-allowed":"pointer",opacity:N?.5:1};return i.jsxs(t.SectionWrapper,e.__assign({},T,{readOnly:f,title:H,customStyles:{margin:"0 0.2rem 0.2rem 0.2rem"}},{children:[i.jsxs("div",e.__assign({className:"textarea-wrapper",style:{display:"flex",alignItems:"flex-start",gap:"8px",width:"100%"},"data-edit-id":w},{children:[i.jsx("div",e.__assign({style:{flex:1,minWidth:0}},{children:i.jsx(n.Textarea,{cognitiveIcon:i.jsx(s.ButtonCognitiveIcon,{}),rows:a,placeholder:p,value:R?O:d,onChange:function(e){R?A(e.target.value):g&&g(e.target.value)},isHighlighted:x,isOpen:h,isReadOnly:f||C,inputReadOnly:B,onToggle:y,showCognitiveIcon:_,tooltipDescription:m,errorMessage:c})})),v&&!f&&i.jsx("div",e.__assign({style:{display:"flex",flexDirection:"row",gap:"8px",marginTop:"0px"}},{children:R?i.jsxs(i.Fragment,{children:[i.jsxs("button",e.__assign({title:"Apply",onClick:function(){if(null!==O){if(O===(null!=d?d:""))return A(null),void(b&&b(null));if(j){var e="sk-".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,8)),i=I||"Description",t=O&&""!==O.trim()?"Update ".concat(i," with ").concat(O):"Remove ".concat(i);z(!0),j("__SKELETON__:".concat(e,":").concat(t))}A(null),b&&b(null)}},disabled:N,style:e.__assign(e.__assign(e.__assign({},F),L),{backgroundColor:"#2563EB",color:"white",width:"auto",padding:"8px 12px"})},{children:[i.jsx(l.Check,{size:20,strokeWidth:2.5})," Apply"]})),i.jsx("button",e.__assign({title:"Cancel",onClick:function(){A(null),b&&b(null)},style:e.__assign(e.__assign({},F),{borderColor:"#E3E8E9",color:"#dc2626"})},{children:i.jsx(l.X,{size:20,strokeWidth:2.5})}))]}):i.jsx("button",e.__assign({title:W?"Save active edits first":"Edit",onClick:function(){E&&E!==w||(b&&b(w),A(null!=d?d:""))},disabled:C||W,style:e.__assign(e.__assign({},F),{color:"#6b7280",cursor:C||W?"not-allowed":"pointer",opacity:C||W?.5:1})},{children:i.jsx(l.Pencil,{size:20})}))}))]})),S===w&&R&&i.jsxs("div",e.__assign({style:{display:"flex",alignItems:"center",gap:"6px",marginTop:"10px"}},{children:[i.jsx(l.AlertTriangle,{size:14,style:{color:"#C2410C"}}),i.jsx("div",e.__assign({style:{color:"#C2410C",fontSize:"13px"}},{children:"Pending - Changes not applied yet. Apply or discard them to continue."}))]})),M&&C&&v&&i.jsxs(i.Fragment,{children:[i.jsx("style",{children:"\n    @keyframes spin {\n      from { transform: rotate(0deg); }\n      to { transform: rotate(360deg); }\n    }\n  "}),i.jsxs("div",e.__assign({style:{display:"flex",alignItems:"center",justifyContent:"flex-start",padding:"4px 0 12px 12px",color:"#141414ff",fontSize:"13px",fontWeight:500,fontStyle:"italic",marginTop:"8px"}},{children:[i.jsx(l.Loader2Icon,{style:{marginRight:8,animation:"spin 1s linear infinite"}}),"Checking the correctness of your ",I||"description","..."]}))]})]}))};
//# sourceMappingURL=TextSection.js.map
