<?php
/**
 * Plugin Name: Aspaclaria Invoices (Compatibility Loader)
 * Description: Compatibility loader. Use "PayCal Invoices" as the main plugin.
 * Version: 2.0.0
 */
if (!defined('ABSPATH')) exit;

$paycal_invoice_loader = __DIR__ . '/paycal-invoices.php';
if (!file_exists($paycal_invoice_loader)) {
    \paycal_debug_log('[PayCal Invoices] Missing compatibility loader target: ' . $paycal_invoice_loader);
    add_action('admin_notices', function () {
        if (current_user_can('manage_options')) {
            echo '<div class="notice notice-error"><p>' . esc_html__('PayCal Invoices compatibility loader could not find the main invoice file.', 'klamra-paycal-for-aspaclaria') . '</p></div>';
        }
    });
    return;
}

try {
    require_once $paycal_invoice_loader;
} catch (Throwable $e) {
    \paycal_debug_log('[PayCal Invoices] Compatibility loader failed: ' . $e->getMessage());
    add_action('admin_notices', function () {
        if (current_user_can('manage_options')) {
            echo '<div class="notice notice-error"><p>' . esc_html__('PayCal Invoices failed to load safely. Check the server error log.', 'klamra-paycal-for-aspaclaria') . '</p></div>';
        }
    });
}
