function _slicedToArray(e,r){return _arrayWithHoles(e)||_iterableToArrayLimit(e,r)||_unsupportedIterableToArray(e,r)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,r){var t;if(e)return"string"==typeof e?_arrayLikeToArray(e,r):"Map"===(t="Object"===(t={}.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:t)||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,r):void 0}function _arrayLikeToArray(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,l=Array(r);t<r;t++)l[t]=e[t];return l}function _iterableToArrayLimit(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var l,n,i,a,o=[],u=!0,d=!1;try{if(i=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;u=!1}else for(;!(u=(l=i.call(t)).done)&&(o.push(l.value),o.length!==r);u=!0);}catch(e){d=!0,n=e}finally{try{if(!u&&null!=t.return&&(a=t.return(),Object(a)!==a))return}finally{if(d)throw n}}return o}}function _arrayWithHoles(e){if(Array.isArray(e))return e}angular.module("c8y.ui").directive("c8yBinaryInput",function(){return e.$inject=["$scope","$element","c8yBase","c8yBinary","c8yModal","c8yAlert","gettext","gettextCatalog"],{restrict:"E",require:"?^form",scope:{initialId:"=?",initialUrl:"=?",editable:"=?",file:"=?outputFile",allowFreeUrlInput:"=?",uploadable:"=?",downloadable:"=?",clearable:"=?",removable:"=?",fileRequired:"=?",setGlobal:"=?"},link:function(e,r,t,l){e.form=l},templateUrl:":::PLUGIN_PATH:::/ui/views/binaryInput.html",controller:e};function e(t,e,r,l,n,i,a,o){var u={url:""},d={upload:{inProgress:!1},download:{progress:0,inProgress:!1}};function s(e,r){return _.isUndefined(e)?r:e}function c(e){return p(l.getIdFromUrl(e.headers("Location")))}function f(e){e&&e.data&&e.data.messsage&&i.danger(e.data.message)}function y(e){e.icon=l.icon(e),e.url=l.getDownloadUrl(e),t.file=e,t.form&&t.form.$setDirty()}function b(){u={url:""},t.file=u,e.find("input[type='file']").val(null)}function g(){var e;t.initialUrl&&(t.initialId=l.getIdFromUrl(t.initialUrl)),t.initialId?p(t.initialId):(e=t.initialUrl,u={url:e},t.file=u)}function p(e){return l.detail(e,{},{silentError:!0}).then(r.getResData).then(y).catch(function(){t.fileNotAvailable=!0})}_.assign(t,{file:u,onFileSelect:function(e){if(!(e.length<1)){e=_slicedToArray(e,1)[0];if(l.hasValidSize(e))return(e=>{d.upload.inProgress=!0;var r=t.setGlobal?{c8y_Global:{}}:void 0;return l.upload(e,r).then(c,f).finally(function(){d.upload.inProgress=!1})})(e);i.danger(o.getString("Selected file is too large – size limit is {{limitBytes | bytes}}.",{limitBytes:l.getBytesSizeLimit()}))}},chooseFile:function(){n({templateUrl:":::PLUGIN_PATH:::/ui/views/binaryInputModal.html",controller:"binaryInputModalCtrl"}).then(function(e){return y(e.file)})},download:function(e){d.download.inProgress=!0,d.download.progress=0;e=l.downloadAndSaveAs(e);return e.then(null,null,function(e){d.download.progress=100*e}),e.finally(function(){d.download.inProgress=!1,d.download.progress=100})},remove:function(e){return n({title:a("Delete file"),body:o.getString('You are about to delete file "{{ name }}". Do you want to proceed?',e),labels:{ok:a("Delete")},status:"danger"}).then(angular.bind(l,l.removeBinary,e)).then(b)},clear:function(){b()},status:d}),t.editable=s(t.editable,!0),t.allowFreeUrlInput=t.editable&&s(t.allowFreeUrlInput,!0),t.uploadable=t.editable&&s(t.uploadable,!0),t.downloadable=s(t.downloadable,!0),t.clearable=t.editable&&s(t.clearable,!0),t.removable=t.editable&&s(t.removable,!1),t.fileRequired=t.editable&&s(t.fileRequired,!1),t.$watch("initialId",g),t.$watch("initialUrl",g)}});