<?php

/**
 * Accordion: Podcast Details.
 *
 * @link    https://aiopodcasting.com
 * @since   1.0.0
 *
 * @package AiO_Podcast_Studio
 */

// Exit if accessed directly
if ( ! defined( 'WPINC' ) ) {
	die;
}

$appearance_settings = aiopod_get_option( 'aiopod_appearance_settings' );

$image              = isset( $post_meta['image'] ) ? $post_meta['image'][0] : '';
$image_id           = isset( $post_meta['image_id'] ) ? $post_meta['image_id'][0] : 0;
$set_featured_image = isset( $post_meta['set_featured_image'] ) ? $post_meta['set_featured_image'][0] : 1;
$is_explicit        = isset( $post_meta['is_explicit'] ) ? $post_meta['is_explicit'][0] : 0;
?>
<div class="aiopod-form-controls">
    <!-- Field: Podcast Artwork -->
    <div id="aiopod-form-control-image" class="aiopod-form-control">
        <label for="aiopod-field-image" class="aiopod-form-label">
            <?php esc_html_e( 'Podcast Artwork', 'aio-podcast-studio' ); ?>
            <span class="aiopod-form-required">*</span>
        </label>

        <div class="aiopod-form-field">
            <div class="aiopod-media-wrapper">
                <div class="aiopod-media-preview">
                    <?php
                    $image_src = $image;

                    if ( ! empty( $image_id ) ) {
                        $image_data = wp_get_attachment_image_src( (int) $image_id );
                        if ( ! empty( $image_data[0] ) ) {
                            $image_src = $image_data[0];
                        }
                    }

                    if ( empty( $image_src ) ) {
                        $image_src = AIOPOD_PLUGIN_PLACEHOLDER_IMAGE_URL;
                    }
                    ?>
                    <img src="<?php echo esc_url( $image_src ); ?>" alt="" loading="lazy" decoding="async" data-default="<?php echo esc_url( AIOPOD_PLUGIN_PLACEHOLDER_IMAGE_URL ); ?>" />
                </div>

                <div class="aiopod-media-uploader">
                    <p class="description">
                        <?php esc_html_e( 'For best results, use a square JPG or PNG image between 1400x1400 and 3000x3000 pixels.', 'aio-podcast-studio' ); ?>
                    </p>

                    <div class="aiopod-input-group">
                        <input type="text" name="image" id="aiopod-field-image" class="widefat" placeholder="<?php esc_attr_e( 'Enter your direct file URL (OR) upload your file using the button here', 'aio-podcast-studio' ); ?> &rarr;" value="<?php echo esc_url( $image ); ?>" data-default="<?php echo esc_url( AIOPOD_PLUGIN_PLACEHOLDER_IMAGE_URL ); ?>" />
                        <input type="hidden" name="image_id" id="aiopod-field-image_id" value="<?php echo esc_attr( $image_id ); ?>" />
                        <button type="button" class="aiopod-upload-media button" data-format="image">
                            <?php esc_html_e( 'Upload File', 'aio-podcast-studio' ); ?>
                        </button>
                    </div>

                    <?php if ( ! empty( $appearance_settings['enable_featured_images'] ) ) : ?>
                        <label>
                            <input type="checkbox" name="set_featured_image" class="aiopod-sync-featured-image" value="1" <?php checked( $set_featured_image, 1 ); ?>/>
                            <?php esc_html_e( 'Store this image as a featured image', 'aio-podcast-studio' ); ?>
                        </label>
                    <?php endif; ?>
                </div>
            </div>  
        </div>
    </div>

    <!-- Field: Explicit Content? -->
    <div id="aiopod-form-control-is_explicit" class="aiopod-form-control">
        <label for="aiopod-field-is_explicit" class="aiopod-form-label">
            <?php esc_html_e( 'Explicit Content?', 'aio-podcast-studio' ); ?>
        </label>
        
        <label class="aiopod-form-field">
            <input type="checkbox" name="is_explicit" id="aiopod-field-is_explicit" value="1" <?php checked( $is_explicit, 1 ); ?> />
            <?php esc_html_e( 'Check this box if your podcast contains explicit language or adult themes.', 'aio-podcast-studio' ); ?>
        </label>							
    </div>    
</div>