<?php

if ( !defined( 'ABSPATH' ) ) {
    exit;
}
$model_src = get_post_meta( $post->ID, '_u3dmv_model_src', true );
$model_height = get_post_meta( $post->ID, '_u3dmv_model_height', true );
$model_display = get_post_meta( $post->ID, '_u3dmv_model_display', true );
$model_position = get_post_meta( $post->ID, '_u3dmv_model_position', true );
$model_dimensions = get_post_meta( $post->ID, '_u3dmv_model_dimensions', true );
$model_dimensions_scale_factor = get_post_meta( $post->ID, '_u3dmv_model_dimensions_scale_factor', true );
$model_dimensions_custom = get_post_meta( $post->ID, '_u3dmv_model_dimensions_custom', true );
$model_dimensions_x = get_post_meta( $post->ID, '_u3dmv_model_dimensions_x', true );
$model_dimensions_y = get_post_meta( $post->ID, '_u3dmv_model_dimensions_y', true );
$model_dimensions_z = get_post_meta( $post->ID, '_u3dmv_model_dimensions_z', true );
$model_poster = get_post_meta( $post->ID, '_u3dmv_model_poster', true );
$model_env = get_post_meta( $post->ID, '_u3dmv_model_env', true );
$model_skybox = get_post_meta( $post->ID, '_u3dmv_model_skybox', true );
$model_tone_mapping = get_post_meta( $post->ID, '_u3dmv_model_tone_mapping', true );
$model_exposure = get_post_meta( $post->ID, '_u3dmv_model_exposure', true );
$model_shadow_int = get_post_meta( $post->ID, '_u3dmv_model_shadow_int', true );
$model_shadow_soft = get_post_meta( $post->ID, '_u3dmv_model_shadow_soft', true );
$model_camera_orbit = get_post_meta( $post->ID, '_u3dmv_model_camera_orbit', true );
$model_camera_orbit_max = get_post_meta( $post->ID, '_u3dmv_model_camera_orbit_max', true );
$model_camera_orbit_min = get_post_meta( $post->ID, '_u3dmv_model_camera_orbit_min', true );
$model_camera_target = get_post_meta( $post->ID, '_u3dmv_model_camera_target', true );
$model_camera_fov = get_post_meta( $post->ID, '_u3dmv_model_camera_fov', true );
$model_camera_fov_max = get_post_meta( $post->ID, '_u3dmv_model_camera_fov_max', true );
$model_camera_fov_min = get_post_meta( $post->ID, '_u3dmv_model_camera_fov_min', true );
$model_loading = get_post_meta( $post->ID, '_u3dmv_model_loading', true );
$model_rotation = get_post_meta( $post->ID, '_u3dmv_model_rotation', true );
$model_ar = get_post_meta( $post->ID, '_u3dmv_model_ar', true );
$model_ios_src = get_post_meta( $post->ID, '_u3dmv_model_ios_src', true );
$gallery = get_post_meta( $post->ID, '_product_image_gallery', true );
$gallery_ids = array_filter( explode( ',', $gallery ) );
?>
<div class="u3dmv-metabox">
    <!-- MODEL SOURCE -->
    <div id="u3dmv-source-selection">
        <h4><?php 
echo esc_html__( '3D Model Viewer Source', 'ultimate-3d-model-viewer' );
?></h4>

        <p>
            <label for="u3dmv_model_src">
                <?php 
echo esc_html__( 'Select or upload a .glb or .gltf file', 'ultimate-3d-model-viewer' );
?>
            </label><br>

            <input
                type="text"
                id="u3dmv_model_src"
                name="u3dmv_model_src"
                readonly
                value="<?php 
echo esc_attr( $model_src );
?>"
            />
            <br>

            <button type="button" class="button u3dmv-upload-btn" id="u3dmv_model_src_upload">
                <?php 
