module.exports = function (grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    cssmin: {
      'wui-3': {
        expand: true,
        cwd: 'src/wui-3',
        src: ['*.css', '!*.min.css'],
        dest: 'src/wui-3',
        ext: '.min.css'
      },
      'wui-7': {
        expand: true,
        cwd: 'src/wui-7',
        src: ['*.css', '!*.min.css'],
        dest: 'src/wui-7',
        ext: '.min.css'
      },
      'wui-9': {
        expand: true,
        cwd: 'src/wui-9',
        src: ['*.css', '!*.min.css'],
        dest: 'src/wui-9',
        ext: '.min.css'
      },
      upload: {
        expand: true,
        cwd: 'src/upload',
        src: ['*.css', '!*.min.css'],
        dest: 'src/upload',
        ext: '.min.css'
      }
    },
    uglify: {
      'wui-3': {
        files: [{
          expand: true,
          cwd: 'src/wui-3',
          src: '**/*.js',
          dest: 'src/wui-3',
          rename: function (dst, src) {
            return dst + '/' + src.replace('.js', '.min.js');
          }
        }]
      },
      'wui-7': {
        files: [{
          expand: true,
          cwd: 'src/wui-7',
          src: '**/*.js',
          dest: 'src/wui-7',
          rename: function (dst, src) {
            return dst + '/' + src.replace('.js', '.min.js');
          }
        }]
      },
      'wui-9': {
        files: [{
          expand: true,
          cwd: 'src/wui-9',
          src: '**/*.js',
          dest: 'src/wui-9',
          rename: function (dst, src) {
            return dst + '/' + src.replace('.js', '.min.js');
          }
        }]
      },
      upload: {
        files: [{
          expand: true,
          cwd: 'src/upload',
          src: '**/*.js',
          dest: 'src/upload',
          rename: function (dst, src) {
            return dst + '/' + src.replace('.js', '.min.js');
          }
        }]
      }
    },
    compress: {
      'wui-3': {
        options: { mode: 'gzip' },
        files: [
          {expand: true, cwd: 'src/wui-3/',src: ['*.min.js'], dest: 'dist/wui-3', ext: '.js'},
          {expand: true, cwd: 'src/wui-3/',src: ['*.min.css'], dest: 'dist/wui-3', ext: '.css'},
          {expand: true, cwd: 'src/wui-3/',src: ['*.min.html'], dest: 'dist/wui-3', ext: '.html'}
        ]
      },
      'wui-6': {
        options: { mode: 'gzip' },
        files: [
          {expand: true, cwd: 'src/wui-7/',src: ['*.min.js'], dest: 'dist/wui-7', ext: '.js'},
          {expand: true, cwd: 'src/wui-7/',src: ['*.min.css'], dest: 'dist/wui-7', ext: '.css'},
          {expand: true, cwd: 'src/wui-7/',src: ['*.min.html'], dest: 'dist/wui-7', ext: '.html'}
        ]
      },
      'wui-8': {
        options: { mode: 'gzip' },
        files: [
          {expand: true, cwd: 'src/wui-9/',src: ['*.min.js'], dest: 'dist/wui-9', ext: '.js'},
          {expand: true, cwd: 'src/wui-9/',src: ['*.min.css'], dest: 'dist/wui-9', ext: '.css'},
          {expand: true, cwd: 'src/wui-9/',src: ['*.min.html'], dest: 'dist/wui-9', ext: '.html'}
        ]
      },
      upload: {
        options: { mode: 'gzip' },
        files: [
          {expand: true, cwd: 'src/upload/',src: ['*.min.js'], dest: 'dist/upload', ext: '.js'},
          {expand: true, cwd: 'src/upload/',src: ['*.min.css'], dest: 'dist/upload', ext: '.css'},
          {expand: true, cwd: 'src/upload/',src: ['*.html'], dest: 'dist/upload', ext: '.html'}
        ]
      }
    },
    htmlmin: {
      'wui-3': {
        options: { removeComments: true, collapseWhitespace: true },
        files: [{
          expand: true,
          cwd: 'src/wui-3',
          src: ['*.html'],
          dest: 'src/wui-3',
          rename: function (dst, src) {
            return dst + '/' + src.replace('.html', '.min.html');
          }
        }]
      },
      'wui-7': {
        options: { removeComments: true, collapseWhitespace: true },
        files: [{
          expand: true,
          cwd: 'src/wui-7',
          src: ['*.html'],
          dest: 'src/wui-7',
          rename: function (dst, src) {
            return dst + '/' + src.replace('.html', '.min.html');
          }
        }]
      },
      'wui-9': {
        options: { removeComments: true, collapseWhitespace: true },
        files: [{
          expand: true,
          cwd: 'src/wui-9',
          src: ['*.html'],
          dest: 'src/wui-9',
          rename: function (dst, src) {
            return dst + '/' + src.replace('.html', '.min.html');
          }
        }]
      },
      upload: {
        options: { removeComments: true, collapseWhitespace: true },
        files: [{
          expand: true,
          cwd: 'src/upload',
          src: ['*.html'],
          dest: 'src/upload',
          rename: function (dst, src) {
            return dst + '/' + src.replace('.html', '.min.html');
          }
        }]
      }
    },
    imagemin: {
      'wui-3':{
        options: { optimizationLevel: 0 },
        files: [
          {'dist/wui-3/rotek.png': 'src/wui-3/rotek.png'},
          {'dist/wui-3/favicon.ico': 'src/wui-3/favicon.ico'}
        ]
      },
      'wui-7':{
        options: { optimizationLevel: 0 },
        files: [
          {'dist/wui-7/rotek.png': 'src/wui-7/rotek.png'},
          {'dist/wui-7/favicon.ico': 'src/wui-7/favicon.ico'}
        ]
      },
      'wui-9':{
        options: { optimizationLevel: 0 },
        files: [
          {'dist/wui-9/rotek.png': 'src/wui-9/rotek.png'},
          {'dist/wui-9/favicon.ico': 'src/wui-9/favicon.ico'}
        ]
      },
      upload:{
        options: { optimizationLevel: 0 },
        files: [
          {'dist/upload/favicon.ico': 'src/upload/favicon.ico'}
        ]
      }
    },
    clean: {
      all: {
        src: [
          '!src/**/*.js',
          '!src/**/*.css',
          'src/**/*.min.js',
          'src/**/*.min.css',
          'src/**/*.min.html'
        ]
      },
      clear: {
        src: 'dist*/*'
      }
    },
    jshint: {
      all: ['Gruntfile.js', 'src/**/*.js']
    }
  });

  grunt.loadNpmTasks('grunt-contrib-htmlmin');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-compress');
  grunt.loadNpmTasks('grunt-contrib-imagemin');
  grunt.loadNpmTasks('grunt-contrib-jshint');

  grunt.registerTask('default', ['cssmin','uglify','htmlmin','clean:all']);
  grunt.registerTask('build', ['cssmin','uglify','htmlmin','compress','clean:all', 'imagemin']);
  grunt.registerTask('clear', ['clean:clear']);
  grunt.registerTask('jhint', ['jshint']);
};
