<?php

namespace Blazemedia\Affiliation\AdminUserInterface\Buttons;

use Blazemedia\Affiliation\API\CachedApi;

/*
 *  Class AffiliateZone
 *  
 *  Bottone e UI per la creazione degli shortcode delle zone
 */

class AffiliateBranded extends Button {

    function __construct() {

        /** 
         * Set the name of the plugin 
         * >> affiliation_link.js
         * 
         * and the name of the ajax endpoint to call into plugin
         * >> affiliation_link_action
         */
        parent::__construct('affiliation_branded', 'affiliation_branded_action', 'dialog-AffiliateBranded.html');
    }

    public function addFieldsToDialog(): array {

        $buttonsFormats = json_decode( CachedApi::getInstance()->get(BLZ_API_FORMAT_PROVIDER.'buttons/'), true );
        $linksFormats = json_decode( CachedApi::getInstance()->get(BLZ_API_FORMAT_PROVIDER.'links/'), true );

        $format[] = array_shift(array_filter($buttonsFormats, fn($format) => $format['code'] == 'btn'));

        $format[] = array_shift(array_filter($linksFormats, fn($format) => $format['code'] == 'lnk'));

        return [

            [
                'name' => 'ApiBrandedContent',
                'value' => BLZ_API_BRANDED_CONTENT
            ],
            [
                'name' => 'formats',
                'value' => json_encode($format)
            ]

        ];
    }


    protected function getZones(): array {

        return [];
    }
}
