(()=>{"use strict";const t=window.React,e=window.wp.element,n="linear-gradient(135deg, #0040E3, #18D4FD)",r=(t,e)=>{return null==(n=e)||""===n||Array.isArray(n)&&0===n.length||"object"==typeof n&&0===Object.keys(n).length||"string"==typeof n&&""===n.trim()||"number"==typeof n&&0===n?"":`${t}: ${e};`;var n},s=t=>{const{color:e="",bgType:s="solid",bg:o="",gradient:l=n}=t||{};return`\n\t\t${r("color",e)}\n\t\t${l||o?r("background","gradient"===s?l:o):""}\n\t`},o=(t,e,n=!0)=>{const{fontFamily:s="Default",fontCategory:o="sans-serif",fontVariant:l=400,fontWeight:i,isUploadFont:a=!0,fontSize:d={desktop:null,tablet:null,mobile:null},fontStyle:c,textTransform:u,textDecoration:p,lineHeight:h,letterSpace:g}=e||{},v=!n||!s||"Default"===s,w=d?.desktop||d,x=d?.tablet||w,m=d?.mobile||x,y=t=>{const e=String(t);return["px","em","rem","%","vh","vw"].some(t=>e.endsWith(t))?e:"number"==typeof t?`${e}px`:""},b=`\n\t\t${v?"":`font-family: '${s}', ${o};`}\n\t\t${r("font-weight",i)}\n\t\t${r("font-size",y(w))}\n\t\t${r("font-style",c)}\n\t\t${r("text-transform",u)}\n\t\t${r("text-decoration",p)}\n\t\t${r("line-height",h)}\n\t\t${r("letter-spacing",g)}\n\t`,f=l&&400!==l?"400i"===l?":ital@1":l?.includes("00i")?`: ital, wght@1, ${l?.replace("00i","00")} `:`: wght@${l} `:"",k=v?"":`https://fonts.googleapis.com/css2?family=${s?.split(" ").join("+")}${f.replace(/ /g,"")}&display=swap`;return{googleFontLink:!a||v?"":`@import url(${k});`,styles:`${t}{\n\t\t\t${b}\n\t\t}\n\t\t@media only screen and (max-width: 1024px) {\n\t\t\t${t}{\n\t\t\t\t${r("font-size",y(x))}\n\t\t\t}\n\t\t}\n\t\t@media only screen and (max-width: 640px) {\n\t\t\t${t}{\n\t\t\t\t${r("font-size",y(m))}\n\t\t\t}\n\t\t}`.replace(/\s+/g," ").trim()}},l=({attributes:e,id:n})=>{const{primaryColor:l,styles:i,radius:a,width:d,align:c,alignment:u}=e,[p,h]=(0,t.useState)(),{playIcon:g,title:v,statusText:w,background:x,progressbarColor:m,iconColor:y,radioIconColor:b,secondaryBackground:f,border:k,subtitle:$,track:j}=i;return(0,t.useEffect)(()=>{const t=`\n ${o("",v?.typography||{}).googleFontLink}\n ${o(`#${n} .title`,v?.typography||{}).styles}\n ${o("",$?.typography||{}).googleFontLink}\n ${o(`#${n} .subtitle`,$?.typography||{}).styles}\n ${o("",j?.typography||{}).googleFontLink}\n ${o(`#${n} [data-plyr=current-track]`,j?.typography||{}).styles}\n #${n}{\n display: flex;\n justify-content: ${u};\n --h5ap-radio-primary-color: ${l};\n --h5ap-radio-icon-color: ${b};\n --h5ap-radio-progress-color: ${m};\n --h5ap-radio-icons-color: ${y};\n }\n #${n} .play-icon {\n ${s(g)}\n }\n #${n} .status-text {\n ${s(w)}\n }\n\n #${n} .title, #${n} .subtitle {\n color: ${v?.color}\n }\n \n #${n} [data-plyr=current-track] {\n ${r("color",j?.color)}\n }\n \n #${n} .radio-wrapper{\n width: ${d};\n }\n #${n} .secondary-container {\n ${r("background",f)}\n }\n \n #${n} .skin_container {\n ${r("background",x)}\n ${(t=>{const{width:e="",style:n="solid",color:s="",side:o="all",radius:l=""}=t||{},i=t=>{const e=o?.toLowerCase();return e?.includes("all")||e?.includes(t)},a=`${e} ${n} ${s}`,d=`\n\t\t${e&&0!==parseInt(e)?["top","right","bottom","left"].map(t=>i(t)?`border-${t}: ${a};`:"").join(""):""}\n\t\t${r("border-radius",l)}\n\t`;return d})(k)}\n }\n \n #${n} .radius{\n border-radius: ${a}\n }\n \n `.replace(/\s+/g," ").trim();h(t)},[d,x,a,n,f,l,c,u,b,i]),(0,t.createElement)("style",null,p)},i=({title:t,sourceType:e,statusText:n})=>`\n
\n ${"stream"===e?`
\n
${n}\n
`:""}\n
\n
\n

${t}

\n
\n
\n \n
\n `,a=({title:t,sourceType:e,statusText:n="LIVE"})=>`
\n
\n
\n
\n
\n ${"stream"===e?`
\n
\n
\n
\n ${n}`:""}\n
\n \n
\n
\n

${t}

\n
\n

\n
\n
\n
\n \n
\n \n \n
\n
\n
\n
`,d=({title:t,sourceType:e,statusText:n="LIVE"})=>`\n
\n
\n ${"stream"===e?`
\n ${n}`:""}\n ${t}\n
\n
\n
\n

\n
\n
\n
\n \n
\n \n \n
\n
\n
\n`,c=({title:t,sourceType:e,subtitle:n,statusText:r})=>`\n
\n
\n
\n ${"stream"===e?`
\n
\n ${r}\n
`:""}\n

${t}

\n ${n?`

${n}

`:""}\n
\n
\n \n
\n
\n\n
\n
\n Now Playing\n \n
\n
\n

\n
\n
\n\n
\n
\n \n
\n
\n \n \n
\n
\n
\n
\n \n \n \n
\n
\n
\n`,u=({attributes:e,id:n,nonce:r})=>{const s=(0,t.useRef)(null),{streamData:o,fetchStreamData:u,isLoading:p,error:h}=((e,n,r=6e4)=>{const[s,o]=(0,t.useState)(null),[l,i]=(0,t.useState)(!1),[a,d]=(0,t.useState)(null),[c,u]=(0,t.useState)(e),p=async()=>{c&&(i(!0),window.wp.ajax.send("h5ap_get_stream_data",{data:{url:c,nonce:n},success:t=>{o(t),i(!1)},error:t=>{d(t),i(!1)}}))};return(0,t.useEffect)(()=>{p();const t=setInterval(()=>{p()},r);return()=>{clearInterval(t)}},[c]),{streamData:s,setSource:u,fetchStreamData:p,isLoading:l,error:a}})(e.source,r),{title:g,subtitle:v,sourceType:w,skin:x,source:m,options:y,statusText:b,multiple_audio:f}=e,{autoplay:k}=y,$={GlassMorphism:a,CompactHorizontal:i,Soft:d,DashboardStyle:c}[e.skin]||null,j=(0,t.useRef)(null);return(0,t.useEffect)(()=>{if(j.current){const t=j.current.elements?.container?.querySelector("[data-plyr=current-track]");t&&(t.innerHTML=o?.trackTitle||"")}},[o,p,h]),(0,t.useEffect)(()=>{if(!s.current)return;const t=new Plyr(s.current.querySelector("audio"),{controls:$?$({sourceType:w,title:g,subtitle:v,statusText:b}):["play","progress","current-time","duration","mute","volume"],autoplay:k,tooltips:{controls:!0,seek:!0}});return t.on("play",()=>{u(),f||document.querySelectorAll("audio").forEach(e=>{e.isEqualNode(t.elements.container.querySelector("audio"))||e.pause()})}),j.current=t,()=>{t.destroy()}},[m,y,x,w,g,v,b,f]),$?(0,t.createElement)(t.Fragment,null,(0,t.createElement)(l,{attributes:e,id:n}),(0,t.createElement)("div",{ref:s,className:`radio_skin_${x.toLowerCase()} radio-wrapper`},(0,t.createElement)("audio",{id:n,className:n,src:m,controls:!0},"Your browser does not support the ",(0,t.createElement)("code",null,"audio")," element."))):(0,t.createElement)("h2",null,"Audio Player")};document.addEventListener("DOMContentLoaded",function(){document.querySelectorAll(".wp-block-h5ap-radio-player").forEach(n=>{const r=JSON.parse(n.dataset.attributes),s=n.dataset.id,o=n.dataset.nonce;n.removeAttribute("data-attributes"),n.removeAttribute("data-id"),n.removeAttribute("data-nonce"),(0,e.createRoot)(n).render((0,t.createElement)(u,{attributes:r,id:s,nonce:o}))})})})();