<?php

// Exit if accessed directly.
if (!defined('ABSPATH')) exit;

class Rdg_Blocks_Logo_Team extends Rdg_Blocks_Base
{
    protected $block_name = BLOCK_RDG_LOGO_TEAM;
    private $block_folder_name = 'rdg-logo-team';
    protected $block_title = 'RDG Logo Team';
    private $block_description = '';
    private $block_icon = 'admin-links';
    private $block_keywords = ['rdg', 'custom', 'logo', 'team'];
    private $block_mode = 'preview';
    private $block_category = RDGBLOCKS_NAME_SLUG;
    protected $is_styles_load = true;

    public function init() {
        $this->register_block();
        $this->register_fields();
    }

    private function register_block() {
        if (function_exists('acf_register_block_type')) {
            $rdg_helpers = new Rdg_Blocks_Helpers();
            acf_register_block_type([
                'name' => $this->block_name,
                'title' => __($this->block_title),
                'description' => __($this->block_description),
                'category' => $this->block_category,
                'icon' => $this->block_icon,
                'keywords' => $this->block_keywords,
                'mode' => $this->block_mode,
                'render_template' => RDGBLOCKS_PLUGIN_DIR . "/blocks/".$this->block_folder_name."/template.php",
                'enqueue_style' => $rdg_helpers->webpack('rdg_logo_team.css'),
                'supports' => [
                    'jsx' => true,
			        'color' => [
                        'background' => true,
                        'gradients'  => false,
                        'text' => false,
                    ],
                ],
            ]);
        }
    }

    private function register_fields() {
        if( function_exists('acf_add_local_field_group') ):
            acf_add_local_field_group(array(
                'key' => 'group_rdg_logo_team_block_sdw3f4ds2314',
                'title' => 'Block_rdg_logo_team',
                'fields' => array(
                    array(
                        'key' => 'field_63bdfeec25819',
                        'label' => 'Image',
                        'name' => 'image',
                        'aria-label' => '',
                        'type' => 'image',
                        'instructions' => '',
                        'required' => 0,
                        'conditional_logic' => 0,
                        'wrapper' => array(
                            'width' => '',
                            'class' => '',
                            'id' => '',
                        ),
                        'return_format' => 'array',
                        'library' => 'all',
                        'min_width' => '',
                        'min_height' => '',
                        'min_size' => '',
                        'max_width' => '',
                        'max_height' => '',
                        'max_size' => '',
                        'mime_types' => '',
                        'preview_size' => 'medium',
                    ),
                    array(
                        'key' => 'field_63be09732616b',
                        'label' => 'Link',
                        'name' => 'link',
                        'aria-label' => '',
                        'type' => 'link',
                        'instructions' => '',
                        'required' => 0,
                        'conditional_logic' => 0,
                        'wrapper' => array(
                            'width' => '',
                            'class' => '',
                            'id' => '',
                        ),
                        'return_format' => 'array',
                    ),
                    array(
                        'key' => 'field_63bdfeec4f901',
                        'label' => 'Title',
                        'name' => 'title',
                        'aria-label' => '',
                        'type' => 'text',
                        'instructions' => '',
                        'required' => 1,
                        'conditional_logic' => 0,
                        'wrapper' => array(
                            'width' => '',
                            'class' => '',
                            'id' => '',
                        ),
                        'default_value' => '',
                        'maxlength' => '',
                        'placeholder' => '',
                        'prepend' => '',
                        'append' => '',
                    ),
                    array(
                        'key' => 'field_63bdfeec535a6',
                        'label' => 'Description',
                        'name' => 'text',
                        'aria-label' => '',
                        'type' => 'wysiwyg',
                        'instructions' => '',
                        'required' => 1,
                        'conditional_logic' => 0,
                        'wrapper' => array(
                            'width' => '',
                            'class' => '',
                            'id' => '',
                        ),
                        'default_value' => '',
                        'tabs' => 'all',
                        'toolbar' => 'full',
                        'media_upload' => 1,
                        'delay' => 0,
                    ),
                ),
                'location' => array(
                    array(
                        array(
                            'param' => 'block',
                            'operator' => '==',
                            'value' => 'acf/rdg-logo-team',
                        ),
                    ),
                ),
                'menu_order' => 1,
                'position' => 'normal',
                'style' => 'default',
                'label_placement' => 'top',
                'instruction_placement' => 'label',
                'hide_on_screen' => '',
                'active' => true,
                'description' => '',
            ));

        endif;
    }

    public function get_width($has_image, $content) {
        if (!empty($content[0]) || !empty($content[1])) {
            $has_items = true;
        } else {
            $has_items = false;
        }

        if ($has_image && $has_items) {
            return ['w-20', 'w-80'];
        }

        if (!$has_image && $has_items) {
            return ['', 'w-100'];
        }

        if ($has_image && !$has_items) {
            return ['w-100', ''];
        }

        return ['', ''];
    }

    public function getColorsToloadGeneratePress() {
        return [
            ['name' => 'color-logo-team-link','slug' => 'color-logo-team-link','color' => '#3a96e0'],
            ['name' => 'color-logo-team-link-hover','slug' => 'color-logo-team-link-hover','color' => '#0160ac'],
            ['name' => 'color-logo-team-title','slug' => 'color-logo-team-title','color' => '#111111'],
            ['name' => 'color-logo-team-description','slug' => 'color-logo-team-description','color' => '#111111'],
            ['name' => 'color-logo-team-dark-gray','slug' => 'color-logo-team-dark-gray','color' => '#555'],
        ];
    }

    public function getStylesToloadGeneratePress() {
        return [
            [
                'customSelector' => '.rdg-logo-team .content .items .item .item-link',
                'fontWeight' => '700',
                'fontSize' => '1rem',
            ],
            [
                'customSelector' => '.rdg-logo-team .content .items .item .item-title',
                'fontWeight' => '700',
                'fontSize' => '1.4rem',
            ],
            [
                'customSelector' => '.rdg-logo-team .content .items .item .item-text',
                'fontSize' => '1rem',
                'lineHeight' => '1.8rem',
            ],
            [
                'customSelector' => '.acf-block-preview .rdg-logo-team a',
                'textDecoration' => 'none',
            ],
        ];
    }
}

$rdg_logo_team_class = new Rdg_Blocks_Logo_Team();
$rdg_logo_team_class->init();

return $rdg_logo_team_class;
