<?php
namespace BLR\Backline\Core;

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

final class ListPage {
    public static function base_url(array $ctx): string {
        return rtrim((string) ($ctx['base_url'] ?? ''), '/') . '/';
    }

    public static function notices(): array {
        return [
            'saved_notice'         => Request::query_absint('saved'),
            'deleted_notice'       => Request::query_absint('deleted'),
            'delete_error_message' => Views::delete_error_message_from_query_arg(),
        ];
    }

    public static function view_mode(): string {
        return Request::query_choice('view', ['list', 'grid'], 'list');
    }

    public static function view_urls(string $base_url, string $path, array $persist_args, string $view_mode): array {
        $base = $base_url . trim($path, '/') . '/';

        return [
            'list_url'            => add_query_arg(array_merge($persist_args, ['view' => 'list']), $base),
            'grid_url'            => add_query_arg(array_merge($persist_args, ['view' => 'grid']), $base),
            'pagination_base_url' => add_query_arg(array_merge($persist_args, ['view' => $view_mode]), $base),
        ];
    }
}
