<?php

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

class Rdg_Blocks_Memberships extends Rdg_Blocks_Base
{
    protected $block_name = BLOCK_RDG_MEMBERSHIPS;
    private $block_folder_name = BLOCK_RDG_MEMBERSHIPS;
    protected $block_title = 'RDG Memberships';
    private $block_description = 'A block to structure 4 sections with info about memberships, it allow to edit the title, description paragraf, price, list of benefits, discount and buttons';
    private $block_icon = 'admin-links';
    private $block_keywords = ['rdg', 'custom', 'button', 'column'];
    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_memberships.css'),
                'example' => array(
                    'attributes' => array(
                        'mode' => 'preview',
                        'data' => array(
                            'isExample' => true,
                            'preview_image' => RDGBLOCKS_PLUGIN_URL."dist/images/rdg-memberships-template-preview.jpg",
                        ),
                    ),
                ),
                'supports' => [
                    'jsx' => true,
			        'color' => [
                        'background' => false,
                        'gradients'  => false,
                        'text' => false,
                    ],
                ],
            ]);
        }
    }

    public function register_fields() {
        add_action( 'acf/include_fields', function() {
            if ( ! function_exists( 'acf_add_local_field_group' ) ) {
                return;
            }
        
            acf_add_local_field_group( array(
            'key' => 'group_64ac79c474d9f',
            'title' => 'Memberships',
            'fields' => array(
                array(
                    'key' => 'field_64bace8734bb2',
                    'label' => 'Title',
                    'name' => 'title',
                    'aria-label' => '',
                    'type' => 'text',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '',
                        'class' => '',
                        'id' => '',
                    ),
                    'default_value' => '',
                    'maxlength' => '',
                    'placeholder' => '',
                    'prepend' => '',
                    'append' => '',
                ),
                array(
                    'key' => 'field_64baa15a84b11',
                    'label' => 'List Style Image',
                    'name' => 'list_style_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_64ac79a8d713c',
                    'label' => 'First Pack',
                    'name' => 'first_pack',
                    'aria-label' => '',
                    'type' => 'group',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '',
                        'class' => '',
                        'id' => '',
                    ),
                    'layout' => 'block',
                    'sub_fields' => array(
                        array(
                            'key' => 'field_64ac7bd7d7154',
                            'label' => 'Title',
                            'name' => 'title',
                            'aria-label' => '',
                            'type' => 'text',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'maxlength' => '',
                            'placeholder' => '',
                            'prepend' => '',
                            'append' => '',
                        ),
                        array(
                            'key' => 'field_64ac7bd8d7155',
                            'label' => 'Description',
                            'name' => 'description',
                            'aria-label' => '',
                            'type' => 'wysiwyg',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'tabs' => 'all',
                            'toolbar' => 'full',
                            'media_upload' => 1,
                            'default_value' => '',
                            'delay' => 0,
                        ),
                        array(
                            'key' => 'field_64ac7bdad7156',
                            'label' => 'Price',
                            'name' => 'price',
                            'aria-label' => '',
                            'type' => 'number',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'min' => '',
                            'max' => '',
                            'placeholder' => '',
                            'step' => '',
                            'prepend' => '',
                            'append' => '',
                        ),
                        array(
                            'key' => 'field_64ac7bdbd7157',
                            '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_64ac79b9d713d',
                    'label' => 'Second Pack',
                    'name' => 'second_pack',
                    'aria-label' => '',
                    'type' => 'group',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '',
                        'class' => '',
                        'id' => '',
                    ),
                    'layout' => 'block',
                    'sub_fields' => array(
                        array(
                            'key' => 'field_64ac7a05d7140',
                            'label' => 'Title',
                            'name' => 'title',
                            'aria-label' => '',
                            'type' => 'text',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'maxlength' => '',
                            'placeholder' => '',
                            'prepend' => '',
                            'append' => '',
                        ),
                        array(
                            'key' => 'field_64ac7a0ed7141',
                            'label' => 'Price',
                            'name' => 'price',
                            'aria-label' => '',
                            'type' => 'number',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'min' => '',
                            'max' => '',
                            'placeholder' => '',
                            'step' => '',
                            'prepend' => '',
                            'append' => '',
                        ),
                        array(
                            'key' => 'field_64ac7a20d7142',
                            'label' => 'Description',
                            'name' => 'description',
                            'aria-label' => '',
                            'type' => 'wysiwyg',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'tabs' => 'all',
                            'toolbar' => 'full',
                            'media_upload' => 1,
                            'delay' => 0,
                        ),
                        array(
                            'key' => 'field_64ac7a3fd7144',
                            'label' => 'List',
                            'name' => 'list',
                            'aria-label' => '',
                            'type' => 'repeater',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'layout' => 'table',
                            'pagination' => 0,
                            'min' => 1,
                            'max' => 2,
                            'collapsed' => '',
                            'button_label' => 'Add Row',
                            'rows_per_page' => 20,
                            'sub_fields' => array(
                                array(
                                    'key' => 'field_64ac7a51d7145',
                                    'label' => 'List Info',
                                    'name' => 'list_info',
                                    'aria-label' => '',
                                    'type' => 'text',
                                    'instructions' => '',
                                    'required' => 0,
                                    'conditional_logic' => 0,
                                    'wrapper' => array(
                                        'width' => '',
                                        'class' => '',
                                        'id' => '',
                                    ),
                                    'default_value' => '',
                                    'maxlength' => '',
                                    'placeholder' => '',
                                    'prepend' => '',
                                    'append' => '',
                                    'parent_repeater' => 'field_64ac7a3fd7144',
                                ),
                            ),
                        ),
                        array(
                            'key' => 'field_64ac7a6cd7146',
                            '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_64ac79c2d713e',
                    'label' => 'Third Pack',
                    'name' => 'third_pack',
                    'aria-label' => '',
                    'type' => 'group',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '',
                        'class' => '',
                        'id' => '',
                    ),
                    'layout' => 'block',
                    'sub_fields' => array(
                        array(
                            'key' => 'field_64ac7aa9d7147',
                            'label' => 'Title',
                            'name' => 'title',
                            'aria-label' => '',
                            'type' => 'text',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'maxlength' => '',
                            'placeholder' => '',
                            'prepend' => '',
                            'append' => '',
                        ),
                        array(
                            'key' => 'field_64ac7aafd7148',
                            'label' => 'Description',
                            'name' => 'description',
                            'aria-label' => '',
                            'type' => 'wysiwyg',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'tabs' => 'all',
                            'toolbar' => 'full',
                            'media_upload' => 1,
                            'delay' => 0,
                        ),
                        array(
                            'key' => 'field_64ac7abad7149',
                            'label' => 'Great Value Image',
                            'name' => 'great_value_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_64ac7aced714a',
                            'label' => 'Great Value',
                            'name' => 'great_value',
                            'aria-label' => '',
                            'type' => 'true_false',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'message' => 'Show great value image?',
                            'default_value' => 1,
                            'ui' => 0,
                            'ui_on_text' => '',
                            'ui_off_text' => '',
                        ),
                        array(
                            'key' => 'field_64ac7b16d714b',
                            'label' => 'Price',
                            'name' => 'price',
                            'aria-label' => '',
                            'type' => 'number',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'min' => '',
                            'max' => '',
                            'placeholder' => '',
                            'step' => '',
                            'prepend' => '',
                            'append' => '',
                        ),
                        array(
                            'key' => 'field_64ac7b1cd714c',
                            '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_64ac79cad713f',
                    'label' => 'Fourth Pack',
                    'name' => 'fourth_pack',
                    'aria-label' => '',
                    'type' => 'group',
                    'instructions' => '',
                    'required' => 0,
                    'conditional_logic' => 0,
                    'wrapper' => array(
                        'width' => '',
                        'class' => '',
                        'id' => '',
                    ),
                    'layout' => 'block',
                    'sub_fields' => array(
                        array(
                            'key' => 'field_64ac7b3cd714d',
                            'label' => 'Title',
                            'name' => 'title',
                            'aria-label' => '',
                            'type' => 'text',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'maxlength' => '',
                            'placeholder' => '',
                            'prepend' => '',
                            'append' => '',
                        ),
                        array(
                            'key' => 'field_64ac7b3dd714e',
                            'label' => 'Discount',
                            'name' => 'discount',
                            'aria-label' => '',
                            'type' => 'text',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'maxlength' => '',
                            'placeholder' => '',
                            'prepend' => '',
                            'append' => '',
                        ),
                        array(
                            'key' => 'field_64ac7b41d714f',
                            'label' => 'Best Deal',
                            'name' => 'best_deal',
                            'aria-label' => '',
                            'type' => 'text',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'default_value' => '',
                            'maxlength' => '',
                            'placeholder' => '',
                            'prepend' => '',
                            'append' => '',
                        ),
                        array(
                            'key' => 'field_64ac7b43d7151',
                            'label' => 'List',
                            'name' => 'list',
                            'aria-label' => '',
                            'type' => 'repeater',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'layout' => 'table',
                            'pagination' => 0,
                            'min' => 1,
                            'max' => 4,
                            'collapsed' => '',
                            'button_label' => 'Add Row',
                            'rows_per_page' => 20,
                            'sub_fields' => array(
                                array(
                                    'key' => 'field_64ac7b65d7153',
                                    'label' => 'List Info',
                                    'name' => 'list_info',
                                    'aria-label' => '',
                                    'type' => 'text',
                                    'instructions' => '',
                                    'required' => 0,
                                    'conditional_logic' => 0,
                                    'wrapper' => array(
                                        'width' => '',
                                        'class' => '',
                                        'id' => '',
                                    ),
                                    'default_value' => '',
                                    'maxlength' => '',
                                    'placeholder' => '',
                                    'prepend' => '',
                                    'append' => '',
                                    'parent_repeater' => 'field_64ac7b43d7151',
                                ),
                            ),
                        ),
                        array(
                            'key' => 'field_64ac7b45d7152',
                            'label' => 'Link',
                            'name' => 'link',
                            'aria-label' => '',
                            'type' => 'link',
                            'instructions' => '',
                            'required' => 0,
                            'conditional_logic' => 0,
                            'wrapper' => array(
                                'width' => '',
                                'class' => '',
                                'id' => '',
                            ),
                            'return_format' => 'array',
                        ),
                    ),
                ),
            ),
            'location' => array(
                array(
                    array(
                        'param' => 'block',
                        'operator' => '==',
                        'value' => 'acf/rdg-memberships',
                    ),
                ),
            ),
            'menu_order' => 0,
            'position' => 'normal',
            'style' => 'default',
            'label_placement' => 'top',
            'instruction_placement' => 'label',
            'hide_on_screen' => '',
            'active' => true,
            'description' => '',
            'show_in_rest' => 0,
        ) );
        } );                         
    }

    public function getColorsToloadGeneratePress() {
        return [
            ['name' => 'color-rdg-memberships-header-bg','slug' => 'color-rdg-memberships-header-bg','color' => '#0578d4'],
            ['name' => 'color-rdg-memberships-header-border','slug' => 'color-rdg-memberships-header-border','color' => '#39a3f7'],
            ['name' => 'color-rdg-memberships-button','slug' => 'color-rdg-memberships-button','color' => '#00bb08'],
            ['name' => 'color-rdg-memberships-button-border','slug' => 'color-rdg-memberships-button-border','color' => '#68f96e'],
            ['name' => 'color-rdg-memberships-gray','slug' => 'color-rdg-memberships-gray','color' => '#f2f2f2'],
            ['name' => 'color-rdg-memberships-primary','slug' => 'color-rdg-memberships-primary','color' => '#0160ac'],
            ['name' => 'color-rdg-memberships-white','slug' => 'color-rdg-memberships-white','color' => '#ffffff'],
            ['name' => 'color-rdg-memberships-black','slug' => 'color-rdg-memberships-black','color' => '#111111'],
        ];
    }

    public function getStylesToloadGeneratePress() {
        return [
            [
                'customSelector' => '.rdg-memberships .title p',
                'fontSize' => '3.2rem',
            ],
            [
                'customSelector' => '.rdg-memberships .column .header',
                'fontWeight' => 'bold',
                'fontSize' => '1.375rem',
            ],
			[
                'customSelector' => '.rdg-memberships .column .first_pack .body .description',
                'fontSize' => '0.9rem',
            ],
			[
                'customSelector' => '.rdg-memberships .column .first_pack .body .footer .price',
                'fontWeight' => 'bolder',
                'fontSize' => '1.75rem',
            ],
            [
                'customSelector' => '.rdg-memberships .column .first_pack .body .footer .btn a',
                'fontWeight' => 'bold',
                'fontSize' => '1rem',
                'textDecoration' => 'none',
            ],
            [
                'customSelector' => '.rdg-memberships .column .second_pack .body .deal .price',
                'fontWeight' => 'bold',
                'fontSize' => '3.375rem',
            ],
            [
                'customSelector' => '.rdg-memberships .column .second_pack .body .deal .list ul li',
                'fontWeight' => 'bold',
                'fontSize' => '1rem',
            ],
            [
                'customSelector' => '.rdg-memberships .column .second_pack .body .description',
                'fontSize' => '0.9rem',
            ],
            [
                'customSelector' => '.rdg-memberships .column .second_pack .body .btn a',
                'fontWeight' => 'bold',
                'fontSize' => '1rem',
                'textDecoration' => 'none',
            ],
            [
                'customSelector' => '.rdg-memberships .column .third_pack .body .left .description',
                'fontSize' => '0.9rem',
            ],
            [
                'customSelector' => '.rdg-memberships .column .third_pack .body .right .price .dollar',
                'fontWeight' => 'bold',
                'fontSize' => '2rem',
            ],
            [
                'customSelector' => '.rdg-memberships .column .third_pack .body .right .price .amount',
                'fontWeight' => 'bold',
                'fontSize' => '3.375rem',
            ],
            [
                'customSelector' => '.rdg-memberships .column .third_pack .body .right .btn',
                'fontWeight' => 'bold',
                'fontSize' => '1rem',
            ],
            [
                'customSelector' => '.rdg-memberships .column .third_pack .body .right .btn a',
                'textDecoration' => 'none',
            ],
            [
                'customSelector' => '.rdg-memberships .column .fourth_pack .body .deal',
                'fontWeight' => 'bold',
                'fontSize' => '1.875rem',
            ],
            [
                'customSelector' => '.rdg-memberships .column .fourth_pack .body .list ul li',
                'fontWeight' => 'bold',
                'fontSize' => '0.8rem',
            ],
            [
                'customSelector' => '.rdg-memberships .column .fourth_pack .body .btn a',
                'fontWeight' => 'bold',
                'fontSize' => '1rem',
                'textDecoration' => 'none',
            ],
        ];
    }
}

$rdg_memberships_class = new Rdg_Blocks_Memberships();
$rdg_memberships_class->init();

return $rdg_memberships_class;