<?php

/**
 * Custom Fields.
 *
 * @link    https://aiopodcasting.com
 * @since   1.0.0
 *
 * @package AiO_Podcast_Studio
 */

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

if ( 'add' === $form ) : ?>
    <!-- Field: Company Name -->
    <div class="aiopod form-field term-company_name-wrap">        
        <label for="aiopod-field-company_name">
            <?php esc_html_e( 'Company Name', 'aio-podcast-studio' ); ?>
        </label>

        <input type="text" name="company_name" id="aiopod-field-company_name" placeholder="<?php esc_attr_e( 'Acme Media', 'aio-podcast-studio' ); ?>" />

        <p class="description">
            <?php esc_html_e( 'Optional. The organization or employer the participant is affiliated with.', 'aio-podcast-studio' ); ?>
        </p>
    </div>

    <!-- Field: Job Title -->
    <div class="aiopod form-field term-job_title-wrap">
        <?php wp_nonce_field( 'aiopod_save_participant_fields', 'aiopod_participant_fields_nonce' ); // Nonce ?>

        <label for="aiopod-field-job_title">
            <?php esc_html_e( 'Job Title', 'aio-podcast-studio' ); ?>
        </label>

        <input type="text" name="job_title" id="aiopod-field-job_title" placeholder="<?php esc_attr_e( 'Founder, CEO', 'aio-podcast-studio' ); ?>" />

        <p class="description">
            <?php esc_html_e( 'The participant\'s professional designation or job title. This is different from their role in a specific podcast or episode.', 'aio-podcast-studio' ); ?>
        </p>
    </div>

    <!-- Field: Website URL -->
    <div class="aiopod form-field term-website_url-wrap">
        <label for="aiopod-field-website_url">
            <?php esc_html_e( 'Website URL', 'aio-podcast-studio' ); ?>
        </label>

        <input type="text" name="website_url" id="aiopod-field-website_url" placeholder="https://www.example.com" />

        <p class="description">
            <?php esc_html_e( 'Optional. A link to the participant\'s personal or professional website.', 'aio-podcast-studio' ); ?>
        </p>
    </div>

    <!-- Field: Facebook Page URL -->
    <div class="aiopod form-field term-facebook_url-wrap">
        <label for="aiopod-field-facebook_url">
            <?php esc_html_e( 'Facebook Page URL', 'aio-podcast-studio' ); ?>
        </label>

        <input type="text" name="facebook_url" id="aiopod-field-facebook_url" placeholder="https://www.facebook.com/your-page-name" />

        <p class="description">
            <?php esc_html_e( 'Optional. The participant\'s official Facebook profile or page.', 'aio-podcast-studio' ); ?>
        </p>
    </div>

    <!-- Field: Twitter / X Profile URL -->
    <div class="aiopod form-field term-twitter_url-wrap">
        <label for="aiopod-field-twitter_url">
            <?php esc_html_e( 'Twitter / X Profile URL', 'aio-podcast-studio' ); ?>
        </label>

        <input type="text" name="twitter_url" id="aiopod-field-twitter_url" placeholder="https://x.com/username" />

        <p class="description">
            <?php esc_html_e( 'Optional. The participant\'s official Twitter / X profile.', 'aio-podcast-studio' ); ?>
        </p>
    </div>

    <!-- Field: Instagram Profile URL -->
    <div class="aiopod form-field term-instagram_url-wrap">
        <label for="aiopod-field-instagram_url">
            <?php esc_html_e( 'Instagram Profile URL', 'aio-podcast-studio' ); ?>
        </label>

        <input type="text" name="instagram_url" id="aiopod-field-instagram_url" placeholder="https://www.instagram.com/username" />

        <p class="description">
            <?php esc_html_e( 'Optional. The participant\'s official Instagram profile.', 'aio-podcast-studio' ); ?>
        </p>
    </div>

    <!-- Field: LinkedIn Page URL -->
    <div class="aiopod form-field term-linkedin_url-wrap">
        <label for="aiopod-field-linkedin_url">
            <?php esc_html_e( 'LinkedIn Page URL', 'aio-podcast-studio' ); ?>
        </label>

        <input type="text" name="linkedin_url" id="aiopod-field-linkedin_url" placeholder="https://www.linkedin.com/company/your-page-name" />

        <p class="description">
            <?php esc_html_e( 'Optional. The participant\'s official LinkedIn profile or page.', 'aio-podcast-studio' ); ?>
        </p>
    </div>

    <!-- Field: YouTube Channel URL -->
    <div class="aiopod form-field term-youtube_url-wrap">
        <label for="aiopod-field-youtube_url">
            <?php esc_html_e( 'YouTube Channel URL', 'aio-podcast-studio' ); ?>
        </label>

        <input type="text" name="youtube_url" id="aiopod-field-youtube_url" placeholder="https://www.youtube.com/@channelname" />

        <p class="description">
            <?php esc_html_e( 'Optional. The participant\'s official YouTube channel.', 'aio-podcast-studio' ); ?>
        </p>
    </div>

    <!-- Field: Profile Image -->
    <div class="aiopod form-field term-image-group">
        <label for="aiopod-terms-image">
            <?php esc_html_e( 'Profile Image', 'aio-podcast-studio' ); ?>
        </label>

        <div id="aiopod-terms-image-wrapper"></div>

        <input type="hidden" name="image" id="aiopod-terms-image" />
        <input type="hidden" name="image_id" id="aiopod-terms-image_id" />            
        
        <p>            
            <input type="button" id="aiopod-terms-upload-image" class="button button-secondary" value="<?php esc_attr_e( 'Upload Image', 'aio-podcast-studio' ); ?>" />
            <input type="button" id="aiopod-terms-remove-image" class="button button-secondary" value="<?php esc_attr_e( 'Remove Image', 'aio-podcast-studio' ); ?>" style="display: none;" />
        </p>  
        
        <p class="description">
            <?php esc_html_e( 'Recommended size: 400 x 400 pixels.', 'aio-podcast-studio' ); ?>
        </p>
    </div>
