var jsBase = [
	'node_modules/jquery/dist/jquery.min.js',
	'node_modules/jquery-migrate/dist/jquery-migrate.min.js',
	'node_modules/jquery-ui-dist/jquery-ui.min.js'
]

var jsBootstrap = [
	'node_modules/bootstrap/dist/js/bootstrap.bundle.min.js',
	'node_modules/bootbox/dist/bootbox.all.min.js',
]

var jsCompat = [
	'node_modules/promise-polyfill/dist/polyfill.min.js',
	'node_modules/es6-promise/dist/es6-promise.min.js',
]

var jsSite = [
	jsBase,
	jsBootstrap,
	'node_modules/jquery-serializejson/jquery.serializejson.min.js',
	'node_modules/currency.js/dist/currency.min.js',
	'resources/shop/js/plugins/smooth_products/js/smoothproducts.min.js',
	'resources/shop/js/site.js',
]

var cssSite = [
	'node_modules/bootstrap/dist/css/bootstrap.min.css',
	'node_modules/@fortawesome/fontawesome-free/css/all.min.css',
	'node_modules/animate.css/animate.min.css',
	'node_modules/icheck-bootstrap/icheck-bootstrap.min.css',
	'resources/shop/js/plugins/smooth_products/css/smoothproducts.css',
	'resources/shop/css/site.css',
]

var jsAdminLTE = [
	jsBase,
	jsBootstrap,
	'node_modules/sizzle/dist/sizzle.min.js',
	'node_modules/admin-lte/dist/js/adminlte.min.js',
	'node_modules/toastr/build/toastr.min.js',
]

var jsCoreInclude = [
	'resources/shop/js/include/core/objectLength.js',
	'resources/shop/js/include/core/url.js',
	'resources/shop/js/include/core/user.js',
	'resources/shop/js/include/form/radio.js',
	'resources/shop/js/include/form/upload.js',
	'resources/shop/js/include/form/validator.js',
	'resources/shop/js/include/layout/animate.js',
	'resources/shop/js/include/layout/scroll.js',
	'resources/shop/js/include/layout/tooltip.js',
]

var jsBundle = [
	'node_modules/jquery-ui-sortable/jquery-ui.min.js',
	'node_modules/jquery-serializejson/jquery.serializejson.min.js',
	'node_modules/jquery-placeholder/jquery.placeholder.js',
	'node_modules/@claviska/jquery-minicolors/jquery.minicolors.js',
	'node_modules/bootstrap-validate/dist/bootstrap-validate.js',
	'node_modules/bootstrap-validator/dist/validator.min.js',
	'node_modules/jquery-validation/dist/jquery.validate.min.js',
	'node_modules/jquery-confirm/dist/jquery-confirm.min.js',
	'node_modules/jquery.cookie/jquery.cookie.js',
	'node_modules/jquery.filer/js/jquery.filer.min.js',
	'node_modules/jquery-file-download/src/Scripts/jquery.fileDownload.js',
	'node_modules/jquery-jeditable/dist/jquery.jeditable.min.js',
	'node_modules/jquery.quicksearch/dist/jquery.quicksearch.min.js',
	'node_modules/jquery.nicescroll/dist/jquery.nicescroll.js',
	'node_modules/jquery-slimscroll/jquery.slimscroll.min.js',
	'node_modules/handlebars/dist/handlebars.min.js',
	'node_modules/swag/lib/swag.min.js',
	'node_modules/multiselect/js/jquery.multi-select.js',
	'node_modules/screenfull/dist/screenfull.js',
	'node_modules/underscore/underscore-min.js',
]

var jsMain = [
	jsCompat,
	jsCoreInclude,
	jsBundle,
]

var cssPrint = [
	// 'node_modules/bootstrap/dist/css/bootstrap.min.css',
	'cssIcons',
	'resources/shop/print.css'
]

