<?php

namespace ViartasThemes\ViartasTheme\Providers;

use Illuminate\Support\Facades\Blade;
use ViartasCore\Core\Providers\BaseThemeServiceProvider;

class ThemeServiceProvider extends BaseThemeServiceProvider
{
    /**
     * @var string
     */
    public string $package_directory = __DIR__;

    /**
     * @var string
     */
    public string $application = 'accounting';

    /**
     * @return array
     */
    public function configs(): array
    {
        return [
            'viartas-theme' => 'viartas-theme',
        ];
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        $this->loadViewsFrom(__DIR__ . '/../../resources/theme', 'viartas');

        $this->loadRoutesFrom(__DIR__ . '/../../routes/accounting.php');

        $this->loadMigrationsFrom(__DIR__ . '/../../database');

        // Register Blade components
        Blade::componentNamespace('Viartas\\AdminTheme\\Components', 'viartas');
/*
        // Publish assets
        if ($this->app->runningInConsole()) {
            // Publish config
            $this->publishes([
                __DIR__ . '/../../config/viartas-theme.php' => config_path('viartas-theme.php'),
            ], 'viartas-config');

            // Publish views
            $this->publishes([
                __DIR__ . '/../../resources/theme' => resource_path('views/vendor/viartas'),
            ], 'viartas-views');

            // Publish assets
            $this->publishes([
                __DIR__ . '/../../public' => public_path('vendor/viartas'),
            ], 'viartas-assets');

            // Publish all
            $this->publishes([
                __DIR__ . '/../../config/viartas-theme.php' => config_path('viartas-theme.php'),
                __DIR__ . '/../../resources/theme' => resource_path('views/vendor/viartas'),
                __DIR__ . '/../../public' => public_path('vendor/viartas'),
            ], 'viartas-all');
        }*/

        // Register Blade directives
        $this->registerBladeDirectives();

        parent::boot();
    }

    /**
     * Register custom Blade directives.
     */
    protected function registerBladeDirectives(): void
    {
        Blade::directive('viartasStyles', function () {
            return "<?php echo view('viartas::accounting.partials.styles')->render(); ?>";
        });

        Blade::directive('viartasScripts', function () {
            return "<?php echo view('viartas::accounting.partials.scripts')->render(); ?>";
        });

        Blade::directive('viartasSidebar', function () {
            return "<?php echo view('viartas::accounting.partials.sidebar')->render(); ?>";
        });

        Blade::directive('viartasHeader', function () {
            return "<?php echo view('viartas::accounting.partials.header')->render(); ?>";
        });
    }


    public function views(): array
    {
        return [
            'accounting.auth.login' => 'theme.accounting.modules.auth.login',
        ];
    }

    /**
     * @return array
     */
    public function icons(): array
    {
        return [
            // Dashboard
            'accounting.dashboard.index'            => '<i class="fa-solid fa-gauge-high"></i>',

            // Content
            'accounting.menus.index'                => '<i class="fa-solid fa-bars"></i>',
            'accounting.pages.index'                => '<i class="fa-solid fa-file-lines"></i>',
            'accounting.post-categories.index'      => '<i class="fa-solid fa-folder-tree"></i>',
            'accounting.posts.index'                => '<i class="fa-solid fa-newspaper"></i>',
            'accounting.custom-links.index'         => '<i class="fa-solid fa-link"></i>',
            'accounting.banners.index'              => '<i class="fa-solid fa-images"></i>',

            // Orders
            'accounting.orders.index'               => '<i class="fa-solid fa-cart-shopping"></i>',
            'accounting.customers.index'            => '<i class="fa-solid fa-user-group"></i>',
            'accounting.invoice-series.index'       => '<i class="fa-solid fa-file-invoice"></i>',
            'accounting.discount-codes.index'       => '<i class="fa-solid fa-percent"></i>',

            // Catalog
            'accounting.products.index'             => '<i class="fa-solid fa-box-open"></i>',
            'accounting.product-categories.index'   => '<i class="fa-solid fa-sitemap"></i>',
            'accounting.attributes.index'           => '<i class="fa-solid fa-sliders"></i>',
            'accounting.attribute-groups.index'     => '<i class="fa-solid fa-layer-group"></i>',

            // Company
            'accounting.warehouses.index'           => '<i class="fa-solid fa-warehouse"></i>',
            'accounting.sellers.index'              => '<i class="fa-solid fa-store"></i>',
            'accounting.cargos.index'               => '<i class="fa-solid fa-truck-fast"></i>',
            'accounting.payments.index'             => '<i class="fa-solid fa-credit-card"></i>',

            // Brands
            'accounting.brands.index'               => '<i class="fa-solid fa-award"></i>',
            'accounting.models.index'               => '<i class="fa-solid fa-cubes"></i>',

            // Users
            'accounting.users.index'                => '<i class="fa-solid fa-users"></i>',
            'accounting.roles.index'                => '<i class="fa-solid fa-user-shield"></i>',
            'accounting.activity.index'             => '<i class="fa-solid fa-clock-rotate-left"></i>',

            // Communications
            'accounting.mail-templates.index'       => '<i class="fa-solid fa-envelope"></i>',

            // Settings
            'accounting.modules.index'              => '<i class="fa-solid fa-puzzle-piece"></i>',
            'accounting.translations.index'         => '<i class="fa-solid fa-language"></i>',
            'accounting.themes.index'               => '<i class="fa-solid fa-palette"></i>',
        ];
    }


