<?php
/**
 * This snippet has been updated to reflect the official supporting of options pages by CMB2
 * in version 2.2.5.
 *
 * If you are using the old version of the options-page registration,
 * it is recommended you swtich to this method.
 */
add_action( 'cmb2_admin_init', 'sherkati_register_theme_options_metabox' );
/**
 * Hook in and register a metabox to handle a theme options page and adds a menu item.
 */
function sherkati_register_theme_options_metabox() {

	/**
	 * Registers options page menu item and form.
	 */
	$cmb_options = new_cmb2_box( array(
		'id'           => 'sherkati_option_metabox',
		'title'        => esc_html__( 'تنظیمات سایت', 'sherkati' ),
		'object_types' => array( 'options-page' ),

		/*
		 * The following parameters are specific to the options-page box
		 * Several of these parameters are passed along to add_menu_page()/add_submenu_page().
		 */

		'option_key'      => 'sherkati_options', // The option key and admin menu page slug.
		// 'icon_url'        => 'dashicons-palmtree', // Menu icon. Only applicable if 'parent_slug' is left empty.
		// 'menu_title'      => esc_html__( 'Options', 'sherkati' ), // Falls back to 'title' (above).
		// 'parent_slug'     => 'themes.php', // Make options page a submenu item of the themes menu.
		// 'capability'      => 'manage_options', // Cap required to view options-page.
		// 'position'        => 1, // Menu position. Only applicable if 'parent_slug' is left empty.
		// 'admin_menu_hook' => 'network_admin_menu', // 'network_admin_menu' to add network-level options page.
		// 'display_cb'      => false, // Override the options-page form output (CMB2_Hookup::options_page_output()).
		// 'save_button'     => esc_html__( 'Save Theme Options', 'sherkati' ), // The text for the options-page save button. Defaults to 'Save'.
	) );

	/*
	 * Options fields ids only need
	 * to be unique within this box.
	 * Prefix is not needed.
	 */

	$header_group = $cmb_options->add_field( array(
		'id'          => 'header-gorup',
		'type'        => 'group',
		'description' =>'تنظیمات مربوط به آدرس و تلفن',
		// 'repeatable'  => false, // use false if you want non-repeatable group
		'options'     => array(
			'group_title'       => 'تنظیمات هدر', // since version 1.1.4, {#} gets replaced by row number
			'add_button'        => __( 'Add Another Entry', 'cmb2' ),
			'remove_button'     => __( 'Remove Entry', 'cmb2' ),
			'sortable'          => true,
			 'closed'         => true, // true to have the groups closed by default
			// 'remove_confirm' => esc_html__( 'Are you sure you want to remove?', 'cmb2' ), // Performs confirmation before removing group.
		),
	) );
	$cmb_options->add_group_field( $header_group, array(
		'name' => 'آدرس شرکت',
		'id'   => 'address',
		'type' => 'text',
		// 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
	) );
	$cmb_options->add_group_field( $header_group, array(
		'name' => 'تلفن شرکت',
		'id'   => 'phone',
		'type' => 'text',
		// 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types)
	) );


	

	$cmb_options->add_field( array(
		'name'    => 'لوگو شرکت',
		'desc'    => 'لوگو شرکت را وارد کنید',
		'id'      => 'logo',
		'type'    => 'file',
		// Optional:
		'options' => array(
			'url' => false, // Hide the text input for the url
		),
		'text'    => array(
			'add_upload_file_text' => 'Add File' // Change upload button text. Default: "Add or Upload File"
		),
		// query_args are passed to wp.media's library query.
		'query_args' => array(
			'type' => 'application/pdf', // Make library only display PDFs.
			// Or only allow gif, jpg, or png images
			// 'type' => array(
			// 	'image/gif',
			// 	'image/jpeg',
			// 	'image/png',
			// ),
		),
		'preview_size' => 'large', // Image size to use when previewing in the admin.
	) );


	$social_group = $cmb_options->add_field( array(
		'id'          => 'soial-gorup',
		'type'        => 'group',
		'description' =>'تنظیمات مربوط به شبکه های اجتماعی',
		'repeatable'  => true, // use false if you want non-repeatable group
		'options'     => array(
			'group_title'       => 'تنظیمات شبکه اجتماعی', // since version 1.1.4, {#} gets replaced by row number
			'add_button'        => __( 'Add Another Entry', 'cmb2' ),
			'remove_button'     => __( 'Remove Entry', 'cmb2' ),
			'sortable'          => true,
			 'closed'         => true, // true to have the groups closed by default
			// 'remove_confirm' => esc_html__( 'Are you sure you want to remove?', 'cmb2' ), // Performs confirmation before removing group.
		),
	) );

	$cmb_options->add_group_field( $social_group,array(
		'name'    => 'آیکون',
		'desc'    => 'نام شبکه اجتماعی وارد کنید',
		'id'      => 'icon',
		'type'    => 'text'
	) );
	
	$cmb_options->add_group_field( $social_group,array(
		'name'    => 'لینک',
		'desc'    => 'لینک شبکه اجتماعی وارد کنید',
		'id'      => 'link',
		'type'    => 'text',
	));
	

	$service_group = $cmb_options->add_field( array(
		'id'          => 'service-gorup',
		'type'        => 'group',
		'repeatable'  => false, // use false if you want non-repeatable group
		'options'     => array(
			'group_title'       => 'تنظیمات هدر خدمات', // since version 1.1.4, {#} gets replaced by row number
			'closed'         => true,
		),
	) );
	$cmb_options->add_group_field( $service_group,array(
		'name'    => 'عنوان کلی',
		'id'      => 'title',
		'type'    => 'text',
	));
	$cmb_options->add_group_field( $service_group,array(
		'name'    => 'توضیحات بخش ',
		'id'      => 'discription',
		'type'    => 'text',
	));

	$service_group_item = $cmb_options->add_field( array(
		'id'          => 'service-gorup-item',
		'type'        => 'group',
		'repeatable'  => true, // use false if you want non-repeatable group
		'options'     => array(
			'group_title'       => 'تنظیمات بخش خدمات', // since version 1.1.4, {#} gets replaced by row number
			'closed'         => true,
		),
	) );

	$cmb_options->add_group_field( $service_group_item,array(
		'name'    => 'آیکون',
		'desc'    => '  آیکن دلخواه را وارد کنید',
		'id'      => 'icon',
		'type'    => 'text',
	));
	
	$cmb_options->add_group_field( $service_group_item,array(
		'name'    => 'عنوان',
		'desc'    => '  عنوان خدمت را وارد کنید',
		'id'      => 'title',
		'type'    => 'text',
	));
	
	$cmb_options->add_group_field( $service_group_item,array(
		'name'    => 'توضیحات',
		'desc'    => '  توضیحات خدمت را وارد کنید',
		'id'      => 'text',
		'type'    => 'text',
	));
$cmb_options->add_field(array(
'name'=>'تصویر زمینه ',
'id'=>'cover',
'type'=>'file'

));

	$amar_group = $cmb_options->add_field( array(
		'id'          => 'amar-gorup',
		'type'        => 'group',
		'repeatable'  => true, // use false if you want non-repeatable group
		'options'     => array(
			'group_title'       => '  آمار شرکت', // since version 1.1.4, {#} gets replaced by row number
			'closed'         => true,
		),
	) );
	
	$cmb_options->add_group_field($amar_group,array(
		'name'    => 'آیکون',
		'desc'    => 'آیکن مربوطه ',
		'id'      => 'icon',
		'type'    => 'text',
	));

	$cmb_options->add_group_field($amar_group,array(
		'name'    => 'تعداد',
		'desc'    => 'آمار گزینه مورد نظر را وارد کنید',
		'id'      => 'number',
		'type'    => 'text',
	));

	$cmb_options->add_group_field($amar_group,array(
		'name'    => 'موضوع',
		'desc'    => 'آمار مربوط به :',
		'id'      => 'subject',
		'type'    => 'text',
	));

$cmb_options->add_field(array(
	'name'    => 'لوگو فوتر',
		'desc'    => '',
		'id'      => 'logo_foot',
		'type'    => 'file',
));

	
$amar_group = $cmb_options->add_field( array(
	'id'          => 'amar-gorup',
	'type'        => 'group',
	'repeatable'  => true, // use false if you want non-repeatable group
	'options'     => array(
		'group_title'       => '  آمار شرکت', // since version 1.1.4, {#} gets replaced by row number
		'closed'         => true,
	),
) );

$cmb_options->add_group_field($amar_group,array(
	'name'    => 'آیکون',
	'desc'    => 'آیکن مربوطه ',
	'id'      => 'icon',
	'type'    => 'text',
));

$cmb_options->add_group_field($amar_group,array(
	'name'    => 'تعداد',
	'desc'    => 'آمار گزینه مورد نظر را وارد کنید',
	'id'      => 'number',
	'type'    => 'text',
));

$compani_tilte = $cmb_options->add_field( array(
	'id'          => 'compani_tilte',
	'type'        => 'group',
	'repeatable'  => false, // use false if you want non-repeatable group
	'options'     => array(
		'group_title'       => 'بخش همکاران ', // since version 1.1.4, {#} gets replaced by row number
		'closed'         => true,
	),
) );

$cmb_options->add_group_field($compani_tilte,array(
	'name'    => 'عنوان بخش همکاران',
	'desc'    => '  ',
	'id'      => 'title',
	'type'    => 'text',
));

$cmb_options->add_group_field($compani_tilte,array(
	'name'    => 'توضیحات',
	'desc'    => 'توضیحات مربوط به همکاران را وارد کنید',
	'id'      => 'discription',
	'type'    => 'text',
));

$compani_pic = $cmb_options->add_field( array(
	'id'          => 'compani_pic',
	'type'        => 'group',
	'repeatable'  => true, // use false if you want non-repeatable group
	'options'     => array(
		'group_title'       => 'لوگو همکاران ', // since version 1.1.4, {#} gets replaced by row number
		'closed'         => true,
	),
) );

$cmb_options->add_group_field($compani_pic,array(
	'name'    => ' تصویر یا لوگوشرکت',
	'desc'    => '  ',
	'id'      => 'pic',
	'type'    => 'file',
));

$cmb_options->add_group_field($compani_pic,array(
	'name'    => 'لینک',
	'desc'    => 'آدرس سایت را وارد کنید',
	'id'      => 'link',
	'type'    => 'text',
));



	$icon_social_group = $cmb_options->add_field( array(
		'id'          => 'icon_social_group',
		'type'        => 'group',
		'repeatable'  => true, // use false if you want non-repeatable group
		'options'     => array(
			'group_title'       => '  شبکه های اجتماعی داخل فوتر ', // since version 1.1.4, {#} gets replaced by row number
			'closed'         => true,
		),
	) );
	$cmb_options->add_group_field( $icon_social_group,array(
		'name' => __( 'انتخاب شبکه اجتماعی', 'cmb' ),
		'id'   => $prefix . 'iconselect',
		'desc' => 'Select Font Awesome icon',
		'type' => 'faiconselect',
		'options' => array(
			'fab fa-facebook' => 'fa fa-facebook',
			'fab fa-500px'  	 => 'fa fa-500px',
			'fab fa-twitter'	 => 'fa fa-twitter',
			'fab fa-yahoo'	 => 'fa fa-yahoo',
			'fab fa-google'	 => 'fa fa-google',
			'fab fa-vimeo'	 => 'fa fa-vimeo',
			'fab fa-instagram'	 => 'fa fa-instagram',
			'fas fa-address-book' => 'fas fa-address-book',

		),
		'attributes' => array(
			'faver' => 5
	)
	) );

	$cmb_options->add_field( array(
		'name'             => 'انتخاب فونت',
		'desc'             => 'انتخاب یک گزینه',
		'id'               => 'wiki_test_select',
		'type'             => 'select',
		'show_option_none' => false,
		'default'          => 'custom',
		'options'          => array(
			'sahel' => __( 'ساحل', 'cmb2' ),
			'yekan'   => __( 'یکان', 'cmb2' ),
		),
	) );
	$cmb_options->add_field( array(
		'name'    => 'انتخاب رنگ سایت',
		'id'      => 'wiki_test_color',
		'type'    => 'colorpicker',
	//	'default' => '#ffffff',
		// 'options' => array(
		// 	'alpha' => true, // Make this a rgba color picker.
		// ),
	) );
}

/**
 * Wrapper function around cmb2_get_option
 * @since  0.1.0
 * @param  string $key     Options array key
 * @param  mixed  $default Optional default value
 * @return mixed           Option value
 */
function sherkati_get_option( $key = '', $default = false ) {
	if ( function_exists( 'cmb2_get_option' ) ) {
		// Use cmb2_get_option as it passes through some key filters.
		return cmb2_get_option( 'sherkati_options', $key, $default );
	}

	// Fallback to get_option if CMB2 is not loaded yet.
	$opts = get_option( 'sherkati_options', $default );

	$val = $default;

	if ( 'all' == $key ) {
		$val = $opts;
	} elseif ( is_array( $opts ) && array_key_exists( $key, $opts ) && false !== $opts[ $key ] ) {
		$val = $opts[ $key ];
	}

	return $val;
}
?>