<!--
Tool to help understand how sending and retrieving feed related info from the database works.
-->

<div style="clear: left;">

    <p>Create/update source</p>

    <p>Retrieve Personal/Business (will store available ones in ctf_builder if successful)</p>
    <a href="" id="ctf_personal_link">Retrieve Personal</a><br>
    <a href="" id="ctf_business_link">Retrieve Business</a>

    <p>Manual account adding</p>

    <form id="ctf_add_source_form" method="post" action="">
        <label for="ctf_access_token">Access Token:</label><input id="ctf_access_token" type="text" name="access_token" value=""><br>
        <label for="ctf_page_name">Page Name (not required):</label><input id="ctf_page_name" type="text" name="name" value=""><br>
        <label for="ctf_page_id">Page ID:</label><input id="ctf_page_id" type="text" name="id" value=""><br>
        <label for="ctf_type">Type:</label><input id="ctf_type" type="text" name="type" value="business"><br>

        <input type="hidden" name="action" value="ctf_source_builder_update"/>
        <input class="button-primary" type="submit" value="Submit"/>
    </form>

    <p>Create/update feed and settings</p>
    <form id="ctf_save_settings_form" method="post" action="">
        <label for="ctf_feed_id">Feed ID: (leave blank for new)</label><input id="ctf_feed_id" type="text" name="feed_id" value=""><br>
        <label for="ctf_feed_title">Feed Title:</label><input id="ctf_feed_title" type="text" name="feed_title" value=""><br>
        <label for="ctf_feed_status">Feed Status (publish or draft):</label><input id="ctf_feed_status" type="text" name="status" value="publish"><br>
        <label for="ctf_src_1">Source 1 (must be the account/page ID):</label><input id="ctf_src_1" type="text" name="sources[]" value=""><br>
        <label for="ctf_src_1">Source 2 (must be the account/page ID):</label><input id="ctf_src_2" type="text" name="sources[]" value=""><br>
        <label for="ctf_num">Number:</label><input id="ctf_num" type="text" name="num" value="10"><br>
        <input type="hidden" name="update_feed" value="true"/>

        <input type="hidden" name="action" value="ctf_feed_saver_manager_builder_update"/>
        <input class="button-primary" type="submit" value="Submit"/>
    </form>

    <p>Get feed settings/posts by ID</p>
    <form id="ctf_get_settings_form" method="post" action="">
        <label for="ctf_settings_feed_id">Feed ID:</label><input id="ctf_settings_feed_id" type="text" name="feed_id" value="1"><br>
        <label for="ctf_settings_include_post_set">Include Posts:</label><input id="ctf_settings_include_post_set" type="checkbox" name="include_post_set" value="1"/>

        <input type="hidden" name="action" value="ctf_feed_saver_manager_get_feed_settings"/>
        <input class="button-primary" type="submit" value="Submit"/>
    </form>

    <p>Pages of things</p>
    <form id="ctf_get_source_page" method="post" action="">
        <label for="ctf_settings_source_page">Source Page:</label><input id="ctf_settings_source_page" type="text" name="page" value="2"><br>
        <input type="hidden" name="action" value="ctf_source_get_page"/>
        <input class="button-primary" type="submit" value="Submit"/>
    </form>

    <form id="ctf_get_feed_page" method="post" action="">
        <label for="ctf_settings_feed_page">Feed Page:</label><input id="ctf_settings_feed_page" type="text" name="page" value="2"><br>
        <input type="hidden" name="action" value="ctf_feed_saver_manager_get_feed_list_page"/>
        <input class="button-primary" type="submit" value="Submit"/>
    </form>

    <p>Locations page by feed ID</p>

    <form id="ctf_get_locations_page" method="post" action="">
        <label for="ctf_settings_locations_feed_id">Feed ID:</label><input id="ctf_settings_locations_feed_id" type="text" name="feed_id" value="1"><br>
        <label for="ctf_settings_locations_page">Locations Page:</label><input id="ctf_settings_locations_page" type="text" name="page" value="2"><br>
        <br><label for="ctf_settings_is_legacy">This is a legacy feed:</label><input id="ctf_settings_is_legacy" type="checkbox" name="is_legacy" value="1"/>
        <input type="hidden" name="action" value="ctf_feed_saver_manager_get_locations_page"/>
        <input class="button-primary" type="submit" value="Submit"/>
    </form>

    <p>Dismiss Onboarding</p>
    <form id="ctf_dismiss_onboarding" method="post" action="">
        <input type="hidden" name="action" value="ctf_dismiss_onboarding"/>
        <input class="button-primary" type="submit" value="Dismiss"/>
    </form>


    <p>Import/Export</p>
    <form id="ctf_import" method="post" action="">
        <input type="hidden" name="action" value="ctf_feed_saver_manager_importer"/>
        <label for="ctf_import_field">Import JSON</label><br>
        <textarea id="ctf_import_field" name="feed_json"></textarea>

        <input class="button-primary" type="submit" value="Submit"/>
    </form>

    <p>Get feed comments</p>
    <form id="ctf_get_comments" method="post" action="">
        <label for="ctf_get_comments_feed_id">Feed ID:</label><input id="ctf_get_comments_feed_id" type="text" name="feed_id" value="1"><br>

        <input type="hidden" name="action" value="ctf_feed_saver_manager_retrieve_comments"/>
        <input class="button-primary" type="submit" value="Submit"/>
    </form>

    <p>Clear single feed cache</p>
    <form id="ctf_clear_single_feed_cache" method="post" action="">
        <label for="ctf_cc_feed_id">Feed ID:</label><input id="ctf_cc_feed_id" type="text" name="feed_id" value="1"><br>

        <input type="hidden" name="action" value="ctf_feed_saver_manager_clear_single_feed_cache"/>
        <input class="button-primary" type="submit" value="Submit"/>
    </form>

</div>
<style>
    .sb-customizer-sidebar {
        display: none !important;
    }
</style>
<script>
    jQuery(document).ready(function($) {
        $('#ctf_personal_link').attr('href',ctf_source.sourceConnectionURLs.personal + ctf_source.sourceConnectionURLs.stateURL);
        $('#ctf_business_link').attr('href',ctf_source.sourceConnectionURLs.business + ctf_source.sourceConnectionURLs.stateURL);

        $('#ctf_source_get_playlist_post_preview, #ctf_clear_single_feed_cache, #ctf_get_comments, #ctf_add_source_form, #ctf_save_settings_form, #ctf_get_settings_form, #ctf_get_source_page, #ctf_get_feed_page, #ctf_get_locations_page, #ctf_dismiss_onboarding, #ctf_source_get_featured_post_preview, #ctf_import').submit(function(event) {

            event.preventDefault();

            var thisData = $(this).serializeArray();
            $.ajax({
                url: ctf_builder.ajax_handler,
                type: 'post',
                data: thisData,
                success: function (data) {
                    if (data.indexOf('{') === 0) {
                        data = JSON.parse(data);
                        console.log(data);

                    }

                }
            });
        });
    });
</script>