import{a as h,s as v,i as I,d as C}from"./Toast-BwR22KmJ.js";const s={video:null,currentEpisode:1,currentServer:0,recommendations:[],isLoading:!0};window.state=s;let t={};function k(){var e,i;t={videoPlayer:document.getElementById("videoPlayer"),videoPlayerContainer:document.getElementById("videoPlayerContainer"),playerLoading:document.getElementById("playerLoading"),closePlayer:document.getElementById("closePlayer"),heroBg:document.getElementById("heroBg"),movieTitle:document.getElementById("movieTitleDesktop"),movieMatch:document.getElementById("movieMatchDesktop"),movieYear:document.getElementById("movieYearDesktop"),movieRating:document.getElementById("movieRatingDesktop"),movieQuality:document.getElementById("movieQualityDesktop"),movieDescription:document.getElementById("movieDescriptionDesktop"),movieTags:document.getElementById("movieTags"),movieTitleMobile:document.getElementById("movieTitleMobile"),movieMatchMobile:document.getElementById("movieMatchMobile"),movieYearMobile:document.getElementById("movieYearMobile"),movieRatingMobile:document.getElementById("movieRatingMobile"),movieDuration:document.getElementById("movieDurationDesktop"),movieDurationMobile:document.getElementById("movieDurationMobile"),movieQualityMobile:document.getElementById("movieQualityMobile"),movieDescriptionMobile:document.getElementById("movieDescriptionMobile"),playBtn:document.getElementById("playBtnDesktop"),addListBtn:document.getElementById("addListBtnDesktop"),addListIcon:(e=document.getElementById("addListBtnDesktop"))==null?void 0:e.querySelector(".material-symbols-outlined"),addListText:(i=document.getElementById("addListBtnDesktop"))==null?void 0:i.querySelector("span:last-child"),playBtnMobile:document.getElementById("playBtnMobile"),addListBtnMobile:document.getElementById("addListBtnMobile"),shareBtnMobile:document.getElementById("shareBtnMobile"),mobilePlayBtn:document.getElementById("mobilePlayBtn"),watchHeader:document.getElementById("watchHeader"),tabNav:document.getElementById("tabNav"),watchBackBtn:document.getElementById("watchBackBtn"),episodesPanel:document.getElementById("episodesPanel"),trailersPanel:document.getElementById("trailersPanel"),detailsPanel:document.getElementById("detailsPanel"),seasonSelect:document.getElementById("seasonSelect"),seasonSelectContainer:document.getElementById("seasonSelectContainer"),episodeCount:document.getElementById("episodeCount"),episodesGrid:document.getElementById("episodesGrid"),episodesLoading:document.getElementById("episodesLoading"),castCarousel:document.getElementById("castCarousel"),recommendationsContainer:document.getElementById("recommendationsContainer"),detailsList:document.getElementById("detailsList"),searchModal:document.getElementById("searchModal"),searchBtn:document.getElementById("searchBtn"),searchInput:document.getElementById("searchInput"),closeSearch:document.getElementById("closeSearch")}}async function w(){const e=new URLSearchParams(window.location.search),i=e.get("id"),r=e.get("slug"),o=parseInt(e.get("ep"))||1;if(s.currentEpisode=o,!i&&!r){B("No video specified");return}k(),$(),await T(i,r),await j()}function $(){if(window.addEventListener("scroll",()=>{t.watchHeader&&(window.scrollY>50?t.watchHeader.style.backgroundColor="rgba(20,20,20,0.95)":t.watchHeader.style.backgroundColor="transparent")}),t.watchBackBtn&&t.watchBackBtn.addEventListener("click",i=>{i.preventDefault(),t.videoPlayerContainer&&(t.videoPlayerContainer.style.display!=="none"||!t.videoPlayerContainer.classList.contains("hidden"))?b():document.referrer&&document.referrer.includes(window.location.host)?window.history.back():window.location.href="/index.html"}),document.addEventListener("keydown",i=>{i.key==="Escape"&&(t.videoPlayerContainer&&!t.videoPlayerContainer.classList.contains("hidden")&&b(),t.searchModal&&!t.searchModal.classList.contains("hidden")&&t.searchModal.classList.add("hidden"))}),[t.playBtn,t.playBtnMobile,t.mobilePlayBtn].forEach(i=>{i&&i.addEventListener("click",()=>{t.videoPlayerContainer&&(t.videoPlayerContainer.classList.remove("hidden"),t.videoPlayerContainer.style.display="block"),t.videoPlayer&&(t.videoPlayer.style.display="block"),M()})}),t.closePlayer&&t.closePlayer.addEventListener("click",()=>{b()}),t.searchBtn&&t.searchBtn.addEventListener("click",()=>{t.searchModal&&(t.searchModal.classList.remove("hidden"),setTimeout(()=>{var i;return(i=t.searchInput)==null?void 0:i.focus()},100))}),t.closeSearch&&t.closeSearch.addEventListener("click",()=>{t.searchModal&&t.searchModal.classList.add("hidden")}),[t.addListBtn,t.addListBtnMobile].forEach(i=>{i&&i.addEventListener("click",()=>{var o;if(!s.video)return;const r=(o=window.historyService)==null?void 0:o.toggleFavorite(s.video);x(r),r?v("Added to My List","success"):v("Removed from My List","info")})}),t.shareBtnMobile&&t.shareBtnMobile.addEventListener("click",()=>{var i;navigator.share?navigator.share({title:((i=s.video)==null?void 0:i.title)||"StreamFlix",url:window.location.href}):(navigator.clipboard.writeText(window.location.href),v("Link copied to clipboard","success"))}),t.tabNav){const i=t.tabNav.querySelectorAll(".tab-btn"),r={episodes:t.episodesPanel,details:t.detailsPanel};i.forEach(o=>{o.addEventListener("click",()=>{const n=o.dataset.tab;i.forEach(l=>{l.classList.remove("text-white","font-bold","border-b-4","border-primary"),l.classList.add("text-gray-400","font-medium")}),o.classList.remove("text-gray-400","font-medium"),o.classList.add("text-white","font-bold","border-b-4","border-primary"),Object.entries(r).forEach(([l,d])=>{d&&(l===n?d.classList.remove("hidden"):d.classList.add("hidden"))})})})}document.querySelectorAll("#mobileBottomNav .nav-item").forEach(i=>{i.addEventListener("click",r=>{r.preventDefault();const o=i.dataset.view;o&&(window.location.href=`/index.html?view=${o}`)})})}function b(){const e=t.videoPlayerContainer||document.getElementById("videoPlayerContainer"),i=t.videoPlayer||document.getElementById("videoPlayer"),r=t.playerLoading||document.getElementById("playerLoading");e&&(e.classList.add("hidden"),e.style.display="none"),C(),i&&(i.innerHTML="",i.style.display="none"),r&&(r.style.display="none")}function x(e){const i=e?"check":"add",r=e?"In List":"My List";if(t.addListBtn){const o=t.addListBtn.querySelector(".material-symbols-outlined"),n=t.addListBtn.querySelector("span:last-child");o&&(o.textContent=i),n&&(n.textContent=r),e?t.addListBtn.classList.add("bg-white/20"):t.addListBtn.classList.remove("bg-white/20")}if(t.addListBtnMobile){const o=t.addListBtnMobile.querySelector(".material-symbols-outlined"),n=t.addListBtnMobile.querySelector("span:last-child");o&&(o.textContent=i),n&&(n.textContent=r),e?(t.addListBtnMobile.classList.add("bg-white/10"),t.addListBtnMobile.classList.remove("bg-[#2b2b2b]")):(t.addListBtnMobile.classList.remove("bg-white/10"),t.addListBtnMobile.classList.add("bg-[#2b2b2b]"))}}async function T(e,i){var r,o,n,l,d,c;try{s.isLoading=!0;let m=null;const u=i||e;if(u)try{const p=await h.getRophimMovie(u);if(p){const a=p.movie||p,y=p.episodes||[];m={id:a.slug||u,slug:a.slug||u,title:a.name||a.title||u,original_title:a.origin_name||a.original_title||"",description:a.content||a.description||"",thumbnail:a.poster_url||a.thumb_url||a.thumbnail||"",year:a.year,rating:((r=a.tmdb)==null?void 0:r.vote_average)||a.rating||"N/A",quality:a.quality||"HD",duration:a.time||a.duration||"",genres:Array.isArray(a.category)?a.category.map(g=>g.name||g):Array.isArray(a.genres)?a.genres:typeof a.genre=="string"?a.genre.split(",").map(g=>g.trim()):[],country:((n=(o=a.country)==null?void 0:o[0])==null?void 0:n.name)||a.country||"",country:((d=(l=a.country)==null?void 0:l[0])==null?void 0:d.name)||a.country||"",cast:a.actor||a.cast||[],director:((c=a.director)==null?void 0:c[0])||a.director||"",source_url:`https://phimmoichill.network/phim/${u}`,episodes:P(y)}}}catch(p){console.warn("API fetch failed:",p)}if(!m)throw new Error("Video data not found");s.video=m,window.historyService&&window.historyService.addToHistory(m,{episode:s.currentEpisode}),_(m),window.historyService&&x(window.historyService.isFavorite(m.slug))}catch(m){console.error("Failed to load video:",m),B("Failed to load video data")}finally{s.isLoading=!1}}function P(e){if(!e||!Array.isArray(e)||e.length===0)return[];const i=e[0];return((i==null?void 0:i.server_data)||[]).map((o,n)=>({number:n+1,name:o.name||`Episode ${n+1}`,title:o.filename||`Episode ${n+1}`,slug:o.slug||"",link_embed:o.link_embed||"",link_m3u8:o.link_m3u8||""}))}function _(e){if(t.heroBg){const i=e.backdrop||e.poster_url||e.thumb_url||e.thumbnail||"";i&&(t.heroBg.style.backgroundImage=`url('${i}')`)}if(t.movieTitle&&(t.movieTitle.textContent=e.title),t.movieYear&&(t.movieYear.textContent=e.year||""),t.movieDuration)if(e.runtime_minutes){const i=Math.floor(e.runtime_minutes/60),r=e.runtime_minutes%60;t.movieDuration.textContent=i>0?`${i}h ${r}m`:`${r}m`}else e.duration&&(t.movieDuration.textContent=e.duration);if(t.movieQuality&&(t.movieQuality.textContent=e.quality||"HD"),t.movieRating){const i=e.rating||e.tmdb_rating;i&&i!=="N/A"?t.movieRating.textContent=typeof i=="number"?`${i.toFixed(1)} ★`:i:t.movieRating.textContent="TV-MA"}if(t.movieMatch){const i=Math.floor(85+Math.random()*14);t.movieMatch.textContent=`${i}% Match`}if(t.movieDescription){const i=e.tmdb_description||e.description||"No description available.";t.movieDescription.innerHTML=i,t.movieDescriptionMobile&&(t.movieDescriptionMobile.innerHTML=i)}if(t.movieTitleMobile&&(t.movieTitleMobile.textContent=e.title),t.movieYearMobile&&(t.movieYearMobile.textContent=e.year||""),t.movieRatingMobile){const i=e.rating||e.tmdb_rating;t.movieRatingMobile.textContent=i&&i!=="N/A"?typeof i=="number"?i.toFixed(1):i:"TV-MA"}if(t.movieDurationMobile&&(t.movieDurationMobile.textContent=t.movieDuration?t.movieDuration.textContent:e.duration||""),t.movieQualityMobile&&(t.movieQualityMobile.textContent=e.quality||"HD"),t.movieMatchMobile&&t.movieMatch&&(t.movieMatchMobile.textContent=t.movieMatch.textContent),t.movieTags){const i=e.genres||[],r=e.director,o=e.country;let n="";i.length>0&&(n+=`
Full Movie
Click Play to watch
${y}
`:""}This stream is currently unavailable. Please try again later or choose another source.
Error loading video: ${e}
${o.name}
${o.character||"Actor"}
`}).join(""):t.castCarousel.innerHTML=r.map(o=>{const n=`/?search=${encodeURIComponent(o)}`,l=o.split(" ").map(d=>d[0]).join("").toUpperCase().slice(0,2);return`${o}
Actor
`}).join("")}async function j(){const e=t.recommendationsContainer;if(e)try{e.innerHTML='No specific recommendations found.
')}catch(i){console.error("Failed to load recommendations:",i),e.innerHTML='Failed to load recommendations
'}}function N(e){const i=e.poster_url||e.thumbnail||e.thumb_url||"",r=e.name||e.title||"Untitled",o=e.year||"",n=e.quality||"HD",l=e.matchScore||Math.floor(Math.random()*15+85),d=e.tmdb_rating||0,c=Math.round(d*10);return`