<?php

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
  exit;
}

$settings_form_id = 'oroku-widget-settings';

$page_header_data = [
  'pretitle'  => strtoupper( orokublocks()->name ),
  'title'     => __( 'Widgets', 'orokublocks' ),
  'text'      => __( 'Here you\'ll be able to control which widgets you want to work with when you are editing your site pages with the Elementor plugin.', 'orokublocks' ),
  'button'    => [
    'text'      => __( 'Save Changes', 'orokublocks' ),
    'form_id'   => $settings_form_id,
    'disabled'  => true
  ]
];

/**
 * Page Header
 */
orokublocks()->admin->requireTemplate( 'page-header', $page_header_data );

$master_switch_setting = [
  'id'      => 'masterswitch',
  'form_id' => $settings_form_id,
  'title'   => __( 'Widgets Master Switch', 'orokublocks' ),
  'text'    => __( 'Use it to turn on or off all switch at once!', 'orokublocks' )
];

/**
 * Setting Box
 */
orokublocks()->admin->requireTemplate( 'setting-box', $master_switch_setting );

$setting_sections = orokublocks()->settings->getWidgetSettingsSections();

?>
<?php if ( count( $setting_sections ) > 0) : ?>
  <form id="<?php echo esc_attr( $settings_form_id ); ?>">
  <?php foreach ( $setting_sections as $setting_section ) : ?>
    <div class="oroku-setting-box-section">
      <h2 class="oroku-setting-box-section__heading oroku-h4"><?php echo esc_html( $setting_section['name'] ); ?></h2>

    <?php

      if ( array_key_exists( 'plugin', $setting_section ) && ( ! orokublocks()->pluginIsActive( $setting_section['plugin'] ) ) ) {
        /**
         * Message Box
         */
        orokublocks()->admin->requireTemplate(
          'message-box',
          [
            'theme' => 'negative',
            'title' => __( 'Plugin not active', 'orokublocks' ),
            'text'  => __( 'The plugin is required in order to be able to use the widgets. Please make sure that the plugin is installed and active if you want to be able to use the widgets.', 'orokublocks' )
          ]
        );
      }

    ?>

      <?php if ( count( $setting_section['settings'] ) > 0) : ?>
        <div class="oroku-setting-box-list">
          <?php foreach ( $setting_section['settings'] as $setting_data ) : ?>
          <?php

            /**
             * Setting Box
             */
            orokublocks()->admin->requireTemplate( 'setting-box', $setting_data );

          ?>
          <?php endforeach; ?>
        </div>
      <?php endif; ?>
    </div>
  <?php endforeach; ?>
  </form>
<?php endif; ?>