<?php

/*
Plugin Name: GiftCard Studio
Plugin URI: https://dynamiapps.com/custom-gift-cards
Description: Let customers design and buy personalized gift cards on your WooCommerce store.
Version: 1.0.31
Author: Shabti Kaplan
Author URI: https://dynamiapps.com
License: GPL2
Text Domain: gift-card-studio
Domain Path: /languages
*/
// Prevent direct access to the file
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
// Freemius SDK bootstrap - must load before anything else in this file (per
// Freemius's own integration requirements: it needs to be the first thing
// that runs so it can correctly detect activation/uninstall edge cases,
// e.g. the free version already being active when the premium version is
// installed).
if ( !function_exists( 'giftcard_studio_fs' ) ) {
    // Create a helper function for easy SDK access.
    function giftcard_studio_fs() {
        global $giftcard_studio_fs;
        if ( !isset( $giftcard_studio_fs ) ) {
            // Include Freemius SDK.
            require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';
            $giftcard_studio_fs = fs_dynamic_init( array(
                'id'               => '33731',
                'slug'             => 'giftcard-studio',
                'type'             => 'plugin',
                'public_key'       => 'pk_074dc8bb5925a0e93a41f20bb45d1',
                'is_premium'       => false,
                'premium_suffix'   => 'Pro',
                'has_addons'       => false,
                'has_paid_plans'   => true,
                'is_org_compliant' => true,
                'menu'             => array(
                    'support' => false,
                ),
                'is_live'          => true,
            ) );
        }
        return $giftcard_studio_fs;
    }

    // Init Freemius.
    giftcard_studio_fs();
    // Signal that SDK was initiated.
    do_action( 'giftcard_studio_fs_loaded' );
}
// Single choke point for every Pro-feature gate in this plugin - covers
// trial + valid paid license in one call (see
// vendor/freemius/includes/class-freemius.php's can_use_premium_code()).
// If Freemius's API shape ever changes, only this function needs updating.
function cgc_is_pro_active() {
    return function_exists( 'giftcard_studio_fs' ) && giftcard_studio_fs()->can_use_premium_code();
}

// Single source of truth for every "Upgrade to Pro" link across the plugin
// (Elementor upsell notice, settings page, block editor hints).
define( 'CGC_UPGRADE_URL', 'https://checkout.freemius.com/plugin/33731/plan/55407/' );
// Loads /languages/gift-card-studio-{locale}.mo for every __()/esc_html__()
// call in this plugin. Hooked on init (not called directly at file-load
// time) since WP 6.7 flags any translation function called before that
// hook as "too early". Each block's own JS-side strings are translated
// separately, via block.json's "textdomain" field (which WordPress core
// uses to auto-wire wp_set_script_translations() when the block is
// registered from that same /languages directory - see register_blocks()
// in class-cgc-blocks.php).
add_action( 'init', function () {
    load_plugin_textdomain( 'gift-card-studio', false, dirname( CGC_PLUGIN_BASENAME ) . '/languages' );
} );
if ( !class_exists( 'CustomGiftCards' ) ) {
    // Define the plugin path
    define( 'CGC_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
    define( 'CGC_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
    define( 'CGC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
    define( 'CGC_PLUGIN_VERSION', '1.0.31' );
    final class CustomGiftCards {
        public function __construct() {
            //frontend
            require_once plugin_dir_path( __FILE__ ) . 'includes/class-cgc-fetch.php';
            //includes
            require_once plugin_dir_path( __FILE__ ) . 'includes/class-cgc-post-type.php';
            //customer-facing form field definitions
            require_once plugin_dir_path( __FILE__ ) . 'includes/class-cgc-form-fields.php';
            //blocks
            require_once plugin_dir_path( __FILE__ ) . 'includes/class-cgc-blocks.php';
            //rest api
            require_once plugin_dir_path( __FILE__ ) . 'includes/class-cgc-rest-api.php';
            //misc hooks
            require_once plugin_dir_path( __FILE__ ) . 'includes/class-cgc-hooks.php';
            //woocommerce hooks
            require_once plugin_dir_path( __FILE__ ) . 'includes/class-cgc-woocommerce.php';
            //elementor widgets (no-op if Elementor isn't active)
            require_once plugin_dir_path( __FILE__ ) . 'includes/class-cgc-elementor.php';
            //wp-admin settings page
            require_once plugin_dir_path( __FILE__ ) . 'includes/class-cgc-admin-settings.php';
        }

    }

    new CustomGiftCards();
}