echo esc_html__( 'Select File', 'ultimate-3d-model-viewer' );
?>
            </button>

            <button type="button" class="button u3dmv-delete-btn" id="u3dmv_model_src_delete">
                <?php 
echo esc_html__( "Delete File", "ultimate-3d-model-viewer" );
?>
            </button>
        </p>
    </div>

    <br>

    <div id="u3dmv-style-selection">
        <h4>Style</h4>

        <p><?php 
echo esc_html__( "Select a height for the model viewer", "ultimate-3d-model-viewer" );
?></p>

        <div class="u3dmv-flex-container">
            <label id="u3dmv_model_height_label" for="u3dmv_model_height">px</label>
            <input
                id="u3dmv_model_height"
                name="u3dmv_model_height"
                type="text"
                value="<?php 
echo esc_attr( $model_height );
?>"
            />
        </div>
    </div>

    <hr>

        <!-- POSITIONING ACCORDION -->
    <details class="u3dmv-accordion">
        <summary><strong><?php 
echo esc_html__( "positioning", "ultimate-3d-model-viewer" );
?></strong></summary>
        <div id="u3dmv-display-selection">
            <p><?php 
echo esc_html__( "Display Size", "ultimate-3d-model-viewer" );
?></p>

            <p><?php 
echo esc_html__( "Would you like the model viewer to occupy half of the page layout?", "ultimate-3d-model-viewer" );
?></p>
            <input
                id="u3dmv_model_display"
                name="u3dmv_model_display"
                type="checkbox"
                value="1"
                <?php 
checked( $model_display, '1' );
?>
            />

            <br>

            <p><?php 
echo esc_html__( "Position of the model viewer", "ultimate-3d-model-viewer" );
?></p>
            <label>
                <input type="radio" name="u3dmv_model_position" value="above" <?php 
checked( $model_position, 'above' );
?> />
                <?php 
echo esc_html__( "Above product image", "ultimate-3d-model-viewer" );
?>
            </label><br>

            <?php 
if ( empty( $gallery_ids ) ) {
    ?>
                <label>
                    <input type="radio" name="u3dmv_model_position" value="under" <?php 
    checked( $model_position, 'under' );
    ?>/>
                    <?php 
    echo esc_html__( "Under product image", "ultimate-3d-model-viewer" );
    ?>
                </label><br>
            <?php 
}
?>

            <label>
                <input type="radio" name="u3dmv_model_position" value="right" <?php 
checked( $model_position, 'right' );
?>/>
                <?php 
echo esc_html__( "Right side of product image", "ultimate-3d-model-viewer" );
?>
            </label><br>

            <label>
                <input type="radio" name="u3dmv_model_position" value="left" <?php 
checked( $model_position, 'left' );
?>/>
                <?php 
echo esc_html__( "Left side of product image", "ultimate-3d-model-viewer" );
?>
            </label><br>

            <label>
                <input type="radio" name="u3dmv_model_position" value="replace" <?php 
checked( $model_position, 'replace' );
?>/>
                <?php 
echo esc_html__( "Replace product image", "ultimate-3d-model-viewer" );
?>
            </label>
        </div>
    </details>

    <hr>

    <!-- SKYBOX ACCORDION -->
    <details class="u3dmv-accordion">
        <summary><strong><?php 
echo esc_html__( 'Skybox', 'ultimate-3d-model-viewer' );
?></strong></summary>
        <div id="u3dmv-skybox-selection">
            <p>
                <label for="u3dmv_model_skybox">
                    <?php 
echo esc_html__( "Select a skybox image (JPG or PNG)", "ultimate-3d-model-viewer" );
?>
                </label>
            </p>

            <input
                type="text"
                id="u3dmv_model_skybox"
                name="u3dmv_model_skybox"
                readonly
                value="<?php 
echo esc_attr( $model_skybox );
?>"
            />
            <br>
            <button type="button" class="button u3dmv-upload-btn" id="u3dmv_model_skybox_upload">
                <?php 
