<?php

namespace ThemesflatAddons\i18n;

if ( !defined( 'ABSPATH' ) ) {
    exit;
}
if ( !class_exists( 'TFL_WPML_Compatibility_Init' ) ) {
    class TFL_WPML_Compatibility_Init
    {
        public function __construct()
        {
            $this->setup_constants();
            $this->includes();
            $this->hooks();
        }
        
        private function setup_constants()
        {
            // Plugin Folder Path
            if ( !defined( 'TFL_WPML_MODULES_DIR' ) ) {
                define( 'TFL_WPML_MODULES_DIR', TFL_PLUGIN_DIR . 'i18n/wpml/modules/' );
            }
        }
        
        private function includes()
        {
            require_once TFL_WPML_MODULES_DIR . 'wpml-carousel.php';
            require_once TFL_WPML_MODULES_DIR . 'wpml-clients.php';
            require_once TFL_WPML_MODULES_DIR . 'wpml-odometers.php';
            require_once TFL_WPML_MODULES_DIR . 'wpml-piecharts.php';
            require_once TFL_WPML_MODULES_DIR . 'wpml-pricing-table.php';
            require_once TFL_WPML_MODULES_DIR . 'wpml-services.php';
            require_once TFL_WPML_MODULES_DIR . 'wpml-stats-bars.php';
            require_once TFL_WPML_MODULES_DIR . 'wpml-team-members.php';
            require_once TFL_WPML_MODULES_DIR . 'wpml-testimonials.php';
            require_once TFL_WPML_MODULES_DIR . 'wpml-testimonials-slider.php';
        }
        
        private function hooks()
        {
            add_filter( 'wpml_elementor_widgets_to_translate', array( $this, 'wpml_widgets_to_translate_filter' ) );
        }
        
        public function wpml_widgets_to_translate_filter( $widgets )
        {
            $tfl_widgets = array(
                'tfl-heading'             => array(
                'conditions' => array(
                'widgetType' => 'tfl-heading',
            ),
                'fields'     => array( array(
                'field'       => 'heading',
                'type'        => __( 'Heading: Title', 'themesflat' ),
                'editor_type' => 'LINE',
            ), array(
                'field'       => 'subtitle',
                'type'        => __( 'Heading: Subheading', 'themesflat' ),
                'editor_type' => 'LINE',
            ), array(
                'field'       => 'short_text',
                'type'        => __( 'Heading: Short Text', 'themesflat' ),
                'editor_type' => 'AREA',
            ) ),
            ),
                'tfl-carousel'            => array(
                'conditions'        => array(
                'widgetType' => 'tfl-carousel',
            ),
                'fields'            => array(),
                'integration-class' => '\\ThemesflatAddons\\i18n\\TFL_WPML_Carousel',
            ),
                'tfl-clients'             => array(
                'conditions'        => array(
                'widgetType' => 'tfl-clients',
            ),
                'fields'            => array(),
                'integration-class' => '\\ThemesflatAddons\\i18n\\TFL_WPML_Clients',
            ),
                'tfl-odometers'           => array(
                'conditions'        => array(
                'widgetType' => 'tfl-odometers',
            ),
                'fields'            => array(),
                'integration-class' => '\\ThemesflatAddons\\i18n\\TFL_WPML_Odometers',
            ),
                'tfl-piecharts'           => array(
                'conditions'        => array(
                'widgetType' => 'tfl-piecharts',
            ),
                'fields'            => array(),
                'integration-class' => '\\ThemesflatAddons\\i18n\\TFL_WPML_Piecharts',
            ),
                'tfl-pricing-table'       => array(
                'conditions'        => array(
                'widgetType' => 'tfl-pricing-table',
            ),
                'fields'            => array(),
                'integration-class' => '\\ThemesflatAddons\\i18n\\TFL_WPML_Pricing_Table',
            ),
                'tfl-services'            => array(
                'conditions'        => array(
                'widgetType' => 'tfl-services',
            ),
                'fields'            => array(),
                'integration-class' => '\\ThemesflatAddons\\i18n\\TFL_WPML_Services',
            ),
                'tfl-stats-bars'          => array(
                'conditions'        => array(
                'widgetType' => 'tfl-stats-bars',
            ),
                'fields'            => array(),
                'integration-class' => '\\ThemesflatAddons\\i18n\\TFL_WPML_Stats_Bars',
            ),
                'tfl-team-members'        => array(
                'conditions'        => array(
                'widgetType' => 'tfl-team-members',
            ),
                'fields'            => array(),
                'integration-class' => '\\ThemesflatAddons\\i18n\\TFL_WPML_Team_Members',
            ),
                'tfl-testimonials'        => array(
                'conditions'        => array(
                'widgetType' => 'tfl-testimonials',
            ),
                'fields'            => array(),
                'integration-class' => '\\ThemesflatAddons\\i18n\\TFL_WPML_Testimonials',
            ),
                'tfl-testimonials-slider' => array(
                'conditions'        => array(
                'widgetType' => 'tfl-testimonials-slider',
            ),
                'fields'            => array(),
                'integration-class' => '\\ThemesflatAddons\\i18n\\TFL_WPML_Testimonials_Slider',
            ),
            );
            $widgets = array_merge( $widgets, $tfl_widgets );
            $tfl_widgets = array(
                'tfl-portfolio' => array(
                'conditions' => array(
                'widgetType' => 'tfl-portfolio',
            ),
                'fields'     => array( array(
                'field'       => 'heading',
                'type'        => __( 'Posts Grid: Heading', 'themesflat' ),
                'editor_type' => 'LINE',
            ) ),
            ),
            );
            $widgets = array_merge( $widgets, $tfl_widgets );
            return $widgets;
        }
    
    }
}