<?php

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

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


// $html_content = file_get_contents('manual_dom_fachai.html');
// require_once('simple_html_dom.php');
// $html = str_get_html($html_content);

$url = 'https://fachaigaming.com/en/games?category=Slot';
require_once('simple_html_dom.php');
$html_content = file_get_contents($url);
$html = str_get_html($html_content);

$insertedGames = [];

foreach ($html->find('div#gameCardList a') as $div) {

        $link = $div->href;
        $link = "https://fachaigaming.com".$link;

        $name = $div->title;

        $provider_id = $id;

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

        $volatility = 0;

        $rtp = 0.0;

        $rtp_low = 0.0;

        $rtp_high = 0.0;

        $max_win = 0;

        $img = $div->find('.gameCardImage img', 0);
        $img = $img->getAttribute('src');
        $img = "https://fachaigaming.com".$img;

        $parts = explode('-', $img);
        $gameId = end($parts);
        $gameId = str_replace("_cover_en.webp", "", $gameId);

        $demo_desk = "https://gamedemo.fcgame.net/game/".$gameId."/en";

        $demo_mob = $demo_desk;

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

        require ('insert_values.php');

        require ('inserted_games.php');

}

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