<?php

namespace Sargilla\Flatlab4;

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

class Flatlab4Preset extends OriginalPreset {

    public static function install()
    {
        static::cleanAndDeleteDirectories();
        static::overrideFiles();
        static::updatePackages();
        static::copyFlatlab4Folder();
        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(FLATLAB4_PATH.'/stubs/webpack.mix.js', base_path('webpack.mix.js'));
        copy(FLATLAB4_PATH.'/stubs/AppServiceProvider.php', app_path('/Providers/AppServiceProvider.php'));
        copy(FLATLAB4_PATH.'/stubs/ExposePermissions.php', app_path('ExposePermissions.php'));
        copy(FLATLAB4_PATH.'/stubs/PermisosDeGestion.php', app_path('Http/Middleware/PermisosDeGestion.php'));
        copy(FLATLAB4_PATH.'/stubs/Kernel.php', app_path('Http/Kernel.php'));
        copy(FLATLAB4_PATH.'/stubs/User.php', app_path('User.php'));
        copy(FLATLAB4_PATH.'/stubs/app.php', base_path('/config/app.php'));
        copy(FLATLAB4_PATH.'/stubs/helpers.php', app_path('/Http/helpers.php'));
        copy(FLATLAB4_PATH.'/stubs/Controller.php', app_path('/Http/Controllers/Controller.php'));
        copy(FLATLAB4_PATH.'/routes/web.php', base_path('/routes/web.php'));
        copy(FLATLAB4_PATH.'/stubs/flatlab4.php', config_path('flatlab4.php'));

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

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

        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",
            "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",
            "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"
            
        // ], Arr::except($packages,['popper.js']));
        ], $packages);
    }

    public static function copyFlatlab4Folder(){
        File::copyDirectory(FLATLAB4_PATH.'/resources/flatlab4/',resource_path('flatlab4/'));
    }

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

}
