import{useDocumentVisibility as e}from"ahooks";import{uniqueId as a}from"lodash-es";import{forwardRef as t,useRef as i,useImperativeHandle as r,useEffect as n}from"react";import{dynamicLoadJs as l,dynamicLoadCss as s}from"../../utils/index.js";import{jsx as o}from"react/jsx-runtime";const p=t(({source:t="",vid:p="",playAuth:y="",cover:c="",width:m="100%",height:u="600px",autoplay:d=!0,showProgress:g=!0,isLive:h=!1,playTime:b=0,onEnded:w,onTimeupdate:x,onGetPlayerInstance:f,aliPlayerProps:v},P)=>{const k=i(null),D=i(null),j=e(),B=i(a("_")).current;r(P,()=>({play:()=>{k.current&&k.current.play()},pause:()=>{k.current&&k.current.pause()},getPlayerInstance:()=>k.current}));const L=()=>{k.current&&(k.current.dispose(),k.current=null)};return n(()=>((t||p&&y)&&(async()=>{if(!D.current)return;window.Aliplayer||(window?.base?.loadDynamicResource?(await window.base.loadDynamicResource({url:"https://g.alicdn.com/apsara-media-box/imp-web-player/2.27.0/aliplayer-min.js",type:"script",attr:{type:"text/javascript"}}),await window.base.loadDynamicResource({url:"https://g.alicdn.com/apsara-media-box/imp-web-player/2.27.0/skins/default/aliplayer-min.css",type:"link",attr:{rel:"stylesheet",type:"text/css"}})):(await l("https://g.alicdn.com/apsara-media-box/imp-web-player/2.27.0/aliplayer-min.js"),await s("https://g.alicdn.com/apsara-media-box/imp-web-player/2.27.0/skins/default/aliplayer-min.css"))),L();const e=[{name:"bigPlayButton",align:"blabs",x:30,y:80},{name:"H5Loading",align:"cc"},{name:"errorDisplay",align:"tlabs",x:0,y:0},{name:"infoDisplay"},{name:"tooltip",align:"blabs",x:0,y:56},{name:"thumbnail"},{name:"controlBar",align:"blabs",x:0,y:0,children:[{name:"playButton",align:"tl",x:15,y:12},{name:"timeDisplay",align:"tl",x:10,y:7},{name:"fullScreenButton",align:"tr",x:10,y:12},{name:"setting",align:"tr",x:15,y:12},{name:"volume",align:"tr",x:5,y:10}]}];g&&e[e.length-1].children.unshift({name:"progress",align:"blabs",x:0,y:44}),k.current=new window.Aliplayer({id:B,...t?{source:t}:{vid:p,playauth:y,qualitySort:"asc",format:"m3u8",encryptType:1,mediaType:"video",isLive:!0,rePlay:!1,playsinline:!0,controlBarVisibility:"hover"},cover:c,width:m,height:u,autoplay:d,isLive:h,useH5Prism:!0,skinLayout:e,...v},e=>{f&&f(e),d&&e.play(),e.on("ended",()=>{w&&w()}),e.on("timeupdate",()=>{x&&x(e.getCurrentTime())}),b>0&&e.seek(b)})})(),()=>{L()}),[t,p,y]),n(()=>{"hidden"===j?k.current&&k.current.pause():k.current&&k.current.play()},[j]),o("div",{ref:D,id:B,style:{width:m,height:u}})});p.displayName="AliPlayer";export{p as default};
