<?php
namespace TbiBank\FusionPay\Block\Adminhtml;

/**
 * Custom renderer for the button field in admin configuration.
 * 
 * This class extends Magento's form field renderer to provide a custom template
 * for rendering a button field within the system configuration.
 */
class ButtonFieldRenderer extends \Magento\Config\Block\System\Config\Form\Field
{
    /**
     * Path to the template file in the theme.
     *
     * @var string
     */
    protected $_template = 'TbiBank_FusionPay::button_field_renderer.phtml';

    /**
     * Generate the HTML for the element. This method assigns the element to the block
     * and renders the HTML based on the custom template.
     * 
     * @param \Magento\Framework\Data\Form\Element\AbstractElement $element Form element
     * @return string HTML string for the element
     */
    protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
    {
        // Pass the form element to the template
        $this->setData('element', $element);
        return $this->_toHtml(); // Renders the HTML based on the assigned template
    }

    /**
     * Provides options for the button renderer. Each option consists of a value and label.
     * The label contains HTML markup for displaying custom buttons with styles and logos.
     * 
     * @return array List of options for the button field
     */
    public function getOptions()
    {
        $logoUrl = 'https://cdn.tbibank.support/logo/tbi-bank.svg';

        $previewHtml =
            '<div class="tbi_button_container1 tbi_admin_button_preview_ro">' .
                '<div id="tbi_button1" class="tbi_button_ro">' .
                    '<div id="tbi_button_body1" class="tbi_button_body_ro">' .
                        '<div class="tbi_button_ro_info">' .
                            '<div class="tbi_button_ro_brand">' .
                                '<img src="' . $logoUrl . '" id="tbi_button_logo1" class="tbi_button_ro_logo" alt="TBI Bank">' .
                            '</div>' .
                            '<div class="tbi_button_ro_divider" aria-hidden="true"></div>' .
                            '<div class="tbi_button_ro_copy">' .
                                '<div class="tbi_button_ro_title">' . __('Pay as little as') . '</div>' .
                                '<div class="tbi_button_line--ro-amount">' .
                                   ' 123.45 ' . __('RON') . ' / ' . __('month') .
                                '</div>' .
                            '</div>' .
                        '</div>' .
                        '<div class="tbi_button_ro_details">' . __('Details here') . '</div>' .
                    '</div>' .
                '</div>' .
            '</div>';

        return [
            [
                'value' => 'button1',
                'label' => '<div class="tbi_button_container">' . __('No button') . '</div>',
            ],
            [
                'value' => 'button2',
                'label' => $previewHtml,
            ],
        ];
    }
}
