<?php

namespace GriffinForms\Admin\App\Html\Modals;

use GriffinForms\Traits\Singleton;
use GriffinForms\Admin\App\Html\Modals\Integrations\Responses;
use GriffinForms\Admin\App\Html\Modals\Integrations\Requests;
use GriffinForms\Admin\App\Html\Modals\Integrations\Scripts;

/**
 * Integrations Modal
 *
 * Provides an interface for managing form integrations with third-party services.
 * Allows users to view available integrations, configure settings, and manage
 * active integrations for their forms.
 */
final class Integrations extends \GriffinForms\Admin\App\Html\Modals\Format
{
    use Singleton;
    use Responses;
    use Requests;
    use Scripts;

    /**
     * Show footer with action buttons
     * @var bool
     */
    protected $has_footer = false;

    /**
     * SQL service for database operations
     * @var mixed
     */
    protected $sql;

    /**
     * AJAX handlers registration
     * Note: setAll() will automatically call setRegisterAjaxHandlers()
     * @var mixed
     */
    protected $registerAjaxHandlers;

    /**
     * Initialize SQL service
     */
    protected function setSql()
    {
        $this->sql = \GriffinForms\Admin\Sql\App::getInstance();
    }

    /**
     * Get modal title displayed in header
     * @return string
     */
    protected function getModalTitle()
    {
        return __('Integrations', 'griffinforms-form-builder');
    }

    /**
     * Render modal body HTML
     * Displays integration grid with category filters
     */
    protected function renderModalBodyHtml()
    {
        echo '<div class="griffinforms-integrations-message-container gf-notice-container mb-3"></div>';
        echo '<div class="griffinforms-integrations-content"></div>';
    }

    /**
     * Output all JavaScript for the modal
     */
    public function getModalJs()
    {
        $this->setupJs();
    }

    /**
     * Private constructor - Singleton pattern
     * Automatically registers AJAX handlers and initializes modal
     */
    private function __construct()
    {
        // Call setAll() to initialize all properties via reflection-based setter discovery
        // This will call: setMeta(), setConfig(), setSettings(), setHeir(), setLog(),
        // setUtility(), setButtons(), setInlineIcons(), setSql(), setModalId(),
        // setActionBtnId(), setCancelBtnId(), and setRegisterAjaxHandlers()
        $this->setAll();
    }
}
