<?php

namespace Oney\ThreeByFour\Block\Head;

use Magento\Framework\View\Element\Template;
use Oney\ThreeByFour\Helper\Config;

/**
 * Widget URL Block
 * 
 * Block for generating Oney widget URL based on environment configuration.
 * Returns production or staging widget URL depending on admin configuration.
 * 
 * @package Oney\ThreeByFour\Block\Head
 * @version 1.0.0
 * @author Oney
 * @since 1.0.0
 */
class WidgetUrl extends Template
{
    /**
     * Configuration helper instance
     * 
     * @var Config
     * @version 1.0.0
     */
    protected $configHelper;

    /**
     * Constructor
     * 
     * @param Template\Context $context Template context
     * @param Config $configHelper Configuration helper
     * @param array $data Additional data
     * @version 1.0.0
     */
    public function __construct(
        Template\Context $context,
        Config $configHelper,
        array $data = []
    ) {
        $this->configHelper = $configHelper;
        parent::__construct($context, $data);
    }

    /**
     * Get Oney widget URL
     * 
     * Returns the appropriate widget URL based on environment configuration.
     * 
     * @return string Widget URL
     * @version 1.0.0
     */
    public function getOneyWidgetUrl(): string
    {
        if ($this->isProduction()) {
            return 'https://assets.oney.io/build/loader.min.js';
        }
        return 'https://assets-staging.oney.io/build/loader.min.js';
    }

    /**
     * Check if production environment
     * 
     * Checks if the current environment is set to production.
     * 
     * @return bool True if production
     * @version 1.0.0
     */
    protected function isProduction(): bool
    {
        return (bool)$this->configHelper->getGeneralConfigValue('environnement');
    }
}
