<?php
if ( ! defined( 'ABSPATH' ) ) exit;

/**
 * Provide a public-facing view for the plugin
 *
 * This file is used to markup the public-facing aspects of the plugin.
 *
 * @link       http://example.com
 * @since      1.0.0
 *
 * @package    Plugin_Name
 * @subpackage Plugin_Name/public/partials
 */

    $custom_dimensions_set = !empty($settings['model_viewer_dimensions']) && !empty($settings['model_viewer_dimensions_custom']);
?>

<!-- This file should primarily consist of HTML with a little bit of PHP. -->


<div class="u3dmv-model-viewer-wrapper">
    <model-viewer
        class="model-viewer"
        <?php echo !empty($settings['model_viewer_dimensions']) ? "data-dim-mode='" . (!empty($settings['model_viewer_dimensions_custom']) ? "custom" : "real") . "'" : ""; ?>
        <?php echo !empty($settings['model_viewer_dimensions'])  && !empty($settings["model_viewer_dimensions_scale"]) ? "data-scale-factor='" . esc_attr($settings['model_viewer_dimensions_scale']) . "'" : "" ?>
        <?php echo $custom_dimensions_set && !empty($settings["model_viewer_dimensions_x"]) ? "data-dim-x='" . esc_attr($settings['model_viewer_dimensions_x']) . "'" : "" ?>
        <?php echo $custom_dimensions_set && !empty($settings["model_viewer_dimensions_y"]) ? "data-dim-y='" . esc_attr($settings['model_viewer_dimensions_y']) . "'" : "" ?>
        <?php echo $custom_dimensions_set && !empty($settings["model_viewer_dimensions_z"]) ? "data-dim-z='" . esc_attr($settings['model_viewer_dimensions_z']) . "'" : "" ?>
        src="<?php echo esc_url( $settings['model_viewer_src']['url'] ?? '' ); ?>"
        poster="<?php echo esc_url( $settings['model_viewer_poster']['url'] ?? '' ); ?>"
        environment-image="<?php echo esc_url( $settings['model_viewer_environment']['url'] ?? '' ); ?>"
        skybox-image="<?php echo esc_url( $settings['model_viewer_skybox']['url'] ?? '' ); ?>"
        loading="<?php echo esc_attr( $settings['model_viewer_loading'] ?? 'auto') ?>"
        tone-mapping="<?php echo esc_attr($settings['model_viewer_tone_mapping']) ?>"
        shadow-intensity="<?php echo esc_attr($settings["model_viewer_sh_intensity"] ?? '0') ?>"
        shadow-softness="<?php echo esc_attr($settings["model_viewer_sh_softness"]) ?? '0' ?>"
        exposure="<?php echo esc_attr($settings["model_viewer_exposure"]["size"] ?? '1,5') ?>"
        touch-action="pan-y"
        camera-orbit="<?php echo esc_attr( $settings['model_viewer_camera_orbit'] ?? '0deg 75deg 105%' ); ?>"
        max-camera-orbit="<?php echo esc_attr( $settings['model_viewer_camera_max_orbit'] ?? 'Infinity 180deg auto' ); ?>"
        min-camera-orbit="<?php echo esc_attr( $settings['model_viewer_camera_min_orbit'] ?? '-Infinity 0deg auto' ); ?>"
        camera-target="<?php echo esc_attr($settings["model_viewer_camera_target"] ?? '') ?>"
        field-of-view="<?php echo esc_attr( $settings['model_viewer_camera_fov'] ?? 'auto' ); ?>"
        max-field-of-view="<?php echo esc_attr( $settings['model_viewer_camera_max_fov'] ?? 'auto' ); ?>"
        min-field-of-view="<?php echo esc_attr( $settings['model_viewer_camera_min_fov'] ?? '25deg' ); ?>"
        camera-controls
        ios-src="<?php echo esc_url($settings['model_viewer_ios_src']['url'] ?? '') ?>"
        <?php echo !empty( $settings['model_viewer_augmented_reality'] ) ? 'ar' : ''; ?>
        <?php echo !empty( $settings['model_viewer_augmented_reality'] ) ? 'ar-modes="webxr scene-viewer quick-look"' : ''; ?>
        <?php echo !empty( $settings['model_viewer_auto_rotate'] ) ? 'auto-rotate' : ''; ?>
    >
        <div id="progress-text">Loading 0%</div>
        <div class="progress-bar hide">
            <div class="update-bar"></div>
        </div>
        <?php if (!empty($settings['model_viewer_dimensions'])): ?>
            <button slot="hotspot-dot+X-Y+Z" class="dot" data-position="1 -1 1" data-normal="1 0 0"></button>
            <button slot="hotspot-dim+X-Y" class="dim" data-position="1 -1 0" data-normal="1 0 0"></button>
            <button slot="hotspot-dot+X-Y-Z" class="dot" data-position="1 -1 -1" data-normal="1 0 0"></button>
            <button slot="hotspot-dim+X-Z" class="dim" data-position="1 0 -1" data-normal="1 0 0"></button>
            <button slot="hotspot-dot+X+Y-Z" class="dot" data-position="1 1 -1" data-normal="0 1 0"></button>
            <button slot="hotspot-dim+Y-Z" class="dim" data-position="0 -1 -1" data-normal="0 1 0"></button>
            <button slot="hotspot-dot-X+Y-Z" class="dot" data-position="-1 1 -1" data-normal="0 1 0"></button>
            <button slot="hotspot-dim-X-Z" class="dim" data-position="-1 0 -1" data-normal="-1 0 0"></button>
            <button slot="hotspot-dot-X-Y-Z" class="dot" data-position="-1 -1 -1" data-normal="-1 0 0"></button>
            <button slot="hotspot-dim-X-Y" class="dim" data-position="-1 -1 0" data-normal="-1 0 0"></button>
            <button slot="hotspot-dot-X-Y+Z" class="dot" data-position="-1 -1 1" data-normal="-1 0 0"></button>
            <svg id="dimLines" width="100%" height="100%" class="dimensionLineContainer">
                <line class="dimensionLine"></line>
                <line class="dimensionLine"></line>
                <line class="dimensionLine"></line>
                <line class="dimensionLine"></line>
                <line class="dimensionLine"></line>
            </svg>
        <?php endif; ?>
    </model-viewer>
</div>