<?php
namespace Themes\ekmal;

use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
use Modules\Vod\Models\VideoTag;
use Modules\Serial\Enums\VodType;
use Modules\Serial\Models\VideoCollection;
use Rezahmady\SettingOperation\Facades\Setting;

class ThemeWidgets
{

    /*
    |--------------------------------------------------------------------------
    | Template options field for ThemeManager
    |--------------------------------------------------------------------------
    |
    |
    | Any fields defined here will show up after the standard page fields:
    | - select template
    | - Theme name (only seen by admins)
    */

    public function widget_banner_with_icon()
    {
        $static_disk = Setting::get('storage_disks.video_static_disk', 'public') ?? 'public';
        CRUD::addFields([
            [   // repeatable
                'name'  => 'slides',
                'label' => 'بنرها',
                'fake'  => true,
                'tab'   => trans('vod::lang.tab_main'),
                'type'  => 'repeatable',
                'fields' => [ // also works as: "fields"
                    [
                        'name' => 'image',
                        'label' => 'تصویر',
                        'fake'  => true,
                        'type' => 'image',
                        'disk' => $static_disk,
                        'withFiles' => [
                            'disk' => $static_disk,
                            'path' => 'images'
                        ],
                    ],
                    [
                        'name' => 'link',
                        'type' => 'text',
                        'prefix' => '<i class="la la-link la-lg"></i>',
                        'label' => 'لینک',
                        'tab'          => 'محتوا',
                        'fake'  => true,
                    ],
                    [
                        'name' => 'alt',
                        'type' => 'text',
                        'label' => 'متن تصویر',
                        'tab'          => 'محتوا',
                        'fake'  => true,
                    ],
                ],

                // optional
                'new_item_label'  => 'افزودن بنر', // customize the text of the button
                'init_rows' => 0, // number of empty rows to be initialized, by default 1
                // 'min_rows' => 2, // minimum rows allowed, when reached the "delete" buttons will be hidden
                'max_rows' => 12, // maximum rows allowed, when reached the "new item" button will be hidden
            ]
        ]);
    }

    public function widget_videos_slider()
    {
        $tags = VideoTag::all()->pluck('title', 'id');
        CRUD::addFields([
            [
                'name' => 'main_title',
                'label' => 'عنوان',
                'prefix' =>'<i class="la la-pencil la-lg"></i>',
                'tab'   => trans('vod::lang.tab_main'),
                'fake'  => true,
                'store_in' => 'extras_translatable',
                'translatable' => true,
            ],[
                'name' => 'main_description',
                'label' => 'توضیح مختصر',
                'prefix' =>'<i class="la la-pencil"></i>',
                'tab'   => trans('vod::lang.tab_main'),
                'fake'  => true,
                'store_in' => 'extras_translatable',
                'wrapper'      => ['class'  => "form-group col-md-6"],
                'translatable' => true,
            ],
            [   // select2_from_array
                'name'        => 'title_position',
                'label'       => "جایگاه عنوان",
                'type'        => 'select2_from_array',
                'wrapper'      => ['class'  => "form-group col-md-6"],
                'options'     => [
                    'right' => 'راست',
                    'center' => 'وسط'
                ],
                'allows_null' => false,
                'tab'   => trans('vod::lang.tab_main'),
                'fake'  => true,
            ],
            [
                'name'   => 'button_label',
                'prefix' =>'<i class="la la-pencil la-lg"></i>',
                'label'  => 'متن دکمه',
                'wrapper'      => ['class'  => "form-group col-md-6"],
                'attributes'   => ['placeholder' => 'متن'],
                'tab'   => trans('vod::lang.tab_main'),
                'fake'  => true,
                'store_in' => 'extras_translatable',
                'translatable' => true,
            ],
            [
                'name' => 'button_link',
                'prefix' => '<i class="la la-link la-lg"></i>',
                'attributes'   => ['placeholder' => 'لینک'],
                'label' => 'لینک دکمه',
                'wrapper'      => ['class'  => "form-group col-md-6"],
                'tab'   => trans('vod::lang.tab_main'),
                'fake'  => true,
            ],
            [
                'name' => 'title',
                'label' => trans('vod::lang.video_title'),
                'type' => 'text',
                'fake'   => true,
                'tab' => trans('theme-ekmal::lang.main_tab'),
                'wrapper'   => [
                    'class'  => "form-group col-md-6"
                ],
            ],
            [
                'name' => 'link',
                'label' => trans('theme-ekmal::lang.link'),
                'type' => 'text',
                'fake'   => true,
                'tab' => trans('theme-ekmal::lang.main_tab'),
                'wrapper'   => [
                    'class'  => "form-group col-md-6"
                ],
            ],
            [
                'name' => 'vod_type',
                'label' => 'نوع',
                'type' => 'radio',
                'options' => VodType::get_translated_array(),
                'inline' => true,
                'fake' => true,
                'tab'   => trans('vod::lang.tab_main'),
            ],
            [   // relationship
                'name' => 'collection', // the method on your model that defines the relationship
                'type' => "select2_from_array",

                'fake' => true,

                // OPTIONALS:
                'label' => 'مجموعه',
                'attribute' => "name", // attribute on model that is shown to user
                'placeholder' => 'یک مجموعه انتخاب کنید', // placeholder for the select2 input
                'options' => VideoCollection::pluck('name', 'id'),
                'tab'   => trans('vod::lang.tab_main'),
                'wrapper'   => [
                    'class'  => "form-group col-md-6"
                ],
            ],
            [
                'label'     => trans("vod::lang.video_tags"),
                'type'      => 'select2_multiple_grouped',
                'name'      => 'tags',
                'multiple'  => true,
                'fake'   => true,
                'attribute' => 'title',
                'model' => VideoTag::class,
                'placeholder' => trans("vod::lang.video_tags_placeholder"),
                'group_by'  => 'group',
                'group_by_attribute' => 'title',
                'group_by_relationship_back' => 'tags',
                'close-on-select' => false,
                'tab'   => trans('vod::lang.tab_main'),
            ],
        ]);
    }

}
