<?php

if (! defined('ABSPATH')) {
    exit;
} class PufferGo_Woo_Archive_Data
{
    public $page_title = '';

    public $page_description = '';

    public $is_category_page = false;

    public $current_category = null;

    public $paged = 1;

    public $max_pages = 0;

    public $current_url = '';

    public static function from_current_query()
    {
        return new self();
    }

    public function __construct()
    {
        $this->is_category_page = function_exists('is_product_category') && is_product_category();

        if ($this->is_category_page) {
            $term = get_queried_object();

            if ($term instanceof WP_Term) {
                $this->current_category = $term;
                $this->page_title = $term->name;
                $this->page_description = term_description($term);
                $term_link = get_term_link($term);
                $this->current_url = is_wp_error($term_link) ? '' : $term_link;
            }
        }

if ('' === $this->page_title) {
            if (function_exists('woocommerce_page_title')) {
                $this->page_title = woocommerce_page_title(false);
            } else {
                $this->page_title = post_type_archive_title('', false);
            }
        }

if ('' === $this->current_url) {
            $this->current_url = function_exists('wc_get_page_permalink') ? wc_get_page_permalink('shop') : '';
        } $this->paged = isset($_GET['paged']) ? absint(wp_unslash($_GET['paged'])) : max(1, (int) get_query_var('paged'));
        $this->max_pages = (int) $GLOBALS['wp_query']->max_num_pages;
    }

    public function get_breadcrumb_items()
    {
        $items = array();
        $shop_url = function_exists('wc_get_page_permalink') ? wc_get_page_permalink('shop') : '';

        if ($this->is_category_page) {
            $items[] = array('url' => $shop_url ?: null, 'label' => __('Products', 'puffergo'), );
            $items[] = array('url' => null, 'label' => $this->page_title, );
        } else {
            $items[] = array('url' => null, 'label' => $this->page_title ?: __('Products', 'puffergo'), );
        }

return $items;
    }
}
