<?php

namespace App\Nova;

use Auth;
use Emilianotisato\NovaTinyMCE\NovaTinyMCE;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Image;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Slug;
use Laravel\Nova\Fields\Trix;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Http\Requests\NovaRequest;
use Spatie\TagsField\Tags;

class Article extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var class-string<\App\Models\Article>
     */
    public static $model = \App\Models\Article::class;

    /**
     * The single value that should be used to represent the resource when being displayed.
     *
     * @var string
     */
    public static $title = 'id';

    /**
     * The columns that should be searched.
     *
     * @var array
     */
    public static $search = [
        'id',
        'title'
    ];

    /**
     * Get the fields displayed by the resource.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
     * @return array
     */
    public function fields(NovaRequest $request)
    {
        return [
            ID::make()->sortable(),
            Image::make('Thumbnail')->disk('public')->rules('max:2048')->help('Max. 2048kb'),
            Text::make("Title")
                ->rules(["required"])
                ->sortable(),
            Slug::make('SEO Title', 'slug')->from('Title')->separator('-')->hideFromIndex()->withMeta([
                'extraAttributes' => ['readonly' => true],
            ]),
            Select::make('Category', 'category')->options([
                'K-Food' => 'K-Food',
                'K-Drama' => 'K-Drama',
                'K-Beauty' => 'K-Beauty',
                'K-Fashion' => 'K-Fashion',
                'News & Event' => 'News & Event'
            ]),
            Tags::make('Tags'),
            // SimpleRepeatable::make('Tags', 'tags', [
            //     Select::make('Tags', 'tags')->options(\App\Models\Tags::all()->pluck('name', 'name'))
            //         ->rules('required')
            //         ->displayUsingLabels(),
            // ]),
            Trix::make('Preview')
                ->sortable()
                ->alwaysShow(),
            NovaTinyMCE::make('Description', 'body')
                ->alwaysShow(),
            DateTime::make('Published At')->default(now()),
            Boolean::make('Highlight', 'is_highlight'),
            Boolean::make('Visible', 'is_visible'),
            Text::make('Created by')->exceptOnForms(),
            Text::make('Updated by')->exceptOnForms()
        ];
    }

    /*public static function authorizedToCreate(Request $request)
    {
        return false;
    }

    public function authorizedToDelete(Request $request)
    {
        return false;
    }

    public function authorizedToReplicate(Request $request)
    {
        return false;
    }*/

    /**
     * Get the cards available for the request.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
     * @return array
     */
    public function cards(NovaRequest $request)
    {
        return [];
    }

    public static function label()
    {
        return 'Articles';
    }

    public static function singularLabel()
    {
        return 'Articles';
    }

    /**
     * Get the filters available for the resource.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
     * @return array
     */
    public function filters(NovaRequest $request)
    {
        return [];
    }

    /**
     * Get the lenses available for the resource.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
     * @return array
     */
    public function lenses(NovaRequest $request)
    {
        return [];
    }

    /**
     * Get the actions available for the resource.
     *
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
     * @return array
     */
    public function actions(NovaRequest $request)
    {
        return [];
    }
}