<?php
/**
 * Plugin Name:       CrispyCohd Advanced Accordion Block
 * Description:       Flexible accordion block allowing core and custom blocks to be used in any configuration. Built to align with WCAG 2.2 and WAI-ARIA Authoring Practices for accordions.
 * Version:           1.0.2
 * Author:            CrispyCohd
 * Author URI:        https://crispycohd.com/
 * License:           GPLv2 or later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       crispycohd-advanced-accordion-block
 * Requires PHP:      7.4
 * Requires at least: 6.5
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

define( 'CRISPYCOHD_AAB_VERSION', '1.0.2' );
define( 'CRISPYCOHD_AAB_PATH', plugin_dir_path( __FILE__ ) );
define( 'CRISPYCOHD_AAB_URL', plugin_dir_url( __FILE__ ) );
define( 'CRISPYCOHD_AAB_UPGRADE_URL', 'https://crispycohd.com/' );

/**
 * Cache-busting asset version: plugin version + file modified time + short content hash.
 * This avoids stale caches even if ZIP installs preserve file timestamps.
 */
if ( ! function_exists( 'crispycohd_aab_asset_version' ) ) {
    function crispycohd_aab_asset_version( $relative_path ) {
        $relative_path = ltrim( str_replace( ['\\'], '/', $relative_path ), '/' );
        $file = CRISPYCOHD_AAB_PATH . $relative_path;

        if ( file_exists( $file ) ) {
            return CRISPYCOHD_AAB_VERSION . '.' . filemtime( $file );
        }
        return CRISPYCOHD_AAB_VERSION;
    }
}

/**
 * Add a "See More" link next to Activate/Deactivate on the Plugins screen.
 */
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), function( $links ) {
    $links[] = '<a href="' . esc_url( CRISPYCOHD_AAB_UPGRADE_URL ) . '" target="_blank" rel="noopener noreferrer">' . esc_html__( 'More from CrispyCohd', 'crispycohd-advanced-accordion-block' ) . '</a>';
    return $links;
} );

require_once CRISPYCOHD_AAB_PATH . 'includes/class-crispycohd-accordion.php';

\CrispyCohd\AdvancedAccordionBlock\Accordion::init();
