'use strict';

const Funnel = require('broccoli-funnel');
const MergeTrees = require('broccoli-merge-trees');
const Path = require('path');

module.exports = {
  name: 'ember-mapbox-gl',

  treeForStyles(tree) {
    const mapboxGlTree = new Funnel(Path.dirname(require.resolve('mapbox-gl')), {
      files: [ 'mapbox-gl.css' ],
      destDir: 'app/styles'
    });

    if (tree) {
      return new MergeTrees([ tree, mapboxGlTree ]);
    }

    return mapboxGlTree;
  },

  treeForVendor(tree) {
    const mapboxGlTree = new Funnel(Path.dirname(require.resolve('mapbox-gl')), {
      files: [
        'mapbox-gl.js',
        'mapbox-gl.js.map',
        'mapbox-gl-dev.js'
      ],
      destDir: '/mapbox-gl'
    });

    if (tree) {
      return new MergeTrees([ tree, mapboxGlTree ]);
    }

    return mapboxGlTree;
  },

  included(app) {
    this._super.included.apply(this, arguments);

    const srcFile = process.env.EMBER_ENV === 'production'
      ? 'vendor/mapbox-gl/mapbox-gl.js'
      : 'vendor/mapbox-gl/mapbox-gl-dev.js';

    app.import(srcFile, {
      using: [
        { transformation: 'amd', as: 'mapbox-gl' }
      ]
    });

    app.import('app/styles/mapbox-gl.css');
  }
};

@@ -598,78 +598,23 @@
     
-'mapbox-gl.js',%0A        'mapbox-gl.js.map',%0A        'mapbox-gl-dev.js'
+this._srcFile()
 %0A   
@@ -769,94 +769,38 @@
 %0A%0A  
-included(app) %7B%0A    this._super.included.apply(this, arguments);%0A%0A    const srcFile = 
+treeForPublic(tree) %7B%0A    if (
 proc
@@ -837,35 +837,124 @@
 ion'
+) %7B
 %0A      
-? 'vendor/mapbox-gl/
+const mapboxGlTree = new Funnel(Path.dirname(require.resolve('mapbox-gl')), %7B%0A        files: %5B%0A          '
 mapb
@@ -965,16 +965,20 @@
 l.js
+.map
 '%0A      
 : 'v
@@ -977,70 +977,314 @@
     
-: 'vendor/mapbox-gl/mapbox-gl-dev.js';%0A%0A    app.import(
+  %5D,%0A        destDir: '/assets'%0A      %7D);%0A  %0A      if (tree) %7B%0A        return new MergeTrees(%5B tree, mapboxGlTree %5D);%0A      %7D%0A  %0A      return mapboxGlTree;%0A    %7D%0A%0A    return tree;%0A  %7D,%0A%0A  included(app) %7B%0A    this._super.included.apply(this, arguments);%0A%0A    app.import('vendor/mapbox-gl/' + this._
 srcFile
+()
 , %7B%0A
@@ -1410,15 +1410,137 @@
 .css');%0A
+  %7D,%0A%0A  _srcFile() %7B%0A    return process.env.EMBER_ENV === 'production'%0A      ? 'mapbox-gl.js'%0A      : 'mapbox-gl-dev.js';%0A
   %7D%0A%7D;%0A

fix source maps