<?php

if ( ! function_exists( 'calla_elated_map_post_video_meta' ) ) {
	function calla_elated_map_post_video_meta() {
		$video_post_format_meta_box = calla_elated_create_meta_box(
			array(
				'scope' => array( 'post' ),
				'title' => esc_html__( 'Video Post Format', 'calla' ),
				'name'  => 'post_format_video_meta'
			)
		);
		
		calla_elated_create_meta_box_field(
			array(
				'name'          => 'eltdf_video_type_meta',
				'type'          => 'select',
				'label'         => esc_html__( 'Video Type', 'calla' ),
				'description'   => esc_html__( 'Choose video type', 'calla' ),
				'parent'        => $video_post_format_meta_box,
				'default_value' => 'social_networks',
				'options'       => array(
					'social_networks' => esc_html__( 'Video Service', 'calla' ),
					'self'            => esc_html__( 'Self Hosted', 'calla' )
				)
			)
		);
		
		$eltdf_video_embedded_container = calla_elated_add_admin_container(
			array(
				'parent' => $video_post_format_meta_box,
				'name'   => 'eltdf_video_embedded_container'
			)
		);
		
		calla_elated_create_meta_box_field(
			array(
				'name'        => 'eltdf_post_video_link_meta',
				'type'        => 'text',
				'label'       => esc_html__( 'Video URL', 'calla' ),
				'description' => esc_html__( 'Enter Video URL', 'calla' ),
				'parent'      => $eltdf_video_embedded_container,
				'dependency' => array(
					'show' => array(
						'eltdf_video_type_meta' => 'social_networks'
					)
				)
			)
		);
		
		calla_elated_create_meta_box_field(
			array(
				'name'        => 'eltdf_post_video_custom_meta',
				'type'        => 'text',
				'label'       => esc_html__( 'Video MP4', 'calla' ),
				'description' => esc_html__( 'Enter video URL for MP4 format', 'calla' ),
				'parent'      => $eltdf_video_embedded_container,
				'dependency' => array(
					'show' => array(
						'eltdf_video_type_meta' => 'self'
					)
				)
			)
		);
		
		calla_elated_create_meta_box_field(
			array(
				'name'        => 'eltdf_post_video_image_meta',
				'type'        => 'image',
				'label'       => esc_html__( 'Video Image', 'calla' ),
				'description' => esc_html__( 'Enter video image', 'calla' ),
				'parent'      => $eltdf_video_embedded_container,
				'dependency' => array(
					'show' => array(
						'eltdf_video_type_meta' => 'self'
					)
				)
			)
		);
	}
	
	add_action( 'calla_elated_meta_boxes_map', 'calla_elated_map_post_video_meta', 22 );
}