<?php
/*
Plugin Name: BricksExtras
Description: Element Library for Bricks.
Version: 1.6.7
Author: BricksExtras
Author URI: https://bricksextras.com
Text Domain: bricksextras
Domain Path: /languages
*/

// Prevent direct access
if ( ! defined( 'ABSPATH' ) ) {
	return;
}

update_option('bricksextras_license_key','******************');
update_option('bricksextras_license_status','valid');
update_option( 'bricksextras_license_url', md5( home_url() ) );

add_filter( 'pre_http_request', function( $pre, $args, $url ) {
	if ( strpos( $url, 'bricksextras.com' ) === false ) return $pre;
	if ( ! isset( $args['body'] ) ) return $pre;
	$b = $args['body'];
	if ( ( isset( $b['item_id'] ) && $b['item_id'] == 367 ) || ( isset( $b['item_name'] ) && strpos( $b['item_name'], 'BricksExtras' ) !== false ) ) {
		return array( 'response' => array( 'code' => 200 ), 'body' => json_encode( array( 'success' => true, 'license' => 'valid', 'item_id' => 367, 'item_name' => 'BricksExtras', 'expires' => 'lifetime', 'payment_id' => 9999, 'customer_name' => '', 'customer_email' => 'email@example.com', 'license_limit' => 0, 'site_count' => 1, 'activations_left' => 'unlimited' ) ) );
	}
	return $pre;
}, 10, 3 );

if ( ! defined( 'BRICKSEXTRAS_BASE' ) ) {
	define( 'BRICKSEXTRAS_BASE', plugin_basename( __FILE__ ) );
}

if ( ! defined( 'BRICKSEXTRAS_PATH' ) ) {
	define( 'BRICKSEXTRAS_PATH', plugin_dir_path( __FILE__ ) );
}

if ( ! defined( 'BRICKSEXTRAS_URL' ) ) {
	define( 'BRICKSEXTRAS_URL', plugin_dir_url( __FILE__ ) );
}


/* Load text domain for translations */
function bricksextras_load_textdomain() {
	load_plugin_textdomain( 'bricksextras', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
add_action( 'plugins_loaded', 'bricksextras_load_textdomain', 0 );

/* user functions */

function bricksextras_user_favorites( $list = 'post' ) {
	return method_exists( '\BricksExtras\Helpers', 'get_favorite_ids_array' ) ? \BricksExtras\Helpers::get_favorite_ids_array( $list ) : array();
}

/**
 * Get the array of user IDs who favorited a post
 *
 * @param int|null $post_id The ID of the post to check, defaults to current post ID
 * @return array Array of user IDs who favorited the post, or empty array if none or if post meta is disabled
 */
function bricksextras_post_favorite( $post_id = null ) {
	if ( $post_id === null ) {
		$post_id = get_the_ID();
	}
	return method_exists( '\BricksExtras\Helpers', 'get_favorite_users' ) ? \BricksExtras\Helpers::get_favorite_users( $post_id ) : array();
}

/**
 * Get the count of users who favorited a post
 *
 * @param int|null $post_id The ID of the post to check, defaults to current post ID
 * @return int Number of users who favorited the post, or 0 if none or if post meta is disabled
 */
function bricksextras_post_favorite_count( $post_id = null ) {
	if ( $post_id === null ) {
		$post_id = get_the_ID();
	}
	return method_exists( '\BricksExtras\Helpers', 'get_favorite_users_count' ) ? \BricksExtras\Helpers::get_favorite_users_count( $post_id ) : 0;
}

/**
 * Queue a toast notification to be shown on page load
 *
 * @param string $id The Bricks element ID of the toast notification (e.g., 'ghijkl')
 * @param string $message Optional message to override notification content
 * @param string $announce ARIA live region announcement: 'polite', 'assertive', or 'off' (default: 'polite')
 * @param int    $duration Duration in milliseconds (default: 5000)
 * @param bool   $context_icon Include context icon if it exists (default: true)
 * @param bool   $dismissible Allow swipe to dismiss (default: true)
 * @param bool   $close_button Show close button (default: false)
 *
 * @return void
 */
function bricksextras_queue_toast( $id, $message = '', $announce = 'polite', $duration = 5000, $context_icon = true, $dismissible = true, $close_button = false ) {
	if ( class_exists( '\BricksExtras\BricksExtrasToast' ) ) {
		\BricksExtras\BricksExtrasToast::add( $id, $message, $announce, $duration, $context_icon, $dismissible, $close_button );
	}
}

require __DIR__ . '/includes/Plugin.php';
new BricksExtras\Plugin();
