<?php

namespace OxygenApp\Views\Modal;

if (!defined('ABSPATH')) exit;

use OxygenApp\Views\BaseView;
use OxygenApp\Views\IView;

class GenericModal extends BaseView implements IView {

    public function render(): void {
        $body = $this->viewData['body'] ?? '';
        $bodyClasses = $this->viewData['bodyClasses'] ?? '';
        $modalSizeClass = $this->viewData['modal_size'] ?? '';
        $popupTitle = $this->viewData['popupTitle'] ?? '';
        $modalId = $this->viewData['modalId'] ?? '';
        $closeBtnLabel = $this->viewData['closeBtnLabel'] ?? esc_html__('Close', 'oxyleaf-app-working-and-relaxing-app');
        $showSaveBtn = $this->viewData['showSaveBtn'] ?? false;
        $saveBtnLabel = $this->viewData['saveBtnLabel'] ?? esc_html__('Save', 'oxyleaf-app-working-and-relaxing-app');
        $saveBtnDisabledByDefault = $this->viewData['saveBtnDisabledByDefault'] ?? true;
        $saveBtnId = $this->viewData['saveBtnId'] ?? uniqid('_');
        ?>
            <div class="modal fade" id="<?php echo esc_attr($modalId) ?>" tabindex="-1" aria-labelledby="modalTitle" aria-hidden="true">
                <div class="modal-dialog modal-dialog-centered <?php echo esc_attr($modalSizeClass) ?>">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title fs-5" id="modalTitle"><?php echo esc_html($popupTitle) ?></h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                        </div>
                        <div class="modal-body <?php echo esc_attr($bodyClasses) ?>">
                            <?php echo wp_kses($body, [
                                'div' => [
                                    'class' => true,
                                    'id' => true,
                                    'style' => true,
                                ],
                                'select' => [
                                    'id' => true,
                                    'class' => true,
                                    'style' => true,
                                    'data-dropdown-parent' => true,
                                ],
                                'option' => [
                                    'value' => true,
                                    'data-image' => true,
                                    'data-name' => true,
                                ],
                                'span' => [
                                    'class' => true,
                                    'style' => true,
                                ],
                                'label' => [
                                    'for' => true,
                                    'class' => true,
                                ],
                                'strong' => [],
                                'em' => [],
                                'br' => [],
                            ]) ?>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-outline-primary skl-cancel-btn" data-bs-dismiss="modal"><?php echo esc_html($closeBtnLabel) ?></button>
                            <?php if ($showSaveBtn): ?>
                                <button id="<?php esc_attr($saveBtnId) ?>" type="button" class="btn btn-primary skl-save-btn" style="margin-left: 7px;" <?php echo $saveBtnDisabledByDefault ? 'disabled' : '' ?>><?php echo esc_html($saveBtnLabel) ?></button>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        <?php
    }
}