import{__assign as o}from'./../../ext-esm/tslib/tslib.es6.js';import{jsxs as n,jsx as i,Fragment as t}from"react/jsx-runtime";import{Grid as e,TextField as s,Box as r}from"@material-ui/core";import{noop as a,isEmpty as c,trim as d}from"lodash";import{useState as l,useEffect as m}from"react";import{CheckSmallIcon as u,CloseSmallIcon as p,WriteIcon as g,DeleteFourIcon as f}from"../../icons/iconParkIcons.js";import"../../icons/customIcons/icons/AddMessage.js";import"../../icons/customIcons/icons/Attention.js";import"../../icons/customIcons/icons/Collapse.js";import"../../icons/customIcons/icons/Dashboard.js";import"../../icons/customIcons/icons/Expand.js";import"../../icons/customIcons/icons/FolderClosed.js";import"../../icons/customIcons/icons/FolderClosedFilled.js";import"../../icons/customIcons/icons/FolderOpened.js";import"../../icons/customIcons/icons/GreaterOrEqual.js";import"../../icons/customIcons/icons/LessOrEqual.js";import"../../icons/customIcons/icons/Search.js";import"../../icons/customIcons/icons/Wellhub.js";import"../../icons/customIcons/icons/MultiRuler.js";import"../../icons/customIcons/icons/Checkbox.js";import"../../icons/customIcons/icons/CheckboxChecked.js";import"../../icons/customIcons/icons/CheckboxIndeterminate.js";import"../../icons/customIcons/icons/Radio.js";import"../../icons/customIcons/icons/RadioChecked.js";import"../../icons/customIcons/icons/SimulFrac.js";import"../../icons/customIcons/icons/ZipperFrac.js";import"../../icons/customIcons/icons/CautionFilled.js";import"../../icons/customIcons/icons/MoreApp.js";import I from"../IconButton/index.js";import{GradientPicker as v}from"../GradientPicker/GradientPicker.js";import{DEFAULT_GRADIENTS as h,DEFAULT_GRADIENT_STOPS as j,TEMP_GRADIENT_ID as S,GRADIENT_MAX_NAME_LENGTH as C}from"./configuration/constants.js";import{GradientList as b}from"./GradientList.js";import{GradientSelect as k}from"./GradientSelect.js";import{useStyles as G}from"./GradientManager.styles.js";var x=function(x){var y,F=x.gradientId,B=x.onGradientEditStateChange,N=void 0===B?a:B,P=x.onChange,w=void 0===P?a:P,E=x.defaultGradients,M=void 0===E?h:E,A=x.defaultGradientStops,D=void 0===A?j:A,L=x.allowNoname,O=x.scaleOptions,R=void 0===O?{scaleFrom:0,scaleTo:100}:O,T=x.className,q=G(),W=new b(x.gradients||[],M,x.onGradientsChange),H=l(null),K=H[0],U=H[1],V=x.disableGradientsManagement||!x.onGradientsChange,Z=W.getHelperText({name:null==K?void 0:K.name,allowNoname:L,gradientId:F});m((function(){N(Boolean(K))}),[Boolean(K)]);var _=(null===(y=W.getById(F))||void 0===y?void 0:y.gradientStops)||x.gradientStops||D,z=function(){if(c(Z)){var o=K.gradientStops,n=d(K.name);if(U(null),n){if(W.getById(K.id||F))return W.update(F,{gradientStops:o,name:n}),void w({gradientId:F,gradientStops:o});var i=W.add(n,o);w({gradientId:null==i?void 0:i.id,gradientStops:o})}else L&&w({gradientStops:o,gradientId:null})}},J=function(o){o===F&&(w({gradientId:null,gradientStops:_}),U(null)),W.remove(o)},Q=function(n){var i=n.trimStart().substring(0,C);U(o(o({},K),{name:i}))};return n(e,o({container:!0,className:T},{children:[i(e,o({item:!0,xs:6},{children:K?i(s,o({InputLabelProps:{shrink:!0},className:q.customGradientName,label:"Gradient Name",value:K.name,onChange:function(o){return Q(o.target.value)},onFocus:function(o){o.target.select()},onKeyDown:function(o){var n;if("Enter"===o.key){var i=null===(n=o.target)||void 0===n?void 0:n.value;i&&(Q(i),z())}},autoFocus:!0,fullWidth:!0},Z)):i(k,{value:F,gradients:x.gradients||[],onChange:function(o){var n,i=W.getById(o);w({gradientId:o,gradientStops:null!==(n=null==i?void 0:i.gradientStops)&&void 0!==n?n:D})},defaultGradients:M,onAction:function(o,n){switch(o){case"add":U({name:"",gradientStops:D,id:S});break;case"delete":J(n)}},readonly:V})})),i(e,o({item:!0,xs:6},{children:i(r,o({display:"flex",alignItems:"center",height:"100%"},{children:i(r,o({display:"flex",paddingLeft:1},{children:n(t,K?{children:[i(I,o({"data-testid":"save-gradient-btn",onClick:z,tooltipProps:{title:"Save"},disabled:!!Z||V},{children:i(u,{})})),i(I,o({"data-testid":"cancel-edit-btn",onClick:function(){U(null)},tooltipProps:{title:"Cancel"}},{children:i(p,{})}))]}:{children:[i(I,o({"data-testid":"edit-gradient-btn",onClick:function(){var o;W.isDefault(F)?U({name:W.newName(),gradientStops:_,id:S}):U({name:(null===(o=W.getById(F))||void 0===o?void 0:o.name)||"",gradientStops:_})},tooltipProps:{title:"Edit"},disabled:V},{children:i(g,{})})),!!W.getById(F)&&!W.isDefault(F)&&i(I,o({"data-testid":"delete-gradient-btn",onClick:function(){return J(F)},tooltipProps:{title:"Remove"},disabled:V},{children:i(f,{})}))]})}))}))})),i(e,o({item:!0,xs:12},{children:i(v,{from:null==R?void 0:R.scaleFrom,to:null==R?void 0:R.scaleTo,unit:null==R?void 0:R.scaleUnit,noScale:!0,gradientStops:(null==K?void 0:K.gradientStops)||_,onChange:function(n){U(o(o({},K),{gradientStops:n}))},readonly:!K,isMoveInputVisible:!0})}))]}))};export{x as GradientManager};
