<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Enqueue section builder modal script on the Reusable Templates admin screen.
 *
 * @param string $hook_suffix Current admin page hook suffix.
 */
function sifency_addons_enqueue_section_builder_assets( $hook_suffix ) {
	$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null;

	$is_section_page = (
		'sifency-addons_page_sifency-templates-shortcode' === $hook_suffix
		|| ( $screen && false !== strpos( $screen->id, 'sifency-templates-shortcode' ) )
	);

	if ( ! $is_section_page ) {
		return;
	}

	sifency_addons_enqueue_template_inline_edit_assets(
		'sifency_update_section_template_details',
		'sifency_section_builder_nonce'
	);

	wp_enqueue_script(
		'sifency-section-builder',
		SIFENCY_ADDONS_URL . 'assets/js/admin/section-builder.js',
		array( 'jquery', 'sifency-template-inline-edit' ),
		SIFENCY_ADDONS_VERSION,
		true
	);

	wp_localize_script(
		'sifency-section-builder',
		'sifencySectionBuilder',
		array(
			'ajaxUrl' => admin_url( 'admin-ajax.php' ),
			'nonce'   => wp_create_nonce( 'sifency_section_builder_nonce' ),
		)
	);
}
add_action( 'admin_enqueue_scripts', 'sifency_addons_enqueue_section_builder_assets' );
