<?php
namespace Wpupgrader\Libraries\WordPress\Plugins\Core\Settings\Page\Callback;

use Wpupgrader\Libraries\WordPress\Plugins\Core\Settings\Page\Callback;

class Colorpicker extends Callback
{
    public function callbackAction()
    {
        echo '<input type="text" value="'.$this->getValue().'" '.$this->getNameIdString().' class="regular-text color-picker-text" onBlur=\'jQuery("#'.$this->getIdString().'").spectrum("set", this.value);\' /> '
             .$this->getTranslateLink().'<p>'.$this->getDescription().'</p>';

        \wp_add_inline_script('common', '
jQuery(function(){
    jQuery("#'.$this->getIdString().'").spectrum({
        "showInput": true,
        "flat": false,
        "showInitial": true,
        "allowEmpty": false,
        "showAlpha": true,
        "disabled": '.(!empty($this->args['disabled']) ? $this->args['disabled'] : 'false').',
        "localStorageKey": '.(!empty($this->args['palette']) ? '"'.$this->args['palette'].'"' : 'false').',
        "showPalette": true,
        "showPaletteOnly": true,
        "togglePaletteOnly": true,
        "cancelText": "Close",
        "chooseText": "Use Color",
        "togglePaletteMoreText": "Customize >>",
        "togglePaletteLessText": "<< Minimize",
        "containerClassName": "'.(!empty($this->args['class']) ? $this->args['class'] : '').'",
        "preferredFormat": "rgb",
        "palette": [],
    });
});'
        );
    }
}