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

use OxygenApp\Views\BaseView;
use OxygenApp\Views\IView;
use OxygenApp\Views\Modal\GenericModal;
use OxygenApp\Config\Flags;

class ModalNewLanguage extends BaseView implements IView {

    public function render(): void {
        
        $flagsData = Flags::getData();
        $baseFlagsUrl = Flags::getBaseURL();
        ob_start();
        ?>
        <div class="form-group mb-3">
            <select id="select-language" style="width: 100%;" data-dropdown-parent="#modal-new-lang" class="form-select select-language">
                <option value="" data-image="" data-name=""><?php echo esc_html_e('Select language', 'oxyleaf-app-working-and-relaxing-app') ?></option>
                <?php foreach ($flagsData as $key => $flagData): ?>
                    <?php
                    $icon = $flagData['flag_4x3'] ?? '';
                    $name = $flagData['name'] ?? '';
                    $code = $flagData['code'] ?? '';
                    $iconUrl = $baseFlagsUrl . $icon;
                    ?>
                    <option value="<?php echo esc_attr($code) ?>" data-image="<?php echo esc_url($iconUrl) ?>" data-name="<?php echo esc_attr($name) ?>">
                        <?php echo esc_html($name) ?>
                    </option>
                <?php endforeach; ?>
            </select>
        </div>
        <?php
        $popupBody = ob_get_clean();

        $gm = new GenericModal([
            'modalId' => 'modal-new-lang',
            'popupTitle' => esc_html__('Add new language', 'oxyleaf-app-working-and-relaxing-app'),
            'body' => $popupBody,
            'modal_size' => 'modal-lg',
            'showSaveBtn' => true,
            'saveBtnLabel' => esc_html__('Add', 'oxyleaf-app-working-and-relaxing-app'),
            'bodyClasses' => 'skl-modal-content medium'
        ]);

        $gm->render();
    }
}