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