<?php

/**
 * Plugin Name: StoreInvoice Print PDF Invoices and Packing Slips
 * Description: Print PDF Invoices for WooCommerce orders. Create and customize PDF invoices, packing slips, delivery notes, and more with ease.
 * Plugin URI:  https://storeplugin.net/plugins/storeinvoice-print-pdf-invoices-and-packing-slips/
 * Version:     1.0.2
 * Author:      StorePlugin
 * Author URI:  https://storeplugin.net/
 * Requires Plugins: woocommerce
 * License:     GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: storeinvoice-print-pdf-invoices-and-packing-slips
 */
defined('ABSPATH') || exit;

require __DIR__ . '/preflight-checker.php';

if (NXTPDFPreflightChecker::isProActive('storeinvoice-print-pdf-invoices-and-packing-slips-pro/storeinvoice-print-pdf-invoices-and-packing-slips-pro.php')) {
	return;
}

/** PSR-4 compatible autoload */
$nxtpdf_autoloader = require __DIR__ . '/vendor/autoload.php';

/** Import necessary classes */
use Storeplugin\PDFInvoice\Framework\Containers\Dice;
use Storeplugin\PDFInvoice\Framework\Utils\AdminNotice;
use Storeplugin\PDFInvoice\Framework\Utils\Utils;
use Storeplugin\PDFInvoice\Container;

/** PATH constant */
if (! defined('NXTPDF_PATH')) {
	define('NXTPDF_PATH', __FILE__);
}

/** DIR constant */
if (! defined('NXTPDF_DIR')) {
	define('NXTPDF_DIR', __DIR__);
}

/** Version constant */
if (! defined('NXTPDF_VERSION')) {
	define('NXTPDF_VERSION', '1.0.2');
}

/** Plugin name constant */
if (! defined('NXTPDF_NAME')) {
	define('NXTPDF_NAME', 'storeinvoice-print-pdf-invoices-and-packing-slips');
}

/** BASE constant */
if (! defined('NXTPDF_BASE')) {
	define('NXTPDF_BASE', plugin_basename(NXTPDF_PATH));
}

/** URL constant (plugin directory URL) */
if (! defined('NXTPDF_URL')) {
	define('NXTPDF_URL', plugins_url('', NXTPDF_PATH));
}

/** Load container with autowiring process */
try {
	$nxtpdf_container = new Container($nxtpdf_autoloader->getPrefixesPsr4());
	$nxtpdf_container->container(new Dice())->register();
} catch (\RuntimeException $e) {
	AdminNotice::error(
		'Failed to initialize dependency container. ' . esc_html($e->getMessage())
	);

	Utils::logError('Container Error', $e);

	return;
} catch (\Throwable $e) {
	$nxtpdf_message = 'An unexpected error occurred during plugin initialization.';

	if (Utils::isDebugMode()) {
		$nxtpdf_message .= '<br><code>' . esc_html($e->getMessage()) . '</code>';
	}

	AdminNotice::error($nxtpdf_message);

	Utils::logError('Fatal Error', $e);

	return;
}
