<?php
if (!defined('ABSPATH')) {
    exit;
}
/* @var UpVimeo_Api_Helper $upvimeo_vimeo_helper */

$upvimeo_vimeo_helper = isset($args['upvimeo_helper']) ? $args['upvimeo_helper'] : (isset($upvimeo_vimeo_helper) ? $upvimeo_vimeo_helper : null);
$upvimeo_db_helper = isset($args['db_helper']) ? $args['db_helper'] : (isset($upvimeo_db_helper) ? $upvimeo_db_helper : null);
$upvimeo_settings_helper = isset($args['settings_helper']) ? $args['settings_helper'] : (isset($upvimeo_settings_helper) ? $upvimeo_settings_helper : null);

/* @var UpVimeo_Db_Helper $upvimeo_db_helper */
/* @var UpVimeo_Settings_Helper $upvimeo_settings_helper */

$upvimeo_view_privacy_opts = $upvimeo_vimeo_helper->get_view_privacy_options_for_forms('admin');
$upvimeo_view_privacy = (int) $upvimeo_settings_helper->get('UPVIMEO_enable_privacy_option_media', 0);
?>

<div class="upvimeo-upload-container">

    <div class="upvimeo-upload-header upvimeo-text-center wvv-mb-30">
        <img src="<?php echo esc_url( plugin_dir_url( dirname( dirname( __FILE__ ) ) ) . 'assets/images/branding/upvimeo-logo-transparent.png' ); ?>" alt="Upvimeo"
            class="upvimeo-branding-logo no-lazy skip-lazy" data-no-lazy="1">
        <div class="upvimeo-header-desc">
            <p><?php esc_html_e('Seamlessly upload your videos directly to Vimeo without worrying about server limits or storage.', 'upvimeo-direct-uploads'); ?>
            </p>
            <p class="upvimeo-sub-desc">
                <?php esc_html_e('Experience fast, secure, and reliable uploads right from your WordPress dashboard.', 'upvimeo-direct-uploads'); ?>
            </p>
        </div>
    </div>

    <div class="upvimeo-upload-card">
        <form class="wvv-video-upload" enctype="multipart/form-data" method="post" action="/">
            <div class="form-row">
                <label for="upvimeo_title"><?php esc_html_e('Title', 'upvimeo-direct-uploads'); ?></label>
                <input type="text" name="upvimeo_title" id="upvimeo_title"
                    placeholder="<?php esc_attr_e('Enter video title', 'upvimeo-direct-uploads'); ?>">
            </div>
            <div class="form-row">
                <label for="upvimeo_description"><?php esc_html_e('Description', 'upvimeo-direct-uploads'); ?></label>
                <textarea name="upvimeo_description" id="upvimeo_description"
                    placeholder="<?php esc_attr_e('Enter video description', 'upvimeo-direct-uploads'); ?>"></textarea>
            </div>
            <?php if ($upvimeo_view_privacy): ?>
                <div class="form-row">
                    <label for="upvimeo_view_privacy"><?php esc_html_e('View Privacy', 'upvimeo-direct-uploads'); ?></label>
                    <select name="upvimeo_view_privacy" id="upvimeo_view_privacy">
                        <?php foreach ($upvimeo_view_privacy_opts as $upvimeo_key => $upvimeo_option): ?>
                            <?php
                            $upvimeo_option_state = $upvimeo_option['default'] && $upvimeo_option['available'] ? 'selected' : '';
                            $upvimeo_option_state .= $upvimeo_option['available'] ? '' : ' disabled';
                            ?>
                            <option <?php echo esc_attr($upvimeo_option_state); ?> value="<?php echo esc_attr($upvimeo_key); ?>">
                                <?php echo esc_html($upvimeo_option['name']); ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                </div>
            <?php endif; ?>
            <div class="form-row">
                <label for="upvimeo_video"><?php esc_html_e('Video File', 'upvimeo-direct-uploads'); ?></label>
                <div class="upvimeo-file-input-wrapper">
                    <input type="file" name="upvimeo_video" id="upvimeo_video">
                </div>
                <div class="upvimeo-progress-bar" style="display: none;">
                    <div class="upvimeo-progress-bar-inner"></div>
                    <div class="upvimeo-progress-bar-value">0%</div>
                </div>
            </div>

            <div class="form-row with-border">
                <button type="submit" class="upvimeo-btn-primary" name="upvimeo_upload" value="1">
                    <?php esc_html_e('Start Upload', 'upvimeo-direct-uploads'); ?>
                    <span class="dashicons dashicons-cloud-upload"
                        style="margin-left:5px; font-size: 18px; width: 18px; height: 18px;"></span>
                </button>

                <div class="upvimeo-loader upvimeo-modern-loader" style="display:none;">
                    <svg class="upvimeo-spinner" viewBox="0 0 50 50">
                        <circle class="path" cx="25" cy="25" r="20" fill="none" stroke-width="4"></circle>
                    </svg>
                    <span><?php esc_html_e('Uploading...', 'upvimeo-direct-uploads'); ?></span>
                </div>
            </div>
        </form>
    </div>

    <div class="upvimeo-back-link-container">
        <a href="<?php echo esc_url(admin_url('admin.php?page=' . UpVimeo_Admin::PAGE_VIMEO)); ?>">
            <span class="dashicons dashicons-arrow-left-alt2"></span>
            <?php esc_html_e('Back to library', 'upvimeo-direct-uploads'); ?>
        </a>
    </div>

</div>