<?php
namespace OxygenApp\Views\Frontend\Content;
if (!defined('ABSPATH')) exit;

use OxygenApp\Views\IView;
use OxygenApp\Views\BaseView;
use OxygenApp\Utils\OptionUtils;
use OxygenApp\Utils\FrontendData;
use OxygenApp\Enums\FrontendDataType;

class BackgroundCredits extends BaseView implements IView
{
    public function render(): void {
        $show_backgrounds_credits = OptionUtils::getInstance()->getOption('show_backgrounds_credits');
        $show_backgrounds_credits = $show_backgrounds_credits === 'on';

        $frontendData = FrontendData::getInstance()->getDefaultSettings(FrontendDataType::ARRAY);

        $background = null;
        if ($frontendData['user_background']) {
            $background = $frontendData['user_background'];
        } else {
            $background = $frontendData['default_background'] ?? null;
        }



        $background_credits_label = $background['background_credits_label'] ?? '';
        $background_credits_url = $background['background_credits_url'] ?? '';
        $cssClasses = 'hidden';
        if ($background && $background_credits_label !== '' && $background_credits_url) {
            $cssClasses = '';
        }

        ?>
        <?php if ($show_backgrounds_credits): ?>
        <div class="fixed left-[20px] bottom-[5%] md:bottom-[5%] z-10 credits-ui <?php echo esc_attr($cssClasses) ?>">
            <a target="_blank" class="text-white font-semibold credits-link" href="<?php echo esc_url($background_credits_url) ?>"><?php echo esc_html($background_credits_label) ?></a>
        </div>
        <?php endif; ?>
        <?php
    }
}