import{h as x,c as n,e as a,a as t,F as b,r as h,n as f,t as u,k,l as w,g as S,o as $,u as _,d as A,f as I}from"../../assets/runtime-dom.esm-bundler-Dxy_DEvW.js";import{d as g,c as j}from"../../assets/pinia-C4Yr3Hdu.js";import{_ as B}from"../../assets/Loading-Y20e_I4J.js";import{_ as T}from"../../assets/CalendarChart-CSie164z.js";const N={class:"fab-container"},O={class:"grid grid-cols-12"},F={class:"col-span-2"},C=["onClick"],G={class:"col-span-10 border-l-4 border-primary-600 bg-grid-gray-100 bg-gray-50 option-tab-content",style:{"min-height":"30rem"}},P={class:"border border-black/5 px-6 py-4"},D={class:"text-lg pb-4 mb-4 border-b border-gray-200"},H={__name:"Tabs",props:{store:{type:Object,default:()=>{}},active:{type:String,default:"daily_clicks"}},setup(c){const e=c,s=x(e.active);return(y,o)=>(a(),n("div",N,[t("div",O,[t("div",F,[(a(!0),n(b,null,h(e.store.tabs,(i,l)=>(a(),n("div",{key:l,class:f(["cursor-pointer flex flex-row items-center h-12 px-4 text-gray-400 bg-gray-100 hover:bg-primary-600 hover:text-white fab-option-navigation",{"fab-current-option-navigation":s.value===l}]),onClick:r=>s.value=l},[o[0]||(o[0]=t("span",{class:"flex items-center justify-center text-lg"},[t("i",{class:"fa-solid fa-sliders"})],-1)),t("span",{class:f(["ml-3 animate__animated",{animate__pulse:s.value===l}])},u(i.label),3)],10,C))),128))]),t("div",G,[t("div",P,[(a(!0),n(b,null,h(e.store.tabs,(i,l)=>(a(),n("div",{key:l,class:f(["animate__animated animate__fadeIn",{hidden:s.value!==l}])},[t("div",D,u(i.label),1),(a(),k(w(i.component)))],2))),128))])])])]))}},L=g("tabs",{state:()=>({tabs:[]}),actions:{setTabs(c){this.tabs=c}}}),E=g("analytics",{state:()=>({analytics:null}),getters:{daily_clicks_calendar_chart:c=>{if(!c.analytics?.daily_clicks)return null;const{labels:e,colors:s}=window.FAB_INSIGHTS,{premium:y}=window.FAB_PLUGIN;let{daily_clicks:o}=c.analytics;y||(o=Object.fromEntries(Object.entries(o).slice(0,7)));const i=Object.entries(o).reduce((r,[p,d])=>{const m=p.split("-")[0];return r[m]||(r[m]={}),r[m][p]=d,r},{});return Object.entries(i).map(([r,p])=>({title:e.analytics.daily_clicks.label+" "+r,data:Object.entries(p).map(([d,m])=>[d,m]),year:parseInt(r),tooltip:{position:"top",formatter:function(d){return`${d.data[0]}: ${d.data[1]} ${e.analytics.daily_clicks.clicks}`}},threshold:Object.values(e.analytics.daily_clicks.threshold)}))}},actions:{setAnalytics(c){this.analytics=c},async fetchAnalytics(c=!1){this.analytics=null;const{nonce:e,rest_api:s,post:y}=window.FAB_INSIGHTS,i=await(await fetch(s.analytics,{method:"POST",headers:{"X-WP-Nonce":e,"Content-Type":"application/json"},body:JSON.stringify({nocache:c,post_id:y.ID,types:["daily_clicks"]})})).json();this.setAnalytics(i.analytics)}}}),U={class:"fab-analytics-daily-clicks"},V={class:"flex items-center justify-between"},z={class:"text-gray-500"},J={key:0,class:"flex items-center gap-x-1"},M=["href"],W={key:1},X=["href"],Y={class:"h-full"},q={key:1},K={__name:"DailyClicks",setup(c){const{premium:e}=window.FAB_PLUGIN,{labels:s,urls:y,colors:o}=window.FAB_INSIGHTS,i=E(),l=S(()=>i.analytics?.daily_clicks);return $(async()=>{await i.fetchAnalytics()}),(r,p)=>(a(),n("div",U,[t("div",V,[t("p",z,u(_(s).analytics.daily_clicks.label),1),_(e)?(a(),n("div",W,[t("a",{href:_(y).config_tracking,class:"text-lg font-medium"},[...p[0]||(p[0]=[t("i",{class:"fas fa-cog"},null,-1)])],8,X)])):(a(),n("div",J,[t("a",{href:_(y).upgrade,class:"text-xs font-medium"},u(_(s).analytics.daily_clicks.missing_clicks),9,M)]))]),t("div",Y,[_(i).analytics?l.value?(a(!0),n(b,{key:2},h(_(i).daily_clicks_calendar_chart,d=>(a(),k(T,{key:d.year,config:d},null,8,["config"]))),128)):(a(),n("p",q,u(_(s).analytics.daily_clicks.no_data),1)):(a(),k(B,{key:0,class:"w-8 h-8 mt-4 mx-2"}))])]))}},Q={class:"fab-container metabox-analytics"},R={__name:"App",setup(c){const{labels:e}=window.FAB_INSIGHTS,s=L();return s.setTabs({daily_clicks:{label:e.analytics.daily_clicks.label,component:K}}),(y,o)=>(a(),n("div",Q,[A(H,{store:_(s),active:"daily_clicks"},null,8,["store"])]))}},v=I(R);v.use(j());v.mount("#fab-metabox-analytics-dom");
//# sourceMappingURL=bundle.DN0A4ihn.js.map
