function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _defineProperty(e,t,r){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _toPropertyKey(e){e=_toPrimitive(e,"string");return"symbol"==_typeof(e)?e:e+""}function _toPrimitive(e,t){if("object"!=_typeof(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0===r)return("string"===t?String:Number)(e);r=r.call(e,t||"default");if("object"!=_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){var r;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(r="Object"===(r={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:r)||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}(()=>{function e(e,t,r,n,a,o,l,i){var m,y=this,c=[],u=n.getDeliveryTypes().defaultDeliveryType,d=n.getDeliveryTypes().standardDeliveryTypes;function s(e){c.length=0,_.forEach(e,function(e){var t=!!e.id;c.push({name:t?e.name:i.getString(e.name),command:e.command,category:t?e.category:i.getString(e.category),deliveryTypes:e.deliveryTypes,id:e.id})})}function p(e){y.result.commandTemplate=e,_.difference(e.deliveryTypes,d)||y.standardDeliveryTypes.push(e.deliveryType),y.commandDeliveryType=_.first(e.deliveryTypes)||u}_.assign(y,{commandTemplates:c,standardDeliveryTypes:d,defaultDeliveryType:u,commandDeliveryTypesSelected:{},validateSelectedDeliveryTypes:function(){return _.isEmpty(_.pickBy(y.commandDeliveryTypesSelected))},result:{action:null,commandTemplate:null},forms:{},onTemplateSelected:p,use:function(e){y.result.action="USE",y.result.deliveryType=e!==u&&e,y.result.commandTemplate=_.clone(y.result.commandTemplate);e=y.result.commandTemplate;e.text=e.text||e.command,y.close(y.result)},execute:function(e){y.result.action="EXECUTE",y.result.deliveryType=e!==u&&e,y.result.commandTemplate=_.clone(y.result.commandTemplate);e=y.result.commandTemplate;e.text=e.command,y.close(y.result)},cancel:function(){y.newCommandTemplate?delete y.newCommandTemplate:y.dismiss()},save:function(){y.newCommandTemplate.deliveryTypes=_.keys(_.pickBy(y.commandDeliveryTypesSelected)),n.saveTemplate(y.newCommandTemplate).then(t.getResData).then(function(e){var e=_.pick(e,["id","name","category","command","text","deliveryTypes"]),t=_.find(c,{id:e.id});t?_.assign(t,e):c.unshift(e),y.result.commandTemplate=e,p(e),delete y.newCommandTemplate})},addNew:function(){y.newCommandTemplate={deviceType:m},y.commandDeliveryTypesSelected=_defineProperty({},u,!0)},hideAddButton:function(){return!!y.newCommandTemplate},edit:function(e){var t;t=_.isEmpty(e.deliveryTypes)?d:e.deliveryTypes;_.forEach(t,function(e){_.assign(y.commandDeliveryTypesSelected,_defineProperty({},e,!0))}),y.newCommandTemplate=e},remove:function(e){y.result.commandTemplate===e&&delete y.result.commandTemplate;n.removeTemplate(e).then(function(){_.pull(c,e)}).then(function(){o.success(l("Shell command template deleted."))})},isDeliveryTypeSupported:function(e,t){t=_.get(t,"deliveryTypes");return _.isEmpty(t)||_.includes(t,e)},getExecuteButtonLabel:function(e){return e!==u?i.getString("Execute (via {{ deliveryType | translate }})",{deliveryType:e}):i.getString("Execute")},appendToEl:document.getElementsByClassName("modal"),getCommandPlaceholder:function(){return i.getString("e.g. {{ example }}",{example:"ls"})}}),(e=>r.detailCached(e).then(t.getResData).then(function(e){return m=_.concat(e.type,e.c8y_DeviceTypes||[]),n.getCommandTemplatesForDeviceType.apply(n,_toConsumableArray(m))}))(e.deviceId).then(s),n.canSendCommandsViaSMS().then(function(e){y.smsEnabled=e}),a.hasAnyRole(["ROLE_INVENTORY_ADMIN","ROLE_MANAGED_OBJECT_ADMIN"]).then(function(e){y.canWrite=e})}e.$inject=["$routeParams","c8yBase","c8yDevices","c8yDeviceShell","c8yPermissions","c8yAlert","gettext","gettextCatalog"],angular.module("c8y.commandTemplates").controller("commandTemplatesCtrl",e)})();