<?php

defined( 'ABSPATH' ) || exit;

/**
 * Return cached Dashicons list with a resilient fallback.
 *
 * @return array<int, string>
 */
function termin_kalender_get_dashicons_list() {
    $css_url     = includes_url( 'css/dashicons.css' );
    $css_content = wp_remote_get( $css_url );

    if ( is_wp_error( $css_content ) ) {
        return [
            'dashicons-art',
            'dashicons-awards',
            'dashicons-book',
            'dashicons-building',
            'dashicons-businessman',
            'dashicons-calendar',
            'dashicons-camera',
            'dashicons-carrot',
            'dashicons-chart-bar',
            'dashicons-chart-line',
            'dashicons-chart-pie',
            'dashicons-clock',
            'dashicons-cloud',
            'dashicons-dashboard',
            'dashicons-desktop',
            'dashicons-download',
            'dashicons-email',
            'dashicons-flag',
            'dashicons-heart',
            'dashicons-info',
            'dashicons-lightbulb',
            'dashicons-location',
            'dashicons-megaphone',
            'dashicons-microphone',
            'dashicons-money',
            'dashicons-phone',
            'dashicons-playlist-audio',
            'dashicons-playlist-video',
            'dashicons-portfolio',
            'dashicons-rss',
            'dashicons-schedule',
            'dashicons-search',
            'dashicons-share',
            'dashicons-shield',
            'dashicons-slides',
            'dashicons-smartphone',
            'dashicons-smiley',
            'dashicons-star-filled',
            'dashicons-tablet',
            'dashicons-tag',
            'dashicons-testimonial',
            'dashicons-tickets',
            'dashicons-translation',
            'dashicons-upload',
            'dashicons-video-alt2',
            'dashicons-visibility',
        ];
    }

    $css_body = wp_remote_retrieve_body( $css_content );
    preg_match_all( '/\.?(dashicons-[a-z0-9-]+):before/', $css_body, $matches );

    return array_values( array_unique( $matches[1] ?? [] ) );
}
