<?php

namespace Sigma\Flatlab;

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\File;
use Laravel\Ui\Presets\Preset as OriginalPreset;

class FlatlabPreset extends OriginalPreset {

    public static function install()
    {
        static::cleanAndDeleteDirectories();
        static::overrideFiles();
        static::updatePackages();
        static::copyFlatlabFolder();
        static::copyLangFolder();
    }

    public static function cleanAndDeleteDirectories()
    {
        File::deleteDirectory(resource_path('sass'));
        File::deleteDirectory(resource_path('js'));
        File::cleanDirectory(resource_path('views'));
        File::deleteDirectory(public_path('js'));
        File::deleteDirectory(public_path('css'));
    }

    public static function overrideFiles()
    {
        copy(FLATLAB_PATH.'/stubs/webpack.mix.js', base_path('webpack.mix.js'));
        copy(FLATLAB_PATH.'/stubs/AppServiceProvider.php', app_path('/Providers/AppServiceProvider.php'));
        copy(FLATLAB_PATH.'/stubs/ExposePermissions.php', app_path('ExposePermissions.php'));
        // copy(FLATLAB_PATH.'/stubs/PermisosDeGestion.php', app_path('Http/Middleware/PermisosDeGestion.php'));
        copy(FLATLAB_PATH.'/stubs/Kernel.php', app_path('Http/Kernel.php'));
        copy(FLATLAB_PATH.'/stubs/User.php', app_path('Models/User.php'));
        copy(FLATLAB_PATH.'/stubs/app.php', base_path('/config/app.php'));
        copy(FLATLAB_PATH.'/stubs/helpers.php', app_path('/Http/helpers.php'));
        copy(FLATLAB_PATH.'/stubs/Controller.php', app_path('/Http/Controllers/Controller.php'));
        copy(FLATLAB_PATH.'/routes/web.php', base_path('/routes/web.php'));
        copy(FLATLAB_PATH.'/stubs/flatlab.php', config_path('flatlab.php'));

        File::copyDirectory(FLATLAB_PATH.'/stubs/ImagesFilters/', app_path('/ImagesFilters/'));
        File::copyDirectory(FLATLAB_PATH.'/stubs/auth/', app_path('/Http/Controllers/Auth/'));
        File::copyDirectory(FLATLAB_PATH.'/stubs/errors', resource_path('/views/errors'));
        File::copyDirectory(FLATLAB_PATH.'/stubs/favicons', public_path('/flatlab/favicons'));

        copy(FLATLAB_PATH.'/database/migrations/2014_10_12_000000_create_users_table.php', database_path('migrations/2014_10_12_000000_create_users_table.php'));
        File::copyDirectory(FLATLAB_PATH.'/database/seeders', database_path('/seeders'));

        passthru('composer dump-autoload');
    }
    public static function updatePackageArray($packages)
    {
        return array_merge([
            "@ckeditor/ckeditor5-build-classic" => "^12.2.0",
            "@ckeditor/ckeditor5-vue" => "^1.0.0-beta.2",
            "@fortawesome/fontawesome-free" => "^5.9.0",
            "@fortawesome/free-brands-svg-icons" => "^5.9.0",
            "@fortawesome/free-regular-svg-icons" => "^5.9.0",
            "@fortawesome/free-solid-svg-icons" => "^5.9.0",
            "@fullcalendar/core" => "4.1.0",
            "@fullcalendar/daygrid" => "4.1.0",
            "@fullcalendar/interaction" => "4.1.0",
            "@fullcalendar/timegrid" => "^4.1.0",
            "@fullcalendar/vue" => "4.1.1",
            "bootstrap" => "^4.5.0",
            "chart.js" => "^2.8.0",
            "chartist" => "0.11.2",
            "datatables.net-bs" => "^1.10.16",
            "datatables.net-rowreorder" => "^1.2.7",
            "dcjqaccordion" => "^2.7.1",
            "flickity"=> "^2.1.1",
            "jquery" => "^3.5.1",
            "jquery.nicescroll" => "^3.7.6",
            "jquery.scrollto"=> "^2.1.2",
            "js-cookie"=> "^2.2.0",
            "moment"=> "^2.24.0",
            "sass"=> "^1.30.0",
            "sass-loader"=> "^8.0.2",
            "slidebars"=> "^2.0.2",
            "sweetalert2" => "8.11.6",
            "swiper" => "^4.4.2",
            "toastr"=> "^2.1.2",
            "tooltip.js"=> "^1.2.0",
            "vue" => "^2.6.11",
            "vee-validate" => "2.2.9",
            "vue-checkbox-radio"=> "^0.6.0",
            "vue-clickaway" => "2.2.2",
            "vue-js-modal"=> "^1.3.15",
            "vue-js-toggle-button"=> "^1.3.0",
            "vue-multiselect"=> "^2.0.8",
            "vue-template-compiler"=> "^2.6.10",
            "vue2-datepicker" => "^2.10.0",
            "vue2-transitions" => "0.3.0",
            "vuedraggable"=> "^2.16.0",
            "vuex"=> "^3.0.1",
            "vue-the-mask"=> "^0.11.1",
            "v-money"=> "^0.8.1",
            
        // ], Arr::except($packages,['popper.js']));
        ], $packages);
    }

    public static function copyFlatlabFolder(){
        File::copyDirectory(FLATLAB_PATH.'/resources/flatlab/',resource_path('flatlab/'));
    }

    public static function copyLangFolder(){
        File::copyDirectory(FLATLAB_PATH.'/resources/lang/',resource_path('lang/'));
    }

}