    /**
     * @return array
     */
    public function javascript(): array
    {
        return [
            'accounting.*' => [
                [
                    'vendor' => 'viartas-themes/viartas-theme',
                    'file' => 'resources/js/app.js',
                    'type' => 'library', //library, module, script
                    'render_as' => 'commonjs', //module, commonjs
                ],
                [
                    'vendor' => 'viartas-js/jquery',
                    'file' => 'resources/js/jquery.js',
                    'type' => 'library', //library, module, script
                    'render_as' => 'commonjs', //module, commonjs
                ],
                [
                    'vendor' => 'viartas-js/alpinejs',
                    'file' => 'resources/js/alpinejs.js',
                    'type' => 'library', //library, module, script
                    'render_as' => 'module', //module, commonjs
                ],
                [
                    'vendor' => 'viartas-js/datatables',
                    'file' => 'resources/js/datatables.js',
                    'type' => 'script', //library, module, script
                    'render_as' => 'commonjs', //module, commonjs
                ],
                [
                    'vendor' => 'viartas-js/datatables-columns-filter',
                    'file' => 'resources/js/datatablesColumnsFilter.js',
                    'type' => 'module', //library, module, script
                    'render_as' => 'module', //module, commonjs
                ],
                [
                    'vendor' => 'viartas-js/daterangepicker',
                    'file' => 'resources/js/daterangepicker.js',
                    'type' => 'module', //library, module, script
                    'render_as' => 'commonjs', //module, commonjs
                ],
                [
                    'vendor' => 'viartas-js/dropzone',
                    'file' => 'resources/js/dropzone.js',
                    'type' => 'module', //library, module, script
                    'render_as' => 'module', //module, commonjs
                ],
                [
                    'vendor' => 'viartas-themes/viartas-theme',
                    'file' => 'resources/js/page-editor.js',
                    'type' => 'script', //library, module, script
                    'render_as' => 'commonjs', //module, commonjs
                ]
            ],
        ];
    }

    /**
     * @return array
     */
    public function css(): array
    {
        return [
            'accounting.*' => [
                [
                    'vendor' => 'viartas-js/datatables',
                    'file' => 'resources/css/datatables.css',
                    'type' => 'module', //library, module, script
                ],
                /*[
                    'vendor' => 'viartas-js/dropzone',
                    'file' => 'resources/css/dropzone.css',
                    'type' => 'module', //library, module, script
                ],*/
                [
                    'vendor' => 'viartas-themes/viartas-theme',
                    'file' => 'resources/css/datatables.css',
                    'type' => 'script', //library, module, script
                ],
                [
                    'vendor' => 'viartas-themes/viartas-theme',
                    'file' => 'resources/css/app.css',
                    'type' => 'script', //library, module, script
                ],
                [
                    'vendor' => 'viartas-js/daterangepicker',
                    'file' => 'resources/css/daterangepicker.css',
                    'type' => 'script', //library, module, script
                ],
                [
                    'vendor' => 'viartas-themes/viartas-theme',
                    'file' => 'resources/css/page-editor.css',
                    'type' => 'script', //library, module, script
                ],
                [
                    'vendor' => 'viartas-themes/viartas-theme',
                    'file' => 'resources/css/dropzone.css',
                    'type' => 'script', //library, module, script
                ]
            ],
        ];
    }
}
