/* ------------------------------------------------------------------------------
* Author: DMCWebZone
* Author URL: https://web-zone.org
* Copyright © Airin Blog by DMCWebZone. All Rights Reserved.
* @package Airin Blog
* Description: Settings plans
* ------------------------------------------------------------------------------ */


jQuery(document).ready(function($) {

    'use strict';

    var attempts = 0;
    var maxAttempts = 100;

    var abCheckPlans = setInterval(function() {
        attempts++;
        if ($('.fs-app-header').length) {

            var token = btoa(AIRINBLOG_PUB_KEY_PLAN.pluginKey + '|' + AIRINBLOG_PUB_KEY_PLAN.oneKey);

			// Content airin
            function airinBlogRenderInfo(data) {
                if (!data.show_info) return;

                var now = new Date();
                var expires = new Date(data.expires);

                if (now <= expires) {
                    var infoBar = `
                        <div class="airinblog-css-set-admin-plans">
                            <div class="airinblog-css-set-admin-plans-info">
                                ${data.text}
                            </div>
                        </div>
                    `;
                    $('.fs-app-header').append(infoBar);
                }
            }

            // JSON
            $.ajax({
                url: 'https://data.web-zone.org/info/plan.json.php',
                headers: {'X-DMCWZMULTI-Token': token},
                dataType: 'json'
            })
            .done(airinBlogRenderInfo)
            .fail(function() {
                $.ajax({
                    url: 'https://data.web-zone.org/info/plan-airin-blog.json.php',
                    headers: {'X-AIRINBLOG-Token': token},
                    dataType: 'json',
                    success: airinBlogRenderInfo
                });
            });

            clearInterval(abCheckPlans);
        }

        if (attempts >= maxAttempts) {
            clearInterval(abCheckPlans);
        }

    }, 100);
    
});
