"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/toConsumableArray"),t=require("@babel/runtime/helpers/classCallCheck"),r=require("@babel/runtime/helpers/createClass"),n=require("@babel/runtime/helpers/defineProperty"),a=require("lodash"),i=require("./configuration/constants.js");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=o(e),s=o(t),d=o(r),l=o(n);function c(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function f(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?c(Object(r),!0).forEach((function(t){l.default(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):c(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var h=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=arguments.length>2?arguments[2]:void 0;s.default(this,e),l.default(this,"gradients",void 0),l.default(this,"defaultGradients",void 0),l.default(this,"onGradientsChange",void 0),this.gradients=t,this.defaultGradients=r,this.onGradientsChange=n}return d.default(e,[{key:"generateId",value:function(e){for(var t=new Set(a.map([].concat(u.default(this.gradients),u.default(this.defaultGradients)),"id")),r=a.snakeCase(e),n=0;t.has(r+(n?"_".concat(n):""));)n+=1;return r+(n?"_".concat(n):"")}},{key:"getById",value:function(e){return a.find(this.gradients,{id:e})||a.find(this.defaultGradients,{id:e})}},{key:"getByName",value:function(e){var t=(e||"").toLocaleLowerCase();return a.find([].concat(u.default(this.gradients),u.default(this.defaultGradients)),(function(e){return e.name.toLocaleLowerCase()===t}))}},{key:"newName",value:function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:i.GRADIENT_NEW_NAME,t=0;this.getByName(e+(t?" ".concat(t):""));)t+=1;return e+(t?" ".concat(t):"")}},{key:"isDefault",value:function(e){return a.some(this.defaultGradients,{id:e})}},{key:"getHelperText",value:function(e){var t=e.name,r=e.allowNoname,n=e.gradientId;if(!r&&!t)return{error:!1,helperText:i.NAME_IS_MISSING_MESSAGE};var a=this.getByName(t);return a&&a.id!==n?{error:!0,helperText:i.ALREADY_EXISTS_MESSAGE}:null}},{key:"add",value:function(e,t){if(!e)throw new Error(i.NAME_IS_MISSING_MESSAGE);if(this.gradients.map((function(e){return e.name.toLocaleLowerCase()})).includes(e.toLocaleLowerCase()))throw new Error(i.ALREADY_EXISTS_MESSAGE);var r={id:this.generateId(e),name:e,gradientStops:t};return this.onGradientsChange([].concat(u.default(this.gradients),[r])),r}},{key:"remove",value:function(e){var t=a.reject(this.gradients,{id:e});return this.onGradientsChange(t),t}},{key:"update",value:function(e,t){var r=this.gradients.map((function(r){return r.id===e?f(f({},r),t):r}));return this.onGradientsChange(r),r}}]),e}();exports.GradientList=h;
//# sourceMappingURL=GradientList.js.map
