<?php

use Carbon\Carbon;
use Database\{Games, Profile, blocked, Follow};
use inc\functions;

$getgame = Games::getGame($user_data)->users;
$player = functions::arrayUnset(explode('|', $getgame), $chatid)[0];
$ProfileUser = Profile::getUser($player);
$photo = NOPHOTO;
if (!is_null($ProfileUser->photo)) {
    $photo = $ProfileUser->photo;
}
$name = is_null($ProfileUser->name) ? '?' : $ProfileUser->name;
$age = is_null($ProfileUser->age) ? '?' : $ProfileUser->age;
$state = is_null($ProfileUser->state) ? '?' : $ProfileUser->state;
$gender = is_null($ProfileUser->gender) ? '?' : $ProfileUser->gender;
$city = is_null($ProfileUser->city) ? '?' : $ProfileUser->city;
$point = $ProfileUser->point;
$usercod = '/Profile_' . $ProfileUser->cod;
$CheckFollow = Follow::checkFollows($chatid, $player);
$CheckBlock = blocked::hasBlocked($chatid, $player);

$FollowTxt = $CheckFollow == false ? msg('AddContact') : msg('RemoveContact');
$FollowData = $CheckFollow == false ? 'AddContact_' . $player : 'RemoveContact_' . $player;
$BlockedTxt = $CheckBlock == true ? msg('UnlockUser') : msg('BlockUser');
$BlockedData = $CheckBlock == true ? 'UnblcokUser_' . $player : 'BlcokUser_' . $player;

$button = [
    'inline_keyboard' => [
        [
            ["text" => $FollowTxt, "callback_data" => $FollowData],
            ["text" => $BlockedTxt, "callback_data" => $BlockedData],
        ]
    ],
    'resize_keyboard' => true
];
$getUpdateTime = Carbon::createFromTimestamp($ProfileUser->lastonline, 'Asia/Tehran')->diffForHumans();

if (Profile::getUser($player)->ingame ==  true) {
    $getUpdateTime = msg('ingame') . $getUpdateTime;
}
$ProfText = str_replace(['#name', '#state', '#ciity', '#age', '#gender', '#point', '#usercod', '#status'], [$name, $state, $city, $age, str_replace(['female', 'male'], ['خانم', 'آقا'], $gender), $point, $usercod, $getUpdateTime], msg('UserProfile'));

if ($photo == NOPHOTO) {
    $Telegram->SendPhoto($chatid, $photo, $ProfText, 'html', false, $button);
} else {
    $Telegram->copyMessage($chatid, CHANNELFORWARD, $photo, $ProfText, 'html', $button);
}
?>