"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require('./../../ext-esm/tslib/tslib.es6.js'),t=require("lodash"),r=require("./configuration/constants.js"),n=function(){function n(e,t,r){void 0===e&&(e=[]),void 0===t&&(t=[]),this.gradients=e,this.defaultGradients=t,this.onGradientsChange=r}return n.prototype.generateId=function(r){for(var n=new Set(t.map(e.__spreadArray(e.__spreadArray([],this.gradients,!0),this.defaultGradients,!0),"id")),a=t.snakeCase(r),i=0;n.has(a+(i?"_".concat(i):""));)i+=1;return a+(i?"_".concat(i):"")},n.prototype.getById=function(e){return t.find(this.gradients,{id:e})||t.find(this.defaultGradients,{id:e})},n.prototype.getByName=function(r){var n=(r||"").toLocaleLowerCase();return t.find(e.__spreadArray(e.__spreadArray([],this.gradients,!0),this.defaultGradients,!0),(function(e){return e.name.toLocaleLowerCase()===n}))},n.prototype.newName=function(e){void 0===e&&(e=r.GRADIENT_NEW_NAME);for(var t=0;this.getByName(e+(t?" ".concat(t):""));)t+=1;return e+(t?" ".concat(t):"")},n.prototype.isDefault=function(e){return t.some(this.defaultGradients,{id:e})},n.prototype.getHelperText=function(e){var t=e.name,n=e.allowNoname,a=e.gradientId;if(!n&&!t)return{error:!1,helperText:r.NAME_IS_MISSING_MESSAGE};var i=this.getByName(t);return i&&i.id!==a?{error:!0,helperText:r.ALREADY_EXISTS_MESSAGE}:null},n.prototype.add=function(t,n){if(!t)throw new Error(r.NAME_IS_MISSING_MESSAGE);if(this.gradients.map((function(e){return e.name.toLocaleLowerCase()})).includes(t.toLocaleLowerCase()))throw new Error(r.ALREADY_EXISTS_MESSAGE);var a={id:this.generateId(t),name:t,gradientStops:n};return this.onGradientsChange(e.__spreadArray(e.__spreadArray([],this.gradients,!0),[a],!1)),a},n.prototype.remove=function(e){var r=t.reject(this.gradients,{id:e});return this.onGradientsChange(r),r},n.prototype.update=function(t,r){var n=this.gradients.map((function(n){return n.id===t?e.__assign(e.__assign({},n),r):n}));return this.onGradientsChange(n),n},n}();exports.GradientList=n;
