<?php
// File: public/class-public.php

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

class PC_HFAP_Public {
    
    public function __construct() {
        add_action('wp_head', array($this, 'output_header_snippets'), 9999);
        add_action('wp_body_open', array($this, 'output_body_snippets'), 9999);
        add_action('wp_footer', array($this, 'output_footer_snippets'), 9999);
        add_action('wp_enqueue_scripts', array($this, 'enqueue_public_assets'));
    }
    
    public function output_header_snippets() {
        $snippets = PC_HFAP_Snippet::get_headers();
        
        if (empty($snippets)) {
            return;
        }
        
        echo "\n<!-- Headers & Footers Code Plugin - Header Snippets -->\n";
        
        foreach ($snippets as $snippet) {
            echo "\n<!-- Snippet: " . esc_html($snippet->get_title()) . " -->\n";
            echo $snippet->get_code() . "\n";
            echo "<!-- End Snippet: " . esc_html($snippet->get_title()) . " -->\n";
        }
        
        echo "\n<!-- End Headers & Footers Code Plugin - Header Snippets -->\n";
    }
    
    public function output_footer_snippets() {
        $snippets = PC_HFAP_Snippet::get_footers();
        
        if (empty($snippets)) {
            return;
        }
        
        echo "\n<!-- Headers & Footers Code Plugin - Footer Snippets -->\n";
        
        foreach ($snippets as $snippet) {
            echo "\n<!-- Snippet: " . esc_html($snippet->get_title()) . " -->\n";
            echo $snippet->get_code() . "\n";
            echo "<!-- End Snippet: " . esc_html($snippet->get_title()) . " -->\n";
        }
        
        echo "\n<!-- End Headers & Footers Code Plugin - Footer Snippets -->\n";
    }

    public function output_body_snippets() {
        $snippets = PC_HFAP_Snippet::get_bodies();

        if (empty($snippets)) {
            return;
        }

        echo "\n<!-- Headers & Footers Code Plugin - Body Snippets -->\n";

        foreach ($snippets as $snippet) {
            echo "\n<!-- Snippet: " . esc_html($snippet->get_title()) . " -->\n";
            echo $snippet->get_code() . "\n";
            echo "<!-- End Snippet: " . esc_html($snippet->get_title()) . " -->\n";
        }

        echo "\n<!-- End Headers & Footers Code Plugin - Body Snippets -->\n";
    }
    
    public function enqueue_public_assets() {
        // Enqueue public styles if needed
        wp_enqueue_style(
            'pc-hfap-public-style',
            PC_HFAP_PLUGIN_URL . 'public/css/public-style.css',
            array(),
            PC_HFAP_VERSION
        );
    }
}
