<?php

namespace App\Providers;

use Laravel\Nova\Nova;
use App\Policies\RolePolicy;
use Laravel\Nova\Cards\Help;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Boolean;
use App\Domain\Feeds\Models\Feed;
use App\Domain\Votes\Models\Vote;
use App\Policies\PermissionPolicy;
use Illuminate\Support\Facades\Gate;
use App\Domain\Comments\Models\Comment;
use App\Domain\Payments\Models\Withdrawal;
use App\Domain\Complaints\Models\Complaint;
use App\Domain\Votes\Observers\VoteObserver;
use App\Domain\Feeds\Observers\NovaFeedObserver;
use Laravel\Nova\NovaApplicationServiceProvider;
use App\Domain\Payments\Observers\WithdrawalObserver;
use App\Domain\Comments\Observers\NovaCommentObserver;
use App\Domain\Complaints\Observers\ComplaintObserver;
use App\Domain\Feeds\Observers\NovaFeedAdsObserver;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();
        Nova::serving(function () {
            Complaint::observe(ComplaintObserver::class);
            Vote::observe(VoteObserver::class);
            Withdrawal::observe(WithdrawalObserver::class);
            Feed::observe(NovaFeedObserver::class);
            Feed::observe(NovaFeedAdsObserver::class);
            Comment::observe(NovaCommentObserver::class);
        });

        \OptimistDigital\NovaSettings\NovaSettings::addSettingsFields([
            Number::make('Количество лидеров', 'vote_leader_count'),
            Number::make('Процент сайта', 'vote_procent_site'),
            Number::make('Процент лидера', 'vote_procent_leader'),
            Number::make('Процент локального лидера', 'vote_procent_local_leader'),
            Boolean::make('Платный режим включен', 'vote_paid_mode')
        ]);




    }

    /**
     * Register the Nova routes.
     *
     * @return void
     */
    protected function routes()
    {
        Nova::routes()
                ->withAuthenticationRoutes()
                ->withPasswordResetRoutes()
                ->register();
    }

    /**
     * Register the Nova gate.
     *
     * This gate determines who can access Nova in non-local environments.
     *
     * @return void
     */
    protected function gate()
    {

        Gate::define('viewNova', function ($user) {
            return $user->hasDirectPermission('access');
            // return in_array($user->email, [

            // ]);
        });
    }

    /**
     * Get the cards that should be displayed on the default Nova dashboard.
     *
     * @return array
     */
    protected function cards()
    {
        return [

            //new Help,
        ];
    }

    /**
     * Get the extra dashboards that should be displayed on the Nova dashboard.
     *
     * @return array
     */
    protected function dashboards()
    {
        return [];
    }

    /**
     * Get the tools that should be listed in the Nova sidebar.
     *
     * @return array
     */
    public function tools()
    {
        return [
            \Vyuldashev\NovaPermission\NovaPermissionTool::make()
            ->rolePolicy(RolePolicy::class)
            ->permissionPolicy(PermissionPolicy::class),
            new \OptimistDigital\NovaSettings\NovaSettings,
        ];
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
