<?php

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

use Carbon_Fields\Field\Field;
use Gigneo\Post_Meta\Serialized;

$gigneo_language_list = array();
$gigneo_languages     = new WP_Term_Query(
	array(
		'taxonomy'   => 'gigneo_language',
		'hide_empty' => false,
	)
);

if ( ! is_wp_error( $gigneo_languages ) && ! empty( $gigneo_languages->terms ) ) {
	foreach ( $gigneo_languages->terms as $gigneo_language ) {
		$gigneo_language_list[ $gigneo_language->slug ] = $gigneo_language->name;
	}
}

$gigneo_language_fields[] = Field::make( 'complex', 'gigneo_pm_languages', esc_html__( 'Languages', 'gigneo' ) )
								->set_datastore( new Serialized() )
								->add_fields(
									array(
										Field::make( 'select', 'name', esc_html__( 'Language', 'gigneo' ) )
											->set_options( $gigneo_language_list )
											->set_classes( 'gn-select2' ),
										Field::make( 'select', 'level', esc_html__( 'Level', 'gigneo' ) )
											->set_options( gigneo_language_levels( false ) )
											->set_classes( 'gn-select2' ),
									)
								)
								->set_header_template( '<%- name %>' )
								->set_collapsed( true );