var cssBundle = [
	'node_modules/bootstrap/dist/css/bootstrap.min.css',
	'node_modules/animate.css/animate.min.css',
	'node_modules/dropzone/dist/min/dropzone.min.css',
	'node_modules/daterangepicker/daterangepicker.css',
	'node_modules/jquery-confirm/dist/jquery-confirm.min.css',
	'node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css',
	'node_modules/bootstrap-sweetalert/dist/sweetalert.css',
	'node_modules/bootstrap4-toggle/css/bootstrap4-toggle.min.css',
	'node_modules/@claviska/jquery-minicolors/jquery.minicolors.css',
	'node_modules/jquery.filer/css/jquery.filer.css',
	'node_modules/jquery.filer/css/themes/jquery.filer-dragdropbox-theme.css',
	'node_modules/jquery.filer/assets/fonts/jquery.filer-icons/jquery-filer.css',
]

var cssIcons = [
	'node_modules/@fortawesome/fontawesome-free/css/fontawesome.min.css',
]

var cssMain = [
	cssBundle,
	cssIcons,
	'resources/shop/css/main.css',
]

var jsDataTables = [
	'node_modules/jszip/dist/jszip.min.js',
	'node_modules/pdfmake/build/pdfmake.min.js',
	'node_modules/pdfmake/build/vfs_fonts.js',
	'node_modules/datatables.net/js/jquery.dataTables.min.js',
	'node_modules/datatables.net-bs4/js/dataTables.bootstrap4.min.js',
	'node_modules/datatables.net-autofill/js/dataTables.autoFill.min.js',
	'node_modules/datatables.net-autofill-bs4/js/autoFill.bootstrap4.min.js',
	'node_modules/datatables.net-buttons/js/dataTables.buttons.min.js',
	'node_modules/datatables.net-buttons-bs4/js/buttons.bootstrap4.min.js',
	'node_modules/datatables.net-buttons/js/buttons.html5.min.js',
	'node_modules/datatables.net-buttons/js/buttons.print.min.js',
	'node_modules/datatables.net-buttons/js/buttons.colVis.min.js',
	'node_modules/datatables.net-colreorder/js/dataTables.colReorder.min.js',
	'node_modules/datatables.net-colreorder-bs4/js/colReorder.bootstrap4.min.js',
	'node_modules/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js',
	'node_modules/datatables.net-fixedheader-bs4/js/fixedHeader.bootstrap4.min.js',
	'node_modules/datatables.net-fixedcolumns/js/dataTables.fixedColumns.min.js',
	'node_modules/datatables.net-fixedcolumns-bs4/js/fixedColumns.bootstrap4.min.js',
	'node_modules/datatables.net-keytable/js/dataTables.keyTable.min.js',
	'node_modules/datatables.net-keytable-bs4/js/keyTable.bootstrap4.min.js',
	'node_modules/datatables.net-responsive/js/dataTables.responsive.min.js',
	'node_modules/datatables.net-rowreorder/js/dataTables.rowReorder.min.js',
	'node_modules/datatables.net-rowreorder-bs4/js/rowReorder.bootstrap4.min.js',
	'node_modules/datatables.net-scroller/js/dataTables.scroller.min.js',
	'node_modules/datatables.net-scroller-bs4/js/scroller.bootstrap4.min.js',
	'node_modules/datatables.net-select/js/dataTables.select.min.js',
	'node_modules/datatables.net-select-bs4/js/select.bootstrap4.min.js',
	/* 'node_modules/yadcf/jquery.dataTables.yadcf.js', */
];

var cssDataTables = [
	'node_modules/datatables.net-bs4/css/dataTables.bootstrap4.min.css',
	'node_modules/datatables.net-autofill-bs4/css/autoFill.bootstrap4.min.css',
	'node_modules/dataTables.net-buttons-bs4/css/buttons.bootstrap4.min.css',
	'node_modules/datatables.net-colreorder-bs4/css/colReorder.bootstrap4.min.css',
	'node_modules/datatables.net-fixedheader-bs4/css/fixedHeader.bootstrap4.min.css',
	'node_modules/datatables.net-fixedcolumns-bs4/css/fixedColumns.bootstrap4.min.css',
	'node_modules/datatables.net-keytable-bs4/css/keyTable.bootstrap4.min.css',
	'node_modules/datatables.net-rowreorder-bs4/css/rowReorder.bootstrap4.min.css',
	'node_modules/datatables.net-scroller-bs4/css/scroller.bootstrap4.min.css',
	'node_modules/datatables.net-select-bs4/css/select.bootstrap4.min.css',
/*	'node_modules/yadcf/jquery.dataTables.yadcf.css',	*/
];


