<?php

/**
 * Banner News Settings
 *
 * @package Chic Lifestyle
 */

add_action('customize_register', 'chic_lifestyle_customize_register_card_section');

function chic_lifestyle_customize_register_card_section($wp_customize)
{

  // Add Pages Select Section.
  $wp_customize->add_section('chic_lifestyle_pages_select_sections', array(
    'title'       => esc_html__('Card Section', 'chic-lifestyle'),
    'description' => esc_html__('Card section', 'chic-lifestyle'),
    'panel'       => 'chic_lifestyle_homepage_panel',
    'priority'    => 2,
  ));

  // Setting for "Show Pages Section" (checkbox).
  $wp_customize->add_setting('display_pages', array(
    'default'           => true,
    'sanitize_callback' => 'chic_lifestyle_sanitize_checkbox',
  ));
  $wp_customize->add_control(new Chic_Lifestyle_Toggle_Control($wp_customize, 'display_pages', array(
    'label'    => esc_html__('Show Card Section', 'chic-lifestyle'),
    'section'  => 'chic_lifestyle_pages_select_sections',
    'settings' => 'display_pages',
    'type'     => 'toggle',
  )));

  $wp_customize->selective_refresh->add_partial('display_pages', array(
      'selector' => '#chic_lifestyle_pages_select_sections > .container'
  ));

  // Setting for "Pages Section Title" (text).
  $wp_customize->add_setting('pages_section_title', array(
    'default'           => '',
    'sanitize_callback' => 'sanitize_text_field',
  ));
  $wp_customize->add_control('pages_section_title', array(
    'label'   => esc_html__('Card Section Title', 'chic-lifestyle'),
    'section' => 'chic_lifestyle_pages_select_sections',
    'type'    => 'text',
  ));

  $wp_customize->add_setting(new Chic_Lifestyle_Repeater_Setting(
    $wp_customize,
    'chic_lifestyle_select_pages',
    array(
      'default'     => '',
      'sanitize_callback' => array('Chic_Lifestyle_Repeater_Setting', 'sanitize_repeater_setting'),
    )
  ));

  $wp_customize->add_control(new Chic_Lifestyle_Control_Repeater(
    $wp_customize,
    'chic_lifestyle_select_pages',
    array(
      'section' => 'chic_lifestyle_pages_select_sections',
      'settings'    => 'chic_lifestyle_select_pages',
      'label'       => esc_attr__('Cards', 'chic-lifestyle'),
      'description' => esc_attr__('Create one or more cards linking to your pages', 'chic-lifestyle'),
      'type' => 'repeater',
      'row_label' => array(
        'type'  => 'field',
        'value' => esc_attr__('Card', 'chic-lifestyle'),
        'field' => 'card_title',
      ),
      'fields' => array(
        'card_text' => array(
          'type'        => 'text',
          'label'       => esc_attr__('Text', 'chic-lifestyle'),
          'default'     => '',
        ),
        'card_url' => array(
          'type'      => 'text',
          'label'     => esc_attr__('URL', 'chic-lifestyle'),
          'default'     => '',
        ),
        'card_page' => array(
          'type'    => 'select',
          'label'   => esc_attr__('Select Page', 'chic-lifestyle'),
          'choices' => chic_lifestyle_get_pages_array(),
          'default'   => '',
        ),
        'card_image' => array(
          'type'      => 'image',
          'label'     => esc_attr__('Background image', 'chic-lifestyle'),
          'default'   => '',
        ),
      ),
    )
  ));
}
