<script lang="ts">
// *** Import Aether specific variables and functions
import { ae_loc } from '$lib/stores/ae_stores';
import { idaa_loc, idaa_sess, idaa_slct, idaa_trig } from '$lib/stores/ae_idaa_stores';
import Help_tech from '$lib/app_components/e_app_help_tech.svelte';

// let ae_promises: key_val = {};
// let ae_tmp: key_val = {};
// let ae_trigger: any = null;
// let ae_triggers: key_val = {};

// let search_submit_results: any = null;

// if (log_lvl) console.log('** Component Loaded: ** Post Options');
</script>

<!-- preset-filled-surface-500 -->
<!-- text-white -->
<div
    class="
        ae_section ae_options filters_and_search
        novi_bg_light
        preset-outlined-surface-800-200 m-auto my-2 flex
        w-full max-w-4xl
        flex-row flex-wrap items-center justify-center

        gap-1

        rounded-md border
        p-2
        ">
    <div
        class="
            ae_group ae_row
            flex w-full max-w-2xl flex-row
            flex-wrap items-center justify-center gap-1
            ">
        <!-- Max posts select options -->
        <span class="flex flex-row items-center justify-around gap-1">
            <label
                class="
                    novi_label
                    form-group w-32 text-sm text-gray-700 md:w-42 dark:text-gray-300
                    "
                for="qry_limit__posts">
                Max posts:

                <select
                    id="qry_limit__posts"
                    bind:value={$idaa_loc.bb.qry__limit}
                    onchange={() => {
                        $idaa_trig.post_li = true;
                    }}
                    class="
                    select preset-tonal-tertiary preset-outline-tertiary-200-800 form-control
                    col-sm-12
                    inline-block
                    w-20
                    px-1 text-sm
                ">
                    <option value={10}>10</option>
                    <option value={25}>25</option>
                    <option value={50}>50</option>
                    <option value={75} class:hidden={!$ae_loc.trusted_access}
                        >75</option>
                    <option value={100} class:hidden={!$ae_loc.trusted_access}
                        >100</option>
                    <option value={150} class:hidden={!$ae_loc.trusted_access}
                        >150</option>
                    <option value={200} class:hidden={!$ae_loc.trusted_access}
                        >200</option>
                    <option value={500} class:hidden={!$ae_loc.trusted_access}
                        >500</option>
                </select>
            </label>
        </span>

        {#if $ae_loc.trusted_access && (!$idaa_loc.bb.qry__hidden || $idaa_loc.bb.qry__hidden == 'not_hidden')}
            <button
                type="button"
                onclick={() => {
                    $idaa_loc.bb.qry__hidden = 'all';
                    $idaa_loc.bb.qry__limit = 100;
                    $idaa_trig.post_li = true;
                }}
                class="
                    novi_btn btn_hide_bb_post ae_btn btn-info
                    btn btn-sm
                    preset-tonal-secondary preset-outlined-secondary-200-800 hover:preset-filled-secondary-200-800
                    transition
                ">
                <span class="fas fa-eye m-1"></span> Show Hidden Posts
            </button>
        {:else if $ae_loc.trusted_access && $idaa_loc.bb.qry__hidden != 'not_hidden'}
            <button
                type="button"
                onclick={() => {
                    $idaa_loc.bb.qry__hidden = 'not_hidden';
                    $idaa_trig.post_li = true;
                }}
                class="
                    novi_btn btn_hide_bb_post ae_btn btn-info
                    btn btn-sm
                    preset-tonal-secondary preset-outlined-secondary-200-800 hover:preset-filled-secondary-200-800
                    transition
                ">
                <span class="fas fa-eye-slash m-1"></span> Hide Hidden Posts
            </button>
        {/if}

        {#if $ae_loc.edit_mode && $ae_loc.manager_access && (!$idaa_loc.bb.qry__enabled || $idaa_loc.bb.qry__enabled == 'enabled')}
            <button
                type="button"
                onclick={() => {
                    $idaa_loc.bb.qry__enabled = 'all';
                    $idaa_loc.bb.qry__hidden = 'all';
                    $idaa_loc.bb.qry__limit = 500;
                    $idaa_trig.post_li = true;
                }}
                class="
                    novi_btn btn_show_bb_post ae_btn btn-warning
                    btn btn-sm
                    preset-tonal-warning preset-outlined-warning-200-800 hover:preset-filled-warning-200-800
                    transition
                ">
                <span class="fas fa-eye m-1"></span> Show Disabled Posts
            </button>
        {:else if $ae_loc.edit_mode && $ae_loc.manager_access && $idaa_loc.bb.qry__enabled != 'enabled'}
            <button
                type="button"
                onclick={() => {
                    $idaa_loc.bb.qry__enabled = 'enabled';
                    $idaa_trig.post_li = true;
                }}
                class="
                    novi_btn btn_hide_bb_post ae_btn btn-warning
                    btn btn-sm
                    preset-tonal-warning preset-outlined-warning-200-800 hover:preset-filled-warning-200-800
                    transition
                    ">
                <span class="fas fa-eye-slash m-1"></span> Hide Disabled Posts
            </button>
        {/if}

        {#if ($ae_loc.trusted_access && $ae_loc.edit_mode) || $idaa_loc.novi_uuid}
            <button
                type="button"
                disabled={!$ae_loc.authenticated_access || $idaa_loc.bb.edit__post_obj || $idaa_sess.bb.edit__post_obj}
                onclick={() => {
                    if (
                        !confirm(
                            'Open a new draft post? It will not be saved until you press Save Changes.'
                        )
                    ) {
                        return false;
                    }

                    $idaa_slct.post_id = null;
                    $idaa_slct.post_obj = {};
                    $idaa_sess.bb.obj_changed = true;
                    $idaa_loc.bb.edit__post_obj = true;
                }}
                class="
                novi_btn novi_white btn-tertiary
                btn
                btn-sm preset-tonal-warning
                preset-outlined-warning-200-800 hover:preset-filled-warning-200-800 text-xs
                transition
                "
                title="Open a new draft post">
                <span class="fas fa-plus m-1"></span> Create New Post
            </button>
        {/if}
    </div>

    <Help_tech
        e_class=""
        e_class_h1="novi_m0"
        e_class_h2="novi_m0"
        e_class_form_hidden="float-right"
        e_class_form_showing="inline-block"
        btn_class="novi_btn"
        show_btn_class="btn-info"
        additional_kv={{
            novi_uuid: $idaa_loc.novi_uuid,
            novi_email: $idaa_loc.novi_email,
            novi_full_name: $idaa_loc.novi_full_name
        }}></Help_tech>
</div>
<!-- END: div filters_and_search -->