echo esc_html__( 'Select File', 'ultimate-3d-model-viewer' );
?>
            </button>

            <button type="button" class="button u3dmv-delete-btn" id="u3dmv_model_skybox_delete">
                <?php 
echo esc_html__( "Delete File", "ultimate-3d-model-viewer" );
?>
            </button>
        </div>
    </details>

    <hr>

    <!-- DIMENSIONS ACCORDION -->
    <details class="u3dmv-accordion">
        <summary><strong><?php 
echo esc_html__( 'Dimensions', 'ultimate-3d-model-viewer' );
?></strong></summary>
        <div id="u3dmv-dimensions-selection">
            <p><?php 
echo esc_html__( "Show dimensions of the 3D product?", "ultimate-3d-model-viewer" );
?></p>
            <input
                id="u3dmv_model_dimensions"
                name="u3dmv_model_dimensions"
                type="checkbox"
                <?php 
checked( $model_dimensions, '1' );
?>
            />

            <!-- SCALE FACTOR -->
            <p><?php 
echo esc_html__( "Are your real dimensions too small or to big? Use a scale factor e.g. 10 or 0.1", "ultimate-3d-model-viewer" );
?></p>
            <div class="u3dmv-flex-container">
                <label id="u3dmv_model_dimensions_scale_factor_label" for="u3dmv_model_dimensions_scale_factor"><?php 
echo esc_html__( "Scale", "ultimate-3d-model-viewer" );
?></label>
                <input 
                    id="u3dmv_model_dimensions_scale_factor"
                    name="u3dmv_model_dimensions_scale_factor"
                    type="text"
                    value="<?php 
echo esc_attr( $model_dimensions_scale_factor );
?>"
                />
            </div>
            

            <p><?php 
echo esc_html__( "Use custom dimensions instead of actual model size?", "ultimate-3d-model-viewer" );
?></p>
            <input
                id="u3dmv_model_dimensions_custom"
                name="u3dmv_model_dimensions_custom"
                type="checkbox"
                <?php 
checked( $model_dimensions_custom, '1' );
?>
            />
            
            <p><?php 
echo esc_html__( "Enter custom width, height and depth in centimeters for your product", "ultimate-3d-model-viewer" );
?></p>

            <div class="u3dmv-flex-container">
                <label id="u3dmv_model_dimensions_x_label" for="u3dmv_model_dimensions_x"><?php 
echo esc_html__( "Width", "ultimate-3d-model-viewer" );
?></label>
                <input 
                    id="u3dmv_model_dimensions_x"
                    name="u3dmv_model_dimensions_x"
                    type="text"
                    value="<?php 
echo esc_attr( $model_dimensions_x );
?>"
                />
            </div>

            <div class="u3dmv-flex-container">
                <label id="u3dmv_model_dimensions_y_label" for="u3dmv_model_dimensions_y"><?php 
echo esc_html__( "Height", "ultimate-3d-model-viewer" );
?></label>
                <input 
                    id="u3dmv_model_dimensions_y"
                    name="u3dmv_model_dimensions_y"
                    type="text"
                    value="<?php 
echo esc_attr( $model_dimensions_y );
?>"
                />
            </div>

            <div class="u3dmv-flex-container">
                <label id="u3dmv_model_dimensions_z_label" for="u3dmv_model_dimensions_z"><?php 
echo esc_html__( "Depth", "ultimate-3d-model-viewer" );
?></label>
                <input 
                    id="u3dmv_model_dimensions_z"
                    name="u3dmv_model_dimensions_z"
                    type="text"
                    value="<?php 
echo esc_attr( $model_dimensions_z );
?>"
                />
            </div>
        </div>
    </details>

    <hr>

    <!-- POSTER OPTIONS ACCORDION -->
    <details class="u3dmv-accordion">
        <summary><strong><?php 
echo esc_html__( 'poster', 'ultimate-3d-model-viewer' );
?></strong></summary>
        <?php 
