const gulp = require('gulp'),

  autoprefixer = require('gulp-autoprefixer'),
  cssnano = require('gulp-cssnano'),
  uglify = require('gulp-uglify'),

  rename = require('gulp-rename'),
  concat = require('gulp-concat'),
  cache = require('gulp-cache'),
  htmlmin = require('gulp-htmlmin'),
  inject = require('gulp-inject'),
  del = require('del'),
  htmlreplace = require('gulp-html-replace');

const scss = require('gulp-scss');
const sass = require('gulp-sass');
const googleWebFonts = require('gulp-google-webfonts');

const fontOptions = { };

gulp.task('styles', function() {
  return gulp.src(['node_modules/backbone.modal/backbone.modal.css', 'node_modules/backbone.modal/backbone.modal.theme.css'])
    .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))

  /* .pipe(gulp.dest('dist/css'))*/
  /* .pipe(rename({suffix: '.min'}))*/
    .pipe(concat('style.min.css'))
    .pipe(cssnano())
    .pipe(gulp.dest('live/css'));
});

gulp.task('copy', function() {
  gulp.src(['src/img/**/*']).pipe(gulp.dest('live/img'));
  gulp.src(['src/gfx/**/*']).pipe(gulp.dest('live/gfx'));
  gulp.src(['src/browserconfig.xml', 'src/site.webmanifest', 'src/service-worker.js', 'src/bridger.js']).pipe(gulp.dest('live'));
  gulp.src(['src/v1/index.html']).pipe(gulp.dest('live'));
});

gulp.task('clean', function() {
  return del(['live']);
});

gulp.task('customMUI', function() {
  return gulp.src(['src/css/custom.scss'])
    .pipe(sass({ 'outputStyle': 'compressed' }).on('error', sass.logError))
    // .pipe(cssnano())
    .pipe(rename('mui.custom.css'))
    // .pipe(gulp.dest(`${dest}/css`));
    .pipe(gulp.dest('live/css'));
});

gulp.task('vendor', function() {
  return gulp.src([
    'node_modules/muicss/dist/js/mui.min.js'
  ])
    .pipe(concat('vendor.js'))

    /* .pipe(uglify({ 'mangle': false }))*/
    .pipe(gulp.dest(`live/js`));
});

gulp.task('fonts', function() {
  return gulp.src('src/fonts.list')
    .pipe(googleWebFonts(fontOptions))
    .pipe(gulp.dest(`live/fonts`))
  ;
});

gulp.task('gotham', function() {
  gulp.src(['fonts/gotham.css']).pipe(gulp.dest('live/fonts'));
  gulp.src(['fonts/GothamSSm-Black.otf', 'fonts/GothamSSm-Bold.otf', 'fonts/GothamSSm-Book.otf', 'fonts/GothamSSm-Light.otf', 'fonts/GothamSSm-Medium.otf']).pipe(gulp.dest('live/fonts'));
});
