(()=>{function t(e,o,i,r,u,n,s,a){var c=this;function l(t){var n=c.selectedInstruction;n&&n.isNew&&f(n),c.selectedInstruction=t}function t(t){c.simulator.instances=t,v(_.pick(c.simulator,["id","instances"]),!0)}function m(){var t=o.resolve(),n=c.simulatorId||e.deviceId;return t=n?i.detail(n).then(d):t}function d(t){c.simulator=t}function f(t){c.selectedInstruction===t&&(c.selectedInstruction=void 0),_.remove(c.simulator.commandQueue,t),p()}function p(){return v(_.pick(c.simulator,["id","commandQueue"]),!0)}function v(t,n){return l(),i.save(t||c.simulator).then(n?_.identity:r.listing)}function h(){o.all({defaultOps:i.operations(),customOps:o.resolve(c.simulator.c8y_CustomOperations)}).then(function(t){var n=t.defaultOps;c.operations=_.flatten([n,_.map(t.customOps,function(t){return{fragment:t,name:u("Custom operation"),removable:!0}})])})}function I(t){return i.toggleOperation(c.simulator,t)}_.assign(c,{$onInit:function(){m()},selectInstruction:l,isInstructionSelected:function(t){return t===c.selectedInstruction},remove:f,loadOperations:h,opActive:function(t){return i.supportsOperation(c.simulator,t)},opToggle:I,changeSimulatorName:function(t){return i.save({id:c.simulator.id,name:t}).then(function(){n.changeTitle({title:t}),a.simulatorInputForm.$setPristine(),s.success(u("Simulator title successfully changed."))})},save:v,addCustomOperation:function(){return r.addCustomOperationDialog().then(function(t){return i.addCustomOperation(c.simulator,t).then(function(){return I(t)}).then(m).then(h)})},removeCustomOperation:function(t){return i.removeOperation(c.simulator,t).then(function(){return i.removeCustomOperation(c.simulator,t)}).then(m).then(h)},editSimulatorInstances:function(){return r.editSimulatorInstances(c.simulator).then(t)},saveCurrentSimulatorCommands:p,saveInstances:function(t){return i.save({id:c.simulator.id,instances:t}).then(function(){a.simulatorInputForm.$setPristine(),s.success(u("Number of instances successfully changed."))})}})}t.$inject=["$routeParams","$q","c8ySimulators","c8ySimulatorsUi","gettext","c8yTitle","c8yAlert","$scope"],angular.module("c8y.simulators").controller("SimulatorDetailController",t)})();