?>
            <!-- PREMIUM NOTICE -->
            <div class="u3dmv-metabox">
                <h4><?php 
echo esc_html__( "Upgrade now to Pro to display a background poster while the model is loading", "ultimate-3d-model-viewer" );
?></h4>
                <a
                    class="button"
                    id="u3dmv_model_upgrade_pro"
                    href="<?php 
echo esc_url( u3mv_fs()->checkout_url() );
?>"
                    target="_blank"
                >
                    <?php 
echo esc_html__( 'Upgrade now', 'ultimate-3d-model-viewer' );
?>
                </a>
            </div>
        <?php 
?>
    </details>

    <hr>

    <!-- ENVIRONMENT ACCORDION -->
    <details class="u3dmv-accordion">
        <summary><strong><?php 
echo esc_html__( 'Environment', 'ultimate-3d-model-viewer' );
?></strong></summary>
        <?php 
?>
            <!-- PREMIUM NOTICE -->
            <div class="u3dmv-metabox">
                <h4><?php 
echo esc_html__( "Upgrade now to Pro to select an environment image that affects the lighting reflections on your model.", "ultimate-3d-model-viewer" );
?></h4>
                <a
                    class="button"
                    id="u3dmv_model_upgrade_pro"
                    href="<?php 
echo esc_url( u3mv_fs()->checkout_url() );
?>"
                    target="_blank"
                >
                    <?php 
echo esc_html__( 'Upgrade now', 'ultimate-3d-model-viewer' );
?>
                </a>
            </div>
        <?php 
?>
    </details>

    <hr>

    <!-- TONE-MAPPING ACCORDION -->
    <details class="u3dmv-accordion">
        <summary><strong><?php 
echo esc_html__( 'tone mapping', 'ultimate-3d-model-viewer' );
?></strong></summary>
        <?php 
?>
            <!-- PREMIUM NOTICE -->
            <div class="u3dmv-metabox">
                <h4><?php 
echo esc_html__( "Upgrade now to Pro to change the tone mapping of the 3D scene.", "ultimate-3d-model-viewer" );
?></h4>
                <a
                    class="button"
                    id="u3dmv_model_upgrade_pro"
                    href="<?php 
echo esc_url( u3mv_fs()->checkout_url() );
?>"
                    target="_blank"
                >
                    <?php 
echo esc_html__( 'Upgrade now', 'ultimate-3d-model-viewer' );
?>
                </a>
            </div>
        <?php 
?>
    </details>

    <hr>

    <!-- EXPOSURE ACCORDION -->
    <details class="u3dmv-accordion">
        <summary><strong><?php 
echo esc_html__( 'exposure', 'ultimate-3d-model-viewer' );
?></strong></summary>
        <?php 
?>
             <!-- PREMIUM NOTICE -->
            <div class="u3dmv-metabox">
                <h4><?php 
echo esc_html__( "Upgrade now to Pro to change the exposure of the 3D scene.", "ultimate-3d-model-viewer" );
?></h4>
                <a
                    class="button"
                    id="u3dmv_model_upgrade_pro"
                    href="<?php 
echo esc_url( u3mv_fs()->checkout_url() );
?>"
                    target="_blank"
                >
                    <?php 
echo esc_html__( 'Upgrade now', 'ultimate-3d-model-viewer' );
?>
                </a>
            </div>
        <?php 
?>
    </details>

    <hr>


    <!-- SHADOW ACCORDION -->
    <details class="u3dmv-accordion">
        <summary><strong><?php 
echo esc_html__( 'shadows', 'ultimate-3d-model-viewer' );
?></strong></summary>
        <?php 
?>
            <!-- PREMIUM NOTICE -->
            <div class="u3dmv-metabox">
                <h4><?php 
echo esc_html__( "Upgrade now to Pro to customize shadows of the 3D scene.", "ultimate-3d-model-viewer" );
?></h4>
                <a
                    class="button"
                    id="u3dmv_model_upgrade_pro"
                    href="<?php 