module.exports = function(grunt) {

	grunt.initConfig({
		pkg: grunt.file.readJSON('package.json'),
		uglify: {
			options: {
				banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
				nameCache: 'built/<%= pkg.name %>.json'
			},
			build: {
				files: [
					{
						'public/assets/js/main.min.js': jsMain,
						'public/assets/plugins/datatables.min.js': jsDataTables,
						'public/assets/plugins/adminlte/adminlte.min.js': jsAdminLTE,
						'public/js/site.min.js': jsSite,
					},
				]
			},
		},
		eslint: {
			target: ['public/assets/js/*']
		},
		webstandards: {
			'src': ['public/assets/js/*']
		},
		concat: {
				options: {
				separator: '\n'
			},
			sitecss: {
				src: cssSite,
				dest: 'public/css/site.min.css'
			},
			siteJs: {
				src: jsSite,
				dest: 'public/js/site.min.js'
			},
			mainjs: {
				src: jsMain,
				dest: 'public/assets/js/main.min.js'
			},
			maincss: {
				src: cssMain,
				dest: 'public/assets/css/main.min.css'
			},
			printcss: {
				src: cssPrint,
				dest: 'public/assets/css/print.min.css'
			},
			adminltejs: {
				src: jsAdminLTE,
				dest: 'public/assets/plugins/adminlte/adminlte.min.js'
			},
			datatablesjs: {
				src: jsDataTables,
				dest: 'public/assets/plugins/datatables.min.js'
			},
			datatablescss: {
				src: cssDataTables,
				dest: 'public/assets/plugins/datatables.min.css'
			},
		},
		cssmin: {
			options: {
				shorthandCompacting: false,
				roundingPrecision: -1
			},
			target: {
				files: [
					{
						'public/assets/css/main.min.css': cssMain
					},
					{
						'public/assets/css/print.min.css': cssPrint
					},
					{
						'public/css/site.min.css': cssSite
					},
				]
			}
		},
		copy: {
			main: {
				files: [
					{
						expand: true,
						cwd: 'node_modules/@fortawesome/fontawesome-free/webfonts/',
						src: ['**'],
						dest: 'public/webfonts/'
					},
					{
						expand: true,
						cwd: 'resources/shop/fonts',
						src: ['**'],
						dest: 'public/fonts/'
					},
					{
						expand: true,
						cwd: 'resources/shop/img',
						src: ['**'],
						dest: 'public/img/'
					},
					{
						expand: true,
						cwd: 'resources/shop/lang',
						src: ['**'],
						dest: 'public/assets/lang/'
					},
					{
						expand: true,
						cwd: 'resources/shop/plugins',
						src: ['**'],
						dest: 'public/assets/plugins/'
					},
					{
						expand: true,
						cwd: 'resources/shop/assets/tpl',
						src: ['**'],
						dest: 'public/assets/tpl/'
					},
					{
						expand: true,
						cwd: 'node_modules/owp.glyphicons/',
						src: ['**'],
						dest: 'public/assets/fonts/glyphicons'
					},
					{
						expand: true,
						cwd: 'node_modules/@claviska/jquery-minicolors/',
						src: ['jquery.minicolors.png'],
						dest: 'public/assets/css/'
					},
					{
						expand: true,
						cwd: 'node_modules/@claviska/jquery-minicolors/',
						src: ['jquery.minicolors.*'],
						dest: 'public/assets/plugins/jquery-minicolors',
					},
					{
						expand: true,
						cwd: 'node_modules/bootstrap-datepicker/dist/',
						src: ['**'],
						dest: 'public/assets/plugins/bootstrap-datepicker',	
					},
					{
						expand: true,
						cwd: 'node_modules/jquery.quicksearch/dist/',
						src: ['jquery.quicksearch.min.js.map'],
						dest: 'public/assets/js/'
					},
					{
						expand: true,
						cwd: 'node_modules/jquery.quicksearch/dist/',
						src: ['**/*.map'],
						dest: 'public/js'	
					},
					{
						expand: true,
						cwd: 'node_modules/pdfmake/build/',
						src: ['pdfmake.min.js.map'],
						dest: 'public/assets/plugins/'
					},
					{
						expand: true,
						cwd: 'node_modules/daterangepicker/',
						src: ['daterangepicker.css'],
						dest: 'public/assets/plugins/daterangepicker',
					},
					{
						expand: true,
						cwd: 'node_modules/daterangepicker/',
						src: ['daterangepicker.js'],
						dest: 'public/assets/plugins/daterangepicker',
					},
					{
						expand: true,
						cwd: 'node_modules/chart.js/dist/',
						src: ['**'],
						dest: 'public/assets/plugins/chartjs'
					},
					{
						expand: true,
						cwd: 'node_modules/highcharts/',
						src: ['**'],
						dest: 'public/assets/plugins/highcharts'
					},
					{
						expand: true,
						cwd: 'node_modules/@highcharts/map-collection/',
						src: ['**'],
						dest: 'public/assets/plugins/highcharts/map',
					},
					{
						expand: true,
						cwd: 'node_modules/nestable2/dist/',
						src: ['**'],
						dest: 'public/assets/plugins/nestable2'	
					},
					{
						expand: true,
						cwd: 'node_modules/bootstrap-autocomplete/dist/latest/',
						src: ['bootstrap-autocomplete.min.js'],
						dest: 'public/assets/plugins/autocomplete'	
					},
					{
						expand: true,
						cwd: 'node_modules/slick-carousel/slick/',
						src: ['**'],
						dest: 'public/assets/plugins/slick',
					},
					{
						expand: true,
						cwd: 'node_modules/jquery-slimscroll/',
						src: ['jquery.slimscroll.min.js'],
						dest: 'public/assets/plugins',
					},
					{
						expand: true,
						cwd: 'node_modules/jquery.nicescroll/dist/',
						src: ['jquery.nicescroll.min.js'],
						dest: 'public/assets/plugins',
					},
					{
						expand: true,
						cwd: 'node_modules/bootstrap4-toggle/',
						src: ['**'],
						dest: 'public/assets/plugins/bootstrap4-toggle',	
					},
					{
						expand: true,
						cwd: 'node_modules/pdfobject/',
						src: ['**'],
						dest: 'public/assets/plugins/pdfobject',	
					},
					{
						expand: true,
						cwd: 'resources/shop/plugins/pdfjs/',
						src: ['**'],
						dest: 'public/assets/plugins/pdfjs',	
					},
					{
						expand: true,
						cwd: 'node_modules/bootstrap4-duallistbox/dist/',
						src: ['*.min.*'],
						dest: 'public/assets/plugins/bootstrap4-duallistbox',
					},
					{
						expand: true,
						cwd: 'node_modules/select2/dist/',
						src: ['**'],
						dest: 'public/assets/plugins/select2',
					},
					{
						expand: true,
						cwd: 'node_modules/tempusdominus-bootstrap-4/build/',
						src: ['**'],
						dest: 'public/assets/plugins/datepicker',
					},
					{
						expand: true,
						cwd: 'node_modules/moment/min/',
						src: ['**'],
						dest: 'public/assets/plugins/moment',
					},
					{
						expand: true,
						cwd: 'node_modules/currency.js/dist/',
						src: ['**'],
						dest: 'public/assets/plugins/currency',
					},
					{
						expand: true,
						cwd: 'node_modules/bootstrap-fileinput/css/',
						src: ['**/*.min.css'],
						dest: 'public/assets/plugins/bootstrap-fileinput/css',	
					},
					{
						expand: true,
						cwd: 'node_modules/bootstrap-fileinput/js/',
						src: ['**'],
						dest: 'public/assets/plugins/bootstrap-fileinput/js',	
					},
					{
						expand: true,
						cwd: 'node_modules/bootstrap-fileinput/img/',
						src: ['**'],
						dest: 'public/assets/plugins/bootstrap-fileinput/img',	
					},
					{
						expand: true,
						cwd: 'node_modules/bootstrap-fileinput/themes/fa/',
						src: ['**'],
						dest: 'public/assets/plugins/bootstrap-fileinput/themes/fa',	
					},
					{
						expand: true,
						cwd: 'node_modules/bootstrap-fileinput/themes/fas/',
						src: ['**'],
						dest: 'public/assets/plugins/bootstrap-fileinput/themes/fas',	
					},
					{
						expand: true,
						cwd: 'resources/shop/js/include/plugins/datatables_lang/',
						src: ['*.json'],
						dest: 'public/assets/plugins/datatables_lang',
					},
					{
						expand: true,
						cwd: 'node_modules/tinymce/',
						src: ['**'],
						dest: 'public/assets/plugins/tinymce',
					},
					{
						expand: true,
						cwd: 'vendor/sebastienheyd/boilerplate/src/public/plugins/tinymce/plugins/',
						src: ['**'],
						dest: 'public/assets/plugins/tinymce/plugins',
					},
					{
						expand: true,
						cwd: 'vendor/sebastienheyd/boilerplate/src/resources/assets/js/vendor/tinymce/plugins/stickytoolbar/',
						src: ['**'],
						dest: 'public/assets/plugins/tinymce/plugins/stickytoolbar',
					},
					{
						expand: true,
						cwd: 'vendor/sebastienheyd/boilerplate/src/resources/assets/js/vendor/tinymce/langs/',
						src: ['**'],
						dest: 'public/assets/plugins/tinymce/langs',
					},
					{
						expand: true,
						cwd: 'vendor/sebastienheyd/boilerplate/src/resources/assets/js/vendor/tinymce/skins/',
						src: ['**'],
						dest: 'public/assets/plugins/tinymce/skins/ui',
					},
					{
						expand: true,
						cwd: 'vendor/sebastienheyd/boilerplate/src/public/plugins/tinymce/skins/ui/boilerplate/',
						src: ['**'],
						dest: 'public/assets/plugins/tinymce/skins/ui/boilerplate',
					},
					{
						expand: true,
						cwd: 'node_modules/icheck-bootstrap/',
						src: ['icheck-bootstrap.min.css'],
						dest: 'public/assets/plugins/icheck/'
					},
					{
						expand: true,
						cwd: 'node_modules/jstree/dist/',
						src: ['**'],
						dest: 'public/assets/plugins/jstree/'
					},
					{
						expand: true,
						cwd: 'node_modules/jquery.fancytree/dist/',
						src: ['**'],
						dest: 'public/assets/plugins/fancytree'	
					},
					{
						expand: true,
						cwd: 'node_modules/jqtree/',
						src: ['tree.jquery.js'],
						dest: 'public/assets/plugins/jqtree'	
					},
					{
						expand: true,
						cwd: 'node_modules/jqtree/',
						src: ['jqtree.css'],
						dest: 'public/assets/plugins/jqtree'	
					},
					{
						expand: true,
						cwd: 'node_modules/sidr/dist/',
						src: ['**'],
						dest: 'public/assets/plugins/sidr'	
					},
					{
						expand: true,
						cwd: 'resources/shop/js/include/',
						src: ['boilerplate.js'],
						dest: 'public/assets/plugins',
					},
				],
			}
		},
		watch: {
			dist: {
				files: ['resources/shop/js/*', 'resources/shop/css/*'],
				// tasks: ['concat', 'copy']
				tasks: ['concat']
			}
		},
	});

	// Load the plugin that provides the "uglify" task.
	grunt.loadNpmTasks('grunt-contrib-concat');
	grunt.loadNpmTasks('grunt-contrib-copy');
	grunt.loadNpmTasks('grunt-contrib-cssmin');
	grunt.loadNpmTasks('grunt-contrib-handlebars');
	grunt.loadNpmTasks('grunt-contrib-uglify');
	grunt.loadNpmTasks('grunt-contrib-watch');
	grunt.loadNpmTasks('grunt-eslint');
	grunt.loadNpmTasks('grunt-webstandards');

	// Default task(s).
	grunt.registerTask('default', ['uglify', 'concat', 'cssmin', 'copy']);
	grunt.registerTask('js', ['uglify']);
	grunt.registerTask('css', ['cssmin', 'copy']);
	grunt.registerTask('dev', ['concat', 'copy']);
	grunt.registerTask('lint', ['eslint']);
	grunt.registerTask('webstandards', ['webstandards']);
};
