<?php

namespace DEVELUXSCT\Options;
if (!defined('ABSPATH')) {
    exit;
}

class Timer_CPT_Query_Data
{
    public static function get_all_timers_id_title(): array
    {
        $develuxsct_args = [
            'post_type' => 'develuxsct_timer',
            'post_status' => 'publish',
            'posts_per_page' => -1,
        ];
        $posts_data = [];
        $develuxsct_query = new \WP_Query($develuxsct_args);
        if ($develuxsct_query->have_posts()) {
            while ($develuxsct_query->have_posts()) {
                $develuxsct_query->the_post();
                $posts_data[] = [
                    'id' => get_the_ID(),
                    'title' => get_the_title()
                ];
            }
        }
        wp_reset_postdata();
        return $posts_data;

    }
    public static function get_all_timers_id_bulk(): array
    {
        static $cached_blocks = null;

        if ($cached_blocks !== null) {
            return $cached_blocks;
        }

        $develuxsct_args = [
            'post_type'      => 'develuxsct_timer',
            'post_status'    => 'publish',
            'posts_per_page' => -1,
            'fields'         => 'ids',
        ];

        $post_ids = get_posts($develuxsct_args);

        $cached_blocks = [];
        foreach ($post_ids as $post_id) {
            $bulk_value = get_post_meta($post_id, 'develux_bulk_item_all_products_ids', true);

            if (!empty($bulk_value)) {
                $cached_blocks[] = [
                    'id'   => (int) $post_id,
                    'bulk' => sanitize_text_field($bulk_value),
                ];
            }
        }

        return $cached_blocks;
    }


}