<?php
/**
 * Setting Box - Template
 * 
 * @package OrokuBlocks
 * @author OrokuBlocks (https://orokublocks.com/)
 * 
 * @since 1.0.0
 * 
 * @param array $args {
 *   @type string $id               Setting Id.
 *   @type string $form_id          Id of the form this setting should be associated with.
 *   @type bool   $checked          True if setting is enabled, false otherwise. Default: false.
 *   @type string $theme            Setting box theme. Optional. Default: 'primary'.
 *   @type string $title            Setting box title.
 *   @type array  $tags {
 *      @type string $name    Tag name.
 *      @type string $theme   Tag theme.
 *   }
 *   @type string $text             Setting box text.
 *   @type array  $links {
 *      @type string $name    Link name.
 *      @type string $href    Link href.
 *   },
 *   @type bool   $locked             True if the setting is locked.
 *   @type string $unlock_url         Unlock link url.
 * }
 */

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

$defaults = [
  'id'          => '',
  'form_id'     => '',
  'checked'     => false,
  'icon'        => '',
  'theme'       => 'primary',
  'tags'        => [],
  'links'       => [],
  'locked'      => false,
  'unlock_url'  => '#'
];

$options = array_merge( $defaults, $args );

$section_id = 'widget_enabled';
$setting_id = $section_id . '_' . $options['id'];

?>
<div class="oroku-setting-box-wrap">
  <div class="oroku-setting-box-wrap__decoration oroku-setting-box-wrap__decoration--theme--<?php echo esc_attr( $options['theme'] ); ?>">
  <?php

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

  ?>
  </div>

  <div class="oroku-setting-box">
    <div class="oroku-setting-box__information">
    <?php if ( $options['icon'] !== '' ) : ?>
      <div class="oroku-setting-box__visual">
        <div class="oroku-widget-icon-box oroku-font-icon oroku-font-icon--<?php echo esc_attr( $options['icon'] ); ?>"></div>
      </div>
    <?php endif; ?>

      <div class="oroku-setting-box__details">
        <div class="oroku-setting-box__title-wrap">
          <h2 class="oroku-setting-box__title oroku-h6"><?php echo esc_html( $options['title'] ); ?></h2>
        <?php

          /**
           * Tag List
           */
          orokublocks()->admin->requireTemplate( 'tag-list',
            [
              'tags'  => $options['tags'],
              'size'  => 'small'
            ]
          );

        ?>
        </div>

        <p class="oroku-setting-box__text"><?php echo esc_html( $options['text'] ); ?></p>
      <?php if ( count( $options['links'] ) > 0 ) : ?>
        <ul class="oroku-setting-box__links oroku-link-list oroku-link-list--style--columned">
        <?php foreach ( $options['links'] as $link ) : ?>
          <li class="oroku-link-list__item">
            <a class="oroku-link-list__link" href="<?php echo esc_url( $link['href'] ); ?>" target="_blank"><?php echo esc_html( $link['name'] ); ?></a>
          </li>
        <?php endforeach; ?>
        </ul>
      <?php endif; ?>
      </div>
    </div>

    <div class="oroku-setting-box__control">
    <?php if ( ! $options['locked'] ) : ?>
      <div class="oroku-toggle-control">
        <input
          id="<?php echo esc_attr( $setting_id ); ?>"
          class="oroku-toggle-control__input"
          type="checkbox"
          name="<?php echo esc_attr( $setting_id ); ?>"
          data-setting-section-id="<?php echo esc_attr( $section_id ); ?>"
        <?php if ( $options['checked'] ) : ?>
          checked
        <?php endif; ?>
        <?php if ( $options['form_id'] !== '' ) : ?>
          form="<?php echo esc_attr( $options['form_id'] ); ?>"
        <?php endif; ?>
        >

        <label class="oroku-toggle-control__label" for="<?php echo esc_attr( $setting_id ); ?>">
          <span class="oroku-visually-hidden"><?php esc_html_e( 'Toggle widget', 'orokublocks' ); ?></span>
        </label>
      </div>
    <?php else: ?>
      <a class="oroku-button oroku-button--theme--negative oroku-button--size--small" href="<?php echo esc_url( $options['unlock_url'] ); ?>" target="_blank">
      <?php

        /**
         * SVG
         */
        orokublocks()->admin->requireTemplate(
          'svg',
          [
            'additional_wrapper_classes'  => 'oroku-button__icon',
            'icon'                        => 'unlocked'
          ]
        );

      ?>
      <?php esc_html_e( 'Unlock Pro', 'orokublocks' ); ?>
      </a>
    <?php endif; ?>
    </div>
  </div>
</div>