<?php elseif ( 'edit' === $form ) : 
    $job_title     = isset( $term_meta['job_title'] ) ? $term_meta['job_title'][0] : '';
    $company_name  = isset( $term_meta['company_name'] ) ? $term_meta['company_name'][0] : '';
    $website_url   = isset( $term_meta['website_url'] ) ? $term_meta['website_url'][0] : '';
    $facebook_url  = isset( $term_meta['facebook_url'] ) ? $term_meta['facebook_url'][0] : '';
    $twitter_url   = isset( $term_meta['twitter_url'] ) ? $term_meta['twitter_url'][0] : '';
    $instagram_url = isset( $term_meta['instagram_url'] ) ? $term_meta['instagram_url'][0] : '';
    $linkedin_url  = isset( $term_meta['linkedin_url'] ) ? $term_meta['linkedin_url'][0] : '';
    $youtube_url   = isset( $term_meta['youtube_url'] ) ? $term_meta['youtube_url'][0] : '';
    $image         = isset( $term_meta['image'] ) ? $term_meta['image'][0] : '';
    $image_id      = isset( $term_meta['image_id'] ) ? $term_meta['image_id'][0] : 0;    

    if ( empty( $image ) && $image_id > 0 ) {
        $image = wp_get_attachment_url( $image_id );
    }
    ?>
    <!-- Field: Company Name -->
    <tr class="aiopod form-field term-company_name-wrap">     
        <th scope="row">   
            <label for="aiopod-field-company_name"><?php esc_html_e( 'Company Name', 'aio-podcast-studio' ); ?></label>
        </th>
        <td>
            <input type="text" name="company_name" id="aiopod-field-company_name" placeholder="<?php esc_attr_e( 'Acme Media', 'aio-podcast-studio' ); ?>" value="<?php echo esc_attr( $company_name ); ?>" />

            <p class="description">
                <?php esc_html_e( 'Optional. The organization or employer the participant is affiliated with.', 'aio-podcast-studio' ); ?>
            </p>
        </td>
    </tr>

    <!-- Field: Job Title -->
    <tr class="aiopod form-field term-job_title-wrap">
        <th scope="row">
            <label for="aiopod-field-job_title"><?php esc_html_e( 'Job Title', 'aio-podcast-studio' ); ?></label>
        </th>

        <td>
            <input type="text" name="job_title" id="aiopod-field-job_title" placeholder="<?php esc_attr_e( 'Founder, CEO', 'aio-podcast-studio' ); ?>" value="<?php echo esc_attr( $job_title ); ?>" />

            <p class="description">
                <?php esc_html_e( 'The participant\'s professional designation or job title. This is different from their role in a specific podcast or episode.', 'aio-podcast-studio' ); ?>
            </p>

            <?php wp_nonce_field( 'aiopod_save_participant_fields', 'aiopod_participant_fields_nonce' ); // Nonce ?>
        </td>
    </tr>

    <!-- Field: Website URL -->
    <tr class="aiopod form-field term-website_url-wrap">
        <th scope="row">
            <label for="aiopod-field-website_url"><?php esc_html_e( 'Website URL', 'aio-podcast-studio' ); ?></label>
        </th>
        <td>
            <input type="text" name="website_url" id="aiopod-field-website_url" placeholder="https://www.example.com" value="<?php echo esc_url( $website_url ); ?>" />

            <p class="description">
                <?php esc_html_e( 'Optional. A link to the participant\'s personal or professional website.', 'aio-podcast-studio' ); ?>
            </p>
        </td>
    </tr>

    <!-- Field: Facebook Page URL -->
    <tr class="aiopod form-field term-facebook_url-wrap">
        <th scope="row">
            <label for="aiopod-field-facebook_url"><?php esc_html_e( 'Facebook Page URL', 'aio-podcast-studio' ); ?></label>
        </th>
        <td>
            <input type="text" name="facebook_url" id="aiopod-field-facebook_url" placeholder="https://www.facebook.com/your-page-name" value="<?php echo esc_url( $facebook_url ); ?>" />

            <p class="description">
                <?php esc_html_e( 'Optional. The participant\'s official Facebook profile or page.', 'aio-podcast-studio' ); ?>
            </p>
        </td>
    </tr>

    <!-- Field: Twitter / X Profile URL -->
    <tr class="aiopod form-field term-twitter_url-wrap">
        <th scope="row">
            <label for="aiopod-field-twitter_url"><?php esc_html_e( 'Twitter / X Profile URL', 'aio-podcast-studio' ); ?></label>
        </th>
        <td>
            <input type="text" name="twitter_url" id="aiopod-field-twitter_url" placeholder="https://x.com/username" value="<?php echo esc_url( $twitter_url ); ?>" />

            <p class="description">
                <?php esc_html_e( 'Optional. The participant\'s official Twitter / X profile.', 'aio-podcast-studio' ); ?>
            </p>
        </td>
    </tr>

    <!-- Field: Instagram Profile URL -->
    <tr class="aiopod form-field term-instagram_url-wrap">
        <th scope="row">
            <label for="aiopod-field-instagram_url"><?php esc_html_e( 'Instagram Profile URL', 'aio-podcast-studio' ); ?></label>
        </th>
        <td>
            <input type="text" name="instagram_url" id="aiopod-field-instagram_url" placeholder="https://www.instagram.com/username" value="<?php echo esc_url( $instagram_url ); ?>" />

            <p class="description">
                <?php esc_html_e( 'Optional. The participant\'s official Instagram profile.', 'aio-podcast-studio' ); ?>
            </p>
        </td>
    </tr>

    <!-- Field: LinkedIn Page URL -->
    <tr class="aiopod form-field term-linkedin_url-wrap">
        <th scope="row">
            <label for="aiopod-field-linkedin_url"><?php esc_html_e( 'LinkedIn Page URL', 'aio-podcast-studio' ); ?></label>
        </th>
        <td>
            <input type="text" name="linkedin_url" id="aiopod-field-linkedin_url" placeholder="https://www.linkedin.com/company/your-page-name" value="<?php echo esc_url( $linkedin_url ); ?>" />

            <p class="description">
                <?php esc_html_e( 'Optional. The participant\'s official LinkedIn profile or page.', 'aio-podcast-studio' ); ?>
            </p>
        </td>
    </tr>

    <!-- Field: YouTube Channel URL -->
    <tr class="aiopod form-field term-youtube_url-wrap">
        <th scope="row">
            <label for="aiopod-field-youtube_url"><?php esc_html_e( 'YouTube Channel URL', 'aio-podcast-studio' ); ?></label>
        </th>
        <td>
            <input type="text" name="youtube_url" id="aiopod-field-youtube_url" placeholder="https://www.youtube.com/@channelname" value="<?php echo esc_url( $youtube_url ); ?>" />

            <p class="description">
                <?php esc_html_e( 'Optional. The participant\'s official YouTube channel.', 'aio-podcast-studio' ); ?>
            </p>
        </td>
    </tr>

    <!-- Field: Profile Image -->
    <tr class="aiopod form-field term-image-wrap">
        <th scope="row">
            <label for="aiopod-terms-image"><?php esc_html_e( 'Profile Image', 'aio-podcast-studio' ); ?></label>
        </th>
        <td>        
            <div id="aiopod-terms-image-wrapper">
				<?php if ( ! empty( $image ) ) : ?>
                    <img src="<?php echo esc_url( $image ); ?>" alt="" loading="lazy" decoding="async" />
                <?php endif; ?>
            </div>

            <input type="hidden" name="image" id="aiopod-terms-image" value="<?php echo esc_attr( $image ); ?>" />
            <input type="hidden" name="image_id" id="aiopod-terms-image_id" value="<?php echo esc_attr( $image_id ); ?>" />

            <p>
                <input type="button" id="aiopod-terms-upload-image" class="button button-secondary" value="<?php esc_attr_e( 'Upload Image', 'aio-podcast-studio' ); ?>" <?php if ( $image ) echo 'style="display: none;"'; ?>/>
                <input type="button" id="aiopod-terms-remove-image" class="button button-secondary" value="<?php esc_attr_e( 'Remove Image', 'aio-podcast-studio' ); ?>" <?php if ( ! $image ) echo 'style="display: none;"'; ?>/>
            </p>

            <p class="description">
                <?php esc_html_e( 'Recommended size: 400 x 400 pixels.', 'aio-podcast-studio' ); ?>
            </p>
        </td>
    </tr>
<?php endif;
