import Ember from 'ember';
import hbs from 'htmlbars-inline-precompile';

const { computed } = Ember;

export default Ember.Component.extend({
  layout: hbs`{{actionText}}`,
  tagName: 'a',
  role: 'button',
  attributeBindings: ['role', 'download', 'href'],
  download: computed('filename', 'extension', function() {
    return `${this.get('filename')}-${new Date().toISOString()}.${this.get('extension')}`;
  }),

  href: computed('data', 'mime', 'stringify', function() {
    let data = this.get('data');
    const mime = this.get('mime');
    if (this.get('stringify')) {
      data = JSON.stringify(data, null, 2);
    }

    const file = new File([data], { type: mime });
    return window.URL.createObjectURL(file);
  }),

  actionText: 'Download',
  data: null,
  filename: null,
  mime: 'text/plain',
  extension: 'txt',
  stringify: false,
});

@@ -411,20 +411,24 @@
  %7D),%0A%0A  
-href
+fileLike
 : comput
@@ -455,15 +455,26 @@
 stri
-n
 gify',
+ 'download',
  fun
@@ -479,24 +479,38 @@
 unction() %7B%0A
+    let file;%0A
     let data
@@ -534,20 +534,59 @@
 ');%0A    
-cons
+let filename = this.get('download');%0A    le
 t mime =
@@ -691,18 +691,146 @@
   %7D%0A
-%0A    const
+    if (window.navigator.msSaveOrOpenBlob) %7B%0A      file = new Blob(%5Bdata%5D, %7B type: mime %7D);%0A      file.name = filename;%0A    %7D else %7B%0A     
  fil
@@ -841,32 +841,42 @@
 new File(%5Bdata%5D,
+ filename,
  %7B type: mime %7D)
@@ -885,53 +885,368 @@
     
-return window.URL.createObjectURL(file);%0A  %7D)
+%7D%0A    return file;%0A  %7D),%0A%0A  href: computed('fileLike', function() %7B%0A    return window.URL.createObjectURL(this.get('fileLike'));%0A  %7D),%0A%0A  click(event) %7B%0A    if (!window.navigator.msSaveOrOpenBlob) %7B%0A      return;%0A    %7D%0A    event.preventDefault();%0A    let file = this.get('fileLike');%0A    //lol whyyyy%0A    window.navigator.msSaveOrOpenBlob(file, file.name);%0A  %7D
 ,%0A%0A 

use ms-specific api for saving Blobs instead of using the File constructor (#4376)