echo esc_url( u3mv_fs()->checkout_url() );
?>"
                    target="_blank"
                >
                    <?php 
echo esc_html__( 'Upgrade now', 'ultimate-3d-model-viewer' );
?>
                </a>
            </div>
        <?php 
?>
    </details>

    <hr>

    <!-- CAMERA OPTIONS ACCORDION -->
    <details class="u3dmv-accordion">
        <summary><strong><?php 
echo esc_html__( 'camera options', 'ultimate-3d-model-viewer' );
?></strong></summary>
        <?php 
?>
            <!-- PREMIUM NOTICE -->
            <div class="u3dmv-metabox">
                <h4><?php 
echo esc_html__( "Upgrade now to Pro to customize camera options of the 3D scene", "ultimate-3d-model-viewer" );
?></h4>
                <a
                    class="button"
                    id="u3dmv_model_upgrade_pro"
                    href="<?php 
echo esc_url( u3mv_fs()->checkout_url() );
?>"
                    target="_blank"
                >
                    <?php 
echo esc_html__( 'Upgrade now', 'ultimate-3d-model-viewer' );
?>
                </a>
            </div>
        <?php 
?>
    </details>

    <hr>

    <!-- LOADING ACCORDION -->
    <details class="u3dmv-accordion">
        <summary><strong><?php 
echo esc_html__( 'loading', 'ultimate-3d-model-viewer' );
?></strong></summary>
        <?php 
?>
            <!-- PREMIUM NOTICE -->
            <div class="u3dmv-metabox">
                <h4><?php 
echo esc_html__( "Upgrade now to Pro to customize the loading strategy of the 3D model", "ultimate-3d-model-viewer" );
?></h4>
                <a
                    class="button"
                    id="u3dmv_model_upgrade_pro"
                    href="<?php 
echo esc_url( u3mv_fs()->checkout_url() );
?>"
                    target="_blank"
                >
                    <?php 
echo esc_html__( 'Upgrade now', 'ultimate-3d-model-viewer' );
?>
                </a>
            </div>
        <?php 
?>
    </details>

    <hr>

    <!-- ROTATION ACCORDION -->
    <details class="u3dmv-accordion">
        <summary><strong><?php 
echo esc_html__( 'auto rotate', 'ultimate-3d-model-viewer' );
?></strong></summary>
        <?php 
?>
             <!-- PREMIUM NOTICE -->
            <div class="u3dmv-metabox">
                <h4><?php 
echo esc_html__( "Upgrade now to Pro to enable auto rotation of the 3D model.", "ultimate-3d-model-viewer" );
?></h4>
                <a
                    class="button"
                    id="u3dmv_model_upgrade_pro"
                    href="<?php 
echo esc_url( u3mv_fs()->checkout_url() );
?>"
                    target="_blank"
                >
                    <?php 
echo esc_html__( 'Upgrade now', 'ultimate-3d-model-viewer' );
?>
                </a>
            </div>
        <?php 
?>
    </details>

    <hr>

    <!-- AR ACCORDION -->
    <details class="u3dmv-accordion">
        <summary><strong><?php 
echo esc_html__( 'augmented reality', 'ultimate-3d-model-viewer' );
?></strong></summary>
        <?php 
?>
             <!-- PREMIUM NOTICE -->
            <div class="u3dmv-metabox">
                <h4><?php 
echo esc_html__( "Upgrade now to Pro to enable augmented reality for mobile devices.", "ultimate-3d-model-viewer" );
?></h4>
                <a
                    class="button"
                    id="u3dmv_model_upgrade_pro"
                    href="<?php 
echo esc_url( u3mv_fs()->checkout_url() );
?>"
                    target="_blank"
                >
                    <?php 
echo esc_html__( 'Upgrade now', 'ultimate-3d-model-viewer' );
?>
                </a>
            </div>
        <?php 
?>
    </details>
</div>
