<?php
if ( ! defined( 'ABSPATH' ) ) exit;
function vista_register_elementor_category( $elements_manager ) {
	$elements_manager->add_category( 'vista-widgets', [
		'title' => esc_html__( 'ویجت های ویستا', 'vista' ),
		'icon'  => 'fa fa-plug',
	] );
}
add_action( 'elementor/elements/categories_registered', 'vista_register_elementor_category' );

function vista_register_elementor_widgets( $widgets_manager ) {
	$dir = get_template_directory() . '/inc/elementor/widgets/';
	$widgets = [
		'class-vista-skills-widget'      => 'Vista_Skills_Widget',
		'class-vista-techstack-widget'   => 'Vista_Techstack_Widget',
		'class-vista-career-widget'      => 'Vista_Career_Widget',
		'class-vista-education-widget'   => 'Vista_Education_Widget',
		'class-vista-services-widget'    => 'Vista_Services_Widget',
		'class-vista-testimonials-widget'=> 'Vista_Testimonials_Widget',
		'class-vista-stats-widget'       => 'Vista_Stats_Widget',
		'class-vista-pricing-widget'     => 'Vista_Pricing_Widget',
		'class-vista-social-widget'      => 'Vista_Social_Widget',
		'class-vista-portfolio-carousel-widget'   => 'Vista_Portfolio_Carousel_Widget',
		'class-vista-portfolio-widget'   => 'Vista_Portfolio_Widget',
		'class-vista-blog-carousel-widget'        => 'Vista_Blog_Carousel_Widget',
		'class-vista-blog-widget'        => 'Vista_Blog_Widget',
		'class-vista-typed-text-widget'  => 'Vista_Typed_Text_Widget',
		'class-vista-button-widget'      => 'Vista_Button_Widget',
		'class-vista-title-widget'       => 'Vista_Section_Title_Widget',
		'class-vista-hero-widget'       => 'Vista_Hero_Image_Widget',
		'class-vista-archive-header-widget'       => 'Vista_Archive_Header_Widget',
	];
	foreach ( $widgets as $file => $class ) {
		$path = $dir . $file . '.php';
		if ( ! file_exists( $path ) ) continue;
		require_once $path;
		if ( class_exists( $class ) ) {
			$widgets_manager->register( new $class() );
		}
	}
}
add_action( 'elementor/widgets/register', 'vista_register_elementor_widgets' );
function vista_enqueue_elementor_assets() {
	$v   = wp_get_theme()->get( 'Version' );
	$uri = get_template_directory_uri() . '/inc/elementor/';
	$dir = get_template_directory()     . '/inc/elementor/';
	if ( file_exists( $dir . 'base.css' ) ) {
		wp_enqueue_style(
			'vista-elementor-base',
			$uri . 'base.css',
			[],
			$v
		);
	}
	
	if ( file_exists( $dir . 'base.js' ) ) {
		wp_enqueue_script(
			'vista-base',
			$uri . 'base.js',
			[ 'vista-typed-js' ],
			$v,
			true
		);
	}
}
add_action( 'wp_enqueue_scripts', 'vista_enqueue_elementor_assets' );
add_action( 'elementor/preview/enqueue_scripts', 'vista_enqueue_elementor_assets' );


function vista_typed_text_register_assets() {
	$v   = wp_get_theme()->get( 'Version' );
	$uri = get_template_directory_uri() . '/inc/elementor/';
	$dir = get_template_directory()     . '/inc/elementor/';
	if ( file_exists( $dir . 'typed.js' ) ) {
		wp_register_script(
			'vista-typed-js',
			$uri . 'typed.js',
			[],
			$v,
			true
		);
	}
}
add_action( 'wp_enqueue_scripts', 'vista_typed_text_register_assets' );
add_action( 'elementor/preview/enqueue_scripts', 'vista_typed_text_register_assets' );
