<script lang="ts">
// console.log(`ae_ Svelte Hosted Files +page data:`, data);

import { onMount } from 'svelte';

// import { api } from '$lib/api.js';
import {
    ae_loc,
    ae_sess,
    ae_api,
    slct,
    slct_trigger
} from '$lib/stores/ae_stores';
// import { ae_util } from '$lib/ae_utils/ae_utils';
import type { key_val } from '$lib/stores/ae_stores';

import Element_manage_hosted_file_li_wrap from '$lib/elements/element_manage_hosted_file_li_all.svelte';
import { Video } from '@lucide/svelte';
let { data } = $props();

let log_lvl = 0;

let ae_promises: key_val = {};

// export let container_class_li = [];

let file_uploads_post_promise;
let download_src;
let download_filename;

if (!$ae_loc.files) {
    $ae_loc.files = {};
    $ae_loc.files.processed_file_kv = {};
    $ae_loc.files.uploaded_file_kv = {};
    $ae_loc.files.video_clip_file_kv = {};
    // $ae_loc.files.uploaded_file_list = [];
    // $ae_loc.files.video_clip_file_list = [];
}
if (!$ae_loc.files.processed_file_kv) {
    $ae_loc.files.processed_file_kv = {};
}

$effect(() => {
    // if ($ae_sess.files.upload_complete && $ae_sess.files.uploaded_file_li) {
    // // Append this list to the $ae_loc.files.uploaded_file_li list
    // $ae_loc.files.uploaded_file_li = [
    //     ...$ae_loc.files.uploaded_file_li,
    //     ...$ae_sess.files.uploaded_file_li
    // ];
    // }

    if ($ae_sess.files.upload_complete && $ae_sess.files.uploaded_file_kv) {
        // Add this key-value pair to the $ae_loc.files.uploaded_file_kv object
        $ae_loc.files.uploaded_file_kv = {
            ...$ae_loc.files.uploaded_file_kv,
            ...$ae_sess.files.uploaded_file_kv
        };
        $ae_sess.files.upload_complete = false;
    }

    if ($ae_sess.files.clip_complete && $ae_sess.files.video_clip_file_kv) {
        // Add this key-value pair to the $ae_loc.files.video_clip_file_kv object
        $ae_loc.files.video_clip_file_kv = {
            ...$ae_loc.files.video_clip_file_kv,
            ...$ae_sess.files.video_clip_file_kv
        };
        $ae_sess.files.clip_complete = false;
    }
});

// $effect(() => {
//     if ($ae_sess.files.upload_complete && $ae_sess.files.uploaded_file_kv) {
//     // Add this key-value pair to the $ae_loc.files.uploaded_file_kv object
//     $ae_loc.files.uploaded_file_kv = {
//         ...$ae_loc.files.uploaded_file_kv,
//         ...$ae_sess.files.uploaded_file_kv
//     };
//     }
// });

// $effect(() => {
//     if ($ae_sess.files.clip_complete && $ae_sess.files.video_clip_file_kv) {
//     // Add this key-value pair to the $ae_loc.files.video_clip_file_kv object
//     $ae_loc.files.video_clip_file_kv = {
//         ...$ae_loc.files.video_clip_file_kv,
//         ...$ae_sess.files.video_clip_file_kv
//     };
//     }
// });

onMount(() => {
    console.log('Hosted Files: AV Utilities +page.svelte');
});
</script>

<!-- <section
    class="
        ae__hosted_files__av_util
        space-y-4
        flex flex-col gap-1
        items-center
        justify-start
        py-1 px-2 pb-16
        h-full
        max-h-full
        min-w-full
        max-w-6xl
        overflow-auto
        "
    > -->

<!-- <div class="border border-gray-200 p-2 rounded-lg"> -->
<h1 class="h1">Æ Hosted Files</h1>

<h2 class="h2">Video Utilities</h2>
<p>Clip, scale, re-encode videos files (mp4).</p>

<a href="hosted_files/video_util" class="btn preset-filled-primary-500">
    <Video size="1em" class="mx-1" />
    Video Utilities
</a>

<hr />

<h2 class="h2">Manage Files</h2>

<Element_manage_hosted_file_li_wrap
    link_to_type={'account'}
    link_to_id={$ae_loc?.account_id}
    allow_basic={true}
    allow_moderator={true}
    class_li={'max-h-full'} />

<!-- </div> -->

<!-- <h2 class="h2">Step X: Manage Hosted Files</h2> -->
<!-- Show files for this account -->
<!-- <Element_manage_hosted_file_li_wrap
    link_to_type={'account'}
    link_to_id={$ae_loc?.account_id}
    allow_basic={true}
    allow_moderator={true}
    container_class_li={''}
    /> -->

<!-- </section> -->
