<?php

/**
 * Redux_Travelpayouts Typography AJAX Class
 *
 * @class Redux_Travelpayouts_Core
 * @version 4.0.0
 * @package Redux_Travelpayouts Framework
 */

defined('ABSPATH') || exit;

if (! class_exists('Redux_Travelpayouts_AJAX_Typography', false)) {

    /**
     * Class Redux_Travelpayouts_AJAX_Typography
     */
    class Redux_Travelpayouts_AJAX_Typography extends Redux_Travelpayouts_Class
    {
        /**
         * Redux_Travelpayouts_AJAX_Typography constructor.
         *
         * @param object $parent RedusFramework object.
         */
        public function __construct($parent)
        {
            parent::__construct($parent);
            add_action('wp_ajax_Redux_Travelpayouts_update_google_fonts', [ $this, 'google_fonts_update' ]);
        }

        /**
         * Google font AJAX callback
         *
         * @return mixed
         */
        public function google_fonts_update()
        {
            $field_class = 'Redux_Travelpayouts_typography';

            if (! class_exists($field_class)) {
                $dir = str_replace('/classes', '', Redux_Travelpayouts_Functions_Ex::wp_normalize_path(dirname(__FILE__)));

                // phpcs:ignore WordPress.NamingConventions.ValidHookName
                $class_file = apply_filters('redux-typeclass-load', $dir . '/fields/typography/class-travelpayouts-typography.php', $field_class);
                if ($class_file) {
                    require_once $class_file;
                }
            }

            if (class_exists($field_class) && method_exists($field_class, 'google_fonts_update_ajax')) {
                $f = new $field_class([], '', $this->parent);

                return $f->google_fonts_update_ajax();
            }

            die();
        }
    }
}
