(()=>{function e(t,e,n,u,s,a){var r=this,l=_(u.Types.values()).filter("numeric").map("name").value();function o(){n(function(){e.find(".optionsForm input").first().trigger("focus")})}function i(){var n,e=r.selectedMessage||{},t=c(e),s=(r.valuesData=[],r.valuesData),a=0,i=u.findMessageForInstruction(r.instruction,r.messages);_.forEach(e.mandatoryValues,function(e){e.mandatory=!0}),_.forEach(t,function(e){var t;a+=1,e.order=a,(t=e).value||t.type===u.Types.DATE.name||s.push(e)}),n=!(e&&i===e),t=c(r.selectedMessage||{}),_.forEach(t,function(e,t){e.inputValue=n?void 0:r.values[t],_.includes(l,e.type)&&!_.isUndefined(e.inputValue)&&(e.inputValue=Number(e.inputValue))}),o()}function c(e){e=_.union(e.mandatoryValues,e.customValues,e.values);return _.reject(e,"value")}function m(e){var t=r.editInstruction;r.messages=e,_.forEach(r.messages,function(e){"INVENTORY"===e.api&&("PUT"===e.method?e.byId?d(e.mandatoryValues,a("ID")):(d(e.mandatoryValues,a("External ID")),_.isEmpty(e.externalIdType)&&d(e.mandatoryValues,a("External ID type"))):"POST"===e.method&&(_.isEmpty(e.externalIdType)&&d(e.mandatoryValues,a("External ID type")),d(e.mandatoryValues,a("External ID"))))}),r.selectedMessage=u.findMessageForInstruction(t,r.messages),"sleep"!==t.type&&i(),o()}function d(e,t){_.some(e,function(e){return e.label===t})||e.unshift({label:t,type:"STRING"})}_.assign(r,{$onInit:function(){_.assign(r,{icons:s.icons})},$onChanges:function(){r.editInstruction=_.clone(r.instruction);var e=r.editInstruction;e&&((r.messages?t.when(r.messages):u.listAllPublishMessages()).then(m),r.values=e.values||[]);delete r.valuesForm},onSelectedMessage:i,remove:function(){r.simulatorCtrl.remove(r.instruction)},canSave:function(e){var e=e.$valid,t=r.instruction,n=r.selectedMessage,s=_.includes(["message","builtin"],t&&t.type);t&&(!s||n)||(e=!1);return e},save:function(){var e=r.instruction,t=r.editInstruction;{var n;delete e.isNew,"sleep"===e.type?e.seconds=t.seconds:(t=r.selectedMessage,n=c(t),e.type=t._template?"message":"builtin",e.values=_.map(n,function(e){e=_([e.value,e.inputValue]).reject(_.isNil).reject(function(e){return""===e}).head();return _.isUndefined(e)?"":e}),e.messageId=t.msgId,e.templateId=t._template?t._template.__externalId:void 0)}r.simulatorCtrl.saveCurrentSimulatorCommands()},cancel:function(){r.instruction.isNew?r.simulatorCtrl.remove(r.instruction):r.simulatorCtrl.selectInstruction()}})}e.$inject=["$q","$element","$timeout","c8ySimulators","c8ySimulatorsUi","gettext"],angular.module("c8y.simulators").component("c8ySimulatorInstructionDetail",{templateUrl:":::PLUGIN_PATH:::/detail/instructionDetail.html",require:{simulatorCtrl:"^c8ySimulatorDetail"},bindings:{instruction:"<"},controllerAs:"vm",controller:e})})();