<?php
 
$_enabledLangs = Database::fetchAll(
    'SELECT code, name, native_name FROM languages WHERE is_enabled = 1 AND is_default = 0 ORDER BY sort_order ASC'
);
$_defaultLang = Database::fetchOne('SELECT code, name FROM languages WHERE is_default = 1 LIMIT 1');

 
$_savedTitlePrompt = Setting::get('import_ai_title_prompt', '');
$_savedTranslatePrompt = Setting::get('import_ai_translate_prompt', '');
$_savedDescPrompt = Setting::get('import_ai_desc_prompt', '');
$_savedTranslateDescPrompt = Setting::get('import_ai_translate_desc_prompt', '');
$_pricing   = CatalogueClient::cataloguePricing();
$_priceVideo = (float) ($_pricing['video'] ?? 0.50);
$_priceAi    = $_pricing['ai'] ?? [];
 
$_priceAiPerLang = is_array($_pricing['ai_per_lang'] ?? null) ? $_pricing['ai_per_lang'] : [];
$_creditRate = (static function (): float {
    $r = Setting::get('catalogue_credit_rate', '');
    return $r !== '' ? (float) $r : 0.01;
})();
 
$_fmtCr = static fn (float $v): string => (rtrim(rtrim(number_format($v, 2), '0'), '.') ?: '0');
$_isApiConnected = (Setting::get('catalogue_api_key', '') !== '' && Setting::get('catalogue_api_secret', '') !== '');
?>
<script>
 
 
 
window.TPFluid = (function () {
    var p = null;
    return {
        load: function () {
            if (typeof window.fluidPlayer === 'function') return Promise.resolve();
            if (p) return p;
            p = new Promise(function (resolve, reject) {
                var s = document.createElement('script');
                s.src = '/assets/vendor/fluidplayer/fluidplayer.min.js';
                s.onload = function () { resolve(); };
                s.onerror = function () { p = null; reject(new Error('fluidplayer')); };
                document.head.appendChild(s);
            });
            return p;
        }
    };
})();
</script>
<style>.fp-preview-modal .fluid_video_wrapper{width:100%!important;height:100%!important}.fp-info-preview .fluid_video_wrapper{width:100%!important}</style>


<div class="mb-6">
    <div class="border-b border-gray-200">
        <nav class="flex gap-6" aria-label="Import tabs">
            <button type="button" onclick="IMP_TABS.switchTo('catalogue')" id="tab-catalogue"
                class="import-tab pb-3 text-sm font-medium border-b-2 transition-colors border-primary-500 text-primary-600">
                <span class="inline-flex items-center gap-1.5">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/><path stroke-linecap="round" stroke-linejoin="round" d="M15.91 11.672a.375.375 0 010 .656l-5.603 3.113a.375.375 0 01-.557-.328V8.887c0-.286.307-.466.557-.327l5.603 3.112z"/></svg>
                    TubePress Catalogue
                </span>
            </button>
            <button type="button" onclick="IMP_TABS.switchTo('csv')" id="tab-csv"
                class="import-tab pb-3 text-sm font-medium border-b-2 transition-colors border-transparent text-gray-500 hover:text-gray-700">
                <span class="inline-flex items-center gap-1.5">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"/></svg>
                    Upload File
                </span>
            </button>
            <button type="button" onclick="IMP_TABS.switchTo('feeds')" id="tab-feeds"
                class="import-tab pb-3 text-sm font-medium border-b-2 transition-colors border-transparent text-gray-500 hover:text-gray-700">
                <span class="inline-flex items-center gap-1.5">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M4 11a9 9 0 0 1 9 9M4 4a16 16 0 0 1 16 16"/><circle cx="5" cy="19" r="1.5" fill="currentColor" stroke="none"/></svg>
                    Feed Import
                </span>
            </button>
        </nav>
    </div>
</div>

<?php require __DIR__ . '/import/_chrome.php'; ?>
<?php require __DIR__ . '/import/_catalogue.php'; ?>
<?php require __DIR__ . '/import/_uploads.php'; ?>
<?php require __DIR__ . '/import/_uploads_js.php'; ?>
<?php require __DIR__ . '/import/_catalogue_js.php'; ?>
