<?php

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

$submenu_items = orokublocks()->admin->getSubmenuItems();

$social_links = orokublocks()->socialLinksGet();

?>
<div class="oroku-wrap">
  <div class="oroku-wrap__inner">
    <div class="oroku-header">
      <div class="oroku-header__items">
        <div class="oroku-main-logo">
        <?php

          /**
           * SVG
           */
          orokublocks()->admin->requireTemplate(
            'svg',
            [
              'additional_wrapper_classes'  => 'oroku-main-logo__icon oroku-icon-orokublocks--size--small',
              'icon'                        => 'orokublocks'
            ]
          );

        ?>
          <h1 class="oroku-main-logo__title"><?php echo esc_html( orokublocks()->name ); ?></h1>
        <?php

          if ( orokublocks()->isProVersionValid() ) {
            /**
             * Tag List
             */
            orokublocks()->admin->requireTemplate( 'tag-list',
              [
                'tags'  => [
                  [
                    'name'  => 'Pro',
                    'theme' => 'highlight'
                  ]
                ]
              ]
            );
          }

        ?>
        </div>

      <?php if ( count( $submenu_items ) > 0 ) : ?>
        <ul class="oroku-menu">
        <?php foreach ( $submenu_items as $submenu_item ) : ?>
          <li class="oroku-menu__item">
            <a class="oroku-menu__link" href="#tab=<?php echo esc_attr( $submenu_item['id'] ); ?>" data-id="<?php echo esc_attr( $submenu_item['id'] ); ?>">
              <?php echo esc_html( $submenu_item['name'] ); ?>
            </a>
          </li>
        <?php endforeach; ?>
        <?php do_action( 'orokublocks_admin_menu_after_submenu_items' ); ?>
        </ul>
      <?php endif; ?>
      </div>

      <div class="oroku-header__items">
      <?php if ( count( $social_links ) > 0 ) : ?>
        <ul class="oroku-social-link-list oroku-social-link-list--style--rounded">
        <?php foreach ( $social_links as $social_link_id => $social_link ) : ?>
          <li class="oroku-social-link-list__item">
            <a class="oroku-social-link-list__link" href="<?php echo esc_url( $social_link['url'] ); ?>" target="_blank">
            <?php

              /**
               * SVG
               */
              orokublocks()->admin->requireTemplate(
                'svg',
                [
                  'additional_wrapper_classes'  => 'oroku-social-link-list__icon',
                  'icon'                        => $social_link_id
                ]
              );

            ?>
              <span class="oroku-visually-hidden"><?php echo esc_html( $social_link['url'] ); ?></span>
            </a>
          </li>
        <?php endforeach; ?>
        </ul>
      <?php endif; ?>

        <a class="oroku-button oroku-button--theme--secondary" href="https://orokublocks.com/documentation" target="_blank"><?php esc_html_e( 'Documentation', 'orokublocks' ); ?></a>
      
      <?php if ( orokublocks()->isProVersionValid() ) : ?>
        <a class="oroku-button oroku-button--theme--primary" href="https://odindesignthemes.ticksy.com/" target="_blank"><?php esc_html_e( 'Support', 'orokublocks' ); ?></a>
      <?php else : ?>
        <a class="oroku-button oroku-button--theme--primary" href="<?php echo esc_url( orokublocks()->getUnlockProUrl() ); ?>" target="_blank"><?php esc_html_e( 'Go Pro!', 'orokublocks' ); ?></a>
      <?php endif; ?>
      </div>
    </div>

  <?php

    if ( ! orokublocks()->pluginIsActive( 'elementor' ) ) {
      /**
       * Message Box
       */
      orokublocks()->admin->requireTemplate(
        'message-box',
        [
          'theme' => 'negative',
          'title' => __( 'Elementor Plugin Required', 'orokublocks' ),
          'text'  => sprintf(
            /* translators: 1: opening anchor tag, 2: closing anchor tag, 3: opening strong tag, 4: closing strong tag, 5: opening strong tag, 6: closing strong tag. */
            __( 'The %1$sElementor%2$s plugin is required. Please make sure to %3$sinstall%4$s and %5$sactivate%6$s it, otherwise you won\'t be able to use the widgets.', 'orokublocks' ),
            '<a href="https://wordpress.org/plugins/elementor/" target="_blank">',
            '</a>',
            '<strong>',
            '</strong>',
            '<strong>',
            '</strong>'
          )
        ]
      );
    }

    $neutral_license_validity_text = sprintf(
      /* translators: 1: opening anchor tag, 2: closing anchor tag, 3: opening strong tag, 4: closing strong tag. */
      __( 'You don\'t have an active license associated with this site. %1$sUpgrade now%2$s to unlock access to all the %3$sOrokuBlocks Pro%4$s plugin features!.', 'orokublocks' ),
      '<a href="' . esc_url( orokublocks()->getFreemiusPricingUrl() ) . '">',
      '</a>',
      '<strong>',
      '</strong>'
    );

    if ( function_exists( 'orokublocks_fs' ) ) {
      if ( orokublocks_fs()->is_registered() ) {
        $neutral_license_validity_text = sprintf(
          /* translators: 1: opening anchor tag, 2: closing anchor tag, 3: opening anchor tag, 4: closing anchor tag, 5: opening strong tag, 6: closing strong tag. */
          __( 'You don\'t have an active license associated with this site. %1$sUpgrade now%2$s or %3$sActivate your License%4$s to unlock access to all the %5$sOrokuBlocks Pro%6$s plugin features!.', 'orokublocks' ),
          '<a href="' . esc_url( orokublocks()->getFreemiusPricingUrl() ) . '">',
          '</a>',
          '<a href="' . esc_url( orokublocks()->getFreemiusAccountUrl() ) . '">',
          '</a>',
          '<strong>',
          '</strong>'
        );
      }
    }

    if ( orokublocks()->isProVersion() ) {
      $license_validity_message_box_args = [
        'initial' => [
          'theme' => 'neutral',
          'title' => __( 'License Required', 'orokublocks' ),
          'text'  => $neutral_license_validity_text
        ],
        'invalid' => [
          'theme' => 'negative',
          'title' => __( 'License Error', 'orokublocks' ),
          'text'  => sprintf(
            /* translators: 1: opening anchor tag, 2: closing anchor tag. */
            __( 'Your license could not be validated. Please make sure that your %1$sLicense%2$s has not expired or reached the maximum amount of site uses.', 'orokublocks' ),
            '<a href="' . esc_url( orokublocks()->getFreemiusAccountUrl() ) . '">',
            '</a>'
          )
        ],
        'valid'   => [
          'theme' => 'positive',
          'title' => __( 'License Validated', 'orokublocks' ),
          'text'  => sprintf(
            /* translators: 1: opening strong tag, 2: closing strong tag. */
            __( 'Your license has been validated, thanks for your purchase!. You now have access and can start enjoying all the %1$sOrokuBlocks Pro%2$s plugin features!.', 'orokublocks' ),
            '<strong>',
            '</strong>'
          )
        ]
      ];

      $license_validity_status = orokublocks()->isProVersionValid() ? 'valid' : 'initial';

      /**
       * Message Box
       */
      orokublocks()->admin->requireTemplate( 'message-box', $license_validity_message_box_args[$license_validity_status] );
    }

  ?>

  <?php if ( ! orokublocks()->isProVersion() ) : ?>
    <a class="oroku-focusable-link" href="<?php echo esc_url( orokublocks()->getUnlockProUrl() ); ?>" target="_blank">
      <div class="oroku-banner">
        <div class="oroku-banner__decoration">
        <?php

          /**
           * SVG
           */
          orokublocks()->admin->requireTemplate(
            'svg',
            [
              'icon'  => 'squiggly-texture'
            ]
          );

        ?>
        </div>

        <div class="oroku-banner__background"></div>

        <div class="oroku-banner__content">
          <div class="oroku-banner__pretitle">
            <img src="<?php echo esc_url( orokublocks()->url ); ?>admin/assets/image/banner-icon.png" alt="">
            <p class="oroku-banner__pretitle-text"><?php esc_html_e( 'GO PRO', 'orokublocks' ); ?></p>
          </div>
          <h2 class="oroku-banner__title oroku-h4">
          <?php

            echo wp_kses(
              sprintf(
                /* translators: 1: opening span tag, 2: closing span tag, 3: opening span tag, 4: closing span tag. */
                __( '%1$sClick Here%2$s & Get Full Access to All %3$sPremium Widgets%4$s', 'orokublocks' ),
                '<span class="oroku-blocky-word">',
                '</span>',
                '<span class="oroku-blocky-word">',
                '</span>'
              ),
              [
                'span'  => [
                  'class' => []
                ]
              ]
            );

          ?>
          </h2>
        </div>
      </div>
    </a>
  <?php endif; ?>

  <?php if ( count( $submenu_items ) > 0 ) : ?>
    <div class="oroku-pages">
    <?php foreach ( $submenu_items as $submenu_item ) : ?>
      <div class="oroku-page" data-id="<?php echo esc_attr( $submenu_item['id'] ); ?>">
      <?php

        $submenu_type = array_key_exists( 'type', $submenu_item ) ? $submenu_item['type'] : '';

        if ( ( $submenu_type === 'pro' ) && orokublocks()->isProVersion() ) {
          orokublocks_pro()->admin->requireTemplate( $submenu_item['id'] );
        } else {
          orokublocks()->admin->requireTemplate( $submenu_item['id'] );
        }

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