<?php
/* @var array $args */
/* @var \Tangibledesign\MyHome\Widgets\User\UserBoxWidget $mhCurrentWidget */
global $mhCurrentWidget;

$element = $args['element'] ?? null;
$user = $args['user'] ?? null;

if (
    !$element
    || !$user instanceof \Tangibledesign\Framework\Models\User\User
) {
    return;
}

$isOnline = $mhCurrentWidget->isUserOnline($element['user_online_minutes'] ?? 5);
?>
<div
    <?php if ($isOnline) : ?>
        class="myhome-user-box__state myhome-user-box__state--online"
    <?php else : ?>
        class="myhome-user-box__state myhome-user-box__state--offline"
    <?php endif; ?>
>
    <?php
    if ($isOnline) :
        if (!empty($element['user_online_text'])):
            echo esc_html($element['user_online_text']);
        else :
            echo esc_html(tdf_string('user_is_online_now'));
        endif;
    else :
        if (!empty($element['user_offline_text'])):
            echo esc_html($element['user_offline_text']);
        else :
            echo esc_html(tdf_string('user_is_offline'));
        endif;
    endif; ?>
</div>