<?php


add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {

  $meta_boxes[] = [
    "id" => "mb-header",
    "title" => "Tlačidlo v menu",
    "settings_pages" => "options",
    "context" => "normal",
    "tab" => "topbar",
    "fields" => [
      [
        "type" => "custom_html",
        "std" => '<h4>Tlačidlo v menu</h4>',
      ],
      [
        'name'          => __('Text tlačidla', 'inoby'),
        'id'            => 'header_cta_btn_text',
        'type'          => 'text',
      ],
      [
        'name'          => __('Odkaz tlačidla', 'inoby'),
        'id'            => 'header_cta_btn_url',
        'type'          => 'text',
      ],
    ],
  ];

  return $meta_boxes;
} );

/**
 * Transparent header function
 */
add_filter( 'body_class','transparent_menu' );
function transparent_menu( $classes ) {
  $queried_object = get_queried_object_id();
  $transparent_header = rwmb_meta("page-transparent-header", [], $queried_object) ?? '';
  if ( $transparent_header == 1 ) {
    inoby_enqueue_parted_script("page", "post_types");
    $classes[] = 'transparent-header';
  }
  
  return $classes;   
}

/**
 * Custom header button
 */
function header_custom_button() {
  $header_btn_text = rwmb_meta("header_cta_btn_text", ["object_type" => "setting"], "options");
  $header_btn_url = rwmb_meta("header_cta_btn_url", ["object_type" => "setting"], "options");
  if (!empty($header_btn_url)):
      echo '<a class="link" href="' . $header_btn_url . '">' . $header_btn_text . "</a>";
  endif;
}
add_action("inoby_right_navigation_start", "header_custom_button", 10, 2);