<?php
defined('ABSPATH') or die('No direct access permitted');
$blockClass["advanced"] = "advancedProBlock"; 
 
use MaxButtons\maxBlocks  as maxBlocks;
use MaxButtons\maxField   as maxField;
	
class advancedProBlock extends advancedBlock 
{
	public function __construct()
	{
		parent::__construct();
		$this->fields['anchor_data'] = array('default' => '');
		$this->fields['anchor_data_value'] = array('default' => ''); 
		
		add_action('mb-after-advanced', array($this, 'advanced_fields')); 
	}		
	
	public function advanced_fields() 
	{
		$data = new maxField(); 
		$data->id = 'anchor_data'; 
		$data->name = $data->id; 
		$data->value = maxBlocks::getValue($data->id); 
		$data->label = __('Data Attribute','maxbuttons-pro'); 
		$data->note = __('Used for targeting plugins and other data sources that make use of the data- attribute.', 'maxbuttons-pro'); 
		$data->before_input = 'data-'; 
		$data->placeholder = "example";
		$data->inputclass = 'medium'; 
		$data->output('start', '');
		
		$dval = new maxField(); 
		$dval->id = 'anchor_data_value'; 
		$dval->name = $dval->id;
		$dval->value= maxBlocks::getValue($dval->id); 
		$dval->label = __('Value', 'maxbuttons-pro'); 
		$dval->placeholder = ''; 
		$dval->inputclass = 'medium'; 
		$dval->output(false, 'end');
	}
	
	public function parse_button($domObj, $mode= 'normal')
	{
		$domObj = parent::parse_button($domObj, $mode); 
 
		$data = $this->data[$this->blockname]; 	
		$button_id = $this->data["id"]; 		
		$anchor = $domObj->find("a",0); 		
 
 		$anchor_data = isset($data['anchor_data']) ? trim($data['anchor_data']) : ''; 
 		$anchor_data_value = isset($data['anchor_data_value']) ? $data['anchor_data_value'] : ''; 
 		if ($anchor_data == '')
 			return $domObj; 
 		
 		$anchor->{'data-' .$anchor_data} = $anchor_data_value;
 
		return $domObj;
	}

}


