/*-----------------------------------------------------------------------------------

    Theme Name: medsfaq - Nutrition Health and Diet HTML Template
    Description: Nutrition Health and Diet HTML Template
    Author: Website Design Templates
    Version: 2.1
        
    ---------------------------------- */    

!function(){"use strict";const e="/api";function t(e){if(!e)return"";if(e.includes("T"))return e;return e.replace(" ","T")+"Z"}function n(e){if(!e)return"";const n=t(e),o=n?new Date(n):null;return o&&Number.isFinite(o.getTime())?o.toLocaleDateString("en-IN",{timeZone:"Asia/Kolkata",month:"short",day:"numeric",year:"numeric"}):""}function o(e){if(!e)return"";const t=document.createElement("div");return t.innerText=e,t.innerHTML}function r(e){if(!e)return;try{sessionStorage.setItem("lastBlogSlug",e)}catch(e){}}function i(e){return`/blog/${encodeURIComponent(e)}`}function a(e,t){return`
        <div class="d-flex align-items-center mb-1-9">
            <div class="flex-shrink-0 image-hover">
                <img src="${t.img||"img/blog/default-blog.jpg"}" class="w-70px border-radius-10" alt="${o(t.blog_title||"Blog")}">
            </div>
            <div class="flex-grow-1 ps-3">
                <h4 class="h6"><a href="/blog/${encodeURIComponent(t.blogslug||"")}" data-blog-slug="${o(t.blogslug||"")}" class="text-white opacity9 text-secondary-hover">${o(t.blog_title||"View Post")}</a></h4>
                <small class="text-secondary">${n(t.created_at||"")}</small>
            </div>
        </div>
    `}async function l(){const t=document.getElementById("footerRecentPostsA"),n=document.getElementById("footerRecentPostsB");if(!t&&!n)return;try{const o=await fetch(`${e}/blogs?limit=4&page=1`),r=await o.json(),i=Array.isArray(r)?r:r.blogs||[],l=i.slice(0,2),c=i.slice(2,4);t&&(t.innerHTML=l.map((e=>a(0,e))).join("")||""),n&&(n.innerHTML=c.map((e=>a(0,e))).join("")||"")}catch(e){t&&(t.innerHTML=""),n&&(n.innerHTML="")}}document.addEventListener("click",(e=>{const t=e.target.closest("a[data-blog-slug]");if(!t)return;const n=t.dataset.blogSlug||"";n&&(r(n),e.preventDefault(),window.location.href=i(n))})),document.addEventListener("DOMContentLoaded",l)}();
