(()=>{function e(t,e,l,n,a,o){var r=this;function i(e){return t.create(e.template,e.externalId).then(m,c)}function m(e){r.onImported({importedTemplate:e})}function c(e){_.isObjectLike(e)&&(e.errorMessage?l.danger(a.getString('Could not import template due to: "{{errorMessage | translate}}".',e)):l.danger(o("Could not import template.")))}r.importTemplate=function(){return e({templateUrl:":::PLUGIN_PATH:::/importTemplate/importTemplate.modal.html",controller:s,controllerAs:"$ctrl",size:"sm"}).then(i)}}function s(o,e,t,r,i){var m=this;m.selection={file:null,template:null,newName:{value:null,edited:!1},newExternalId:{value:null,edited:!1}},m.externalIdType=t.externalIdType,m.onSmartRestTemplateFileSelected=function(a){{var e;a.length&&((e=new FileReader).onload=function(n){o.$apply(function(){try{var e=JSON.parse(n.target.result);t=a[0],l=e,m.selection.file=t,m.selection.template=l,m.selection.newName.value=m.selection.newName.edited?m.selection.newName.value:l.name,m.selection.newExternalId.value=m.selection.newExternalId.edited?m.selection.newExternalId.value:l.__externalId,o.importForm.name.$setTouched(),o.importForm.externalId.$setTouched()}catch(e){r.danger(i("Cannot load template from selected file.")),m.selection.file=null,m.selection.template=null}var t,l})},e.readAsText(a[0]))}},m.importSelectedTemplate=function(){e.close({template:_.assign(m.selection.template,{name:m.selection.newName.value}),externalId:m.selection.newExternalId.value})},m.cancel=e.dismiss}s.$inject=["$scope","$uibModalInstance","c8ySmartRestTemplates","c8yAlert","gettext"],e.$inject=["c8ySmartRestTemplates","c8yModal","c8yAlert","c8yLocales","gettextCatalog","gettext"],angular.module("c8y.smartRestEditor").component("c8ySmartRestImportTemplate",{bindings:{onImported:"&"},templateUrl:":::PLUGIN_PATH:::/importTemplate/importTemplate.button.html",controller:e,controllerAs:"$ctrl"})})();