<?php

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

$page_header_data = [
  'pretitle'  => strtoupper( orokublocks()->name ),
  'title'     => __( 'System', 'orokublocks' ),
  'text'      => __( 'Here you\'ll find details about your WordPress site, if you run into any issues we\'ll ask you to send us a screenshot of this page.', 'orokublocks' )
];

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

$active_theme = wp_get_theme();

$active_theme_type = __( 'Parent Theme', 'orokublocks' );

if ( $active_theme->parent() !== false ) {
  $active_theme_type = __( 'Child Theme', 'orokublocks' );
}

$active_plugins = orokublocks()->admin->getActivePlugins();

$active_plugins_data = [];

foreach ( $active_plugins as $active_plugin ) {
  $active_plugins_data[] = [
    $active_plugin['Name'],
    $active_plugin['Author'],
    $active_plugin['Version']
  ];
}

$system_details_data = [
  [
    'title'   => __( 'General Information', 'orokublocks' ),
    'details' => [
      [
        __( 'WordPress', 'orokublocks' ),
        wp_get_wp_version()
      ],
      [
        __( 'PHP', 'orokublocks' ),
        phpversion()
      ]
    ]
  ],
  [
    'title'   => __( 'Active Theme', 'orokublocks' ),
    'details' => [
      [
        $active_theme['Name'],
        wp_kses( $active_theme['Author'], [] ),
        $active_theme['Version'],
        $active_theme_type
      ]
    ]
  ],
  [
    'title'   => __( 'Active Plugins', 'orokublocks' ),
    'details' => $active_plugins_data
  ]
];

?>
<?php if ( count( $system_details_data ) > 0 ) : ?>
  <div class="oroku-details-list">
  <?php foreach ( $system_details_data as $system_details ) : ?>
  <?php

    /**
     * Details
     */
    orokublocks()->admin->requireTemplate( 'details', $system_details );

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