<?php
/**
 * Includes: Pages
 */
if (!defined('ABSPATH')) {
    die('Sorry, you cannot access this page.');
}

/**
 * Add display states for pages
 */
function chama_add_display_page_states($post_states, $post)
{

    switch ($post->ID) {
        case get_option('chama_hub_page'):
            $post_states['chama_hub_page'] = __('Hub Page', 'chama');
            break;

        case get_option('chama_donate_page'):
            $post_states['chama_donate_page'] = __('Donate Page', 'chama');
            break;

        case get_option('chama_membership_page'):
            $post_states['chama_membership_page'] = __('Membership Page', 'chama');
            break;
        case get_option('chama_crowdfunding_page'):
            $post_states['chama_crowdfunding_page'] = __('Crowdfunding Page', 'chama');
            break;
        case get_option('chama_commissions_page'):
            $post_states['chama_commissions_page'] = __('Commissions Page', 'chama');
            break;
        case get_option('chama_login_page'):
            $post_states['chama_login_page'] = __('Login Page', 'chama');
            break;
        case get_option('chama_registration_page'):
            $post_states['chama_registration_page'] = __('Registration Page', 'chama');
            break;
        case get_option('chama_edit_account_page'):
            $post_states['chama_edit_account_page'] = __('Edit Account Page', 'chama');
            break;
        case get_option('chama_edit_password_page'):
            $post_states['chama_edit_password_page'] = __('Edit Password Page', 'chama');
            break;
        case get_option('chama_forgot_password_page'):
            $post_states['chama_forgot_password_page'] = __('Forgot Password Page', 'chama');
            break;
        case get_option('chama_reset_password_page'):
            $post_states['chama_reset_password_page'] = __('Reset Password Page', 'chama');
            break;
        case get_option('chama_verify_email_page'):
            $post_states['chama_verify_email_page'] = __('Verify Email Page', 'chama');
            break;
        case get_option('chama_account_page'):
            $post_states['chama_account_page'] = __('Account Page', 'chama');
            break;
        case get_option('chama_payment_page'):
            $post_states['chama_payment_page'] = __('Payment Page', 'chama');
            break;
        case get_option('chama_payment_confirmation_page'):
            $post_states['chama_payment_confirmation_page'] = __('Payment Confirmation Page', 'chama');
            break;
        case get_option('chama_subscription_page'):
            $post_states['chama_subscription_page'] = __('Subscription Page', 'chama');
            break;
        case get_option('chama_subscription_confirmation_page'):
            $post_states['chama_subscription_confirmation_page'] = __('Subscription Confirmation Page', 'chama');
            break;
        case get_option('chama_newsletter_sign_up_confirmation_page'):
            $post_states['chama_newsletter_sign_up_confirmation_page'] = __('Newsletter Signup Confirmation Page', 'chama');
            break;
        case get_option('chama_newsletter_opt_out_confirmation_page'):
            $post_states['chama_newsletter_opt_out_confirmation_page'] = __('Newsletter Opt-out Confirmation Page', 'chama');
            break;

    }

    return $post_states;
}

// Add a post display state for Chama pages.
add_filter('display_post_states', 'chama_add_display_page_states', 10, 2);
/**
 * Add body classes for pages
 */
add_filter('body_class', 'chama_add_body_classes_from_page_options');
function chama_add_body_classes_from_page_options($classes) {
    if (!is_page()) {
        return $classes;
    }

    $page_id = get_queried_object_id(); // Current page ID

    $pages = [
        'chama_hub_page'                    => 'hub-page',
        'chama_donate_page'                 => 'donate-page',
        'chama_membership_page'            => 'membership-page',
        'chama_crowdfunding_page'          => 'crowdfunding-page',
        'chama_commissions_page'           => 'commissions-page',
        'chama_login_page'                 => 'login-page',
        'chama_registration_page'          => 'registration-page',
        'chama_edit_account_page'          => 'edit-account-page',
        'chama_edit_password_page'         => 'edit-password-page',
        'chama_forgot_password_page'       => 'forgot-password-page',
        'chama_reset_password_page'        => 'reset-password-page',
        'chama_verify_email_page'          => 'verify-email-page',
        'chama_account_page'               => 'account-page',
        'chama_payment_page'               => 'payment-page',
        'chama_payment_confirmation_page'  => 'payment-confirmation-page',
        'chama_subscription_page'          => 'subscription-page',
        'chama_subscription_confirmation_page' => 'subscription-confirmation-page',
        'chama_newsletter_sign_up_confirmation_page' => 'newsletter-sign-up-confirmation-page',
        'chama_newsletter_opt_out_confirmation_page' => 'newsletter-opt-out-confirmation-page',
    ];

    foreach ($pages as $option => $class_name) {
        if ((int) get_option($option) === $page_id) {
            $classes[] = 'chamawp-page';
            $classes[] = 'chama-' . $class_name;
            break; // Only add one match
        }
    }

    return $classes;
}