<?php

// Connect to the database
require_once('pdo.php');
require_once('get_provider_translit.php');
require ('create_images.php');

$id = 19; 
$provider_translit = getProviderTranslit($id);

// Load HTML content from file
$manualHTML = file_get_contents('manual_dom_spribe.html');

$doc = new DOMDocument();
$doc->loadHTML($manualHTML);
$h3Content = $doc->getElementsByTagName('h3')->item(0)->textContent;

// Modify the content of the first p element
$pElement = $doc->getElementsByTagName('p')->item(0);
$pElement->textContent = 'New content for the paragraph';

// Convert the modified HTML back to a string
$modifiedHTML = $doc->saveHTML();

// Output the modified HTML
// echo $modifiedHTML;

$url = 'https://spribe.co/games';
require_once('simple_html_dom.php');
$html_content = file_get_contents($url);
$html = str_get_html($modifiedHTML);

$insertedGames = [];

foreach ($html->find('.row .col-6') as $div) {

        $link = $div->find('a.link', 0);
        $link = $link->href;
        $link = "https://spribe.co".$link;

        $name = $div->find('p.accordion-text', 0);
        $name = $name->plaintext;

        $provider_id = $id;
        
        $translit = str_replace(" ", "-", $name);
        $translit = str_replace("&#039;", "-", $translit);
        $translit = preg_replace("/[^a-zA-Z0-9\-]/", "", $translit);
        $translit = str_replace("---", "-", $translit);
        $translit = str_replace("--", "-", $translit);

        $parts = explode('/', $link);
        $gameId = end($parts);
        
        $demo_desk = "https://demo.spribe.io/launch/".$gameId."?currency=USD&lang=EN";
        
        $demo_mob = $demo_desk;
        
        $volatility = 0;

        $rtp = 0.0;

        $rtp_low = 0.0;
        
        $rtp_high = 0.0;
        
        $max_win = 0.0;
        
        $img = $div->find('.card-img-top', 0);
        $img = $img->src;
        $img = "https://spribe.co".$img;

        createImage($provider_translit, $translit, $img);

        require ('insert_values.php');

        require ('inserted_games.php');
}

// echo json_encode(['insertedGames' => $insertedGames]);
?>
