<?php
/**
 * Scene elements list metabox.
 *
 * @package scene3d
 *
 * @var WP_Post   $post
 * @var Dashboard $this
 */

use Scene3d\admin\Dashboard;
use Scene3d\Plugin;

$elements             = $this->get_fields( $post->post_content, 'elements' );
$element_descriptions = apply_filters(
	'scene3d_elements_descriptions',
	[
		''           => __( 'Select one type of element', 'scene3d' ),
		'glb'        => __( 'glTF v2.0 file (.glb or .gltf format)', 'scene3d' ),
		'fbx'        => __( 'FBX ASCII version 7.0 and newer, or binary version 6400 and newer.', 'scene3d', ),
		'stl'        => __( 'STL file, binary or ASCII', 'scene3d', ),
		'obj'        => __( 'OBJ file (Wavefront)', 'scene3d', ),
		'spotlight'  => __( 'This light gets emitted from a single point in one direction, along a cone that increases in size the further from the light it gets. This light can cast shadows', 'scene3d' ),
		'pointlight' => __( 'A light that gets emitted from a single point in all directions. This light can cast shadows', 'scene3d' ),
		'floor'      => __( 'A simple plane geometry to serve as a floor on the scene', 'scene3d' ),
	]
);
$elements_options     = apply_filters(
	'scene3d_elements_options',
	[
		''           => '--' . __( 'Select an element', 'scene3d' ) . '--',
		'glb'        => __( 'GLTF/GLB file', 'scene3d' ),
		'fbx'        => __( 'FBX file', 'scene3d' ),
		'stl'        => __( 'STL file', 'scene3d' ),
		'obj'        => __( 'OBJ file', 'scene3d' ),
		'spotlight'  => __( 'Spotlight', 'scene3d' ),
		'pointlight' => __( 'Point light', 'scene3d' ),
		'floor'      => __( 'Floor', 'scene3d' ),
	]
);
?>
<div>
	<input type="hidden" id="elements-postdata" value="<?php echo esc_attr( Plugin::encode( $elements ) ); ?>"/>
	<div>
		<p>
			<label for="new-element">
				<span class="label"><?php esc_html_e( 'Add element to the scene', 'scene3d' ); ?></span>
			</label>
		</p>
		<select id="new-element" class="dynamic-description">
			<?php foreach ( $elements_options as $key => $value ) : ?>
			<option value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value ); ?></option>
			<?php endforeach; ?>
		</select>
		<button class="button" id="add-element"><?php esc_html_e( 'Add element', 'scene3d' ); ?></button>
		<p class="description dynamic" data-descriptions="<?php echo esc_attr( rawurlencode( wp_json_encode( $element_descriptions ) ) ); ?>"></p>
		<input type="hidden" id="attachment-url" value=""/>
		<input type="hidden" id="attachment-type" value=""/>
		<input type="hidden" id="attachment-filename" value=""/>
		<p id="attachment-error" class="error-message"></p>
	</div>
</div>
<hr/>
<div id="elements-list"></div>
