// =======================
// POLICIES PORTAL SHORTCODE
// =======================

add_shortcode('policies_portal', 'policies_portal_function');

function policies_portal_function() {

ob_start();

$args = array(
    'post_type' => 'policies',
    'posts_per_page' => -1,
    'orderby' => 'meta_value',
    'meta_key' => 'effective_date',
    'order' => 'DESC'
);

$query = new WP_Query($args);

if ($query->have_posts()) {

    echo '<div class="document-grid">';

    while ($query->have_posts()) : $query->the_post();

        $file = get_field('document_file');
        $description = get_field('short_description');
        $date = get_field('effective_date');

        echo '<div class="document-card">';

        echo '<div class="document-meta">';

        if ($date) {
            echo '<span class="document-date">Effective: ' . date('F j, Y', strtotime($date)) . '</span>';
        }

        echo '</div>';

        echo '<h3 class="document-title">' . get_the_title() . '</h3>';

        if ($description) {
            echo '<p class="document-description">' . esc_html($description) . '</p>';
        }

        if ($file) {
            echo '' . esc_url($file['url']) . 'View Policy</a>';
        }

        echo '</div>';

    endwhile;

    echo '</div>';

} else {
    echo '<p>No policies available.</p>';
}

wp_reset_postdata();

return ob_get_clean();
}

// =======================
// NOTICES PORTAL SHORTCODE
// =======================

add_shortcode('notices_portal', 'notices_portal_function');

function notices_portal_function() {

ob_start();

$args = array(
    'post_type' => 'notices',
    'posts_per_page' => -1,
    'orderby' => 'date',
    'order' => 'DESC'
);

$query = new WP_Query($args);

if ($query->have_posts()) {

    echo '<div class="notice-grid">';

    while ($query->have_posts()) : $query->the_post();

        $summary = get_field('summary');
        $file = get_field('document_file');

        echo '<div class="notice-card">';

        echo '<span class="notice-date">' . get_the_date('F j, Y') . '</span>';

        echo '<h3 class="notice-title">' . get_the_title() . '</h3>';

        if ($summary) {
            echo '<p class="notice-summary">' . esc_html($summary) . '</p>';
        }

        if ($file) {
            echo ' . '" target="_blank" class="document-btn">View Notice</a>';
        }

        echo '</div>';

    endwhile;

    echo '</div>';

} else {
    echo '<p>No notices found.</p>';
}

wp_reset_postdata();

return ob_get_clean();
}





