From 3b9c084d18f83a3c4684eef264dfea882bfb84e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Fri, 12 Jan 2024 18:26:17 +0100 Subject: [PATCH] Fix: Text fields not visible in UI editor --- .vscode/settings.json | 2 +- dist/plex-meets-homeassistant.js | 10 +++--- src/editor.ts | 34 ++++++++++--------- src/modules/utils.ts | 15 +++++++-- src/plex-meets-homeassistant.ts | 56 ++++++++++++++++++-------------- 5 files changed, 69 insertions(+), 48 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index affee9e..8a24178 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,6 @@ "javascript.suggestionActions.enabled": false, "yaml.format.enable": true, "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" } } diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index f3d113c..91abbe5 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -1,4 +1,4 @@ -var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var e,i=(function(e,i){(function(){var n,s="Expected a function",r="__lodash_hash_undefined__",a="__lodash_placeholder__",o=16,l=32,h=64,c=128,u=256,d=1/0,p=9007199254740991,f=NaN,y=4294967295,m=[["ary",c],["bind",1],["bindKey",2],["curry",8],["curryRight",o],["flip",512],["partial",l],["partialRight",h],["rearg",u]],g="[object Arguments]",v="[object Array]",x="[object Boolean]",E="[object Date]",b="[object Error]",w="[object Function]",S="[object GeneratorFunction]",_="[object Map]",C="[object Number]",T="[object Object]",k="[object Promise]",z="[object RegExp]",L="[object Set]",$="[object String]",P="[object Symbol]",N="[object WeakMap]",M="[object ArrayBuffer]",I="[object DataView]",A="[object Float32Array]",R="[object Float64Array]",B="[object Int8Array]",H="[object Int16Array]",D="[object Int32Array]",q="[object Uint8Array]",U="[object Uint8ClampedArray]",O="[object Uint16Array]",W="[object Uint32Array]",j=/\b__p \+= '';/g,V=/\b(__p \+=) '' \+/g,F=/(__e\(.*?\)|\b__t\)) \+\n'';/g,X=/&(?:amp|lt|gt|quot|#39);/g,Y=/[&<>"']/g,K=RegExp(X.source),G=RegExp(Y.source),Z=/<%-([\s\S]+?)%>/g,J=/<%([\s\S]+?)%>/g,Q=/<%=([\s\S]+?)%>/g,tt=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,et=/^\w*$/,it=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,nt=/[\\^$.*+?()[\]{}|]/g,st=RegExp(nt.source),rt=/^\s+/,at=/\s/,ot=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,lt=/\{\n\/\* \[wrapped with (.+)\] \*/,ht=/,? & /,ct=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,ut=/[()=,{}\[\]\/\s]/,dt=/\\(\\)?/g,pt=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,ft=/\w*$/,yt=/^[-+]0x[0-9a-f]+$/i,mt=/^0b[01]+$/i,gt=/^\[object .+?Constructor\]$/,vt=/^0o[0-7]+$/i,xt=/^(?:0|[1-9]\d*)$/,Et=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,bt=/($^)/,wt=/['\n\r\u2028\u2029\\]/g,St="\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff",_t="\\u2700-\\u27bf",Ct="a-z\\xdf-\\xf6\\xf8-\\xff",Tt="A-Z\\xc0-\\xd6\\xd8-\\xde",kt="\\ufe0e\\ufe0f",zt="\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",Lt="['’]",$t="[\\ud800-\\udfff]",Pt="["+zt+"]",Nt="["+St+"]",Mt="\\d+",It="[\\u2700-\\u27bf]",At="["+Ct+"]",Rt="[^\\ud800-\\udfff"+zt+Mt+_t+Ct+Tt+"]",Bt="\\ud83c[\\udffb-\\udfff]",Ht="[^\\ud800-\\udfff]",Dt="(?:\\ud83c[\\udde6-\\uddff]){2}",qt="[\\ud800-\\udbff][\\udc00-\\udfff]",Ut="["+Tt+"]",Ot="(?:"+At+"|"+Rt+")",Wt="(?:"+Ut+"|"+Rt+")",jt="(?:['’](?:d|ll|m|re|s|t|ve))?",Vt="(?:['’](?:D|LL|M|RE|S|T|VE))?",Ft="(?:"+Nt+"|"+Bt+")?",Xt="[\\ufe0e\\ufe0f]?",Yt=Xt+Ft+"(?:\\u200d(?:"+[Ht,Dt,qt].join("|")+")"+Xt+Ft+")*",Kt="(?:"+[It,Dt,qt].join("|")+")"+Yt,Gt="(?:"+[Ht+Nt+"?",Nt,Dt,qt,$t].join("|")+")",Zt=RegExp(Lt,"g"),Jt=RegExp(Nt,"g"),Qt=RegExp(Bt+"(?="+Bt+")|"+Gt+Yt,"g"),te=RegExp([Ut+"?"+At+"+"+jt+"(?="+[Pt,Ut,"$"].join("|")+")",Wt+"+"+Vt+"(?="+[Pt,Ut+Ot,"$"].join("|")+")",Ut+"?"+Ot+"+"+jt,Ut+"+"+Vt,"\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])","\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Mt,Kt].join("|"),"g"),ee=RegExp("[\\u200d\\ud800-\\udfff"+St+kt+"]"),ie=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,ne=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],se=-1,re={};re[A]=re[R]=re[B]=re[H]=re[D]=re[q]=re[U]=re[O]=re[W]=!0,re[g]=re[v]=re[M]=re[x]=re[I]=re[E]=re[b]=re[w]=re[_]=re[C]=re[T]=re[z]=re[L]=re[$]=re[N]=!1;var ae={};ae[g]=ae[v]=ae[M]=ae[I]=ae[x]=ae[E]=ae[A]=ae[R]=ae[B]=ae[H]=ae[D]=ae[_]=ae[C]=ae[T]=ae[z]=ae[L]=ae[$]=ae[P]=ae[q]=ae[U]=ae[O]=ae[W]=!0,ae[b]=ae[w]=ae[N]=!1;var oe={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},le=parseFloat,he=parseInt,ce="object"==typeof t&&t&&t.Object===Object&&t,ue="object"==typeof self&&self&&self.Object===Object&&self,de=ce||ue||Function("return this")(),pe=i&&!i.nodeType&&i,fe=pe&&e&&!e.nodeType&&e,ye=fe&&fe.exports===pe,me=ye&&ce.process,ge=function(){try{var t=fe&&fe.require&&fe.require("util").types;return t||me&&me.binding&&me.binding("util")}catch(t){}}(),ve=ge&&ge.isArrayBuffer,xe=ge&&ge.isDate,Ee=ge&&ge.isMap,be=ge&&ge.isRegExp,we=ge&&ge.isSet,Se=ge&&ge.isTypedArray;function _e(t,e,i){switch(i.length){case 0:return t.call(e);case 1:return t.call(e,i[0]);case 2:return t.call(e,i[0],i[1]);case 3:return t.call(e,i[0],i[1],i[2])}return t.apply(e,i)}function Ce(t,e,i,n){for(var s=-1,r=null==t?0:t.length;++s-1}function Pe(t,e,i){for(var n=-1,s=null==t?0:t.length;++n-1;);return i}function ti(t,e){for(var i=t.length;i--&&qe(e,t[i],0)>-1;);return i}function ei(t,e){for(var i=t.length,n=0;i--;)t[i]===e&&++n;return n}var ii=Ve({"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","Ç":"C","ç":"c","Ð":"D","ð":"d","È":"E","É":"E","Ê":"E","Ë":"E","è":"e","é":"e","ê":"e","ë":"e","Ì":"I","Í":"I","Î":"I","Ï":"I","ì":"i","í":"i","î":"i","ï":"i","Ñ":"N","ñ":"n","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","Ù":"U","Ú":"U","Û":"U","Ü":"U","ù":"u","ú":"u","û":"u","ü":"u","Ý":"Y","ý":"y","ÿ":"y","Æ":"Ae","æ":"ae","Þ":"Th","þ":"th","ß":"ss","Ā":"A","Ă":"A","Ą":"A","ā":"a","ă":"a","ą":"a","Ć":"C","Ĉ":"C","Ċ":"C","Č":"C","ć":"c","ĉ":"c","ċ":"c","č":"c","Ď":"D","Đ":"D","ď":"d","đ":"d","Ē":"E","Ĕ":"E","Ė":"E","Ę":"E","Ě":"E","ē":"e","ĕ":"e","ė":"e","ę":"e","ě":"e","Ĝ":"G","Ğ":"G","Ġ":"G","Ģ":"G","ĝ":"g","ğ":"g","ġ":"g","ģ":"g","Ĥ":"H","Ħ":"H","ĥ":"h","ħ":"h","Ĩ":"I","Ī":"I","Ĭ":"I","Į":"I","İ":"I","ĩ":"i","ī":"i","ĭ":"i","į":"i","ı":"i","Ĵ":"J","ĵ":"j","Ķ":"K","ķ":"k","ĸ":"k","Ĺ":"L","Ļ":"L","Ľ":"L","Ŀ":"L","Ł":"L","ĺ":"l","ļ":"l","ľ":"l","ŀ":"l","ł":"l","Ń":"N","Ņ":"N","Ň":"N","Ŋ":"N","ń":"n","ņ":"n","ň":"n","ŋ":"n","Ō":"O","Ŏ":"O","Ő":"O","ō":"o","ŏ":"o","ő":"o","Ŕ":"R","Ŗ":"R","Ř":"R","ŕ":"r","ŗ":"r","ř":"r","Ś":"S","Ŝ":"S","Ş":"S","Š":"S","ś":"s","ŝ":"s","ş":"s","š":"s","Ţ":"T","Ť":"T","Ŧ":"T","ţ":"t","ť":"t","ŧ":"t","Ũ":"U","Ū":"U","Ŭ":"U","Ů":"U","Ű":"U","Ų":"U","ũ":"u","ū":"u","ŭ":"u","ů":"u","ű":"u","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","Ż":"Z","Ž":"Z","ź":"z","ż":"z","ž":"z","IJ":"IJ","ij":"ij","Œ":"Oe","œ":"oe","ʼn":"'n","ſ":"s"}),ni=Ve({"&":"&","<":"<",">":">",'"':""","'":"'"});function si(t){return"\\"+oe[t]}function ri(t){return ee.test(t)}function ai(t){var e=-1,i=Array(t.size);return t.forEach((function(t,n){i[++e]=[n,t]})),i}function oi(t,e){return function(i){return t(e(i))}}function li(t,e){for(var i=-1,n=t.length,s=0,r=[];++i",""":'"',"'":"'"}),yi=function t(e){var i,at=(e=null==e?de:yi.defaults(de.Object(),e,yi.pick(de,ne))).Array,St=e.Date,_t=e.Error,Ct=e.Function,Tt=e.Math,kt=e.Object,zt=e.RegExp,Lt=e.String,$t=e.TypeError,Pt=at.prototype,Nt=Ct.prototype,Mt=kt.prototype,It=e["__core-js_shared__"],At=Nt.toString,Rt=Mt.hasOwnProperty,Bt=0,Ht=(i=/[^.]+$/.exec(It&&It.keys&&It.keys.IE_PROTO||""))?"Symbol(src)_1."+i:"",Dt=Mt.toString,qt=At.call(kt),Ut=de._,Ot=zt("^"+At.call(Rt).replace(nt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Wt=ye?e.Buffer:n,jt=e.Symbol,Vt=e.Uint8Array,Ft=Wt?Wt.allocUnsafe:n,Xt=oi(kt.getPrototypeOf,kt),Yt=kt.create,Kt=Mt.propertyIsEnumerable,Gt=Pt.splice,Qt=jt?jt.isConcatSpreadable:n,ee=jt?jt.iterator:n,oe=jt?jt.toStringTag:n,ce=function(){try{var t=pr(kt,"defineProperty");return t({},"",{}),t}catch(t){}}(),ue=e.clearTimeout!==de.clearTimeout&&e.clearTimeout,pe=St&&St.now!==de.Date.now&&St.now,fe=e.setTimeout!==de.setTimeout&&e.setTimeout,me=Tt.ceil,ge=Tt.floor,Be=kt.getOwnPropertySymbols,Ve=Wt?Wt.isBuffer:n,mi=e.isFinite,gi=Pt.join,vi=oi(kt.keys,kt),xi=Tt.max,Ei=Tt.min,bi=St.now,wi=e.parseInt,Si=Tt.random,_i=Pt.reverse,Ci=pr(e,"DataView"),Ti=pr(e,"Map"),ki=pr(e,"Promise"),zi=pr(e,"Set"),Li=pr(e,"WeakMap"),$i=pr(kt,"create"),Pi=Li&&new Li,Ni={},Mi=qr(Ci),Ii=qr(Ti),Ai=qr(ki),Ri=qr(zi),Bi=qr(Li),Hi=jt?jt.prototype:n,Di=Hi?Hi.valueOf:n,qi=Hi?Hi.toString:n;function Ui(t){if(no(t)&&!Fa(t)&&!(t instanceof Vi)){if(t instanceof ji)return t;if(Rt.call(t,"__wrapped__"))return Ur(t)}return new ji(t)}var Oi=function(){function t(){}return function(e){if(!io(e))return{};if(Yt)return Yt(e);t.prototype=e;var i=new t;return t.prototype=n,i}}();function Wi(){}function ji(t,e){this.__wrapped__=t,this.__actions__=[],this.__chain__=!!e,this.__index__=0,this.__values__=n}function Vi(t){this.__wrapped__=t,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=y,this.__views__=[]}function Fi(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e=e?t:e)),t}function cn(t,e,i,s,r,a){var o,l=1&e,h=2&e,c=4&e;if(i&&(o=r?i(t,s,r,a):i(t)),o!==n)return o;if(!io(t))return t;var u=Fa(t);if(u){if(o=function(t){var e=t.length,i=new t.constructor(e);return e&&"string"==typeof t[0]&&Rt.call(t,"index")&&(i.index=t.index,i.input=t.input),i}(t),!l)return Ps(t,o)}else{var d=mr(t),p=d==w||d==S;if(Ga(t))return Cs(t,l);if(d==T||d==g||p&&!r){if(o=h||p?{}:vr(t),!l)return h?function(t,e){return Ns(t,yr(t),e)}(t,function(t,e){return t&&Ns(e,Ao(e),t)}(o,t)):function(t,e){return Ns(t,fr(t),e)}(t,an(o,t))}else{if(!ae[d])return r?t:{};o=function(t,e,i){var n,s=t.constructor;switch(e){case M:return Ts(t);case x:case E:return new s(+t);case I:return function(t,e){var i=e?Ts(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.byteLength)}(t,i);case A:case R:case B:case H:case D:case q:case U:case O:case W:return ks(t,i);case _:return new s;case C:case $:return new s(t);case z:return function(t){var e=new t.constructor(t.source,ft.exec(t));return e.lastIndex=t.lastIndex,e}(t);case L:return new s;case P:return n=t,Di?kt(Di.call(n)):{}}}(t,d,l)}}a||(a=new Gi);var f=a.get(t);if(f)return f;a.set(t,o),lo(t)?t.forEach((function(n){o.add(cn(n,e,i,n,t,a))})):so(t)&&t.forEach((function(n,s){o.set(s,cn(n,e,i,s,t,a))}));var y=u?n:(c?h?ar:rr:h?Ao:Io)(t);return Te(y||t,(function(n,s){y&&(n=t[s=n]),nn(o,s,cn(n,e,i,s,t,a))})),o}function un(t,e,i){var s=i.length;if(null==t)return!s;for(t=kt(t);s--;){var r=i[s],a=e[r],o=t[r];if(o===n&&!(r in t)||!a(o))return!1}return!0}function dn(t,e,i){if("function"!=typeof t)throw new $t(s);return Mr((function(){t.apply(n,i)}),e)}function pn(t,e,i,n){var s=-1,r=$e,a=!0,o=t.length,l=[],h=e.length;if(!o)return l;i&&(e=Ne(e,Ge(i))),n?(r=Pe,a=!1):e.length>=200&&(r=Je,a=!1,e=new Ki(e));t:for(;++s-1},Xi.prototype.set=function(t,e){var i=this.__data__,n=sn(i,t);return n<0?(++this.size,i.push([t,e])):i[n][1]=e,this},Yi.prototype.clear=function(){this.size=0,this.__data__={hash:new Fi,map:new(Ti||Xi),string:new Fi}},Yi.prototype.delete=function(t){var e=ur(this,t).delete(t);return this.size-=e?1:0,e},Yi.prototype.get=function(t){return ur(this,t).get(t)},Yi.prototype.has=function(t){return ur(this,t).has(t)},Yi.prototype.set=function(t,e){var i=ur(this,t),n=i.size;return i.set(t,e),this.size+=i.size==n?0:1,this},Ki.prototype.add=Ki.prototype.push=function(t){return this.__data__.set(t,r),this},Ki.prototype.has=function(t){return this.__data__.has(t)},Gi.prototype.clear=function(){this.__data__=new Xi,this.size=0},Gi.prototype.delete=function(t){var e=this.__data__,i=e.delete(t);return this.size=e.size,i},Gi.prototype.get=function(t){return this.__data__.get(t)},Gi.prototype.has=function(t){return this.__data__.has(t)},Gi.prototype.set=function(t,e){var i=this.__data__;if(i instanceof Xi){var n=i.__data__;if(!Ti||n.length<199)return n.push([t,e]),this.size=++i.size,this;i=this.__data__=new Yi(n)}return i.set(t,e),this.size=i.size,this};var fn=As(wn),yn=As(Sn,!0);function mn(t,e){var i=!0;return fn(t,(function(t,n,s){return i=!!e(t,n,s)})),i}function gn(t,e,i){for(var s=-1,r=t.length;++s0&&i(o)?e>1?xn(o,e-1,i,n,s):Me(s,o):n||(s[s.length]=o)}return s}var En=Rs(),bn=Rs(!0);function wn(t,e){return t&&En(t,e,Io)}function Sn(t,e){return t&&bn(t,e,Io)}function _n(t,e){return Le(e,(function(e){return Qa(t[e])}))}function Cn(t,e){for(var i=0,s=(e=bs(e,t)).length;null!=t&&ie}function Ln(t,e){return null!=t&&Rt.call(t,e)}function $n(t,e){return null!=t&&e in kt(t)}function Pn(t,e,i){for(var s=i?Pe:$e,r=t[0].length,a=t.length,o=a,l=at(a),h=1/0,c=[];o--;){var u=t[o];o&&e&&(u=Ne(u,Ge(e))),h=Ei(u.length,h),l[o]=!i&&(e||r>=120&&u.length>=120)?new Ki(o&&u):n}u=t[0];var d=-1,p=l[0];t:for(;++d=o?l:l*("desc"==i[n]?-1:1)}return t.index-e.index}(t,e,i)}))}function Xn(t,e,i){for(var n=-1,s=e.length,r={};++n-1;)o!==t&&Gt.call(o,l,1),Gt.call(t,l,1);return t}function Kn(t,e){for(var i=t?e.length:0,n=i-1;i--;){var s=e[i];if(i==n||s!==r){var r=s;Er(s)?Gt.call(t,s,1):ps(t,s)}}return t}function Gn(t,e){return t+ge(Si()*(e-t+1))}function Zn(t,e){var i="";if(!t||e<1||e>p)return i;do{e%2&&(i+=t),(e=ge(e/2))&&(t+=t)}while(e);return i}function Jn(t,e){return Ir(zr(t,e,al),t+"")}function Qn(t){return Ji(Wo(t))}function ts(t,e){var i=Wo(t);return Br(i,hn(e,0,i.length))}function es(t,e,i,s){if(!io(t))return t;for(var r=-1,a=(e=bs(e,t)).length,o=a-1,l=t;null!=l&&++rs?0:s+e),(i=i>s?s:i)<0&&(i+=s),s=e>i?0:i-e>>>0,e>>>=0;for(var r=at(s);++n>>1,a=t[r];null!==a&&!co(a)&&(i?a<=e:a=200){var h=e?null:Zs(t);if(h)return hi(h);a=!1,s=Je,l=new Ki}else l=e?[]:o;t:for(;++n=s?t:rs(t,e,i)}var _s=ue||function(t){return de.clearTimeout(t)};function Cs(t,e){if(e)return t.slice();var i=t.length,n=Ft?Ft(i):new t.constructor(i);return t.copy(n),n}function Ts(t){var e=new t.constructor(t.byteLength);return new Vt(e).set(new Vt(t)),e}function ks(t,e){var i=e?Ts(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.length)}function zs(t,e){if(t!==e){var i=t!==n,s=null===t,r=t==t,a=co(t),o=e!==n,l=null===e,h=e==e,c=co(e);if(!l&&!c&&!a&&t>e||a&&o&&h&&!l&&!c||s&&o&&h||!i&&h||!r)return 1;if(!s&&!a&&!c&&t1?i[r-1]:n,o=r>2?i[2]:n;for(a=t.length>3&&"function"==typeof a?(r--,a):n,o&&br(i[0],i[1],o)&&(a=r<3?n:a,r=1),e=kt(e);++s-1?r[a?e[o]:o]:n}}function Us(t){return sr((function(e){var i=e.length,r=i,a=ji.prototype.thru;for(t&&e.reverse();r--;){var o=e[r];if("function"!=typeof o)throw new $t(s);if(a&&!l&&"wrapper"==lr(o))var l=new ji([],!0)}for(r=l?r:i;++r1&&v.reverse(),d&&hl))return!1;var c=a.get(t),u=a.get(e);if(c&&u)return c==e&&u==t;var d=-1,p=!0,f=2&i?new Ki:n;for(a.set(t,e),a.set(e,t);++d-1&&t%1==0&&t1?"& ":"")+e[n],e=e.join(i>2?", ":" "),t.replace(ot,"{\n/* [wrapped with "+e+"] */\n")}(n,function(t,e){return Te(m,(function(i){var n="_."+i[0];e&i[1]&&!$e(t,n)&&t.push(n)})),t.sort()}(function(t){var e=t.match(lt);return e?e[1].split(ht):[]}(n),i)))}function Rr(t){var e=0,i=0;return function(){var s=bi(),r=16-(s-i);if(i=s,r>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(n,arguments)}}function Br(t,e){var i=-1,s=t.length,r=s-1;for(e=e===n?s:e;++i1?t[e-1]:n;return i="function"==typeof i?(t.pop(),i):n,oa(t,i)}));function fa(t){var e=Ui(t);return e.__chain__=!0,e}function ya(t,e){return e(t)}var ma=sr((function(t){var e=t.length,i=e?t[0]:0,s=this.__wrapped__,r=function(e){return ln(e,t)};return!(e>1||this.__actions__.length)&&s instanceof Vi&&Er(i)?((s=s.slice(i,+i+(e?1:0))).__actions__.push({func:ya,args:[r],thisArg:n}),new ji(s,this.__chain__).thru((function(t){return e&&!t.length&&t.push(n),t}))):this.thru(r)})),ga=Ms((function(t,e,i){Rt.call(t,i)?++t[i]:on(t,i,1)})),va=qs(Vr),xa=qs(Fr);function Ea(t,e){return(Fa(t)?Te:fn)(t,cr(e,3))}function ba(t,e){return(Fa(t)?ke:yn)(t,cr(e,3))}var wa=Ms((function(t,e,i){Rt.call(t,i)?t[i].push(e):on(t,i,[e])})),Sa=Jn((function(t,e,i){var n=-1,s="function"==typeof e,r=Ya(t)?at(t.length):[];return fn(t,(function(t){r[++n]=s?_e(e,t,i):Nn(t,e,i)})),r})),_a=Ms((function(t,e,i){on(t,i,e)}));function Ca(t,e){return(Fa(t)?Ne:Un)(t,cr(e,3))}var Ta=Ms((function(t,e,i){t[i?0:1].push(e)}),(function(){return[[],[]]})),ka=Jn((function(t,e){if(null==t)return[];var i=e.length;return i>1&&br(t,e[0],e[1])?e=[]:i>2&&br(e[0],e[1],e[2])&&(e=[e[0]]),Fn(t,xn(e,1),[])})),za=pe||function(){return de.Date.now()};function La(t,e,i){return e=i?n:e,e=t&&null==e?t.length:e,Qs(t,c,n,n,n,n,e)}function $a(t,e){var i;if("function"!=typeof e)throw new $t(s);return t=go(t),function(){return--t>0&&(i=e.apply(this,arguments)),t<=1&&(e=n),i}}var Pa=Jn((function(t,e,i){var n=1;if(i.length){var s=li(i,hr(Pa));n|=l}return Qs(t,n,e,i,s)})),Na=Jn((function(t,e,i){var n=3;if(i.length){var s=li(i,hr(Na));n|=l}return Qs(e,n,t,i,s)}));function Ma(t,e,i){var r,a,o,l,h,c,u=0,d=!1,p=!1,f=!0;if("function"!=typeof t)throw new $t(s);function y(e){var i=r,s=a;return r=a=n,u=e,l=t.apply(s,i)}function m(t){return u=t,h=Mr(v,e),d?y(t):l}function g(t){var i=t-c;return c===n||i>=e||i<0||p&&t-u>=o}function v(){var t=za();if(g(t))return x(t);h=Mr(v,function(t){var i=e-(t-c);return p?Ei(i,o-(t-u)):i}(t))}function x(t){return h=n,f&&r?y(t):(r=a=n,l)}function E(){var t=za(),i=g(t);if(r=arguments,a=this,c=t,i){if(h===n)return m(c);if(p)return _s(h),h=Mr(v,e),y(c)}return h===n&&(h=Mr(v,e)),l}return e=xo(e)||0,io(i)&&(d=!!i.leading,o=(p="maxWait"in i)?xi(xo(i.maxWait)||0,e):o,f="trailing"in i?!!i.trailing:f),E.cancel=function(){h!==n&&_s(h),u=0,r=c=a=h=n},E.flush=function(){return h===n?l:x(za())},E}var Ia=Jn((function(t,e){return dn(t,1,e)})),Aa=Jn((function(t,e,i){return dn(t,xo(e)||0,i)}));function Ra(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new $t(s);var i=function(){var n=arguments,s=e?e.apply(this,n):n[0],r=i.cache;if(r.has(s))return r.get(s);var a=t.apply(this,n);return i.cache=r.set(s,a)||r,a};return i.cache=new(Ra.Cache||Yi),i}function Ba(t){if("function"!=typeof t)throw new $t(s);return function(){var e=arguments;switch(e.length){case 0:return!t.call(this);case 1:return!t.call(this,e[0]);case 2:return!t.call(this,e[0],e[1]);case 3:return!t.call(this,e[0],e[1],e[2])}return!t.apply(this,e)}}Ra.Cache=Yi;var Ha=ws((function(t,e){var i=(e=1==e.length&&Fa(e[0])?Ne(e[0],Ge(cr())):Ne(xn(e,1),Ge(cr()))).length;return Jn((function(n){for(var s=-1,r=Ei(n.length,i);++s=e})),Va=Mn(function(){return arguments}())?Mn:function(t){return no(t)&&Rt.call(t,"callee")&&!Kt.call(t,"callee")},Fa=at.isArray,Xa=ve?Ge(ve):function(t){return no(t)&&kn(t)==M};function Ya(t){return null!=t&&eo(t.length)&&!Qa(t)}function Ka(t){return no(t)&&Ya(t)}var Ga=Ve||xl,Za=xe?Ge(xe):function(t){return no(t)&&kn(t)==E};function Ja(t){if(!no(t))return!1;var e=kn(t);return e==b||"[object DOMException]"==e||"string"==typeof t.message&&"string"==typeof t.name&&!ao(t)}function Qa(t){if(!io(t))return!1;var e=kn(t);return e==w||e==S||"[object AsyncFunction]"==e||"[object Proxy]"==e}function to(t){return"number"==typeof t&&t==go(t)}function eo(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=p}function io(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function no(t){return null!=t&&"object"==typeof t}var so=Ee?Ge(Ee):function(t){return no(t)&&mr(t)==_};function ro(t){return"number"==typeof t||no(t)&&kn(t)==C}function ao(t){if(!no(t)||kn(t)!=T)return!1;var e=Xt(t);if(null===e)return!0;var i=Rt.call(e,"constructor")&&e.constructor;return"function"==typeof i&&i instanceof i&&At.call(i)==qt}var oo=be?Ge(be):function(t){return no(t)&&kn(t)==z},lo=we?Ge(we):function(t){return no(t)&&mr(t)==L};function ho(t){return"string"==typeof t||!Fa(t)&&no(t)&&kn(t)==$}function co(t){return"symbol"==typeof t||no(t)&&kn(t)==P}var uo=Se?Ge(Se):function(t){return no(t)&&eo(t.length)&&!!re[kn(t)]},po=Ys(qn),fo=Ys((function(t,e){return t<=e}));function yo(t){if(!t)return[];if(Ya(t))return ho(t)?di(t):Ps(t);if(ee&&t[ee])return function(t){for(var e,i=[];!(e=t.next()).done;)i.push(e.value);return i}(t[ee]());var e=mr(t);return(e==_?ai:e==L?hi:Wo)(t)}function mo(t){return t?(t=xo(t))===d||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function go(t){var e=mo(t),i=e%1;return e==e?i?e-i:e:0}function vo(t){return t?hn(go(t),0,y):0}function xo(t){if("number"==typeof t)return t;if(co(t))return f;if(io(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=io(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Ke(t);var i=mt.test(t);return i||vt.test(t)?he(t.slice(2),i?2:8):yt.test(t)?f:+t}function Eo(t){return Ns(t,Ao(t))}function bo(t){return null==t?"":us(t)}var wo=Is((function(t,e){if(Cr(e)||Ya(e))Ns(e,Io(e),t);else for(var i in e)Rt.call(e,i)&&nn(t,i,e[i])})),So=Is((function(t,e){Ns(e,Ao(e),t)})),_o=Is((function(t,e,i,n){Ns(e,Ao(e),t,n)})),Co=Is((function(t,e,i,n){Ns(e,Io(e),t,n)})),To=sr(ln),ko=Jn((function(t,e){t=kt(t);var i=-1,s=e.length,r=s>2?e[2]:n;for(r&&br(e[0],e[1],r)&&(s=1);++i1),e})),Ns(t,ar(t),i),n&&(i=cn(i,7,ir));for(var s=e.length;s--;)ps(i,e[s]);return i})),Do=sr((function(t,e){return null==t?{}:function(t,e){return Xn(t,e,(function(e,i){return $o(t,i)}))}(t,e)}));function qo(t,e){if(null==t)return{};var i=Ne(ar(t),(function(t){return[t]}));return e=cr(e),Xn(t,i,(function(t,i){return e(t,i[0])}))}var Uo=Js(Io),Oo=Js(Ao);function Wo(t){return null==t?[]:Ze(t,Io(t))}var jo=Hs((function(t,e,i){return e=e.toLowerCase(),t+(i?Vo(e):e)}));function Vo(t){return Qo(bo(t).toLowerCase())}function Fo(t){return(t=bo(t))&&t.replace(Et,ii).replace(Jt,"")}var Xo=Hs((function(t,e,i){return t+(i?"-":"")+e.toLowerCase()})),Yo=Hs((function(t,e,i){return t+(i?" ":"")+e.toLowerCase()})),Ko=Bs("toLowerCase"),Go=Hs((function(t,e,i){return t+(i?"_":"")+e.toLowerCase()})),Zo=Hs((function(t,e,i){return t+(i?" ":"")+Qo(e)})),Jo=Hs((function(t,e,i){return t+(i?" ":"")+e.toUpperCase()})),Qo=Bs("toUpperCase");function tl(t,e,i){return t=bo(t),(e=i?n:e)===n?function(t){return ie.test(t)}(t)?function(t){return t.match(te)||[]}(t):function(t){return t.match(ct)||[]}(t):t.match(e)||[]}var el=Jn((function(t,e){try{return _e(t,n,e)}catch(t){return Ja(t)?t:new _t(t)}})),il=sr((function(t,e){return Te(e,(function(e){e=Dr(e),on(t,e,Pa(t[e],t))})),t}));function nl(t){return function(){return t}}var sl=Us(),rl=Us(!0);function al(t){return t}function ol(t){return Bn("function"==typeof t?t:cn(t,1))}var ll=Jn((function(t,e){return function(i){return Nn(i,t,e)}})),hl=Jn((function(t,e){return function(i){return Nn(t,i,e)}}));function cl(t,e,i){var n=Io(e),s=_n(e,n);null!=i||io(e)&&(s.length||!n.length)||(i=e,e=t,t=this,s=_n(e,Io(e)));var r=!(io(i)&&"chain"in i&&!i.chain),a=Qa(t);return Te(s,(function(i){var n=e[i];t[i]=n,a&&(t.prototype[i]=function(){var e=this.__chain__;if(r||e){var i=t(this.__wrapped__),s=i.__actions__=Ps(this.__actions__);return s.push({func:n,args:arguments,thisArg:t}),i.__chain__=e,i}return n.apply(t,Me([this.value()],arguments))})})),t}function ul(){}var dl=Vs(Ne),pl=Vs(ze),fl=Vs(Re);function yl(t){return wr(t)?je(Dr(t)):function(t){return function(e){return Cn(e,t)}}(t)}var ml=Xs(),gl=Xs(!0);function vl(){return[]}function xl(){return!1}var El,bl=js((function(t,e){return t+e}),0),wl=Gs("ceil"),Sl=js((function(t,e){return t/e}),1),_l=Gs("floor"),Cl=js((function(t,e){return t*e}),1),Tl=Gs("round"),kl=js((function(t,e){return t-e}),0);return Ui.after=function(t,e){if("function"!=typeof e)throw new $t(s);return t=go(t),function(){if(--t<1)return e.apply(this,arguments)}},Ui.ary=La,Ui.assign=wo,Ui.assignIn=So,Ui.assignInWith=_o,Ui.assignWith=Co,Ui.at=To,Ui.before=$a,Ui.bind=Pa,Ui.bindAll=il,Ui.bindKey=Na,Ui.castArray=function(){if(!arguments.length)return[];var t=arguments[0];return Fa(t)?t:[t]},Ui.chain=fa,Ui.chunk=function(t,e,i){e=(i?br(t,e,i):e===n)?1:xi(go(e),0);var s=null==t?0:t.length;if(!s||e<1)return[];for(var r=0,a=0,o=at(me(s/e));rr?0:r+i),(s=s===n||s>r?r:go(s))<0&&(s+=r),s=i>s?0:vo(s);i>>0)?(t=bo(t))&&("string"==typeof e||null!=e&&!oo(e))&&!(e=us(e))&&ri(t)?Ss(di(t),0,i):t.split(e,i):[]},Ui.spread=function(t,e){if("function"!=typeof t)throw new $t(s);return e=null==e?0:xi(go(e),0),Jn((function(i){var n=i[e],s=Ss(i,0,e);return n&&Me(s,n),_e(t,this,s)}))},Ui.tail=function(t){var e=null==t?0:t.length;return e?rs(t,1,e):[]},Ui.take=function(t,e,i){return t&&t.length?rs(t,0,(e=i||e===n?1:go(e))<0?0:e):[]},Ui.takeRight=function(t,e,i){var s=null==t?0:t.length;return s?rs(t,(e=s-(e=i||e===n?1:go(e)))<0?0:e,s):[]},Ui.takeRightWhile=function(t,e){return t&&t.length?ys(t,cr(e,3),!1,!0):[]},Ui.takeWhile=function(t,e){return t&&t.length?ys(t,cr(e,3)):[]},Ui.tap=function(t,e){return e(t),t},Ui.throttle=function(t,e,i){var n=!0,r=!0;if("function"!=typeof t)throw new $t(s);return io(i)&&(n="leading"in i?!!i.leading:n,r="trailing"in i?!!i.trailing:r),Ma(t,e,{leading:n,maxWait:e,trailing:r})},Ui.thru=ya,Ui.toArray=yo,Ui.toPairs=Uo,Ui.toPairsIn=Oo,Ui.toPath=function(t){return Fa(t)?Ne(t,Dr):co(t)?[t]:Ps(Hr(bo(t)))},Ui.toPlainObject=Eo,Ui.transform=function(t,e,i){var n=Fa(t),s=n||Ga(t)||uo(t);if(e=cr(e,4),null==i){var r=t&&t.constructor;i=s?n?new r:[]:io(t)&&Qa(r)?Oi(Xt(t)):{}}return(s?Te:wn)(t,(function(t,n,s){return e(i,t,n,s)})),i},Ui.unary=function(t){return La(t,1)},Ui.union=na,Ui.unionBy=sa,Ui.unionWith=ra,Ui.uniq=function(t){return t&&t.length?ds(t):[]},Ui.uniqBy=function(t,e){return t&&t.length?ds(t,cr(e,2)):[]},Ui.uniqWith=function(t,e){return e="function"==typeof e?e:n,t&&t.length?ds(t,n,e):[]},Ui.unset=function(t,e){return null==t||ps(t,e)},Ui.unzip=aa,Ui.unzipWith=oa,Ui.update=function(t,e,i){return null==t?t:fs(t,e,Es(i))},Ui.updateWith=function(t,e,i,s){return s="function"==typeof s?s:n,null==t?t:fs(t,e,Es(i),s)},Ui.values=Wo,Ui.valuesIn=function(t){return null==t?[]:Ze(t,Ao(t))},Ui.without=la,Ui.words=tl,Ui.wrap=function(t,e){return Da(Es(e),t)},Ui.xor=ha,Ui.xorBy=ca,Ui.xorWith=ua,Ui.zip=da,Ui.zipObject=function(t,e){return vs(t||[],e||[],nn)},Ui.zipObjectDeep=function(t,e){return vs(t||[],e||[],es)},Ui.zipWith=pa,Ui.entries=Uo,Ui.entriesIn=Oo,Ui.extend=So,Ui.extendWith=_o,cl(Ui,Ui),Ui.add=bl,Ui.attempt=el,Ui.camelCase=jo,Ui.capitalize=Vo,Ui.ceil=wl,Ui.clamp=function(t,e,i){return i===n&&(i=e,e=n),i!==n&&(i=(i=xo(i))==i?i:0),e!==n&&(e=(e=xo(e))==e?e:0),hn(xo(t),e,i)},Ui.clone=function(t){return cn(t,4)},Ui.cloneDeep=function(t){return cn(t,5)},Ui.cloneDeepWith=function(t,e){return cn(t,5,e="function"==typeof e?e:n)},Ui.cloneWith=function(t,e){return cn(t,4,e="function"==typeof e?e:n)},Ui.conformsTo=function(t,e){return null==e||un(t,e,Io(e))},Ui.deburr=Fo,Ui.defaultTo=function(t,e){return null==t||t!=t?e:t},Ui.divide=Sl,Ui.endsWith=function(t,e,i){t=bo(t),e=us(e);var s=t.length,r=i=i===n?s:hn(go(i),0,s);return(i-=e.length)>=0&&t.slice(i,r)==e},Ui.eq=Oa,Ui.escape=function(t){return(t=bo(t))&&G.test(t)?t.replace(Y,ni):t},Ui.escapeRegExp=function(t){return(t=bo(t))&&st.test(t)?t.replace(nt,"\\$&"):t},Ui.every=function(t,e,i){var s=Fa(t)?ze:mn;return i&&br(t,e,i)&&(e=n),s(t,cr(e,3))},Ui.find=va,Ui.findIndex=Vr,Ui.findKey=function(t,e){return He(t,cr(e,3),wn)},Ui.findLast=xa,Ui.findLastIndex=Fr,Ui.findLastKey=function(t,e){return He(t,cr(e,3),Sn)},Ui.floor=_l,Ui.forEach=Ea,Ui.forEachRight=ba,Ui.forIn=function(t,e){return null==t?t:En(t,cr(e,3),Ao)},Ui.forInRight=function(t,e){return null==t?t:bn(t,cr(e,3),Ao)},Ui.forOwn=function(t,e){return t&&wn(t,cr(e,3))},Ui.forOwnRight=function(t,e){return t&&Sn(t,cr(e,3))},Ui.get=Lo,Ui.gt=Wa,Ui.gte=ja,Ui.has=function(t,e){return null!=t&&gr(t,e,Ln)},Ui.hasIn=$o,Ui.head=Yr,Ui.identity=al,Ui.includes=function(t,e,i,n){t=Ya(t)?t:Wo(t),i=i&&!n?go(i):0;var s=t.length;return i<0&&(i=xi(s+i,0)),ho(t)?i<=s&&t.indexOf(e,i)>-1:!!s&&qe(t,e,i)>-1},Ui.indexOf=function(t,e,i){var n=null==t?0:t.length;if(!n)return-1;var s=null==i?0:go(i);return s<0&&(s=xi(n+s,0)),qe(t,e,s)},Ui.inRange=function(t,e,i){return e=mo(e),i===n?(i=e,e=0):i=mo(i),function(t,e,i){return t>=Ei(e,i)&&t=-9007199254740991&&t<=p},Ui.isSet=lo,Ui.isString=ho,Ui.isSymbol=co,Ui.isTypedArray=uo,Ui.isUndefined=function(t){return t===n},Ui.isWeakMap=function(t){return no(t)&&mr(t)==N},Ui.isWeakSet=function(t){return no(t)&&"[object WeakSet]"==kn(t)},Ui.join=function(t,e){return null==t?"":gi.call(t,e)},Ui.kebabCase=Xo,Ui.last=Jr,Ui.lastIndexOf=function(t,e,i){var s=null==t?0:t.length;if(!s)return-1;var r=s;return i!==n&&(r=(r=go(i))<0?xi(s+r,0):Ei(r,s-1)),e==e?function(t,e,i){for(var n=i+1;n--;)if(t[n]===e)return n;return n}(t,e,r):De(t,Oe,r,!0)},Ui.lowerCase=Yo,Ui.lowerFirst=Ko,Ui.lt=po,Ui.lte=fo,Ui.max=function(t){return t&&t.length?gn(t,al,zn):n},Ui.maxBy=function(t,e){return t&&t.length?gn(t,cr(e,2),zn):n},Ui.mean=function(t){return We(t,al)},Ui.meanBy=function(t,e){return We(t,cr(e,2))},Ui.min=function(t){return t&&t.length?gn(t,al,qn):n},Ui.minBy=function(t,e){return t&&t.length?gn(t,cr(e,2),qn):n},Ui.stubArray=vl,Ui.stubFalse=xl,Ui.stubObject=function(){return{}},Ui.stubString=function(){return""},Ui.stubTrue=function(){return!0},Ui.multiply=Cl,Ui.nth=function(t,e){return t&&t.length?Vn(t,go(e)):n},Ui.noConflict=function(){return de._===this&&(de._=Ut),this},Ui.noop=ul,Ui.now=za,Ui.pad=function(t,e,i){t=bo(t);var n=(e=go(e))?ui(t):0;if(!e||n>=e)return t;var s=(e-n)/2;return Fs(ge(s),i)+t+Fs(me(s),i)},Ui.padEnd=function(t,e,i){t=bo(t);var n=(e=go(e))?ui(t):0;return e&&ne){var s=t;t=e,e=s}if(i||t%1||e%1){var r=Si();return Ei(t+r*(e-t+le("1e-"+((r+"").length-1))),e)}return Gn(t,e)},Ui.reduce=function(t,e,i){var n=Fa(t)?Ie:Fe,s=arguments.length<3;return n(t,cr(e,4),i,s,fn)},Ui.reduceRight=function(t,e,i){var n=Fa(t)?Ae:Fe,s=arguments.length<3;return n(t,cr(e,4),i,s,yn)},Ui.repeat=function(t,e,i){return e=(i?br(t,e,i):e===n)?1:go(e),Zn(bo(t),e)},Ui.replace=function(){var t=arguments,e=bo(t[0]);return t.length<3?e:e.replace(t[1],t[2])},Ui.result=function(t,e,i){var s=-1,r=(e=bs(e,t)).length;for(r||(r=1,t=n);++sp)return[];var i=y,n=Ei(t,y);e=cr(e),t-=y;for(var s=Ye(n,e);++i=a)return t;var l=i-ui(s);if(l<1)return s;var h=o?Ss(o,0,l).join(""):t.slice(0,l);if(r===n)return h+s;if(o&&(l+=h.length-l),oo(r)){if(t.slice(l).search(r)){var c,u=h;for(r.global||(r=zt(r.source,bo(ft.exec(r))+"g")),r.lastIndex=0;c=r.exec(u);)var d=c.index;h=h.slice(0,d===n?l:d)}}else if(t.indexOf(us(r),l)!=l){var p=h.lastIndexOf(r);p>-1&&(h=h.slice(0,p))}return h+s},Ui.unescape=function(t){return(t=bo(t))&&K.test(t)?t.replace(X,fi):t},Ui.uniqueId=function(t){var e=++Bt;return bo(t)+e},Ui.upperCase=Jo,Ui.upperFirst=Qo,Ui.each=Ea,Ui.eachRight=ba,Ui.first=Yr,cl(Ui,(El={},wn(Ui,(function(t,e){Rt.call(Ui.prototype,e)||(El[e]=t)})),El),{chain:!1}),Ui.VERSION="4.17.21",Te(["bind","bindKey","curry","curryRight","partial","partialRight"],(function(t){Ui[t].placeholder=Ui})),Te(["drop","take"],(function(t,e){Vi.prototype[t]=function(i){i=i===n?1:xi(go(i),0);var s=this.__filtered__&&!e?new Vi(this):this.clone();return s.__filtered__?s.__takeCount__=Ei(i,s.__takeCount__):s.__views__.push({size:Ei(i,y),type:t+(s.__dir__<0?"Right":"")}),s},Vi.prototype[t+"Right"]=function(e){return this.reverse()[t](e).reverse()}})),Te(["filter","map","takeWhile"],(function(t,e){var i=e+1,n=1==i||3==i;Vi.prototype[t]=function(t){var e=this.clone();return e.__iteratees__.push({iteratee:cr(t,3),type:i}),e.__filtered__=e.__filtered__||n,e}})),Te(["head","last"],(function(t,e){var i="take"+(e?"Right":"");Vi.prototype[t]=function(){return this[i](1).value()[0]}})),Te(["initial","tail"],(function(t,e){var i="drop"+(e?"":"Right");Vi.prototype[t]=function(){return this.__filtered__?new Vi(this):this[i](1)}})),Vi.prototype.compact=function(){return this.filter(al)},Vi.prototype.find=function(t){return this.filter(t).head()},Vi.prototype.findLast=function(t){return this.reverse().find(t)},Vi.prototype.invokeMap=Jn((function(t,e){return"function"==typeof t?new Vi(this):this.map((function(i){return Nn(i,t,e)}))})),Vi.prototype.reject=function(t){return this.filter(Ba(cr(t)))},Vi.prototype.slice=function(t,e){t=go(t);var i=this;return i.__filtered__&&(t>0||e<0)?new Vi(i):(t<0?i=i.takeRight(-t):t&&(i=i.drop(t)),e!==n&&(i=(e=go(e))<0?i.dropRight(-e):i.take(e-t)),i)},Vi.prototype.takeRightWhile=function(t){return this.reverse().takeWhile(t).reverse()},Vi.prototype.toArray=function(){return this.take(y)},wn(Vi.prototype,(function(t,e){var i=/^(?:filter|find|map|reject)|While$/.test(e),s=/^(?:head|last)$/.test(e),r=Ui[s?"take"+("last"==e?"Right":""):e],a=s||/^find/.test(e);r&&(Ui.prototype[e]=function(){var e=this.__wrapped__,o=s?[1]:arguments,l=e instanceof Vi,h=o[0],c=l||Fa(e),u=function(t){var e=r.apply(Ui,Me([t],o));return s&&d?e[0]:e};c&&i&&"function"==typeof h&&1!=h.length&&(l=c=!1);var d=this.__chain__,p=!!this.__actions__.length,f=a&&!d,y=l&&!p;if(!a&&c){e=y?e:new Vi(this);var m=t.apply(e,o);return m.__actions__.push({func:ya,args:[u],thisArg:n}),new ji(m,d)}return f&&y?t.apply(this,o):(m=this.thru(u),f?s?m.value()[0]:m.value():m)})})),Te(["pop","push","shift","sort","splice","unshift"],(function(t){var e=Pt[t],i=/^(?:push|sort|unshift)$/.test(t)?"tap":"thru",n=/^(?:pop|shift)$/.test(t);Ui.prototype[t]=function(){var t=arguments;if(n&&!this.__chain__){var s=this.value();return e.apply(Fa(s)?s:[],t)}return this[i]((function(i){return e.apply(Fa(i)?i:[],t)}))}})),wn(Vi.prototype,(function(t,e){var i=Ui[e];if(i){var n=i.name+"";Rt.call(Ni,n)||(Ni[n]=[]),Ni[n].push({name:e,func:i})}})),Ni[Os(n,2).name]=[{name:"wrapper",func:n}],Vi.prototype.clone=function(){var t=new Vi(this.__wrapped__);return t.__actions__=Ps(this.__actions__),t.__dir__=this.__dir__,t.__filtered__=this.__filtered__,t.__iteratees__=Ps(this.__iteratees__),t.__takeCount__=this.__takeCount__,t.__views__=Ps(this.__views__),t},Vi.prototype.reverse=function(){if(this.__filtered__){var t=new Vi(this);t.__dir__=-1,t.__filtered__=!0}else(t=this.clone()).__dir__*=-1;return t},Vi.prototype.value=function(){var t=this.__wrapped__.value(),e=this.__dir__,i=Fa(t),n=e<0,s=i?t.length:0,r=function(t,e,i){for(var n=-1,s=i.length;++n=this.__values__.length;return{done:t,value:t?n:this.__values__[this.__index__++]}},Ui.prototype.plant=function(t){for(var e,i=this;i instanceof Wi;){var s=Ur(i);s.__index__=0,s.__values__=n,e?r.__wrapped__=s:e=s;var r=s;i=i.__wrapped__}return r.__wrapped__=t,e},Ui.prototype.reverse=function(){var t=this.__wrapped__;if(t instanceof Vi){var e=t;return this.__actions__.length&&(e=new Vi(this)),(e=e.reverse()).__actions__.push({func:ya,args:[ia],thisArg:n}),new ji(e,this.__chain__)}return this.thru(ia)},Ui.prototype.toJSON=Ui.prototype.valueOf=Ui.prototype.value=function(){return ms(this.__wrapped__,this.__actions__)},Ui.prototype.first=Ui.prototype.head,ee&&(Ui.prototype[ee]=function(){return this}),Ui}();fe?((fe.exports=yi)._=yi,pe._=yi):de._=yi}).call(t)}(e={exports:{}},e.exports),e.exports);const n={ratio:1.471,minimumWidth:138,expandedWidth:220,expandedHeight:324,episodeRatio:.563,minimumEpisodeWidth:300},s={kodi:["movie","episode","epg"],androidtv:["movie","show","season","episode","clip","track","artist","album"],plexPlayer:["movie","show","season","episode","clip","track","artist","album"],cast:["movie","episode","artist","album","track"],vlcTelnet:["track"],sonos:["track","artist","album"]};var r=function(t,e){return function(){for(var i=new Array(arguments.length),n=0;n=0)return;l[s]="set-cookie"===s?(l[s]?l[s]:[]).concat([a]):l[s]?l[s]+", "+a:a}})),l):l):null,c={data:t.responseType&&"text"!==t.responseType?r.response:r.responseText,status:r.status,statusText:r.statusText,headers:h,config:t,request:r};!function(t,e,i){var n=i.config.validateStatus;i.status&&n&&!n(i.status)?e(b("Request failed with status code "+i.status,i.config,null,i.request,i)):t(i)}(e,i,c),r=null}},r.onabort=function(){r&&(i(b("Request aborted",t,"ECONNABORTED",r)),r=null)},r.onerror=function(){i(b("Network Error",t,null,r)),r=null},r.ontimeout=function(){var e="timeout of "+t.timeout+"ms exceeded";t.timeoutErrorMessage&&(e=t.timeoutErrorMessage),i(b(e,t,"ECONNABORTED",r)),r=null},p.isStandardBrowserEnv()){var u=(t.withCredentials||_(c))&&t.xsrfCookieName?w.read(t.xsrfCookieName):void 0;u&&(s[t.xsrfHeaderName]=u)}if("setRequestHeader"in r&&p.forEach(s,(function(t,e){void 0===n&&"content-type"===e.toLowerCase()?delete s[e]:r.setRequestHeader(e,t)})),p.isUndefined(t.withCredentials)||(r.withCredentials=!!t.withCredentials),t.responseType)try{r.responseType=t.responseType}catch(e){if("json"!==t.responseType)throw e}"function"==typeof t.onDownloadProgress&&r.addEventListener("progress",t.onDownloadProgress),"function"==typeof t.onUploadProgress&&r.upload&&r.upload.addEventListener("progress",t.onUploadProgress),t.cancelToken&&t.cancelToken.promise.then((function(t){r&&(r.abort(),i(t),r=null)})),n||(n=null),r.send(n)}))},T={"Content-Type":"application/x-www-form-urlencoded"};function k(t,e){!p.isUndefined(t)&&p.isUndefined(t["Content-Type"])&&(t["Content-Type"]=e)}var z,L={adapter:(("undefined"!=typeof XMLHttpRequest||"undefined"!=typeof process&&"[object process]"===Object.prototype.toString.call(process))&&(z=C),z),transformRequest:[function(t,e){return E(e,"Accept"),E(e,"Content-Type"),p.isFormData(t)||p.isArrayBuffer(t)||p.isBuffer(t)||p.isStream(t)||p.isFile(t)||p.isBlob(t)?t:p.isArrayBufferView(t)?t.buffer:p.isURLSearchParams(t)?(k(e,"application/x-www-form-urlencoded;charset=utf-8"),t.toString()):p.isObject(t)?(k(e,"application/json;charset=utf-8"),JSON.stringify(t)):t}],transformResponse:[function(t){if("string"==typeof t)try{t=JSON.parse(t)}catch(t){}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,validateStatus:function(t){return t>=200&&t<300}};L.headers={common:{Accept:"application/json, text/plain, */*"}},p.forEach(["delete","get","head"],(function(t){L.headers[t]={}})),p.forEach(["post","put","patch"],(function(t){L.headers[t]=p.merge(T)}));var $=L;function P(t){t.cancelToken&&t.cancelToken.throwIfRequested()}var N=function(t){return P(t),t.headers=t.headers||{},t.data=v(t.data,t.headers,t.transformRequest),t.headers=p.merge(t.headers.common||{},t.headers[t.method]||{},t.headers),p.forEach(["delete","get","head","post","put","patch","common"],(function(e){delete t.headers[e]})),(t.adapter||$.adapter)(t).then((function(e){return P(t),e.data=v(e.data,e.headers,t.transformResponse),e}),(function(e){return x(e)||(P(t),e&&e.response&&(e.response.data=v(e.response.data,e.response.headers,t.transformResponse))),Promise.reject(e)}))},M=function(t,e){e=e||{};var i={},n=["url","method","data"],s=["headers","auth","proxy","params"],r=["baseURL","transformRequest","transformResponse","paramsSerializer","timeout","timeoutMessage","withCredentials","adapter","responseType","xsrfCookieName","xsrfHeaderName","onUploadProgress","onDownloadProgress","decompress","maxContentLength","maxBodyLength","maxRedirects","transport","httpAgent","httpsAgent","cancelToken","socketPath","responseEncoding"],a=["validateStatus"];function o(t,e){return p.isPlainObject(t)&&p.isPlainObject(e)?p.merge(t,e):p.isPlainObject(e)?p.merge({},e):p.isArray(e)?e.slice():e}function l(n){p.isUndefined(e[n])?p.isUndefined(t[n])||(i[n]=o(void 0,t[n])):i[n]=o(t[n],e[n])}p.forEach(n,(function(t){p.isUndefined(e[t])||(i[t]=o(void 0,e[t]))})),p.forEach(s,l),p.forEach(r,(function(n){p.isUndefined(e[n])?p.isUndefined(t[n])||(i[n]=o(void 0,t[n])):i[n]=o(void 0,e[n])})),p.forEach(a,(function(n){n in e?i[n]=o(t[n],e[n]):n in t&&(i[n]=o(void 0,t[n]))}));var h=n.concat(s).concat(r).concat(a),c=Object.keys(t).concat(Object.keys(e)).filter((function(t){return-1===h.indexOf(t)}));return p.forEach(c,l),i};function I(t){this.defaults=t,this.interceptors={request:new g,response:new g}}I.prototype.request=function(t){"string"==typeof t?(t=arguments[1]||{}).url=arguments[0]:t=t||{},(t=M(this.defaults,t)).method?t.method=t.method.toLowerCase():this.defaults.method?t.method=this.defaults.method.toLowerCase():t.method="get";var e=[N,void 0],i=Promise.resolve(t);for(this.interceptors.request.forEach((function(t){e.unshift(t.fulfilled,t.rejected)})),this.interceptors.response.forEach((function(t){e.push(t.fulfilled,t.rejected)}));e.length;)i=i.then(e.shift(),e.shift());return i},I.prototype.getUri=function(t){return t=M(this.defaults,t),y(t.url,t.params,t.paramsSerializer).replace(/^\?/,"")},p.forEach(["delete","get","head","options"],(function(t){I.prototype[t]=function(e,i){return this.request(M(i||{},{method:t,url:e,data:(i||{}).data}))}})),p.forEach(["post","put","patch"],(function(t){I.prototype[t]=function(e,i,n){return this.request(M(n||{},{method:t,url:e,data:i}))}}));var A=I;function R(t){this.message=t}R.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},R.prototype.__CANCEL__=!0;var B=R;function H(t){if("function"!=typeof t)throw new TypeError("executor must be a function.");var e;this.promise=new Promise((function(t){e=t}));var i=this;t((function(t){i.reason||(i.reason=new B(t),e(i.reason))}))}H.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},H.source=function(){var t;return{token:new H((function(e){t=e})),cancel:t}};var D=H;function q(t){var e=new A(t),i=r(A.prototype.request,e);return p.extend(i,A.prototype,e),p.extend(i,e),i}var U=q($);U.Axios=A,U.create=function(t){return q(M(U.defaults,t))},U.Cancel=B,U.CancelToken=D,U.isCancel=x,U.all=function(t){return Promise.all(t)},U.spread=function(t){return function(e){return t.apply(null,e)}},U.isAxiosError=function(t){return"object"==typeof t&&!0===t.isAxiosError};var O=U,W=U;O.default=W;var j=O;class V{constructor(t,e=!1,n,s="http",r="titleSort:asc"){this.serverInfo={},this.clients=[],this.requestTimeout=1e4,this.sections=[],this.providers=[],this.livetv={},this.livetvepg={},this.collections=!1,this.playlists=[],this.init=async()=>{await Promise.all([this.getSections(),this.getClients(),this.getServerID()])},this.getClients=async()=>{const t=this.authorizeURL(`${this.getBasicURL()}/clients`);try{const e=await j.get(t,{timeout:this.requestTimeout});this.clients=e.data.MediaContainer.Server}catch(e){throw Error(`${e.message} while requesting URL "${t}".`)}return this.clients},this.getProviders=async()=>{if(i.isEmpty(this.providers)){const t=this.authorizeURL(`${this.getBasicURL()}/media/providers`),e=await j.get(t,{timeout:this.requestTimeout});this.providers=e.data.MediaContainer.MediaProvider}return this.providers},this.getLiveTV=async()=>{if(i.isEmpty(this.livetv)){const t={},e=await this.getProviders(),n=[],s=[];i.forEach(e,(t=>{if(i.isEqual(t.protocols,"livetv")){const e=this.authorizeURL(`${this.getBasicURL()}/${t.identifier}/tags?type=310`);n.push(j.get(e,{timeout:this.requestTimeout})),s.push(t.title)}}));const r=await Promise.all(n);i.forEach(r,((e,i)=>{t[s[i]]=e.data.MediaContainer.Directory})),this.livetv=t}return this.livetv},this.getEPG=async()=>{if(i.isEmpty(this.livetvepg)){const t={},e=await this.getProviders(),n=[],s=[];i.forEach(e,(t=>{if(i.isEqual(t.protocols,"livetv")){let e=this.authorizeURL(`${this.getBasicURL()}/${t.identifier}/grid?type=1&sort=beginsAt`);e+=`&endsAt>=${Math.floor(Date.now()/1e3)}`,e+=`&beginsAt<=${Math.floor(Date.now()/1e3)}`,n.push(j.get(e,{timeout:this.requestTimeout})),s.push(t.title)}}));const r=await Promise.all(n);i.forEach(r,((e,n)=>{t[s[n]]={},i.forEach(e.data.MediaContainer.Metadata,(e=>{t[s[n]][e.Media[0].channelCallSign]=e}))})),this.livetvepg=t}return this.livetvepg},this.getServerID=async()=>(i.isEmpty(this.serverInfo)&&await this.getServerInfo(),this.serverInfo.machineIdentifier),this.getServerInfo=async()=>{const t=this.authorizeURL(`${this.getBasicURL()}/`);return this.serverInfo=(await j.get(t,{timeout:this.requestTimeout})).data.MediaContainer,this.serverInfo},this.getSections=async()=>{if(i.isEmpty(this.sections)){const t=this.authorizeURL(`${this.getBasicURL()}/library/sections`),e=await j.get(t,{timeout:this.requestTimeout});this.sections=e.data.MediaContainer.Directory}return this.sections},this.getCollections=async()=>{if(!i.isArray(this.collections)){const t=await this.getSections(),e=[];i.forEach(t,(t=>{e.push(this.getCollection(t.key))}));const n=await Promise.all(e),s=[];i.forEach(n,(t=>{i.forEach(t,(t=>{s.push(t)}))})),this.collections=s}return this.collections},this.getPlaylists=async()=>{if(i.isEmpty(this.playlists)){this.playlists=[];const t=this.authorizeURL(`${this.getBasicURL()}/playlists`),e=await j.get(t,{timeout:this.requestTimeout});this.playlists=e.data.MediaContainer.Metadata}return this.playlists},this.getCollection=async t=>{const e=this.authorizeURL(`${this.getBasicURL()}/library/sections/${t}/collections`),n=await j.get(e,{timeout:this.requestTimeout});return i.isNil(n.data.MediaContainer.Metadata)?[]:n.data.MediaContainer.Metadata},this.getSectionData=async(t,e=!1)=>this.exportSectionsData([await this.getSectionDataWithoutProcessing(t,e)]),this.getChildren=async t=>{let e=this.authorizeURL(`${this.getBasicURL()}${t}`);e+=`&sort=${this.sort}`;let n={};try{n=await j.get(e,{timeout:this.requestTimeout})}catch(s){if(!i.includes(s.message,"Request failed with status code 500"))throw s;{e+="&X-Plex-Container-Start=0&X-Plex-Container-Size=50",n=await j.get(e,{timeout:this.requestTimeout});const{totalSize:s}=n.data.MediaContainer;let r=50;const a=[];for(;r{n.data.MediaContainer.Metadata=i.concat(n.data.MediaContainer.Metadata,t.data.MediaContainer.Metadata)}))}}return n.data.MediaContainer.Metadata},this.getCollectionData=async t=>this.getChildren(t),this.getPlaylistData=async t=>this.getChildren(t),this.getSectionDataWithoutProcessing=async(t,e=!1)=>{let n=`${this.getBasicURL()}/library/sections/${t}`;e?i.isEqual(e,"folder")?n+="/folder":(n+="/all",n+=`?type=${e}`):n+="/all",n=this.authorizeURL(n),n+=`&sort=${this.sort}`,n+="&includeCollections=1&includeExternalMedia=1&includeAdvanced=1&includeMeta=1";let s={};try{s=await j.get(n,{timeout:this.requestTimeout})}catch(e){if(!i.includes(e.message,"Request failed with status code 500"))throw e;{n+="&X-Plex-Container-Start=0&X-Plex-Container-Size=50",s=await j.get(n,{timeout:this.requestTimeout});const{totalSize:e}=s.data.MediaContainer;let r=50;const a=[];for(;r{s.data.MediaContainer.Metadata=i.concat(s.data.MediaContainer.Metadata,t.data.MediaContainer.Metadata)}))}}return s},this.getSectionsData=async()=>{const t=await this.getSections(),e=[];return i.forEach(t,(t=>{e.push(this.getSectionDataWithoutProcessing(t.key))})),this.exportSectionsData(await Promise.all(e))},this.getRecentyAdded=async(t=!1)=>{if(t){const t=await this.getHubs();let e={};return i.forEach(t.Hub,(t=>{if(i.isEqual(t.key,"/hubs/home/recentlyAdded?type=2"))return e=t,!1})),e}const e=this.authorizeURL(`${this.getBasicURL()}/hubs/home/recentlyAdded?type=2&X-Plex-Container-Start=0&X-Plex-Container-Size=50`);return(await j.get(e,{timeout:this.requestTimeout})).data.MediaContainer},this.getHubs=async()=>{const t=this.authorizeURL(`${this.getBasicURL()}/hubs?includeEmpty=1&count=50&includeFeaturedTags=1&includeTypeFirst=1&includeStations=1&includeExternalMetadata=1&excludePlaylists=1`);return(await j.get(t,{timeout:this.requestTimeout})).data.MediaContainer},this.getWatchNext=async()=>{const t=await this.getSections();let e="";i.forEach(t,(t=>{e+=`${t.key},`})),e=e.slice(0,-1);const n=this.authorizeURL(`${this.getBasicURL()}/hubs/continueWatching/items?contentDirectoryID=${e}`);return(await j.get(n,{timeout:this.requestTimeout})).data.MediaContainer},this.tune=async(t,e)=>{e="PlexMeetsHomeAssistant3",console.log(t);let n=this.authorizeURL(`${this.getBasicURL()}/livetv/dvrs/12/channels/${t}/tune?X-Plex-Language=en-us`);console.log("Starting tune process..."),n=`${this.getBasicURL()}/livetv/dvrs/12/channels/`,n+=`${t}`,n+="/tune",n+=`?X-Plex-Client-Identifier=${e}`,n+=`&X-Plex-Session-Identifier=${e}`;const s=(await j.post(this.authorizeURL(n),{timeout:this.requestTimeout})).data.MediaContainer;console.log("Tuning started.");let r=`${this.getBasicURL()}/video/:/transcode/universal/start.mpd`;r+="?hasMDE=1",r+=`&path=${encodeURIComponent(s.MediaSubscription[0].MediaGrabOperation[0].Metadata.key)}`,r+="&mediaIndex=0",r+="&partIndex=0",r+="&protocol=dash",r+="&fastSeek=1",r+="&directPlay=0",r+="&directStream=1",r+="&subtitleSize=100",r+="&audioBoost=100",r+="&location=lan",r+="&addDebugOverlay=0",r+="&autoAdjustQuality=0",r+="&directStreamAudio=1",r+="&mediaBufferSize=102400",r+=`&session=${e}`,r+="&subtitles=burn",r+="©ts=0",r+="&Accept-Language=en-GB",r+=`&X-Plex-Session-Identifier=${e}`,r+="&X-Plex-Client-Profile-Extra=append-transcode-target-codec%28type%3DvideoProfile%26context%3Dstreaming%26audioCodec%3Daac%26protocol%3Ddash%29",r+="&X-Plex-Incomplete-Segments=1",r+="&X-Plex-Product=Plex%20Web",r+="&X-Plex-Version=4.59.2",r+=`&X-Plex-Client-Identifier=${e}`,r+="&X-Plex-Platform=Chrome",r+="&X-Plex-Platform-Version=92.0",r+="&X-Plex-Sync-Version=2",r+="&X-Plex-Features=external-media%2Cindirect-media",r+="&X-Plex-Model=bundled",r+="&X-Plex-Device=OSX",r+="&X-Plex-Device-Name=Chrome",r+="&X-Plex-Device-Screen-Resolution=1792x444%2C1792x1120",r+="&X-Plex-Language=en-GB";let a=`${this.getBasicURL()}/video/:/transcode/universal/decision`;a+="?advancedSubtitles=text",a+="&audioBoost=100",a+="&autoAdjustQuality=0",a+="&directPlay=1",a+="&directStream=1",a+="&directStreamAudio=1",a+="&fastSeek=1",a+="&hasMDE=1",a+="&location=lan",a+="&mediaIndex=0",a+="&partIndex=0",a+=`&path=${s.MediaSubscription[0].MediaGrabOperation[0].Metadata.key}`,a+="&protocol=*",a+=`&session=${e}`,a+="&skipSubtitles=1",a+="&videoBitrate=200000",a+="&videoQuality=100",a+=`&X-Plex-Client-Identifier=${e}`,a+="&X-Plex-Platform=Android";const o=this.authorizeURL(`${this.getBasicURL()}${s.MediaSubscription[0].MediaGrabOperation[0].Metadata.key}?includeBandwidths=1&offset=-1&X-Plex-Incomplete-Segments=1&X-Plex-Session-Identifier=${e}`);console.log("Getting info about channel stream...");const l=await j.get(o,{timeout:6e4});if(console.log(l.data),i.isNil(l.data.MediaContainer.Metadata[0].Media[0].TranscodeSession)){console.log("NOT STARTED - Starting...");const t=await j.get(this.authorizeURL(r),{timeout:6e4});console.log(t),console.log("____")}const h=async t=>new Promise((e=>setTimeout(e,t)));console.log("Deciding...");let c=await j.get(this.authorizeURL(a),{timeout:this.requestTimeout});for(;parseFloat(c.data.MediaContainer.Metadata[0].Media[0].Part[0].key.split("offset=")[1].split("&")[0])<3;)await h(500),c=await j.get(this.authorizeURL(a),{timeout:this.requestTimeout}),console.log("Waiting for new url...");return c.data.MediaContainer.Metadata[0].Media[0].Part[0].key},this.getContinueWatching=async()=>{const t=await this.getHubs();let e={};return i.forEach(t.Hub,(t=>{if(i.isEqual(t.key,"/hubs/home/continueWatching"))return e=t,!1})),e},this.getOnDeck=async()=>{const t=await this.getHubs();let e={};return i.forEach(t.Hub,(t=>{if(i.isEqual(t.key,"/hubs/home/onDeck"))return e=t,!1})),e},this.getBasicURL=()=>`${this.protocol}://${this.ip}${!1===this.port?"":`:${this.port}`}`,this.authorizeURL=t=>i.includes(t,"X-Plex-Token")?t:i.includes(t,"?")?`${t}&X-Plex-Token=${this.token}`:`${t}?X-Plex-Token=${this.token}`,this.getDetails=async t=>{const e=this.authorizeURL(`${this.getBasicURL()}/library/metadata/${t}?includeConcerts=1&includeExtras=1&includeOnDeck=1&includePopularLeaves=1&includePreferences=1&includeReviews=1&includeChapters=1&includeStations=1&includeExternalMedia=1&asyncAugmentMetadata=1&asyncCheckFiles=1&asyncRefreshAnalysis=1&asyncRefreshLocalMediaAgent=1`);return(await j.get(e,{timeout:this.requestTimeout})).data.MediaContainer.Metadata[0]},this.getLibraryData=async t=>{const e=this.authorizeURL(`${this.getBasicURL()}${t}`);return(await j.get(e,{timeout:this.requestTimeout})).data.MediaContainer.Metadata},this.exportSectionsData=t=>{const e=[];return i.forEach(t,(t=>{e.push(t.data.MediaContainer)})),e},this.ip=t,this.port=e,this.token=n,this.protocol=s,this.sort=r}}const F=t=>t?t.toString().replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'"):"",X=t=>t.sendMessagePromise({type:"config/entity_registry/list"}),Y=t=>Math.max(t.scrollHeight,t.offsetHeight,t.clientHeight,t.scrollHeight,t.offsetHeight),K=t=>{let e=0,n=0;for(;t&&t.offsetParent&&!i.isNaN(t.offsetLeft)&&!i.isNaN(t.offsetTop);){e+=t.offsetLeft-t.scrollLeft,n+=t.offsetTop-t.scrollTop;const i=t.offsetParent;i&&(t=i)}return{top:n,left:e}},G=t=>{const e=t.getElementsByClassName("videoPlayer")[0].children[0];if(!e)return!1;const i=document.getElementsByTagName("body")[0];return e.offsetWidth===i.offsetWidth&&e.offsetHeight===i.offsetHeight||t.videoElem&&t.videoElem.classList.contains("simulatedFullScreen")},Z=t=>`PlexMeetsHomeAssistant: 404 Error requesting library feed for ${t}. Plex API might have changed or using outdated server. Library ${t} will not work.`,J=async t=>new Promise((e=>setTimeout(e,t))),Q=async(t,e)=>t.callApi("GET",`states/${e}`),tt=(t,e)=>{let i=`${t}`;for(;i.length{const o=s/4,l=document.createElement("tr");l.classList.add("trackContainer"),a?l.classList.add("even"):l.classList.add("odd");const h=document.createElement("td");h.className="trackIndexElem",h.innerHTML=`${F(n.index)}`,h.style.fontSize=`${s}px`,h.style.lineHeight=`${s}px`,h.style.marginBottom=`${o}px`;const c=document.createElement("div");if(c.className="trackInteractiveArea",t){const e=t.getPlayButton(n.type);e.addEventListener("click",(e=>{e.stopPropagation(),t.play(n,!0)})),t.isPlaySupported(n)&&e.classList.remove("disabled"),c.append(e)}h.append(c),l.append(h);const u=document.createElement("td");u.className="trackTitleElem",i.isEmpty(n.title)?i.isEmpty(n.titleSort)||(u.innerHTML=F(n.titleSort)):u.innerHTML=F(n.title),u.style.fontSize=`${s}px`,u.style.lineHeight=`${s}px`,u.style.marginBottom=`${o}px`,l.append(u);const d=i.get(n,"Media[0].duration"),p=document.createElement("td");if(p.className="trackLengthElem",p.style.fontSize=`${s}px`,p.style.lineHeight=`${s}px`,p.style.marginBottom=`${o}px`,d){const t=Math.floor(d/60/1e3),e=Math.round((d-1e3*t)/6e3);p.innerHTML=F(`${tt(t,2)}:${tt(e,2)}`)}return l.append(p),l.addEventListener("click",(t=>{t.stopPropagation()})),l},it=(t,e,i,s,r)=>{const a=document.createElement("div");a.className="episodeContainer",a.style.width=`${n.episodeWidth}px`;const o=e.authorizeURL(`${e.getBasicURL()}/photo/:/transcode?width=${n.episodeWidth}&height=${n.episodeHeight}&minSize=1&upscale=1&url=${i.thumb}`),l=document.createElement("div");if(l.className="episodeElem",l.style.width=`${n.episodeWidth}px`,l.style.height=`${n.episodeHeight}px`,l.style.backgroundImage=`url('${o}')`,l.dataset.clicked="false",void 0===i.lastViewedAt){const t=document.createElement("div");t.className="toViewEpisode",l.appendChild(t)}const h=document.createElement("div");if(h.className="interactiveArea",t){const e=t.getPlayButton(i.type);e.addEventListener("click",(e=>{e.stopPropagation(),t.play(i,!0)})),t.isPlaySupported(i)&&e.classList.remove("disabled"),h.append(e)}l.append(h),a.append(l);const c=document.createElement("div");c.className="episodeTitleElem",c.innerHTML=F(i.title);const u=s/4,d=r/4;c.style.fontSize=`${s}px`,c.style.lineHeight=`${s}px`,c.style.marginBottom=`${u}px`,a.append(c);const p=document.createElement("div");if(p.className="episodeNumber",p.style.fontSize=`${r}px`,p.style.lineHeight=`${r}px`,p.style.marginTop=`${d}px`,p.style.marginBottom=`${d}px`,"episode"===i.type)p.innerHTML=F(`Episode ${F(i.index)}`);else if("clip"===i.type){let t="";switch(i.subtype){case"behindTheScenes":t="Behind the Scenes";break;case"trailer":t="Trailer";break;case"scene":case"sceneOrSample":t="Scene";break;default:t=i.subtype}p.innerHTML=F(t)}return a.append(p),a.addEventListener("click",(t=>{t.stopPropagation()})),a};class nt{constructor(t,e,n,r,a,o,l,h,c){this.playButtons=[],this.readyPlayersForType={},this.entityStates={},this.plexPlayerEntity="",this.runBefore=!1,this.runAfter=!1,this.supported=s,this.playActionButton=document.createElement("button"),this.playActionClickFunction=!1,this.entityRegistry=[],this.shuffle=!1,this.getKodiSearchResults=async()=>JSON.parse((await Q(this.hass,"sensor.kodi_media_sensor_search")).attributes.data),this.getKodiSearch=async(t,e=!1)=>{await this.hass.callService("kodi_media_sensors","call_method",{entity_id:"sensor.kodi_media_sensor_search",method:"search",item:{media_type:"all",value:t}});const n=await this.getKodiSearchResults();let s={};if(i.forEach(n,(e=>i.isEqual(e.title,t)||i.isEqual(e.label,t)?(s=e,!1):void 0)),i.isEmpty(s)&&!e)throw alert(`Title ${t} not found in Kodi.`),Error(`Title ${t} not found in Kodi.`);return s},this.getKodiTVShowSeason=async(t,e)=>{await this.hass.callService("kodi_media_sensors","call_method",{entity_id:"sensor.kodi_media_sensor_search",method:"search",item:{media_type:"tvshow",value:t}});let n={};const s=await this.getKodiSearchResults();if(i.forEach(s,(t=>{if(i.isEqual(t.season,e))return n=t,!1})),i.isEmpty(n))throw Error(`Season ${e} not found in Kodi for TV Show ${t}.`);return n},this.play=async(t,e=!1)=>{if(i.isArray(this.runBefore)){const t=`${this.runBefore[0]}.${this.runBefore[1]}`;await this.hass.callService(this.runBefore[0],this.runBefore[1],{});const e=await Q(this.hass,t);i.isEqual(e.state,"on")&&await(async(t,e,i)=>{let n=await Q(t,e);for(;n.state!==i;)n=await Q(t,e),await J(1e3)})(this.hass,t,"off")}const n=this.getPlayService(t,!0);let s,r=t;switch(i.isEqual(t.type,"epg")&&(r=t.epg,s=""),n.key){case"kodi":await this.playViaKodi(n.value,t,t.type);break;case"vlcTelnet":await this.playViaVLCTelnet(n.value,t,t.type);break;case"androidtv":if(i.isEqual(t.type,"epg")){const i=`${Math.floor(Date.now()/1e3)}`,r=await this.plex.tune(t.channelIdentifier,i);await this.playViaAndroidTV(n.value,r,e,s)}else await this.playViaAndroidTV(n.value,r.key,e,s);break;case"plexPlayer":await this.playViaPlexPlayer(n.value,r.key.split("/")[3]);break;case"cast":case"sonos":if(i.isEqual(t.type,"epg")){const e=`PlexMeetsHomeAssistant-${Math.floor(Date.now()/1e3)}`,i=await this.plex.tune(t.channelIdentifier,e);this.playViaCast(n.value,`${i}`,"epg")}else if(this.hass.services.plex){const t=i.isNil(r.librarySectionTitle)?this.libraryName:r.librarySectionTitle;try{switch(r.type){case"artist":await this.playViaCastPlex(n.value,"MUSIC",{library_name:t,artist_name:r.title,shuffle:this.shuffle?1:0});break;case"album":await this.playViaCastPlex(n.value,"MUSIC",{library_name:t,artist_name:r.parentTitle,album_name:r.title,shuffle:this.shuffle?1:0});break;case"track":await this.playViaCastPlex(n.value,"MUSIC",{library_name:t,artist_name:r.grandparentTitle,album_name:r.parentTitle,track_name:r.title,shuffle:this.shuffle?1:0});break;case"movie":await this.playViaCastPlex(n.value,"movie",{library_name:t,title:r.title});break;case"episode":await this.playViaCastPlex(n.value,"EPISODE",{library_name:t,show_name:r.grandparentTitle,season_number:r.parentIndex,episode_number:r.index});break;default:i.isNil(r.Media)?console.error("Casting this content directly is not possible. Consider using Plex integration."):this.playViaCast(n.value,r.Media[0].Part[0].key)}}catch(t){console.log(t),this.playViaCast(n.value,r.Media[0].Part[0].key)}}else{if(i.isNil(i.get(r,"Media[0].Part[0].key")))throw Error(`No service available to play ${r.title}!`);this.playViaCast(n.value,i.get(r,"Media[0].Part[0].key"))}break;default:throw Error(`No service available to play ${r.title}!`)}i.isArray(this.runAfter)&&await this.hass.callService(this.runAfter[0],this.runAfter[1],{})},this.plexPlayerCreateQueue=async(t,e,i,n=!1,s=!1,r=!1)=>{const a=`${e.getBasicURL()}/playQueues?type=${i}&shuffle=${n?"1":"0"}&repeat=${s?"1":"0"}&continuous=${r?"1":"0"}&own=1&uri=server://${await e.getServerID()}/com.plexapp.plugins.library${t}`,o=await j({method:"post",url:a,headers:{"X-Plex-Token":e.token,"X-Plex-Client-Identifier":"PlexMeetsHomeAssistant"}});if(200!==o.status)throw Error("Error reaching Plex to generate queue");return{playQueueID:o.data.MediaContainer.playQueueID,playQueueSelectedMetadataItemID:o.data.MediaContainer.playQueueSelectedMetadataItemID}},this.playViaPlexPlayer=async(t,e)=>{const n=this.getPlexPlayerMachineIdentifier(t);let{plex:s}=this;i.isObject(t)&&!i.isNil(t.plex)&&(s=t.plex);const{playQueueID:r,playQueueSelectedMetadataItemID:a}=await this.plexPlayerCreateQueue(`/library/metadata/${e}`,this.plex,"video");let o=s.getBasicURL();o+="/player/playback/playMedia",o+="?type=video",o+="&commandID=1",o+="&providerIdentifier=com.plexapp.plugins.library",o+=`&containerKey=/playQueues/${r}`,o+=`&key=/library/metadata/${a}`,o+="&offset=0",o+=`&machineIdentifier=${await this.plex.getServerID()}`,o+=`&protocol=${this.plex.protocol}`,o+=`&address=${this.plex.ip}`,o+=`&port=${this.plex.port}`,o+=`&token=${this.plex.token}`,o=s.authorizeURL(o);try{const t=await j({method:"get",url:o,headers:{"X-Plex-Target-Client-Identifier":n,"X-Plex-Client-Identifier":"PlexMeetsHomeAssistant"}});if(200!==t.status)throw Error("Error while asking plex to play a movie - server request error.");if(!i.includes(t.data,'status="OK"'))throw Error("Error while asking plex to play a movie - target device not available.")}catch(t){try{await this.hass.callService("rest_command","pmha_playmedia",{url:o,target_client_identifier:n,client_identifier:"PlexMeetsHomeAssistant"})}catch(t){}throw i.includes(t.message,"404")?Error("Defined plexPlayer is currently not available for playback."):t}},this.playViaKodi=async(t,e,n)=>{if("epg"===n)try{const n=await this.getKodiSearch(i.get(e,"channelCallSign"),!0);await this.hass.callService("kodi","call_method",{entity_id:t,method:"Player.Open",item:{channelid:n.channelid}})}catch(i){const n=`${this.plex.getBasicURL()}${await this.plex.tune(e.channelIdentifier,"todo")}`;await this.hass.callService("kodi","call_method",{entity_id:t,method:"Player.Open",item:{file:n}})}else if("movie"===n){const i=await this.getKodiSearch(e.title);await this.hass.callService("kodi","call_method",{entity_id:t,method:"Player.Open",item:{movieid:i.movieid}})}else{if("episode"!==n)throw Error(`Plex type ${n} is not supported in Kodi.`);{const n=await this.getKodiSearch(e.grandparentTitle),s=await this.getKodiTVShowSeason(n.tvshowid,e.parentIndex);let r={};if(i.forEach(s.episodes,(t=>{if(i.isEqual(t.episode,e.index))return r=t,!1})),i.isEmpty(r))throw Error(`Episode ${e.index} not found in Kodi for TV Show ${e.grandparentTitle} (id: ${n.tvshowid}) season ${e.parentIndex}.`);await this.hass.callService("kodi","call_method",{entity_id:t,method:"Player.Open",item:{episodeid:r.episodeid}})}}},this.playViaVLCTelnet=async(t,e,i)=>{switch(i){case"track":this.hass.callService("media_player","play_media",{entity_id:t,media_content_type:"music",media_content_id:this.plex.authorizeURL(`${this.plex.getBasicURL()}${e.Media[0].Part[0].key}`)});break;default:console.error(`Type ${i} is not supported on entity ${t}.`)}},this.playViaCast=(t,e,n="video")=>{if(i.isEqual(n,"video"))this.hass.callService("media_player","play_media",{entity_id:t,media_content_type:n,media_content_id:this.plex.authorizeURL(`${this.plex.getBasicURL()}${e}`)});else if(i.isEqual(n,"epg")){const i={entity_id:t,media_content_type:"application/vnd.apple.mpegurl",media_content_id:e=this.plex.authorizeURL(`${this.plex.getBasicURL()}${e}`)};this.hass.callService("media_player","play_media",i)}},this.playViaCastPlex=(t,e,n)=>{const s=i.get(this.plex,"serverInfo.friendlyName"),r=i.clone(n);return s&&(r.plex_server=s),this.hass.callService("media_player","play_media",{entity_id:t,media_content_type:e,media_content_id:`plex://${JSON.stringify(r)}`})},this.playViaAndroidTV=async(t,e,i=!1,n="com.plexapp.plugins.library")=>{let s="am start";i&&(s+=' --ez "android.intent.extra.START_PLAYBACK" true'),s+=` -a android.intent.action.VIEW 'plex://server://${await this.plex.getServerID()}/${n}${e}'`,this.hass.callService("androidtv","adb_command",{entity_id:t,command:"HOME"}),this.hass.callService("androidtv","adb_command",{entity_id:t,command:s})},this.getPlayButton=t=>{const e=document.createElement("button");return e.name="playButton",e.classList.add("disabled"),this.isTouchDevice()&&e.classList.add("touchDevice"),e.setAttribute("data-mediaType",t),this.playButtons.push(e),e},this.setPlayActionDisplay=t=>{this.updateDetailPlayAction().style.display=t},this.setPlayActionButtonType=t=>{const e=this.updateDetailPlayAction();e.setAttribute("data-mediaType",t);const n={type:t};i.isEmpty(this.getPlayService(n))?e.classList.add("disabled"):e.classList.remove("disabled")},this.updateDetailPlayAction=()=>(this.card.getElementsByClassName("detailPlayAction").length>0&&(this.playActionButton=this.card.getElementsByClassName("detailPlayAction")[0]),this.playActionButton),this.setPlayButtonClickFunction=t=>{const e=this.updateDetailPlayAction();this.playActionClickFunction&&e.removeEventListener("click",this.playActionClickFunction),e.addEventListener("click",t),this.playActionClickFunction=t},this.getPlayActionButton=()=>this.playActionButton,this.isTouchDevice=()=>"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,this.refreshAvailableServicesPeriodically=async()=>{const t=async t=>new Promise((e=>setTimeout(e,t)));for(;;){await this.refreshStates();const e=i.clone(this.readyPlayersForType);i.forEach(this.readyPlayersForType,((t,n)=>{const s={type:n};this.getPlayService(s,!0),i.isEqual(e,this.readyPlayersForType)||i.forEach(this.playButtons,(t=>{const e=t.getAttribute("data-mediaType");i.isEmpty(this.readyPlayersForType[e])?t.classList.add("disabled"):t.classList.remove("disabled")}));const r=this.getPlayActionButton(),a=r.getAttribute("data-mediaType");a&&(i.isEmpty(this.readyPlayersForType[a])?r.classList.add("disabled"):r.classList.remove("disabled"))})),await t(1e3)}},this.exportEntity=(t,e)=>{const n=[];if(i.isEqual(e,"inputSelect")||i.isEqual(e,"inputText"))if(i.isArray(t))for(let e=0;e{i.isEqual(t.entity_id,s)&&(r=t.platform)})),n.push({value:s,key:r})}else{const e=i.get(this.entityStates[t],"state");let s="plexPlayer";i.forEach(this.entityRegistry,(t=>{i.isEqual(t.entity_id,e)&&(s=t.platform)})),n.push({value:e,key:s})}else i.isArray(t)?i.forEach(t,(t=>{n.push({value:t,key:e})})):n.push({value:t,key:e});return n},this.getPlayService=(t,e=!1)=>{if(!i.isNil(this.readyPlayersForType[t.type])&&!1===e)return this.readyPlayersForType[t.type];let n={};return i.forEach(this.entity,((e,s)=>{if(i.isEmpty(n)){const r=this.exportEntity(e,s);i.forEach(r,(e=>{if(i.includes(this.supported[e.key],t.type)&&("kodi"===e.key&&this.isKodiSupported(e.value)||"androidtv"===e.key&&this.isAndroidTVSupported(e.value)||"plexPlayer"===e.key&&this.isPlexPlayerSupported(e.value)||"cast"===e.key&&this.isCastSupported(e.value)||"vlcTelnet"===e.key&&this.isVLCTelnetSupported(e.value)||"sonos"===e.key&&this.isSonosSupported(e.value)))return n={key:e.key,value:e.value},!1}))}})),this.readyPlayersForType[t.type]=n,this.readyPlayersForType[t.type]},this.init=async()=>{if(!i.isNil(this.entity.plexPlayer))if(i.isArray(this.entity.plexPlayer)){for(let t=0;t{for(const[,t]of Object.entries(this.entity)){const e=t;if(i.isArray(e)){for(const t of e)if(!i.isNil(this.hass.states[t]))try{this.entityStates[t]=await Q(this.hass,t)}catch(t){}}else try{i.isNil(this.hass.states[e])||(this.entityStates[e]=await Q(this.hass,e))}catch(t){}}try{this.hass.states["sensor.kodi_media_sensor_search"]&&(this.entityStates["sensor.kodi_media_sensor_search"]=await Q(this.hass,"sensor.kodi_media_sensor_search"))}catch(t){}for(const[t,e]of Object.entries(this.entity))if(i.isEqual(t,"inputSelect")||i.isEqual(t,"inputText")){const n=this.exportEntity(e,t);for(const t of n)if(!i.isNil(this.hass.states[t.value]))try{this.entityStates[t.value]=await Q(this.hass,t.value)}catch(t){}}return this.entityStates},this.getPlexPlayerMachineIdentifier=t=>{i.isString(t)&&i.isEqual(t.split(" | ").length,4)&&([,,,t]=t.split(" | "));let e="",{plex:n}=this,s="";return i.isString(t)?s=t.trim():i.isObjectLike(t)&&!i.isNil(t.identifier)&&(s=t.identifier.trim(),!i.isNil(t.plex)&&t.plex&&(n=t.plex)),i.forEach(n.clients,(t=>{if(i.isEqual(t.machineIdentifier,s)||i.isEqual(t.product,s)||i.isEqual(t.name,s)||i.isEqual(t.host,s)||i.isEqual(t.address,s))return e=t.machineIdentifier,!1})),e},this.isPlaySupported=t=>!i.isEmpty(this.getPlayService(t)),this.isPlexPlayerSupported=t=>{let e=!1;return this.getPlexPlayerMachineIdentifier(t)&&(e=!0),e||!i.isEqual(this.runBefore,!1)},this.isKodiSupported=t=>{if(t){const e=this.entityStates["sensor.kodi_media_sensor_search"]&&"unavailable"!==this.entityStates["sensor.kodi_media_sensor_search"].state;return this.entityStates[t]&&"off"!==this.entityStates[t].state&&"unavailable"!==this.entityStates[t].state&&e||!i.isEqual(this.runBefore,!1)&&e}return!1},this.isVLCTelnetSupported=t=>this.entityStates[t]&&!i.isNil(this.entityStates[t].attributes)&&"unavailable"!==this.entityStates[t].state||!i.isEqual(this.runBefore,!1),this.isSonosSupported=t=>this.entityStates[t]&&!i.isNil(this.entityStates[t].attributes)&&"unavailable"!==this.entityStates[t].state||!i.isEqual(this.runBefore,!1),this.isCastSupported=t=>this.entityStates[t]&&!i.isNil(this.entityStates[t].attributes)&&"unavailable"!==this.entityStates[t].state||!i.isEqual(this.runBefore,!1),this.isAndroidTVSupported=t=>this.entityStates[t]&&!i.isEqual(this.entityStates[t].state,"off")&&this.entityStates[t].attributes&&void 0!==this.entityStates[t].attributes.adb_response||!i.isEqual(this.runBefore,!1),this.entityRegistry=h,this.card=t,this.hass=e,this.plex=n,this.entity=r,this.shuffle=c,this.libraryName=l,!i.isEmpty(a)&&this.hass.states[a]&&(this.runBefore=a.split(".")),!i.isEmpty(o)&&this.hass.states[o]&&(this.runAfter=o.split(".")),this.refreshAvailableServicesPeriodically(),this.playActionButton.classList.add("detailPlayAction"),this.playActionButton.innerText="Play"}}class st extends HTMLElement{constructor(){super(...arguments),this.plexPort=!1,this.plexProtocol="http",this.config={},this.ip=document.createElement("paper-input"),this.token=document.createElement("paper-input"),this.port=document.createElement("paper-input"),this.maxCount=document.createElement("paper-input"),this.maxRows=document.createElement("paper-input"),this.displayTitleMain=document.createElement("select"),this.displaySubtitleMain=document.createElement("select"),this.useHorizontalScroll=document.createElement("select"),this.useShuffle=document.createElement("select"),this.minWidth=document.createElement("paper-input"),this.minEpisodeWidth=document.createElement("paper-input"),this.minExpandedWidth=document.createElement("paper-input"),this.minExpandedHeight=document.createElement("paper-input"),this.fontSize1=document.createElement("paper-input"),this.fontSize2=document.createElement("paper-input"),this.fontSize3=document.createElement("paper-input"),this.fontSize4=document.createElement("paper-input"),this.cardTitle=document.createElement("paper-input"),this.libraryName=document.createElement("select"),this.protocol=document.createElement("select"),this.tabs=document.createElement("paper-tabs"),this.sort=document.createElement("select"),this.displayTypeData={},this.displayType=document.createElement("select"),this.sortOrder=document.createElement("select"),this.playTrailer=document.createElement("select"),this.showExtras=document.createElement("select"),this.showSearch=document.createElement("select"),this.runBefore=document.createElement("select"),this.runAfter=document.createElement("select"),this.entitiesSection=document.createElement("div"),this.devicesTabs=0,this.entities=[],this.scriptEntities=[],this.sections=[],this.collections=[],this.playlists=[],this.clients={},this.entitiesRegistry=!1,this.plexValidSection=document.createElement("div"),this.loaded=!1,this.livetv={},this.fireEvent=(t,e,i,n={})=>{i=null==i?{}:i;const s=new Event(e,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed});return s.detail=i,t.dispatchEvent(s),s},this.generateTitle=t=>{const e=document.createElement("h4");return e.innerText=t,e.style.marginBottom="0",e.style.marginTop="0",e.style.paddingTop="0",e.style.paddingBottom="0",e.style.color="rgb(225, 225, 225)",e.style.fontWeight="300",e.style.fontSize="12px",e},this.valueUpdated=()=>{const t=i.clone(this.config);if(this.config.protocol=this.protocol.value,this.config.ip=this.ip.value.replace(/^https?:\/\//i,"").replace(/\/$/,""),this.config.token=this.token.value,this.config.port=this.port.value,this.loaded&&(this.config.entity||(this.config.entity=[]),!i.isEmpty(this.libraryName.value))){this.config.libraryName=this.libraryName.value;let t="";i.isEqual(this.sortOrder.value,"Ascending")?t="asc":i.isEqual(this.sortOrder.value,"Descending")&&(t="desc"),i.isEmpty(t)||i.isEmpty(this.sort.value)?this.config.sort="":this.config.sort=`${this.sort.value}:${t}`,this.config.displayType=this.displayTypeData[this.displayType.value],i.isEmpty(this.maxCount.value)?this.config.maxCount="":this.config.maxCount=this.maxCount.value,i.isEmpty(this.maxRows.value)?this.config.maxRows="":this.config.maxRows=this.maxRows.value,i.isEmpty(this.useHorizontalScroll.value)?this.config.useHorizontalScroll="No":this.config.useHorizontalScroll=this.useHorizontalScroll.value,i.isEmpty(this.useShuffle.value)?this.config.useShuffle="No":this.config.useShuffle=this.useShuffle.value,i.isEmpty(this.displayTitleMain.value)?this.config.displayTitleMain="Yes":this.config.displayTitleMain=this.displayTitleMain.value,i.isEmpty(this.displaySubtitleMain.value)?this.config.displaySubtitleMain="Yes":this.config.displaySubtitleMain=this.displaySubtitleMain.value,i.isEmpty(this.minWidth.value)?this.config.minWidth="":this.config.minWidth=this.minWidth.value,i.isEmpty(this.minEpisodeWidth.value)?this.config.minEpisodeWidth="":this.config.minEpisodeWidth=this.minEpisodeWidth.value,i.isEmpty(this.minExpandedWidth.value)?this.config.minExpandedWidth="":this.config.minExpandedWidth=this.minExpandedWidth.value,i.isEmpty(this.fontSize1.value)?this.config.fontSize1="":this.config.fontSize1=this.fontSize1.value,i.isEmpty(this.fontSize2.value)?this.config.fontSize2="":this.config.fontSize2=this.fontSize2.value,i.isEmpty(this.fontSize3.value)?this.config.fontSize3="":this.config.fontSize3=this.fontSize3.value,i.isEmpty(this.fontSize4.value)?this.config.fontSize4="":this.config.fontSize4=this.fontSize4.value,i.isEmpty(this.minExpandedHeight.value)?this.config.minExpandedHeight="":this.config.minExpandedHeight=this.minExpandedHeight.value,i.isEmpty(this.cardTitle.value)?this.config.title="":this.config.title=this.cardTitle.value,i.isEmpty(this.entities)||(this.config.entity=[],i.forEach(this.entities,(t=>{i.isEmpty(t.value)||i.includes(this.config.entity,t.value)||this.config.entity.push(t.value)}))),i.isEqual(this.playTrailer.value,"Yes")?this.config.playTrailer=!0:i.isEqual(this.playTrailer.value,"No")?this.config.playTrailer=!1:i.isEqual(this.playTrailer.value,"Muted")&&(this.config.playTrailer="muted"),i.isEqual(this.showExtras.value,"Yes")?this.config.showExtras=!0:i.isEqual(this.showExtras.value,"No")&&(this.config.showExtras=!1),i.isEqual(this.showSearch.value,"Yes")?this.config.showSearch=!0:i.isEqual(this.showSearch.value,"No")&&(this.config.showSearch=!1),this.config.runBefore=this.runBefore.value,this.config.runAfter=this.runAfter.value}i.isEqual(this.config,t)||this.fireEvent(this,"config-changed",{config:this.config})},this.render=async()=>{const t=(t,e="",n=!1)=>{i.isEmpty(e)&&(e=t);const s=document.createElement("option");return s.innerHTML=e.replace(/ /g," "),s.label=t,s.value=t,n&&(s.disabled=!0),s},e=(e,n)=>{if(this.entitiesRegistry){const s=document.createElement("div"),r=document.createElement("select");r.appendChild(t(""));const a=[];return i.forEach(this.entitiesRegistry,(e=>{if(i.isEqual(e.platform,"cast")||i.isEqual(e.platform,"kodi")||i.isEqual(e.platform,"androidtv")||i.isEqual(e.platform,"input_select")||i.isEqual(e.platform,"input_text")||i.isEqual(e.platform,"vlc_telnet")||i.isEqual(e.platform,"sonos")){const i=`${e.platform} | ${e.entity_id}`;r.appendChild(t(i)),a.push(i)}})),i.forEach(this.clients,(e=>{const i=`plexPlayer | ${e.name} | ${e.address} | ${e.machineIdentifier}`;r.appendChild(t(i)),a.push(i)})),i.isArray(this.config.entity)&&i.forEach(this.config.entity,(e=>{i.includes(a,e)||(r.appendChild(t(e)),a.push(e))})),r.label="Entity",r.value=e,r.style.width="100%",r.style.height="40px",r.className="entitiesDropDown",r.addEventListener("change",n),this.entities.push(r),s.appendChild(this.generateTitle("Entity")),s.appendChild(r),s}return!1};this.content&&this.content.remove(),this.hassObj&&!this.entitiesRegistry&&(i.forOwn(this.hassObj.states,((t,e)=>{i.startsWith(e,"script.")&&this.scriptEntities.push(e)})),this.entitiesRegistry=await X(this.hassObj.connection)),this.entities=[],this.content=document.createElement("div");const n=document.createElement("h2");n.innerHTML="Plex Configuration",n.style.margin="0px",n.style.padding="0px",this.content.appendChild(n),this.content.appendChild(this.generateTitle("Plex Protocol")),this.protocol.innerHTML="";const s=location.protocol;i.isEqual(s,"http:")&&this.protocol.appendChild(t("http")),this.protocol.appendChild(t("https")),this.protocol.style.width="100%",this.protocol.style.height="40px",this.protocol.addEventListener("change",this.valueUpdated),i.isEmpty(this.config.protocol)?i.isEqual(s,"http:")?this.protocol.value="http":this.protocol.value="https":this.protocol.value=this.config.protocol,this.content.appendChild(this.protocol),this.ip.label="Plex IP Address / Hostname",this.config.ip?this.ip.value=this.config.ip.replace(/^https?:\/\//i,"").replace(/\/$/,""):this.ip.value=this.config.ip,this.ip.addEventListener("change",this.valueUpdated),this.content.appendChild(this.ip),this.port.label="Plex Port (Optional)",this.port.value=this.config.port,this.port.type="number",this.port.addEventListener("change",this.valueUpdated),this.content.appendChild(this.port),this.token.label="Plex Token",this.token.value=this.config.token,this.token.addEventListener("change",this.valueUpdated),this.content.appendChild(this.token),this.content.appendChild(this.generateTitle("Plex Library")),this.libraryName.innerHTML="",this.libraryName.appendChild(t("Smart Libraries","",!0)),this.libraryName.appendChild(t("Continue Watching")),this.libraryName.appendChild(t("Deck")),this.libraryName.appendChild(t("Recently Added")),this.libraryName.appendChild(t("Watch Next")),this.libraryName.disabled=!0,this.libraryName.style.width="100%",this.libraryName.style.height="40px",this.libraryName.addEventListener("change",this.valueUpdated);const r=document.createElement("div");r.style.color="red",this.content.appendChild(this.libraryName),this.content.appendChild(r),this.appendChild(this.content),this.plex=new V(this.config.ip.replace(/^https?:\/\//i,"").replace(/\/$/,""),this.plexPort,this.config.token,this.plexProtocol,this.config.sort),this.sections=await this.plex.getSections(),i.forEach(this.sections,(e=>!i.isEqual(e.title,this.config.libraryName)||!i.isEqual(e.type,"artist")||(this.content.appendChild(this.generateTitle("Use shuffle when playing")),this.useShuffle.innerHTML="",this.useShuffle.appendChild(t("Yes")),this.useShuffle.appendChild(t("No")),this.useShuffle.slot="dropdown-content",this.useShuffle.label="Use shuffle when playing",this.useShuffle.style.width="100%",this.useShuffle.style.height="40px",this.useShuffle.addEventListener("change",this.valueUpdated),i.isEmpty(this.config.useShuffle)?this.useShuffle.value="No":this.useShuffle.value=this.config.useShuffle,this.content.appendChild(this.useShuffle),!1))),this.livetv=await this.plex.getLiveTV(),this.collections=await this.plex.getCollections(),this.playlists=await this.plex.getPlaylists(),this.clients=await this.plex.getClients(),this.plexValidSection.style.display="none",this.plexValidSection.innerHTML="";let a=!0,o=!0;if(i.isArray(this.config.entity))i.forEach(this.config.entity,(t=>{if(i.isObjectLike(t))return o=!i.includes(i.keys(this.config.entity),"plexPlayer"),a=!1,!1}));else if(i.isObjectLike(this.config.entity)&&(o=!i.includes(i.keys(this.config.entity),"plexPlayer"),a=!1,o)){const t=[];a=!0,i.isObjectLike(this.config.entity)&&i.forOwn(this.config.entity,(e=>{i.isString(e)?t.push(e):i.isArray(e)&&i.forEach(e,(e=>{t.push(e)}))})),this.config.entity=t}const l=document.createElement("h2");if(l.innerHTML="Devices Configuration",l.style.lineHeight="29px",l.style.marginBottom="0px",l.style.marginTop="20px",a){const t=document.createElement("button");t.style.float="right",t.style.fontSize="20px",t.style.cursor="pointer",t.innerHTML="+",t.addEventListener("click",(()=>{const t=e("",this.valueUpdated);t&&this.entitiesSection.appendChild(t)})),l.appendChild(t)}if(this.plexValidSection.appendChild(l),this.entitiesSection.innerHTML="",this.plexValidSection.appendChild(this.entitiesSection),a)i.isString(this.config.entity)&&(this.config.entity=[this.config.entity]),i.isArray(this.config.entity)&&i.forEach(this.config.entity,(t=>{if(i.isString(t)){const i=e(t,this.valueUpdated);i&&this.entitiesSection.appendChild(i)}}));else{const t=document.createElement("div");t.innerHTML="Devices configuration is not available when using plexPlayer client device.
You can edit any other settings through UI and use Show code editor to edit entities.

If you are not using server settings for plexPlayer with identifier and server key, you can migrate your settings to UI by removing plexPlayer section and readd through UI.",this.plexValidSection.appendChild(t)}const h=document.createElement("h2");if(h.innerHTML="View Configuration",h.style.lineHeight="29px",h.style.marginBottom="0px",h.style.marginTop="20px",this.plexValidSection.appendChild(h),this.displayType.innerHTML="",this.displayType.style.width="100%",this.displayType.style.height="40px",this.displayType.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.generateTitle("Display Type (Optional)")),this.plexValidSection.appendChild(this.displayType),this.cardTitle.label="Card title (Optional)",this.cardTitle.value=this.config.title,this.cardTitle.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.cardTitle),this.maxCount.label="Maximum number of items to display (Optional)",this.maxCount.value=this.config.maxCount,this.maxCount.type="number",this.maxCount.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.maxCount),this.useHorizontalScroll.innerHTML="",this.plexValidSection.appendChild(this.generateTitle("Use horizontal scroll")),this.useHorizontalScroll.appendChild(t("Yes")),this.useHorizontalScroll.appendChild(t("No")),this.useHorizontalScroll.style.width="100%",this.useHorizontalScroll.style.height="40px",this.useHorizontalScroll.addEventListener("change",this.valueUpdated),i.isEmpty(this.config.useHorizontalScroll)?this.useHorizontalScroll.value="No":this.useHorizontalScroll.value=this.config.useHorizontalScroll,this.plexValidSection.appendChild(this.useHorizontalScroll),this.maxRows.label="Maximum number of rows to display (Optional)",this.maxRows.value=this.config.maxRows,this.maxRows.type="number",this.maxRows.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.maxRows),this.sort.innerHTML="",this.sort.style.width="100%",this.sort.style.height="40px",this.sort.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.generateTitle("Sort")),this.plexValidSection.appendChild(this.sort),this.sortOrder.innerHTML="",this.sortOrder.appendChild(t("Ascending")),this.sortOrder.appendChild(t("Descending")),this.plexValidSection.appendChild(this.generateTitle("Sort Order")),this.sortOrder.style.width="100%",this.sortOrder.style.height="40px",this.sortOrder.addEventListener("change",this.valueUpdated),i.isEmpty(this.config.sort))this.sortOrder.value="Ascending";else{const t=this.config.sort.split(":")[1];i.isEmpty(t)||i.isEqual(t,"asc")?this.sortOrder.value="Ascending":i.isEqual(t,"desc")&&(this.sortOrder.value="Descending")}this.plexValidSection.appendChild(this.sortOrder),this.plexValidSection.appendChild(this.generateTitle("Play Trailer")),this.playTrailer.innerHTML="",this.playTrailer.appendChild(t("Yes")),this.playTrailer.appendChild(t("Muted")),this.playTrailer.appendChild(t("No")),this.playTrailer.style.width="100%",this.playTrailer.style.height="40px",this.playTrailer.addEventListener("change",this.valueUpdated);let c="Yes";i.isEqual(this.config.playTrailer,"muted")?c="Muted":this.config.playTrailer||(c="No"),this.playTrailer.value=c,this.plexValidSection.appendChild(this.playTrailer),this.showExtras.innerHTML="",this.showExtras.appendChild(t("Yes")),this.showExtras.appendChild(t("No")),this.plexValidSection.appendChild(this.generateTitle("Show Extras")),this.showExtras.style.width="100%",this.showExtras.style.height="40px",this.showExtras.addEventListener("change",this.valueUpdated);let u="Yes";this.config.showExtras||(u="No"),this.showExtras.value=u,this.plexValidSection.appendChild(this.showExtras),this.showSearch.innerHTML="",this.showSearch.appendChild(t("Yes")),this.showSearch.appendChild(t("No")),this.plexValidSection.appendChild(this.generateTitle("Show Search")),this.showSearch.style.width="100%",this.showSearch.style.height="40px",this.showSearch.addEventListener("change",this.valueUpdated);let d="Yes";this.config.showSearch||(d="No"),this.showSearch.value=d,this.plexValidSection.appendChild(this.showSearch),this.runBefore.innerHTML="",this.runBefore.appendChild(t("")),i.forEach(this.scriptEntities,(e=>{this.runBefore.appendChild(t(e))})),this.plexValidSection.appendChild(this.generateTitle("Script to execute before starting the media (Optional)")),this.runBefore.style.width="100%",this.runBefore.style.height="40px",this.runBefore.addEventListener("change",this.valueUpdated),this.runBefore.value=this.config.runBefore,this.plexValidSection.appendChild(this.runBefore),this.runAfter.innerHTML="",this.runAfter.appendChild(t("")),i.forEach(this.scriptEntities,(e=>{this.runAfter.appendChild(t(e))})),this.plexValidSection.appendChild(this.generateTitle("Script to execute after starting the media (Optional)")),this.runAfter.style.width="100%",this.runAfter.style.height="40px",this.runAfter.addEventListener("change",this.valueUpdated),this.runAfter.value=this.config.runAfter,this.plexValidSection.appendChild(this.runAfter);const p=document.createElement("h2");if(p.innerHTML="Style Configuration",p.style.lineHeight="29px",p.style.marginBottom="0px",p.style.marginTop="20px",this.plexValidSection.appendChild(p),this.minWidth.label="Minimum width of the card (Optional)",this.minWidth.value=this.config.minWidth,this.minWidth.type="number",this.minWidth.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.minWidth),this.minExpandedWidth.label="Expanded width of the card (Optional)",this.minExpandedWidth.value=this.config.minExpandedWidth,this.minExpandedWidth.type="number",this.minExpandedWidth.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.minExpandedWidth),this.minExpandedHeight.label="Expanded height of the card (Optional)",this.minExpandedHeight.value=this.config.minExpandedHeight,this.minExpandedHeight.type="number",this.minExpandedHeight.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.minExpandedHeight),this.minEpisodeWidth.label="Minimum width of the episode card (Optional)",this.minEpisodeWidth.value=this.config.minEpisodeWidth,this.minEpisodeWidth.type="number",this.minEpisodeWidth.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.minEpisodeWidth),this.displayTitleMain.innerHTML="",this.displayTitleMain.appendChild(t("Yes")),this.displayTitleMain.appendChild(t("No")),this.plexValidSection.appendChild(this.generateTitle("Display title under poster")),this.displayTitleMain.style.width="100%",this.displayTitleMain.style.height="40px",this.displayTitleMain.addEventListener("change",this.valueUpdated),i.isEmpty(this.config.displayTitleMain)?this.displayTitleMain.value="Yes":this.displayTitleMain.value=this.config.displayTitleMain,this.plexValidSection.appendChild(this.displayTitleMain),this.fontSize1.label="Font size used in titles under cards (Optional)",this.fontSize1.value=this.config.fontSize1,this.fontSize1.type="number",this.fontSize1.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.fontSize1),this.displaySubtitleMain.innerHTML="",this.displaySubtitleMain.appendChild(t("Yes")),this.displaySubtitleMain.appendChild(t("No")),this.plexValidSection.appendChild(this.generateTitle("Display sub-title under poster")),this.displaySubtitleMain.style.width="100%",this.displaySubtitleMain.style.height="40px",this.displaySubtitleMain.addEventListener("change",this.valueUpdated),i.isEmpty(this.config.displaySubtitleMain)?this.displaySubtitleMain.value="Yes":this.displaySubtitleMain.value=this.config.displaySubtitleMain,this.plexValidSection.appendChild(this.displaySubtitleMain),this.fontSize2.label="Font size used in sub-titles under cards (Optional)",this.fontSize2.value=this.config.fontSize2,this.fontSize2.type="number",this.fontSize2.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.fontSize2),this.fontSize3.label="Font size used in title of the opened content (Optional)",this.fontSize3.value=this.config.fontSize3,this.fontSize3.type="number",this.fontSize3.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.fontSize3),this.fontSize4.label="Font size used in sub-titles, to-view count and description of the opened content (Optional)",this.fontSize4.value=this.config.fontSize4,this.fontSize4.type="number",this.fontSize4.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.fontSize4),i.isEmpty(this.livetv)||(this.libraryName.appendChild(t("Live TV","",!0)),i.forEach(i.keys(this.livetv),(e=>{i.isEqual(this.config.libraryName,e)&&(r.innerHTML=`Warning: ${this.config.libraryName} play action currently only supported with Kodi.
You might also need custom build of kodi-media-sensors, see detailed configuration for more information.`),this.libraryName.appendChild(t(e))}))),!i.isEmpty(this.sections)){this.libraryName.appendChild(t("Libraries","",!0)),i.forEach(this.sections,(e=>{this.libraryName.appendChild(t(e.title))})),i.isEmpty(this.collections)||(this.libraryName.appendChild(t("Collections","",!0)),i.forEach(this.collections,(e=>{this.libraryName.appendChild(t(e.title))}))),i.isEmpty(this.playlists)||(this.libraryName.appendChild(t("Playlists","",!0)),i.forEach(this.playlists,(e=>{this.libraryName.appendChild(t(e.title))}))),this.libraryName.disabled=!1,this.libraryName.value=this.config.libraryName;let e="";if(i.forEach(this.sections,(t=>{if(i.isEqual(t.title,this.libraryName.value))return e=t.key,!1})),i.isEmpty(e))this.displayType.style.display="none",this.config.displayType="",this.displayType.value="",this.sort.style.display="none",this.sortOrder.style.display="none",this.config.sort="";else{const n=await this.plex.getSectionData(e),s=i.get(n,"[0].Meta.Type");if(!i.isNil(s)&&s.length>1){let e=0;this.displayType.appendChild(t("",""));let r=!1;i.forEach(s,(s=>{if("track"!==s.type&&"episode"!==s.type&&("folder"!==s.type||"folder"===s.type&&i.isEqual(i.get(n,"[0].viewGroup"),"artist"))){let n=s.key.split("type=")[1];"folder"===s.type&&(n="folder"),i.isEqual(n,this.config.displayType)&&(r=!0),this.displayTypeData[s.title]=n,this.displayType.appendChild(t(s.title)),e+=1}})),e>1?(this.displayType.style.display="block",i.isEmpty(this.config.displayType)||!r?this.displayType.value="":i.forEach(this.displayTypeData,((t,e)=>{i.isEqual(t,this.config.displayType)&&(this.displayType.value=e)}))):(this.displayType.style.display="none",this.config.displayType="",this.displayType.value="")}else this.displayType.style.display="none",this.config.displayType="",this.displayType.value="";let r=0;this.config.displayType&&i.forEach(s,((t,e)=>{t.key.split("type=")[1]===parseInt(this.config.displayType,10)&&(r=parseInt(e,10))}));const a=i.get(n,`[0].Meta.Type[${r}].Sort`);!i.isNil(a)&&a.length>0&&"folder"!==this.config.displayType?(i.forEach(a,(e=>{this.sort.appendChild(t(e.key))})),this.sort.style.display="block",this.sortOrder.style.display="block"):(this.sort.style.display="none",this.sortOrder.style.display="none",this.config.sort="")}if(i.isEmpty(this.config.sort))this.sort.value="",this.sortOrder.value="";else{this.sort.value=this.config.sort.split(":")[0];const t=this.config.sort.split(":")[1];i.isEmpty(t)||i.isEqual(t,"asc")?this.sortOrder.value="Ascending":i.isEqual(t,"desc")&&(this.sortOrder.value="Descending")}this.plexValidSection.style.display="block"}this.loaded=!0,this.content.appendChild(this.plexValidSection)},this.setConfig=t=>{this.config=JSON.parse(JSON.stringify(t)),t.port&&!i.isEqual(t.port,"")?this.plexPort=t.port:this.plexPort=!1;const e=location.protocol;t.protocol?this.plexProtocol=t.protocol:i.isEqual(e,"http:")?this.config.protocol="http":this.config.protocol="https",t.sort||(this.config.sort="titleSort:asc"),t.displayType||(this.config.displayType=""),i.isNil(t.playTrailer)?this.config.playTrailer=!0:this.config.playTrailer=t.playTrailer,i.isNil(t.showExtras)?this.config.showExtras=!0:this.config.showExtras=t.showExtras,i.isNil(t.showSearch)?this.config.showSearch=!0:this.config.showSearch=t.showSearch,i.isNil(t.runBefore)||(this.config.runBefore=t.runBefore),i.isNil(t.runAfter)||(this.config.runAfter=t.runAfter),i.isNil(t.title)||(this.config.title=t.title),i.isNumber(this.config.maxCount)&&(this.config.maxCount=`${this.config.maxCount}`),i.isNumber(this.config.maxRows)&&(this.config.maxRows=`${this.config.maxRows}`),i.isNil(this.config.useHorizontalScroll)||(this.config.useHorizontalScroll=`${this.config.useHorizontalScroll}`),i.isNil(this.config.useShuffle)||(this.config.useShuffle=`${this.config.useShuffle}`),i.isNil(this.config.displayTitleMain)||(this.config.displayTitleMain=`${this.config.displayTitleMain}`),i.isNil(this.config.displaySubtitleMain)||(this.config.displaySubtitleMain=`${this.config.displaySubtitleMain}`),i.isNumber(this.config.minWidth)&&(this.config.minWidth=`${this.config.minWidth}`),i.isNumber(this.config.minEpisodeWidth)&&(this.config.minEpisodeWidth=`${this.config.minEpisodeWidth}`),i.isNumber(this.config.minExpandedWidth)&&(this.config.minExpandedWidth=`${this.config.minExpandedWidth}`),i.isNumber(this.config.fontSize1)&&(this.config.fontSize1=`${this.config.fontSize1}`),i.isNumber(this.config.fontSize2)&&(this.config.fontSize2=`${this.config.fontSize2}`),i.isNumber(this.config.fontSize3)&&(this.config.fontSize3=`${this.config.fontSize3}`),i.isNumber(this.config.fontSize4)&&(this.config.fontSize4=`${this.config.fontSize4}`),i.isNumber(this.config.minExpandedHeight)&&(this.config.minExpandedHeight=`${this.config.minExpandedHeight}`),this.render()},this.configChanged=t=>{const e=new Event("config-changed",{bubbles:!0,composed:!0});e.detail={config:t},this.dispatchEvent(e)}}set hass(t){this.hassObj=t}} +var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var e,i=(function(e,i){(function(){var n,s="Expected a function",r="__lodash_hash_undefined__",a="__lodash_placeholder__",o=16,l=32,h=64,c=128,u=256,d=1/0,p=9007199254740991,f=NaN,y=4294967295,m=[["ary",c],["bind",1],["bindKey",2],["curry",8],["curryRight",o],["flip",512],["partial",l],["partialRight",h],["rearg",u]],g="[object Arguments]",v="[object Array]",x="[object Boolean]",E="[object Date]",b="[object Error]",w="[object Function]",S="[object GeneratorFunction]",_="[object Map]",C="[object Number]",T="[object Object]",k="[object Promise]",z="[object RegExp]",L="[object Set]",$="[object String]",P="[object Symbol]",M="[object WeakMap]",N="[object ArrayBuffer]",I="[object DataView]",A="[object Float32Array]",R="[object Float64Array]",B="[object Int8Array]",H="[object Int16Array]",D="[object Int32Array]",q="[object Uint8Array]",U="[object Uint8ClampedArray]",O="[object Uint16Array]",W="[object Uint32Array]",j=/\b__p \+= '';/g,V=/\b(__p \+=) '' \+/g,F=/(__e\(.*?\)|\b__t\)) \+\n'';/g,X=/&(?:amp|lt|gt|quot|#39);/g,Y=/[&<>"']/g,K=RegExp(X.source),G=RegExp(Y.source),Z=/<%-([\s\S]+?)%>/g,J=/<%([\s\S]+?)%>/g,Q=/<%=([\s\S]+?)%>/g,tt=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,et=/^\w*$/,it=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,nt=/[\\^$.*+?()[\]{}|]/g,st=RegExp(nt.source),rt=/^\s+/,at=/\s/,ot=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,lt=/\{\n\/\* \[wrapped with (.+)\] \*/,ht=/,? & /,ct=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,ut=/[()=,{}\[\]\/\s]/,dt=/\\(\\)?/g,pt=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,ft=/\w*$/,yt=/^[-+]0x[0-9a-f]+$/i,mt=/^0b[01]+$/i,gt=/^\[object .+?Constructor\]$/,vt=/^0o[0-7]+$/i,xt=/^(?:0|[1-9]\d*)$/,Et=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,bt=/($^)/,wt=/['\n\r\u2028\u2029\\]/g,St="\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff",_t="\\u2700-\\u27bf",Ct="a-z\\xdf-\\xf6\\xf8-\\xff",Tt="A-Z\\xc0-\\xd6\\xd8-\\xde",kt="\\ufe0e\\ufe0f",zt="\\xac\\xb1\\xd7\\xf7\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf\\u2000-\\u206f \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",Lt="['’]",$t="[\\ud800-\\udfff]",Pt="["+zt+"]",Mt="["+St+"]",Nt="\\d+",It="[\\u2700-\\u27bf]",At="["+Ct+"]",Rt="[^\\ud800-\\udfff"+zt+Nt+_t+Ct+Tt+"]",Bt="\\ud83c[\\udffb-\\udfff]",Ht="[^\\ud800-\\udfff]",Dt="(?:\\ud83c[\\udde6-\\uddff]){2}",qt="[\\ud800-\\udbff][\\udc00-\\udfff]",Ut="["+Tt+"]",Ot="(?:"+At+"|"+Rt+")",Wt="(?:"+Ut+"|"+Rt+")",jt="(?:['’](?:d|ll|m|re|s|t|ve))?",Vt="(?:['’](?:D|LL|M|RE|S|T|VE))?",Ft="(?:"+Mt+"|"+Bt+")?",Xt="[\\ufe0e\\ufe0f]?",Yt=Xt+Ft+"(?:\\u200d(?:"+[Ht,Dt,qt].join("|")+")"+Xt+Ft+")*",Kt="(?:"+[It,Dt,qt].join("|")+")"+Yt,Gt="(?:"+[Ht+Mt+"?",Mt,Dt,qt,$t].join("|")+")",Zt=RegExp(Lt,"g"),Jt=RegExp(Mt,"g"),Qt=RegExp(Bt+"(?="+Bt+")|"+Gt+Yt,"g"),te=RegExp([Ut+"?"+At+"+"+jt+"(?="+[Pt,Ut,"$"].join("|")+")",Wt+"+"+Vt+"(?="+[Pt,Ut+Ot,"$"].join("|")+")",Ut+"?"+Ot+"+"+jt,Ut+"+"+Vt,"\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])","\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Nt,Kt].join("|"),"g"),ee=RegExp("[\\u200d\\ud800-\\udfff"+St+kt+"]"),ie=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,ne=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],se=-1,re={};re[A]=re[R]=re[B]=re[H]=re[D]=re[q]=re[U]=re[O]=re[W]=!0,re[g]=re[v]=re[N]=re[x]=re[I]=re[E]=re[b]=re[w]=re[_]=re[C]=re[T]=re[z]=re[L]=re[$]=re[M]=!1;var ae={};ae[g]=ae[v]=ae[N]=ae[I]=ae[x]=ae[E]=ae[A]=ae[R]=ae[B]=ae[H]=ae[D]=ae[_]=ae[C]=ae[T]=ae[z]=ae[L]=ae[$]=ae[P]=ae[q]=ae[U]=ae[O]=ae[W]=!0,ae[b]=ae[w]=ae[M]=!1;var oe={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},le=parseFloat,he=parseInt,ce="object"==typeof t&&t&&t.Object===Object&&t,ue="object"==typeof self&&self&&self.Object===Object&&self,de=ce||ue||Function("return this")(),pe=i&&!i.nodeType&&i,fe=pe&&e&&!e.nodeType&&e,ye=fe&&fe.exports===pe,me=ye&&ce.process,ge=function(){try{var t=fe&&fe.require&&fe.require("util").types;return t||me&&me.binding&&me.binding("util")}catch(t){}}(),ve=ge&&ge.isArrayBuffer,xe=ge&&ge.isDate,Ee=ge&&ge.isMap,be=ge&&ge.isRegExp,we=ge&&ge.isSet,Se=ge&&ge.isTypedArray;function _e(t,e,i){switch(i.length){case 0:return t.call(e);case 1:return t.call(e,i[0]);case 2:return t.call(e,i[0],i[1]);case 3:return t.call(e,i[0],i[1],i[2])}return t.apply(e,i)}function Ce(t,e,i,n){for(var s=-1,r=null==t?0:t.length;++s-1}function Pe(t,e,i){for(var n=-1,s=null==t?0:t.length;++n-1;);return i}function ti(t,e){for(var i=t.length;i--&&qe(e,t[i],0)>-1;);return i}function ei(t,e){for(var i=t.length,n=0;i--;)t[i]===e&&++n;return n}var ii=Ve({"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","Ç":"C","ç":"c","Ð":"D","ð":"d","È":"E","É":"E","Ê":"E","Ë":"E","è":"e","é":"e","ê":"e","ë":"e","Ì":"I","Í":"I","Î":"I","Ï":"I","ì":"i","í":"i","î":"i","ï":"i","Ñ":"N","ñ":"n","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","Ù":"U","Ú":"U","Û":"U","Ü":"U","ù":"u","ú":"u","û":"u","ü":"u","Ý":"Y","ý":"y","ÿ":"y","Æ":"Ae","æ":"ae","Þ":"Th","þ":"th","ß":"ss","Ā":"A","Ă":"A","Ą":"A","ā":"a","ă":"a","ą":"a","Ć":"C","Ĉ":"C","Ċ":"C","Č":"C","ć":"c","ĉ":"c","ċ":"c","č":"c","Ď":"D","Đ":"D","ď":"d","đ":"d","Ē":"E","Ĕ":"E","Ė":"E","Ę":"E","Ě":"E","ē":"e","ĕ":"e","ė":"e","ę":"e","ě":"e","Ĝ":"G","Ğ":"G","Ġ":"G","Ģ":"G","ĝ":"g","ğ":"g","ġ":"g","ģ":"g","Ĥ":"H","Ħ":"H","ĥ":"h","ħ":"h","Ĩ":"I","Ī":"I","Ĭ":"I","Į":"I","İ":"I","ĩ":"i","ī":"i","ĭ":"i","į":"i","ı":"i","Ĵ":"J","ĵ":"j","Ķ":"K","ķ":"k","ĸ":"k","Ĺ":"L","Ļ":"L","Ľ":"L","Ŀ":"L","Ł":"L","ĺ":"l","ļ":"l","ľ":"l","ŀ":"l","ł":"l","Ń":"N","Ņ":"N","Ň":"N","Ŋ":"N","ń":"n","ņ":"n","ň":"n","ŋ":"n","Ō":"O","Ŏ":"O","Ő":"O","ō":"o","ŏ":"o","ő":"o","Ŕ":"R","Ŗ":"R","Ř":"R","ŕ":"r","ŗ":"r","ř":"r","Ś":"S","Ŝ":"S","Ş":"S","Š":"S","ś":"s","ŝ":"s","ş":"s","š":"s","Ţ":"T","Ť":"T","Ŧ":"T","ţ":"t","ť":"t","ŧ":"t","Ũ":"U","Ū":"U","Ŭ":"U","Ů":"U","Ű":"U","Ų":"U","ũ":"u","ū":"u","ŭ":"u","ů":"u","ű":"u","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","Ż":"Z","Ž":"Z","ź":"z","ż":"z","ž":"z","IJ":"IJ","ij":"ij","Œ":"Oe","œ":"oe","ʼn":"'n","ſ":"s"}),ni=Ve({"&":"&","<":"<",">":">",'"':""","'":"'"});function si(t){return"\\"+oe[t]}function ri(t){return ee.test(t)}function ai(t){var e=-1,i=Array(t.size);return t.forEach((function(t,n){i[++e]=[n,t]})),i}function oi(t,e){return function(i){return t(e(i))}}function li(t,e){for(var i=-1,n=t.length,s=0,r=[];++i",""":'"',"'":"'"}),yi=function t(e){var i,at=(e=null==e?de:yi.defaults(de.Object(),e,yi.pick(de,ne))).Array,St=e.Date,_t=e.Error,Ct=e.Function,Tt=e.Math,kt=e.Object,zt=e.RegExp,Lt=e.String,$t=e.TypeError,Pt=at.prototype,Mt=Ct.prototype,Nt=kt.prototype,It=e["__core-js_shared__"],At=Mt.toString,Rt=Nt.hasOwnProperty,Bt=0,Ht=(i=/[^.]+$/.exec(It&&It.keys&&It.keys.IE_PROTO||""))?"Symbol(src)_1."+i:"",Dt=Nt.toString,qt=At.call(kt),Ut=de._,Ot=zt("^"+At.call(Rt).replace(nt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Wt=ye?e.Buffer:n,jt=e.Symbol,Vt=e.Uint8Array,Ft=Wt?Wt.allocUnsafe:n,Xt=oi(kt.getPrototypeOf,kt),Yt=kt.create,Kt=Nt.propertyIsEnumerable,Gt=Pt.splice,Qt=jt?jt.isConcatSpreadable:n,ee=jt?jt.iterator:n,oe=jt?jt.toStringTag:n,ce=function(){try{var t=pr(kt,"defineProperty");return t({},"",{}),t}catch(t){}}(),ue=e.clearTimeout!==de.clearTimeout&&e.clearTimeout,pe=St&&St.now!==de.Date.now&&St.now,fe=e.setTimeout!==de.setTimeout&&e.setTimeout,me=Tt.ceil,ge=Tt.floor,Be=kt.getOwnPropertySymbols,Ve=Wt?Wt.isBuffer:n,mi=e.isFinite,gi=Pt.join,vi=oi(kt.keys,kt),xi=Tt.max,Ei=Tt.min,bi=St.now,wi=e.parseInt,Si=Tt.random,_i=Pt.reverse,Ci=pr(e,"DataView"),Ti=pr(e,"Map"),ki=pr(e,"Promise"),zi=pr(e,"Set"),Li=pr(e,"WeakMap"),$i=pr(kt,"create"),Pi=Li&&new Li,Mi={},Ni=qr(Ci),Ii=qr(Ti),Ai=qr(ki),Ri=qr(zi),Bi=qr(Li),Hi=jt?jt.prototype:n,Di=Hi?Hi.valueOf:n,qi=Hi?Hi.toString:n;function Ui(t){if(no(t)&&!Fa(t)&&!(t instanceof Vi)){if(t instanceof ji)return t;if(Rt.call(t,"__wrapped__"))return Ur(t)}return new ji(t)}var Oi=function(){function t(){}return function(e){if(!io(e))return{};if(Yt)return Yt(e);t.prototype=e;var i=new t;return t.prototype=n,i}}();function Wi(){}function ji(t,e){this.__wrapped__=t,this.__actions__=[],this.__chain__=!!e,this.__index__=0,this.__values__=n}function Vi(t){this.__wrapped__=t,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=y,this.__views__=[]}function Fi(t){var e=-1,i=null==t?0:t.length;for(this.clear();++e=e?t:e)),t}function cn(t,e,i,s,r,a){var o,l=1&e,h=2&e,c=4&e;if(i&&(o=r?i(t,s,r,a):i(t)),o!==n)return o;if(!io(t))return t;var u=Fa(t);if(u){if(o=function(t){var e=t.length,i=new t.constructor(e);return e&&"string"==typeof t[0]&&Rt.call(t,"index")&&(i.index=t.index,i.input=t.input),i}(t),!l)return Ps(t,o)}else{var d=mr(t),p=d==w||d==S;if(Ga(t))return Cs(t,l);if(d==T||d==g||p&&!r){if(o=h||p?{}:vr(t),!l)return h?function(t,e){return Ms(t,yr(t),e)}(t,function(t,e){return t&&Ms(e,Ao(e),t)}(o,t)):function(t,e){return Ms(t,fr(t),e)}(t,an(o,t))}else{if(!ae[d])return r?t:{};o=function(t,e,i){var n,s=t.constructor;switch(e){case N:return Ts(t);case x:case E:return new s(+t);case I:return function(t,e){var i=e?Ts(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.byteLength)}(t,i);case A:case R:case B:case H:case D:case q:case U:case O:case W:return ks(t,i);case _:return new s;case C:case $:return new s(t);case z:return function(t){var e=new t.constructor(t.source,ft.exec(t));return e.lastIndex=t.lastIndex,e}(t);case L:return new s;case P:return n=t,Di?kt(Di.call(n)):{}}}(t,d,l)}}a||(a=new Gi);var f=a.get(t);if(f)return f;a.set(t,o),lo(t)?t.forEach((function(n){o.add(cn(n,e,i,n,t,a))})):so(t)&&t.forEach((function(n,s){o.set(s,cn(n,e,i,s,t,a))}));var y=u?n:(c?h?ar:rr:h?Ao:Io)(t);return Te(y||t,(function(n,s){y&&(n=t[s=n]),nn(o,s,cn(n,e,i,s,t,a))})),o}function un(t,e,i){var s=i.length;if(null==t)return!s;for(t=kt(t);s--;){var r=i[s],a=e[r],o=t[r];if(o===n&&!(r in t)||!a(o))return!1}return!0}function dn(t,e,i){if("function"!=typeof t)throw new $t(s);return Nr((function(){t.apply(n,i)}),e)}function pn(t,e,i,n){var s=-1,r=$e,a=!0,o=t.length,l=[],h=e.length;if(!o)return l;i&&(e=Me(e,Ge(i))),n?(r=Pe,a=!1):e.length>=200&&(r=Je,a=!1,e=new Ki(e));t:for(;++s-1},Xi.prototype.set=function(t,e){var i=this.__data__,n=sn(i,t);return n<0?(++this.size,i.push([t,e])):i[n][1]=e,this},Yi.prototype.clear=function(){this.size=0,this.__data__={hash:new Fi,map:new(Ti||Xi),string:new Fi}},Yi.prototype.delete=function(t){var e=ur(this,t).delete(t);return this.size-=e?1:0,e},Yi.prototype.get=function(t){return ur(this,t).get(t)},Yi.prototype.has=function(t){return ur(this,t).has(t)},Yi.prototype.set=function(t,e){var i=ur(this,t),n=i.size;return i.set(t,e),this.size+=i.size==n?0:1,this},Ki.prototype.add=Ki.prototype.push=function(t){return this.__data__.set(t,r),this},Ki.prototype.has=function(t){return this.__data__.has(t)},Gi.prototype.clear=function(){this.__data__=new Xi,this.size=0},Gi.prototype.delete=function(t){var e=this.__data__,i=e.delete(t);return this.size=e.size,i},Gi.prototype.get=function(t){return this.__data__.get(t)},Gi.prototype.has=function(t){return this.__data__.has(t)},Gi.prototype.set=function(t,e){var i=this.__data__;if(i instanceof Xi){var n=i.__data__;if(!Ti||n.length<199)return n.push([t,e]),this.size=++i.size,this;i=this.__data__=new Yi(n)}return i.set(t,e),this.size=i.size,this};var fn=As(wn),yn=As(Sn,!0);function mn(t,e){var i=!0;return fn(t,(function(t,n,s){return i=!!e(t,n,s)})),i}function gn(t,e,i){for(var s=-1,r=t.length;++s0&&i(o)?e>1?xn(o,e-1,i,n,s):Ne(s,o):n||(s[s.length]=o)}return s}var En=Rs(),bn=Rs(!0);function wn(t,e){return t&&En(t,e,Io)}function Sn(t,e){return t&&bn(t,e,Io)}function _n(t,e){return Le(e,(function(e){return Qa(t[e])}))}function Cn(t,e){for(var i=0,s=(e=bs(e,t)).length;null!=t&&ie}function Ln(t,e){return null!=t&&Rt.call(t,e)}function $n(t,e){return null!=t&&e in kt(t)}function Pn(t,e,i){for(var s=i?Pe:$e,r=t[0].length,a=t.length,o=a,l=at(a),h=1/0,c=[];o--;){var u=t[o];o&&e&&(u=Me(u,Ge(e))),h=Ei(u.length,h),l[o]=!i&&(e||r>=120&&u.length>=120)?new Ki(o&&u):n}u=t[0];var d=-1,p=l[0];t:for(;++d=o?l:l*("desc"==i[n]?-1:1)}return t.index-e.index}(t,e,i)}))}function Xn(t,e,i){for(var n=-1,s=e.length,r={};++n-1;)o!==t&&Gt.call(o,l,1),Gt.call(t,l,1);return t}function Kn(t,e){for(var i=t?e.length:0,n=i-1;i--;){var s=e[i];if(i==n||s!==r){var r=s;Er(s)?Gt.call(t,s,1):ps(t,s)}}return t}function Gn(t,e){return t+ge(Si()*(e-t+1))}function Zn(t,e){var i="";if(!t||e<1||e>p)return i;do{e%2&&(i+=t),(e=ge(e/2))&&(t+=t)}while(e);return i}function Jn(t,e){return Ir(zr(t,e,al),t+"")}function Qn(t){return Ji(Wo(t))}function ts(t,e){var i=Wo(t);return Br(i,hn(e,0,i.length))}function es(t,e,i,s){if(!io(t))return t;for(var r=-1,a=(e=bs(e,t)).length,o=a-1,l=t;null!=l&&++rs?0:s+e),(i=i>s?s:i)<0&&(i+=s),s=e>i?0:i-e>>>0,e>>>=0;for(var r=at(s);++n>>1,a=t[r];null!==a&&!co(a)&&(i?a<=e:a=200){var h=e?null:Zs(t);if(h)return hi(h);a=!1,s=Je,l=new Ki}else l=e?[]:o;t:for(;++n=s?t:rs(t,e,i)}var _s=ue||function(t){return de.clearTimeout(t)};function Cs(t,e){if(e)return t.slice();var i=t.length,n=Ft?Ft(i):new t.constructor(i);return t.copy(n),n}function Ts(t){var e=new t.constructor(t.byteLength);return new Vt(e).set(new Vt(t)),e}function ks(t,e){var i=e?Ts(t.buffer):t.buffer;return new t.constructor(i,t.byteOffset,t.length)}function zs(t,e){if(t!==e){var i=t!==n,s=null===t,r=t==t,a=co(t),o=e!==n,l=null===e,h=e==e,c=co(e);if(!l&&!c&&!a&&t>e||a&&o&&h&&!l&&!c||s&&o&&h||!i&&h||!r)return 1;if(!s&&!a&&!c&&t1?i[r-1]:n,o=r>2?i[2]:n;for(a=t.length>3&&"function"==typeof a?(r--,a):n,o&&br(i[0],i[1],o)&&(a=r<3?n:a,r=1),e=kt(e);++s-1?r[a?e[o]:o]:n}}function Us(t){return sr((function(e){var i=e.length,r=i,a=ji.prototype.thru;for(t&&e.reverse();r--;){var o=e[r];if("function"!=typeof o)throw new $t(s);if(a&&!l&&"wrapper"==lr(o))var l=new ji([],!0)}for(r=l?r:i;++r1&&v.reverse(),d&&hl))return!1;var c=a.get(t),u=a.get(e);if(c&&u)return c==e&&u==t;var d=-1,p=!0,f=2&i?new Ki:n;for(a.set(t,e),a.set(e,t);++d-1&&t%1==0&&t1?"& ":"")+e[n],e=e.join(i>2?", ":" "),t.replace(ot,"{\n/* [wrapped with "+e+"] */\n")}(n,function(t,e){return Te(m,(function(i){var n="_."+i[0];e&i[1]&&!$e(t,n)&&t.push(n)})),t.sort()}(function(t){var e=t.match(lt);return e?e[1].split(ht):[]}(n),i)))}function Rr(t){var e=0,i=0;return function(){var s=bi(),r=16-(s-i);if(i=s,r>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(n,arguments)}}function Br(t,e){var i=-1,s=t.length,r=s-1;for(e=e===n?s:e;++i1?t[e-1]:n;return i="function"==typeof i?(t.pop(),i):n,oa(t,i)}));function fa(t){var e=Ui(t);return e.__chain__=!0,e}function ya(t,e){return e(t)}var ma=sr((function(t){var e=t.length,i=e?t[0]:0,s=this.__wrapped__,r=function(e){return ln(e,t)};return!(e>1||this.__actions__.length)&&s instanceof Vi&&Er(i)?((s=s.slice(i,+i+(e?1:0))).__actions__.push({func:ya,args:[r],thisArg:n}),new ji(s,this.__chain__).thru((function(t){return e&&!t.length&&t.push(n),t}))):this.thru(r)})),ga=Ns((function(t,e,i){Rt.call(t,i)?++t[i]:on(t,i,1)})),va=qs(Vr),xa=qs(Fr);function Ea(t,e){return(Fa(t)?Te:fn)(t,cr(e,3))}function ba(t,e){return(Fa(t)?ke:yn)(t,cr(e,3))}var wa=Ns((function(t,e,i){Rt.call(t,i)?t[i].push(e):on(t,i,[e])})),Sa=Jn((function(t,e,i){var n=-1,s="function"==typeof e,r=Ya(t)?at(t.length):[];return fn(t,(function(t){r[++n]=s?_e(e,t,i):Mn(t,e,i)})),r})),_a=Ns((function(t,e,i){on(t,i,e)}));function Ca(t,e){return(Fa(t)?Me:Un)(t,cr(e,3))}var Ta=Ns((function(t,e,i){t[i?0:1].push(e)}),(function(){return[[],[]]})),ka=Jn((function(t,e){if(null==t)return[];var i=e.length;return i>1&&br(t,e[0],e[1])?e=[]:i>2&&br(e[0],e[1],e[2])&&(e=[e[0]]),Fn(t,xn(e,1),[])})),za=pe||function(){return de.Date.now()};function La(t,e,i){return e=i?n:e,e=t&&null==e?t.length:e,Qs(t,c,n,n,n,n,e)}function $a(t,e){var i;if("function"!=typeof e)throw new $t(s);return t=go(t),function(){return--t>0&&(i=e.apply(this,arguments)),t<=1&&(e=n),i}}var Pa=Jn((function(t,e,i){var n=1;if(i.length){var s=li(i,hr(Pa));n|=l}return Qs(t,n,e,i,s)})),Ma=Jn((function(t,e,i){var n=3;if(i.length){var s=li(i,hr(Ma));n|=l}return Qs(e,n,t,i,s)}));function Na(t,e,i){var r,a,o,l,h,c,u=0,d=!1,p=!1,f=!0;if("function"!=typeof t)throw new $t(s);function y(e){var i=r,s=a;return r=a=n,u=e,l=t.apply(s,i)}function m(t){return u=t,h=Nr(v,e),d?y(t):l}function g(t){var i=t-c;return c===n||i>=e||i<0||p&&t-u>=o}function v(){var t=za();if(g(t))return x(t);h=Nr(v,function(t){var i=e-(t-c);return p?Ei(i,o-(t-u)):i}(t))}function x(t){return h=n,f&&r?y(t):(r=a=n,l)}function E(){var t=za(),i=g(t);if(r=arguments,a=this,c=t,i){if(h===n)return m(c);if(p)return _s(h),h=Nr(v,e),y(c)}return h===n&&(h=Nr(v,e)),l}return e=xo(e)||0,io(i)&&(d=!!i.leading,o=(p="maxWait"in i)?xi(xo(i.maxWait)||0,e):o,f="trailing"in i?!!i.trailing:f),E.cancel=function(){h!==n&&_s(h),u=0,r=c=a=h=n},E.flush=function(){return h===n?l:x(za())},E}var Ia=Jn((function(t,e){return dn(t,1,e)})),Aa=Jn((function(t,e,i){return dn(t,xo(e)||0,i)}));function Ra(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new $t(s);var i=function(){var n=arguments,s=e?e.apply(this,n):n[0],r=i.cache;if(r.has(s))return r.get(s);var a=t.apply(this,n);return i.cache=r.set(s,a)||r,a};return i.cache=new(Ra.Cache||Yi),i}function Ba(t){if("function"!=typeof t)throw new $t(s);return function(){var e=arguments;switch(e.length){case 0:return!t.call(this);case 1:return!t.call(this,e[0]);case 2:return!t.call(this,e[0],e[1]);case 3:return!t.call(this,e[0],e[1],e[2])}return!t.apply(this,e)}}Ra.Cache=Yi;var Ha=ws((function(t,e){var i=(e=1==e.length&&Fa(e[0])?Me(e[0],Ge(cr())):Me(xn(e,1),Ge(cr()))).length;return Jn((function(n){for(var s=-1,r=Ei(n.length,i);++s=e})),Va=Nn(function(){return arguments}())?Nn:function(t){return no(t)&&Rt.call(t,"callee")&&!Kt.call(t,"callee")},Fa=at.isArray,Xa=ve?Ge(ve):function(t){return no(t)&&kn(t)==N};function Ya(t){return null!=t&&eo(t.length)&&!Qa(t)}function Ka(t){return no(t)&&Ya(t)}var Ga=Ve||xl,Za=xe?Ge(xe):function(t){return no(t)&&kn(t)==E};function Ja(t){if(!no(t))return!1;var e=kn(t);return e==b||"[object DOMException]"==e||"string"==typeof t.message&&"string"==typeof t.name&&!ao(t)}function Qa(t){if(!io(t))return!1;var e=kn(t);return e==w||e==S||"[object AsyncFunction]"==e||"[object Proxy]"==e}function to(t){return"number"==typeof t&&t==go(t)}function eo(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=p}function io(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function no(t){return null!=t&&"object"==typeof t}var so=Ee?Ge(Ee):function(t){return no(t)&&mr(t)==_};function ro(t){return"number"==typeof t||no(t)&&kn(t)==C}function ao(t){if(!no(t)||kn(t)!=T)return!1;var e=Xt(t);if(null===e)return!0;var i=Rt.call(e,"constructor")&&e.constructor;return"function"==typeof i&&i instanceof i&&At.call(i)==qt}var oo=be?Ge(be):function(t){return no(t)&&kn(t)==z},lo=we?Ge(we):function(t){return no(t)&&mr(t)==L};function ho(t){return"string"==typeof t||!Fa(t)&&no(t)&&kn(t)==$}function co(t){return"symbol"==typeof t||no(t)&&kn(t)==P}var uo=Se?Ge(Se):function(t){return no(t)&&eo(t.length)&&!!re[kn(t)]},po=Ys(qn),fo=Ys((function(t,e){return t<=e}));function yo(t){if(!t)return[];if(Ya(t))return ho(t)?di(t):Ps(t);if(ee&&t[ee])return function(t){for(var e,i=[];!(e=t.next()).done;)i.push(e.value);return i}(t[ee]());var e=mr(t);return(e==_?ai:e==L?hi:Wo)(t)}function mo(t){return t?(t=xo(t))===d||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function go(t){var e=mo(t),i=e%1;return e==e?i?e-i:e:0}function vo(t){return t?hn(go(t),0,y):0}function xo(t){if("number"==typeof t)return t;if(co(t))return f;if(io(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=io(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Ke(t);var i=mt.test(t);return i||vt.test(t)?he(t.slice(2),i?2:8):yt.test(t)?f:+t}function Eo(t){return Ms(t,Ao(t))}function bo(t){return null==t?"":us(t)}var wo=Is((function(t,e){if(Cr(e)||Ya(e))Ms(e,Io(e),t);else for(var i in e)Rt.call(e,i)&&nn(t,i,e[i])})),So=Is((function(t,e){Ms(e,Ao(e),t)})),_o=Is((function(t,e,i,n){Ms(e,Ao(e),t,n)})),Co=Is((function(t,e,i,n){Ms(e,Io(e),t,n)})),To=sr(ln),ko=Jn((function(t,e){t=kt(t);var i=-1,s=e.length,r=s>2?e[2]:n;for(r&&br(e[0],e[1],r)&&(s=1);++i1),e})),Ms(t,ar(t),i),n&&(i=cn(i,7,ir));for(var s=e.length;s--;)ps(i,e[s]);return i})),Do=sr((function(t,e){return null==t?{}:function(t,e){return Xn(t,e,(function(e,i){return $o(t,i)}))}(t,e)}));function qo(t,e){if(null==t)return{};var i=Me(ar(t),(function(t){return[t]}));return e=cr(e),Xn(t,i,(function(t,i){return e(t,i[0])}))}var Uo=Js(Io),Oo=Js(Ao);function Wo(t){return null==t?[]:Ze(t,Io(t))}var jo=Hs((function(t,e,i){return e=e.toLowerCase(),t+(i?Vo(e):e)}));function Vo(t){return Qo(bo(t).toLowerCase())}function Fo(t){return(t=bo(t))&&t.replace(Et,ii).replace(Jt,"")}var Xo=Hs((function(t,e,i){return t+(i?"-":"")+e.toLowerCase()})),Yo=Hs((function(t,e,i){return t+(i?" ":"")+e.toLowerCase()})),Ko=Bs("toLowerCase"),Go=Hs((function(t,e,i){return t+(i?"_":"")+e.toLowerCase()})),Zo=Hs((function(t,e,i){return t+(i?" ":"")+Qo(e)})),Jo=Hs((function(t,e,i){return t+(i?" ":"")+e.toUpperCase()})),Qo=Bs("toUpperCase");function tl(t,e,i){return t=bo(t),(e=i?n:e)===n?function(t){return ie.test(t)}(t)?function(t){return t.match(te)||[]}(t):function(t){return t.match(ct)||[]}(t):t.match(e)||[]}var el=Jn((function(t,e){try{return _e(t,n,e)}catch(t){return Ja(t)?t:new _t(t)}})),il=sr((function(t,e){return Te(e,(function(e){e=Dr(e),on(t,e,Pa(t[e],t))})),t}));function nl(t){return function(){return t}}var sl=Us(),rl=Us(!0);function al(t){return t}function ol(t){return Bn("function"==typeof t?t:cn(t,1))}var ll=Jn((function(t,e){return function(i){return Mn(i,t,e)}})),hl=Jn((function(t,e){return function(i){return Mn(t,i,e)}}));function cl(t,e,i){var n=Io(e),s=_n(e,n);null!=i||io(e)&&(s.length||!n.length)||(i=e,e=t,t=this,s=_n(e,Io(e)));var r=!(io(i)&&"chain"in i&&!i.chain),a=Qa(t);return Te(s,(function(i){var n=e[i];t[i]=n,a&&(t.prototype[i]=function(){var e=this.__chain__;if(r||e){var i=t(this.__wrapped__),s=i.__actions__=Ps(this.__actions__);return s.push({func:n,args:arguments,thisArg:t}),i.__chain__=e,i}return n.apply(t,Ne([this.value()],arguments))})})),t}function ul(){}var dl=Vs(Me),pl=Vs(ze),fl=Vs(Re);function yl(t){return wr(t)?je(Dr(t)):function(t){return function(e){return Cn(e,t)}}(t)}var ml=Xs(),gl=Xs(!0);function vl(){return[]}function xl(){return!1}var El,bl=js((function(t,e){return t+e}),0),wl=Gs("ceil"),Sl=js((function(t,e){return t/e}),1),_l=Gs("floor"),Cl=js((function(t,e){return t*e}),1),Tl=Gs("round"),kl=js((function(t,e){return t-e}),0);return Ui.after=function(t,e){if("function"!=typeof e)throw new $t(s);return t=go(t),function(){if(--t<1)return e.apply(this,arguments)}},Ui.ary=La,Ui.assign=wo,Ui.assignIn=So,Ui.assignInWith=_o,Ui.assignWith=Co,Ui.at=To,Ui.before=$a,Ui.bind=Pa,Ui.bindAll=il,Ui.bindKey=Ma,Ui.castArray=function(){if(!arguments.length)return[];var t=arguments[0];return Fa(t)?t:[t]},Ui.chain=fa,Ui.chunk=function(t,e,i){e=(i?br(t,e,i):e===n)?1:xi(go(e),0);var s=null==t?0:t.length;if(!s||e<1)return[];for(var r=0,a=0,o=at(me(s/e));rr?0:r+i),(s=s===n||s>r?r:go(s))<0&&(s+=r),s=i>s?0:vo(s);i>>0)?(t=bo(t))&&("string"==typeof e||null!=e&&!oo(e))&&!(e=us(e))&&ri(t)?Ss(di(t),0,i):t.split(e,i):[]},Ui.spread=function(t,e){if("function"!=typeof t)throw new $t(s);return e=null==e?0:xi(go(e),0),Jn((function(i){var n=i[e],s=Ss(i,0,e);return n&&Ne(s,n),_e(t,this,s)}))},Ui.tail=function(t){var e=null==t?0:t.length;return e?rs(t,1,e):[]},Ui.take=function(t,e,i){return t&&t.length?rs(t,0,(e=i||e===n?1:go(e))<0?0:e):[]},Ui.takeRight=function(t,e,i){var s=null==t?0:t.length;return s?rs(t,(e=s-(e=i||e===n?1:go(e)))<0?0:e,s):[]},Ui.takeRightWhile=function(t,e){return t&&t.length?ys(t,cr(e,3),!1,!0):[]},Ui.takeWhile=function(t,e){return t&&t.length?ys(t,cr(e,3)):[]},Ui.tap=function(t,e){return e(t),t},Ui.throttle=function(t,e,i){var n=!0,r=!0;if("function"!=typeof t)throw new $t(s);return io(i)&&(n="leading"in i?!!i.leading:n,r="trailing"in i?!!i.trailing:r),Na(t,e,{leading:n,maxWait:e,trailing:r})},Ui.thru=ya,Ui.toArray=yo,Ui.toPairs=Uo,Ui.toPairsIn=Oo,Ui.toPath=function(t){return Fa(t)?Me(t,Dr):co(t)?[t]:Ps(Hr(bo(t)))},Ui.toPlainObject=Eo,Ui.transform=function(t,e,i){var n=Fa(t),s=n||Ga(t)||uo(t);if(e=cr(e,4),null==i){var r=t&&t.constructor;i=s?n?new r:[]:io(t)&&Qa(r)?Oi(Xt(t)):{}}return(s?Te:wn)(t,(function(t,n,s){return e(i,t,n,s)})),i},Ui.unary=function(t){return La(t,1)},Ui.union=na,Ui.unionBy=sa,Ui.unionWith=ra,Ui.uniq=function(t){return t&&t.length?ds(t):[]},Ui.uniqBy=function(t,e){return t&&t.length?ds(t,cr(e,2)):[]},Ui.uniqWith=function(t,e){return e="function"==typeof e?e:n,t&&t.length?ds(t,n,e):[]},Ui.unset=function(t,e){return null==t||ps(t,e)},Ui.unzip=aa,Ui.unzipWith=oa,Ui.update=function(t,e,i){return null==t?t:fs(t,e,Es(i))},Ui.updateWith=function(t,e,i,s){return s="function"==typeof s?s:n,null==t?t:fs(t,e,Es(i),s)},Ui.values=Wo,Ui.valuesIn=function(t){return null==t?[]:Ze(t,Ao(t))},Ui.without=la,Ui.words=tl,Ui.wrap=function(t,e){return Da(Es(e),t)},Ui.xor=ha,Ui.xorBy=ca,Ui.xorWith=ua,Ui.zip=da,Ui.zipObject=function(t,e){return vs(t||[],e||[],nn)},Ui.zipObjectDeep=function(t,e){return vs(t||[],e||[],es)},Ui.zipWith=pa,Ui.entries=Uo,Ui.entriesIn=Oo,Ui.extend=So,Ui.extendWith=_o,cl(Ui,Ui),Ui.add=bl,Ui.attempt=el,Ui.camelCase=jo,Ui.capitalize=Vo,Ui.ceil=wl,Ui.clamp=function(t,e,i){return i===n&&(i=e,e=n),i!==n&&(i=(i=xo(i))==i?i:0),e!==n&&(e=(e=xo(e))==e?e:0),hn(xo(t),e,i)},Ui.clone=function(t){return cn(t,4)},Ui.cloneDeep=function(t){return cn(t,5)},Ui.cloneDeepWith=function(t,e){return cn(t,5,e="function"==typeof e?e:n)},Ui.cloneWith=function(t,e){return cn(t,4,e="function"==typeof e?e:n)},Ui.conformsTo=function(t,e){return null==e||un(t,e,Io(e))},Ui.deburr=Fo,Ui.defaultTo=function(t,e){return null==t||t!=t?e:t},Ui.divide=Sl,Ui.endsWith=function(t,e,i){t=bo(t),e=us(e);var s=t.length,r=i=i===n?s:hn(go(i),0,s);return(i-=e.length)>=0&&t.slice(i,r)==e},Ui.eq=Oa,Ui.escape=function(t){return(t=bo(t))&&G.test(t)?t.replace(Y,ni):t},Ui.escapeRegExp=function(t){return(t=bo(t))&&st.test(t)?t.replace(nt,"\\$&"):t},Ui.every=function(t,e,i){var s=Fa(t)?ze:mn;return i&&br(t,e,i)&&(e=n),s(t,cr(e,3))},Ui.find=va,Ui.findIndex=Vr,Ui.findKey=function(t,e){return He(t,cr(e,3),wn)},Ui.findLast=xa,Ui.findLastIndex=Fr,Ui.findLastKey=function(t,e){return He(t,cr(e,3),Sn)},Ui.floor=_l,Ui.forEach=Ea,Ui.forEachRight=ba,Ui.forIn=function(t,e){return null==t?t:En(t,cr(e,3),Ao)},Ui.forInRight=function(t,e){return null==t?t:bn(t,cr(e,3),Ao)},Ui.forOwn=function(t,e){return t&&wn(t,cr(e,3))},Ui.forOwnRight=function(t,e){return t&&Sn(t,cr(e,3))},Ui.get=Lo,Ui.gt=Wa,Ui.gte=ja,Ui.has=function(t,e){return null!=t&&gr(t,e,Ln)},Ui.hasIn=$o,Ui.head=Yr,Ui.identity=al,Ui.includes=function(t,e,i,n){t=Ya(t)?t:Wo(t),i=i&&!n?go(i):0;var s=t.length;return i<0&&(i=xi(s+i,0)),ho(t)?i<=s&&t.indexOf(e,i)>-1:!!s&&qe(t,e,i)>-1},Ui.indexOf=function(t,e,i){var n=null==t?0:t.length;if(!n)return-1;var s=null==i?0:go(i);return s<0&&(s=xi(n+s,0)),qe(t,e,s)},Ui.inRange=function(t,e,i){return e=mo(e),i===n?(i=e,e=0):i=mo(i),function(t,e,i){return t>=Ei(e,i)&&t=-9007199254740991&&t<=p},Ui.isSet=lo,Ui.isString=ho,Ui.isSymbol=co,Ui.isTypedArray=uo,Ui.isUndefined=function(t){return t===n},Ui.isWeakMap=function(t){return no(t)&&mr(t)==M},Ui.isWeakSet=function(t){return no(t)&&"[object WeakSet]"==kn(t)},Ui.join=function(t,e){return null==t?"":gi.call(t,e)},Ui.kebabCase=Xo,Ui.last=Jr,Ui.lastIndexOf=function(t,e,i){var s=null==t?0:t.length;if(!s)return-1;var r=s;return i!==n&&(r=(r=go(i))<0?xi(s+r,0):Ei(r,s-1)),e==e?function(t,e,i){for(var n=i+1;n--;)if(t[n]===e)return n;return n}(t,e,r):De(t,Oe,r,!0)},Ui.lowerCase=Yo,Ui.lowerFirst=Ko,Ui.lt=po,Ui.lte=fo,Ui.max=function(t){return t&&t.length?gn(t,al,zn):n},Ui.maxBy=function(t,e){return t&&t.length?gn(t,cr(e,2),zn):n},Ui.mean=function(t){return We(t,al)},Ui.meanBy=function(t,e){return We(t,cr(e,2))},Ui.min=function(t){return t&&t.length?gn(t,al,qn):n},Ui.minBy=function(t,e){return t&&t.length?gn(t,cr(e,2),qn):n},Ui.stubArray=vl,Ui.stubFalse=xl,Ui.stubObject=function(){return{}},Ui.stubString=function(){return""},Ui.stubTrue=function(){return!0},Ui.multiply=Cl,Ui.nth=function(t,e){return t&&t.length?Vn(t,go(e)):n},Ui.noConflict=function(){return de._===this&&(de._=Ut),this},Ui.noop=ul,Ui.now=za,Ui.pad=function(t,e,i){t=bo(t);var n=(e=go(e))?ui(t):0;if(!e||n>=e)return t;var s=(e-n)/2;return Fs(ge(s),i)+t+Fs(me(s),i)},Ui.padEnd=function(t,e,i){t=bo(t);var n=(e=go(e))?ui(t):0;return e&&ne){var s=t;t=e,e=s}if(i||t%1||e%1){var r=Si();return Ei(t+r*(e-t+le("1e-"+((r+"").length-1))),e)}return Gn(t,e)},Ui.reduce=function(t,e,i){var n=Fa(t)?Ie:Fe,s=arguments.length<3;return n(t,cr(e,4),i,s,fn)},Ui.reduceRight=function(t,e,i){var n=Fa(t)?Ae:Fe,s=arguments.length<3;return n(t,cr(e,4),i,s,yn)},Ui.repeat=function(t,e,i){return e=(i?br(t,e,i):e===n)?1:go(e),Zn(bo(t),e)},Ui.replace=function(){var t=arguments,e=bo(t[0]);return t.length<3?e:e.replace(t[1],t[2])},Ui.result=function(t,e,i){var s=-1,r=(e=bs(e,t)).length;for(r||(r=1,t=n);++sp)return[];var i=y,n=Ei(t,y);e=cr(e),t-=y;for(var s=Ye(n,e);++i=a)return t;var l=i-ui(s);if(l<1)return s;var h=o?Ss(o,0,l).join(""):t.slice(0,l);if(r===n)return h+s;if(o&&(l+=h.length-l),oo(r)){if(t.slice(l).search(r)){var c,u=h;for(r.global||(r=zt(r.source,bo(ft.exec(r))+"g")),r.lastIndex=0;c=r.exec(u);)var d=c.index;h=h.slice(0,d===n?l:d)}}else if(t.indexOf(us(r),l)!=l){var p=h.lastIndexOf(r);p>-1&&(h=h.slice(0,p))}return h+s},Ui.unescape=function(t){return(t=bo(t))&&K.test(t)?t.replace(X,fi):t},Ui.uniqueId=function(t){var e=++Bt;return bo(t)+e},Ui.upperCase=Jo,Ui.upperFirst=Qo,Ui.each=Ea,Ui.eachRight=ba,Ui.first=Yr,cl(Ui,(El={},wn(Ui,(function(t,e){Rt.call(Ui.prototype,e)||(El[e]=t)})),El),{chain:!1}),Ui.VERSION="4.17.21",Te(["bind","bindKey","curry","curryRight","partial","partialRight"],(function(t){Ui[t].placeholder=Ui})),Te(["drop","take"],(function(t,e){Vi.prototype[t]=function(i){i=i===n?1:xi(go(i),0);var s=this.__filtered__&&!e?new Vi(this):this.clone();return s.__filtered__?s.__takeCount__=Ei(i,s.__takeCount__):s.__views__.push({size:Ei(i,y),type:t+(s.__dir__<0?"Right":"")}),s},Vi.prototype[t+"Right"]=function(e){return this.reverse()[t](e).reverse()}})),Te(["filter","map","takeWhile"],(function(t,e){var i=e+1,n=1==i||3==i;Vi.prototype[t]=function(t){var e=this.clone();return e.__iteratees__.push({iteratee:cr(t,3),type:i}),e.__filtered__=e.__filtered__||n,e}})),Te(["head","last"],(function(t,e){var i="take"+(e?"Right":"");Vi.prototype[t]=function(){return this[i](1).value()[0]}})),Te(["initial","tail"],(function(t,e){var i="drop"+(e?"":"Right");Vi.prototype[t]=function(){return this.__filtered__?new Vi(this):this[i](1)}})),Vi.prototype.compact=function(){return this.filter(al)},Vi.prototype.find=function(t){return this.filter(t).head()},Vi.prototype.findLast=function(t){return this.reverse().find(t)},Vi.prototype.invokeMap=Jn((function(t,e){return"function"==typeof t?new Vi(this):this.map((function(i){return Mn(i,t,e)}))})),Vi.prototype.reject=function(t){return this.filter(Ba(cr(t)))},Vi.prototype.slice=function(t,e){t=go(t);var i=this;return i.__filtered__&&(t>0||e<0)?new Vi(i):(t<0?i=i.takeRight(-t):t&&(i=i.drop(t)),e!==n&&(i=(e=go(e))<0?i.dropRight(-e):i.take(e-t)),i)},Vi.prototype.takeRightWhile=function(t){return this.reverse().takeWhile(t).reverse()},Vi.prototype.toArray=function(){return this.take(y)},wn(Vi.prototype,(function(t,e){var i=/^(?:filter|find|map|reject)|While$/.test(e),s=/^(?:head|last)$/.test(e),r=Ui[s?"take"+("last"==e?"Right":""):e],a=s||/^find/.test(e);r&&(Ui.prototype[e]=function(){var e=this.__wrapped__,o=s?[1]:arguments,l=e instanceof Vi,h=o[0],c=l||Fa(e),u=function(t){var e=r.apply(Ui,Ne([t],o));return s&&d?e[0]:e};c&&i&&"function"==typeof h&&1!=h.length&&(l=c=!1);var d=this.__chain__,p=!!this.__actions__.length,f=a&&!d,y=l&&!p;if(!a&&c){e=y?e:new Vi(this);var m=t.apply(e,o);return m.__actions__.push({func:ya,args:[u],thisArg:n}),new ji(m,d)}return f&&y?t.apply(this,o):(m=this.thru(u),f?s?m.value()[0]:m.value():m)})})),Te(["pop","push","shift","sort","splice","unshift"],(function(t){var e=Pt[t],i=/^(?:push|sort|unshift)$/.test(t)?"tap":"thru",n=/^(?:pop|shift)$/.test(t);Ui.prototype[t]=function(){var t=arguments;if(n&&!this.__chain__){var s=this.value();return e.apply(Fa(s)?s:[],t)}return this[i]((function(i){return e.apply(Fa(i)?i:[],t)}))}})),wn(Vi.prototype,(function(t,e){var i=Ui[e];if(i){var n=i.name+"";Rt.call(Mi,n)||(Mi[n]=[]),Mi[n].push({name:e,func:i})}})),Mi[Os(n,2).name]=[{name:"wrapper",func:n}],Vi.prototype.clone=function(){var t=new Vi(this.__wrapped__);return t.__actions__=Ps(this.__actions__),t.__dir__=this.__dir__,t.__filtered__=this.__filtered__,t.__iteratees__=Ps(this.__iteratees__),t.__takeCount__=this.__takeCount__,t.__views__=Ps(this.__views__),t},Vi.prototype.reverse=function(){if(this.__filtered__){var t=new Vi(this);t.__dir__=-1,t.__filtered__=!0}else(t=this.clone()).__dir__*=-1;return t},Vi.prototype.value=function(){var t=this.__wrapped__.value(),e=this.__dir__,i=Fa(t),n=e<0,s=i?t.length:0,r=function(t,e,i){for(var n=-1,s=i.length;++n=this.__values__.length;return{done:t,value:t?n:this.__values__[this.__index__++]}},Ui.prototype.plant=function(t){for(var e,i=this;i instanceof Wi;){var s=Ur(i);s.__index__=0,s.__values__=n,e?r.__wrapped__=s:e=s;var r=s;i=i.__wrapped__}return r.__wrapped__=t,e},Ui.prototype.reverse=function(){var t=this.__wrapped__;if(t instanceof Vi){var e=t;return this.__actions__.length&&(e=new Vi(this)),(e=e.reverse()).__actions__.push({func:ya,args:[ia],thisArg:n}),new ji(e,this.__chain__)}return this.thru(ia)},Ui.prototype.toJSON=Ui.prototype.valueOf=Ui.prototype.value=function(){return ms(this.__wrapped__,this.__actions__)},Ui.prototype.first=Ui.prototype.head,ee&&(Ui.prototype[ee]=function(){return this}),Ui}();fe?((fe.exports=yi)._=yi,pe._=yi):de._=yi}).call(t)}(e={exports:{}},e.exports),e.exports);const n={ratio:1.471,minimumWidth:138,expandedWidth:220,expandedHeight:324,episodeRatio:.563,minimumEpisodeWidth:300},s={kodi:["movie","episode","epg"],androidtv:["movie","show","season","episode","clip","track","artist","album"],plexPlayer:["movie","show","season","episode","clip","track","artist","album"],cast:["movie","episode","artist","album","track"],vlcTelnet:["track"],sonos:["track","artist","album"]};var r=function(t,e){return function(){for(var i=new Array(arguments.length),n=0;n=0)return;l[s]="set-cookie"===s?(l[s]?l[s]:[]).concat([a]):l[s]?l[s]+", "+a:a}})),l):l):null,c={data:t.responseType&&"text"!==t.responseType?r.response:r.responseText,status:r.status,statusText:r.statusText,headers:h,config:t,request:r};!function(t,e,i){var n=i.config.validateStatus;i.status&&n&&!n(i.status)?e(b("Request failed with status code "+i.status,i.config,null,i.request,i)):t(i)}(e,i,c),r=null}},r.onabort=function(){r&&(i(b("Request aborted",t,"ECONNABORTED",r)),r=null)},r.onerror=function(){i(b("Network Error",t,null,r)),r=null},r.ontimeout=function(){var e="timeout of "+t.timeout+"ms exceeded";t.timeoutErrorMessage&&(e=t.timeoutErrorMessage),i(b(e,t,"ECONNABORTED",r)),r=null},p.isStandardBrowserEnv()){var u=(t.withCredentials||_(c))&&t.xsrfCookieName?w.read(t.xsrfCookieName):void 0;u&&(s[t.xsrfHeaderName]=u)}if("setRequestHeader"in r&&p.forEach(s,(function(t,e){void 0===n&&"content-type"===e.toLowerCase()?delete s[e]:r.setRequestHeader(e,t)})),p.isUndefined(t.withCredentials)||(r.withCredentials=!!t.withCredentials),t.responseType)try{r.responseType=t.responseType}catch(e){if("json"!==t.responseType)throw e}"function"==typeof t.onDownloadProgress&&r.addEventListener("progress",t.onDownloadProgress),"function"==typeof t.onUploadProgress&&r.upload&&r.upload.addEventListener("progress",t.onUploadProgress),t.cancelToken&&t.cancelToken.promise.then((function(t){r&&(r.abort(),i(t),r=null)})),n||(n=null),r.send(n)}))},T={"Content-Type":"application/x-www-form-urlencoded"};function k(t,e){!p.isUndefined(t)&&p.isUndefined(t["Content-Type"])&&(t["Content-Type"]=e)}var z,L={adapter:(("undefined"!=typeof XMLHttpRequest||"undefined"!=typeof process&&"[object process]"===Object.prototype.toString.call(process))&&(z=C),z),transformRequest:[function(t,e){return E(e,"Accept"),E(e,"Content-Type"),p.isFormData(t)||p.isArrayBuffer(t)||p.isBuffer(t)||p.isStream(t)||p.isFile(t)||p.isBlob(t)?t:p.isArrayBufferView(t)?t.buffer:p.isURLSearchParams(t)?(k(e,"application/x-www-form-urlencoded;charset=utf-8"),t.toString()):p.isObject(t)?(k(e,"application/json;charset=utf-8"),JSON.stringify(t)):t}],transformResponse:[function(t){if("string"==typeof t)try{t=JSON.parse(t)}catch(t){}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,validateStatus:function(t){return t>=200&&t<300}};L.headers={common:{Accept:"application/json, text/plain, */*"}},p.forEach(["delete","get","head"],(function(t){L.headers[t]={}})),p.forEach(["post","put","patch"],(function(t){L.headers[t]=p.merge(T)}));var $=L;function P(t){t.cancelToken&&t.cancelToken.throwIfRequested()}var M=function(t){return P(t),t.headers=t.headers||{},t.data=v(t.data,t.headers,t.transformRequest),t.headers=p.merge(t.headers.common||{},t.headers[t.method]||{},t.headers),p.forEach(["delete","get","head","post","put","patch","common"],(function(e){delete t.headers[e]})),(t.adapter||$.adapter)(t).then((function(e){return P(t),e.data=v(e.data,e.headers,t.transformResponse),e}),(function(e){return x(e)||(P(t),e&&e.response&&(e.response.data=v(e.response.data,e.response.headers,t.transformResponse))),Promise.reject(e)}))},N=function(t,e){e=e||{};var i={},n=["url","method","data"],s=["headers","auth","proxy","params"],r=["baseURL","transformRequest","transformResponse","paramsSerializer","timeout","timeoutMessage","withCredentials","adapter","responseType","xsrfCookieName","xsrfHeaderName","onUploadProgress","onDownloadProgress","decompress","maxContentLength","maxBodyLength","maxRedirects","transport","httpAgent","httpsAgent","cancelToken","socketPath","responseEncoding"],a=["validateStatus"];function o(t,e){return p.isPlainObject(t)&&p.isPlainObject(e)?p.merge(t,e):p.isPlainObject(e)?p.merge({},e):p.isArray(e)?e.slice():e}function l(n){p.isUndefined(e[n])?p.isUndefined(t[n])||(i[n]=o(void 0,t[n])):i[n]=o(t[n],e[n])}p.forEach(n,(function(t){p.isUndefined(e[t])||(i[t]=o(void 0,e[t]))})),p.forEach(s,l),p.forEach(r,(function(n){p.isUndefined(e[n])?p.isUndefined(t[n])||(i[n]=o(void 0,t[n])):i[n]=o(void 0,e[n])})),p.forEach(a,(function(n){n in e?i[n]=o(t[n],e[n]):n in t&&(i[n]=o(void 0,t[n]))}));var h=n.concat(s).concat(r).concat(a),c=Object.keys(t).concat(Object.keys(e)).filter((function(t){return-1===h.indexOf(t)}));return p.forEach(c,l),i};function I(t){this.defaults=t,this.interceptors={request:new g,response:new g}}I.prototype.request=function(t){"string"==typeof t?(t=arguments[1]||{}).url=arguments[0]:t=t||{},(t=N(this.defaults,t)).method?t.method=t.method.toLowerCase():this.defaults.method?t.method=this.defaults.method.toLowerCase():t.method="get";var e=[M,void 0],i=Promise.resolve(t);for(this.interceptors.request.forEach((function(t){e.unshift(t.fulfilled,t.rejected)})),this.interceptors.response.forEach((function(t){e.push(t.fulfilled,t.rejected)}));e.length;)i=i.then(e.shift(),e.shift());return i},I.prototype.getUri=function(t){return t=N(this.defaults,t),y(t.url,t.params,t.paramsSerializer).replace(/^\?/,"")},p.forEach(["delete","get","head","options"],(function(t){I.prototype[t]=function(e,i){return this.request(N(i||{},{method:t,url:e,data:(i||{}).data}))}})),p.forEach(["post","put","patch"],(function(t){I.prototype[t]=function(e,i,n){return this.request(N(n||{},{method:t,url:e,data:i}))}}));var A=I;function R(t){this.message=t}R.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},R.prototype.__CANCEL__=!0;var B=R;function H(t){if("function"!=typeof t)throw new TypeError("executor must be a function.");var e;this.promise=new Promise((function(t){e=t}));var i=this;t((function(t){i.reason||(i.reason=new B(t),e(i.reason))}))}H.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},H.source=function(){var t;return{token:new H((function(e){t=e})),cancel:t}};var D=H;function q(t){var e=new A(t),i=r(A.prototype.request,e);return p.extend(i,A.prototype,e),p.extend(i,e),i}var U=q($);U.Axios=A,U.create=function(t){return q(N(U.defaults,t))},U.Cancel=B,U.CancelToken=D,U.isCancel=x,U.all=function(t){return Promise.all(t)},U.spread=function(t){return function(e){return t.apply(null,e)}},U.isAxiosError=function(t){return"object"==typeof t&&!0===t.isAxiosError};var O=U,W=U;O.default=W;var j=O;class V{constructor(t,e=!1,n,s="http",r="titleSort:asc"){this.serverInfo={},this.clients=[],this.requestTimeout=1e4,this.sections=[],this.providers=[],this.livetv={},this.livetvepg={},this.collections=!1,this.playlists=[],this.init=async()=>{await Promise.all([this.getSections(),this.getClients(),this.getServerID()])},this.getClients=async()=>{const t=this.authorizeURL(`${this.getBasicURL()}/clients`);try{const e=await j.get(t,{timeout:this.requestTimeout});this.clients=e.data.MediaContainer.Server}catch(e){throw Error(`${e.message} while requesting URL "${t}".`)}return this.clients},this.getProviders=async()=>{if(i.isEmpty(this.providers)){const t=this.authorizeURL(`${this.getBasicURL()}/media/providers`),e=await j.get(t,{timeout:this.requestTimeout});this.providers=e.data.MediaContainer.MediaProvider}return this.providers},this.getLiveTV=async()=>{if(i.isEmpty(this.livetv)){const t={},e=await this.getProviders(),n=[],s=[];i.forEach(e,(t=>{if(i.isEqual(t.protocols,"livetv")){const e=this.authorizeURL(`${this.getBasicURL()}/${t.identifier}/tags?type=310`);n.push(j.get(e,{timeout:this.requestTimeout})),s.push(t.title)}}));const r=await Promise.all(n);i.forEach(r,((e,i)=>{t[s[i]]=e.data.MediaContainer.Directory})),this.livetv=t}return this.livetv},this.getEPG=async()=>{if(i.isEmpty(this.livetvepg)){const t={},e=await this.getProviders(),n=[],s=[];i.forEach(e,(t=>{if(i.isEqual(t.protocols,"livetv")){let e=this.authorizeURL(`${this.getBasicURL()}/${t.identifier}/grid?type=1&sort=beginsAt`);e+=`&endsAt>=${Math.floor(Date.now()/1e3)}`,e+=`&beginsAt<=${Math.floor(Date.now()/1e3)}`,n.push(j.get(e,{timeout:this.requestTimeout})),s.push(t.title)}}));const r=await Promise.all(n);i.forEach(r,((e,n)=>{t[s[n]]={},i.forEach(e.data.MediaContainer.Metadata,(e=>{t[s[n]][e.Media[0].channelCallSign]=e}))})),this.livetvepg=t}return this.livetvepg},this.getServerID=async()=>(i.isEmpty(this.serverInfo)&&await this.getServerInfo(),this.serverInfo.machineIdentifier),this.getServerInfo=async()=>{const t=this.authorizeURL(`${this.getBasicURL()}/`);return this.serverInfo=(await j.get(t,{timeout:this.requestTimeout})).data.MediaContainer,this.serverInfo},this.getSections=async()=>{if(i.isEmpty(this.sections)){const t=this.authorizeURL(`${this.getBasicURL()}/library/sections`),e=await j.get(t,{timeout:this.requestTimeout});this.sections=e.data.MediaContainer.Directory}return this.sections},this.getCollections=async()=>{if(!i.isArray(this.collections)){const t=await this.getSections(),e=[];i.forEach(t,(t=>{e.push(this.getCollection(t.key))}));const n=await Promise.all(e),s=[];i.forEach(n,(t=>{i.forEach(t,(t=>{s.push(t)}))})),this.collections=s}return this.collections},this.getPlaylists=async()=>{if(i.isEmpty(this.playlists)){this.playlists=[];const t=this.authorizeURL(`${this.getBasicURL()}/playlists`),e=await j.get(t,{timeout:this.requestTimeout});this.playlists=e.data.MediaContainer.Metadata}return this.playlists},this.getCollection=async t=>{const e=this.authorizeURL(`${this.getBasicURL()}/library/sections/${t}/collections`),n=await j.get(e,{timeout:this.requestTimeout});return i.isNil(n.data.MediaContainer.Metadata)?[]:n.data.MediaContainer.Metadata},this.getSectionData=async(t,e=!1)=>this.exportSectionsData([await this.getSectionDataWithoutProcessing(t,e)]),this.getChildren=async t=>{let e=this.authorizeURL(`${this.getBasicURL()}${t}`);e+=`&sort=${this.sort}`;let n={};try{n=await j.get(e,{timeout:this.requestTimeout})}catch(s){if(!i.includes(s.message,"Request failed with status code 500"))throw s;{e+="&X-Plex-Container-Start=0&X-Plex-Container-Size=50",n=await j.get(e,{timeout:this.requestTimeout});const{totalSize:s}=n.data.MediaContainer;let r=50;const a=[];for(;r{n.data.MediaContainer.Metadata=i.concat(n.data.MediaContainer.Metadata,t.data.MediaContainer.Metadata)}))}}return n.data.MediaContainer.Metadata},this.getCollectionData=async t=>this.getChildren(t),this.getPlaylistData=async t=>this.getChildren(t),this.getSectionDataWithoutProcessing=async(t,e=!1)=>{let n=`${this.getBasicURL()}/library/sections/${t}`;e?i.isEqual(e,"folder")?n+="/folder":(n+="/all",n+=`?type=${e}`):n+="/all",n=this.authorizeURL(n),n+=`&sort=${this.sort}`,n+="&includeCollections=1&includeExternalMedia=1&includeAdvanced=1&includeMeta=1";let s={};try{s=await j.get(n,{timeout:this.requestTimeout})}catch(e){if(!i.includes(e.message,"Request failed with status code 500"))throw e;{n+="&X-Plex-Container-Start=0&X-Plex-Container-Size=50",s=await j.get(n,{timeout:this.requestTimeout});const{totalSize:e}=s.data.MediaContainer;let r=50;const a=[];for(;r{s.data.MediaContainer.Metadata=i.concat(s.data.MediaContainer.Metadata,t.data.MediaContainer.Metadata)}))}}return s},this.getSectionsData=async()=>{const t=await this.getSections(),e=[];return i.forEach(t,(t=>{e.push(this.getSectionDataWithoutProcessing(t.key))})),this.exportSectionsData(await Promise.all(e))},this.getRecentyAdded=async(t=!1)=>{if(t){const t=await this.getHubs();let e={};return i.forEach(t.Hub,(t=>{if(i.isEqual(t.key,"/hubs/home/recentlyAdded?type=2"))return e=t,!1})),e}const e=this.authorizeURL(`${this.getBasicURL()}/hubs/home/recentlyAdded?type=2&X-Plex-Container-Start=0&X-Plex-Container-Size=50`);return(await j.get(e,{timeout:this.requestTimeout})).data.MediaContainer},this.getHubs=async()=>{const t=this.authorizeURL(`${this.getBasicURL()}/hubs?includeEmpty=1&count=50&includeFeaturedTags=1&includeTypeFirst=1&includeStations=1&includeExternalMetadata=1&excludePlaylists=1`);return(await j.get(t,{timeout:this.requestTimeout})).data.MediaContainer},this.getWatchNext=async()=>{const t=await this.getSections();let e="";i.forEach(t,(t=>{e+=`${t.key},`})),e=e.slice(0,-1);const n=this.authorizeURL(`${this.getBasicURL()}/hubs/continueWatching/items?contentDirectoryID=${e}`);return(await j.get(n,{timeout:this.requestTimeout})).data.MediaContainer},this.tune=async(t,e)=>{e="PlexMeetsHomeAssistant3",console.log(t);let n=this.authorizeURL(`${this.getBasicURL()}/livetv/dvrs/12/channels/${t}/tune?X-Plex-Language=en-us`);console.log("Starting tune process..."),n=`${this.getBasicURL()}/livetv/dvrs/12/channels/`,n+=`${t}`,n+="/tune",n+=`?X-Plex-Client-Identifier=${e}`,n+=`&X-Plex-Session-Identifier=${e}`;const s=(await j.post(this.authorizeURL(n),{timeout:this.requestTimeout})).data.MediaContainer;console.log("Tuning started.");let r=`${this.getBasicURL()}/video/:/transcode/universal/start.mpd`;r+="?hasMDE=1",r+=`&path=${encodeURIComponent(s.MediaSubscription[0].MediaGrabOperation[0].Metadata.key)}`,r+="&mediaIndex=0",r+="&partIndex=0",r+="&protocol=dash",r+="&fastSeek=1",r+="&directPlay=0",r+="&directStream=1",r+="&subtitleSize=100",r+="&audioBoost=100",r+="&location=lan",r+="&addDebugOverlay=0",r+="&autoAdjustQuality=0",r+="&directStreamAudio=1",r+="&mediaBufferSize=102400",r+=`&session=${e}`,r+="&subtitles=burn",r+="©ts=0",r+="&Accept-Language=en-GB",r+=`&X-Plex-Session-Identifier=${e}`,r+="&X-Plex-Client-Profile-Extra=append-transcode-target-codec%28type%3DvideoProfile%26context%3Dstreaming%26audioCodec%3Daac%26protocol%3Ddash%29",r+="&X-Plex-Incomplete-Segments=1",r+="&X-Plex-Product=Plex%20Web",r+="&X-Plex-Version=4.59.2",r+=`&X-Plex-Client-Identifier=${e}`,r+="&X-Plex-Platform=Chrome",r+="&X-Plex-Platform-Version=92.0",r+="&X-Plex-Sync-Version=2",r+="&X-Plex-Features=external-media%2Cindirect-media",r+="&X-Plex-Model=bundled",r+="&X-Plex-Device=OSX",r+="&X-Plex-Device-Name=Chrome",r+="&X-Plex-Device-Screen-Resolution=1792x444%2C1792x1120",r+="&X-Plex-Language=en-GB";let a=`${this.getBasicURL()}/video/:/transcode/universal/decision`;a+="?advancedSubtitles=text",a+="&audioBoost=100",a+="&autoAdjustQuality=0",a+="&directPlay=1",a+="&directStream=1",a+="&directStreamAudio=1",a+="&fastSeek=1",a+="&hasMDE=1",a+="&location=lan",a+="&mediaIndex=0",a+="&partIndex=0",a+=`&path=${s.MediaSubscription[0].MediaGrabOperation[0].Metadata.key}`,a+="&protocol=*",a+=`&session=${e}`,a+="&skipSubtitles=1",a+="&videoBitrate=200000",a+="&videoQuality=100",a+=`&X-Plex-Client-Identifier=${e}`,a+="&X-Plex-Platform=Android";const o=this.authorizeURL(`${this.getBasicURL()}${s.MediaSubscription[0].MediaGrabOperation[0].Metadata.key}?includeBandwidths=1&offset=-1&X-Plex-Incomplete-Segments=1&X-Plex-Session-Identifier=${e}`);console.log("Getting info about channel stream...");const l=await j.get(o,{timeout:6e4});if(console.log(l.data),i.isNil(l.data.MediaContainer.Metadata[0].Media[0].TranscodeSession)){console.log("NOT STARTED - Starting...");const t=await j.get(this.authorizeURL(r),{timeout:6e4});console.log(t),console.log("____")}const h=async t=>new Promise((e=>setTimeout(e,t)));console.log("Deciding...");let c=await j.get(this.authorizeURL(a),{timeout:this.requestTimeout});for(;parseFloat(c.data.MediaContainer.Metadata[0].Media[0].Part[0].key.split("offset=")[1].split("&")[0])<3;)await h(500),c=await j.get(this.authorizeURL(a),{timeout:this.requestTimeout}),console.log("Waiting for new url...");return c.data.MediaContainer.Metadata[0].Media[0].Part[0].key},this.getContinueWatching=async()=>{const t=await this.getHubs();let e={};return i.forEach(t.Hub,(t=>{if(i.isEqual(t.key,"/hubs/home/continueWatching"))return e=t,!1})),e},this.getOnDeck=async()=>{const t=await this.getHubs();let e={};return i.forEach(t.Hub,(t=>{if(i.isEqual(t.key,"/hubs/home/onDeck"))return e=t,!1})),e},this.getBasicURL=()=>`${this.protocol}://${this.ip}${!1===this.port?"":`:${this.port}`}`,this.authorizeURL=t=>i.includes(t,"X-Plex-Token")?t:i.includes(t,"?")?`${t}&X-Plex-Token=${this.token}`:`${t}?X-Plex-Token=${this.token}`,this.getDetails=async t=>{const e=this.authorizeURL(`${this.getBasicURL()}/library/metadata/${t}?includeConcerts=1&includeExtras=1&includeOnDeck=1&includePopularLeaves=1&includePreferences=1&includeReviews=1&includeChapters=1&includeStations=1&includeExternalMedia=1&asyncAugmentMetadata=1&asyncCheckFiles=1&asyncRefreshAnalysis=1&asyncRefreshLocalMediaAgent=1`);return(await j.get(e,{timeout:this.requestTimeout})).data.MediaContainer.Metadata[0]},this.getLibraryData=async t=>{const e=this.authorizeURL(`${this.getBasicURL()}${t}`);return(await j.get(e,{timeout:this.requestTimeout})).data.MediaContainer.Metadata},this.exportSectionsData=t=>{const e=[];return i.forEach(t,(t=>{e.push(t.data.MediaContainer)})),e},this.ip=t,this.port=e,this.token=n,this.protocol=s,this.sort=r}}const F=t=>t?t.toString().replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'"):"",X=()=>{const t=document.createElement("ha-textfield");return t.style.width="100%",t.style.marginTop="10px",t.style.marginBottom="10px",t},Y=t=>t.sendMessagePromise({type:"config/entity_registry/list"}),K=t=>Math.max(t.scrollHeight,t.offsetHeight,t.clientHeight,t.scrollHeight,t.offsetHeight),G=t=>{let e=0,n=0;for(;t&&t.offsetParent&&!i.isNaN(t.offsetLeft)&&!i.isNaN(t.offsetTop);){e+=t.offsetLeft-t.scrollLeft,n+=t.offsetTop-t.scrollTop;const i=t.offsetParent;i&&(t=i)}return{top:n,left:e}},Z=t=>{const e=t.getElementsByClassName("videoPlayer")[0].children[0];if(!e)return!1;const i=document.getElementsByTagName("body")[0];return e.offsetWidth===i.offsetWidth&&e.offsetHeight===i.offsetHeight||t.videoElem&&t.videoElem.classList.contains("simulatedFullScreen")},J=t=>`PlexMeetsHomeAssistant: 404 Error requesting library feed for ${t}. Plex API might have changed or using outdated server. Library ${t} will not work.`,Q=async t=>new Promise((e=>setTimeout(e,t))),tt=async(t,e)=>t.callApi("GET",`states/${e}`),et=(t,e)=>{let i=`${t}`;for(;i.length{const o=s/4,l=document.createElement("tr");l.classList.add("trackContainer"),a?l.classList.add("even"):l.classList.add("odd");const h=document.createElement("td");h.className="trackIndexElem",h.innerHTML=`${F(n.index)}`,h.style.fontSize=`${s}px`,h.style.lineHeight=`${s}px`,h.style.marginBottom=`${o}px`;const c=document.createElement("div");if(c.className="trackInteractiveArea",t){const e=t.getPlayButton(n.type);e.addEventListener("click",(e=>{e.stopPropagation(),t.play(n,!0)})),t.isPlaySupported(n)&&e.classList.remove("disabled"),c.append(e)}h.append(c),l.append(h);const u=document.createElement("td");u.className="trackTitleElem",i.isEmpty(n.title)?i.isEmpty(n.titleSort)||(u.innerHTML=F(n.titleSort)):u.innerHTML=F(n.title),u.style.fontSize=`${s}px`,u.style.lineHeight=`${s}px`,u.style.marginBottom=`${o}px`,l.append(u);const d=i.get(n,"Media[0].duration"),p=document.createElement("td");if(p.className="trackLengthElem",p.style.fontSize=`${s}px`,p.style.lineHeight=`${s}px`,p.style.marginBottom=`${o}px`,d){const t=Math.floor(d/60/1e3),e=Math.round((d-1e3*t)/6e3);p.innerHTML=F(`${et(t,2)}:${et(e,2)}`)}return l.append(p),l.addEventListener("click",(t=>{t.stopPropagation()})),l},nt=(t,e,i,s,r)=>{const a=document.createElement("div");a.className="episodeContainer",a.style.width=`${n.episodeWidth}px`;const o=e.authorizeURL(`${e.getBasicURL()}/photo/:/transcode?width=${n.episodeWidth}&height=${n.episodeHeight}&minSize=1&upscale=1&url=${i.thumb}`),l=document.createElement("div");if(l.className="episodeElem",l.style.width=`${n.episodeWidth}px`,l.style.height=`${n.episodeHeight}px`,l.style.backgroundImage=`url('${o}')`,l.dataset.clicked="false",void 0===i.lastViewedAt){const t=document.createElement("div");t.className="toViewEpisode",l.appendChild(t)}const h=document.createElement("div");if(h.className="interactiveArea",t){const e=t.getPlayButton(i.type);e.addEventListener("click",(e=>{e.stopPropagation(),t.play(i,!0)})),t.isPlaySupported(i)&&e.classList.remove("disabled"),h.append(e)}l.append(h),a.append(l);const c=document.createElement("div");c.className="episodeTitleElem",c.innerHTML=F(i.title);const u=s/4,d=r/4;c.style.fontSize=`${s}px`,c.style.lineHeight=`${s}px`,c.style.marginBottom=`${u}px`,a.append(c);const p=document.createElement("div");if(p.className="episodeNumber",p.style.fontSize=`${r}px`,p.style.lineHeight=`${r}px`,p.style.marginTop=`${d}px`,p.style.marginBottom=`${d}px`,"episode"===i.type)p.innerHTML=F(`Episode ${F(i.index)}`);else if("clip"===i.type){let t="";switch(i.subtype){case"behindTheScenes":t="Behind the Scenes";break;case"trailer":t="Trailer";break;case"scene":case"sceneOrSample":t="Scene";break;default:t=i.subtype}p.innerHTML=F(t)}return a.append(p),a.addEventListener("click",(t=>{t.stopPropagation()})),a};class st{constructor(t,e,n,r,a,o,l,h,c){this.playButtons=[],this.readyPlayersForType={},this.entityStates={},this.plexPlayerEntity="",this.runBefore=!1,this.runAfter=!1,this.supported=s,this.playActionButton=document.createElement("button"),this.playActionClickFunction=!1,this.entityRegistry=[],this.shuffle=!1,this.getKodiSearchResults=async()=>JSON.parse((await tt(this.hass,"sensor.kodi_media_sensor_search")).attributes.data),this.getKodiSearch=async(t,e=!1)=>{await this.hass.callService("kodi_media_sensors","call_method",{entity_id:"sensor.kodi_media_sensor_search",method:"search",item:{media_type:"all",value:t}});const n=await this.getKodiSearchResults();let s={};if(i.forEach(n,(e=>i.isEqual(e.title,t)||i.isEqual(e.label,t)?(s=e,!1):void 0)),i.isEmpty(s)&&!e)throw alert(`Title ${t} not found in Kodi.`),Error(`Title ${t} not found in Kodi.`);return s},this.getKodiTVShowSeason=async(t,e)=>{await this.hass.callService("kodi_media_sensors","call_method",{entity_id:"sensor.kodi_media_sensor_search",method:"search",item:{media_type:"tvshow",value:t}});let n={};const s=await this.getKodiSearchResults();if(i.forEach(s,(t=>{if(i.isEqual(t.season,e))return n=t,!1})),i.isEmpty(n))throw Error(`Season ${e} not found in Kodi for TV Show ${t}.`);return n},this.play=async(t,e=!1)=>{if(i.isArray(this.runBefore)){const t=`${this.runBefore[0]}.${this.runBefore[1]}`;await this.hass.callService(this.runBefore[0],this.runBefore[1],{});const e=await tt(this.hass,t);i.isEqual(e.state,"on")&&await(async(t,e,i)=>{let n=await tt(t,e);for(;n.state!==i;)n=await tt(t,e),await Q(1e3)})(this.hass,t,"off")}const n=this.getPlayService(t,!0);let s,r=t;switch(i.isEqual(t.type,"epg")&&(r=t.epg,s=""),n.key){case"kodi":await this.playViaKodi(n.value,t,t.type);break;case"vlcTelnet":await this.playViaVLCTelnet(n.value,t,t.type);break;case"androidtv":if(i.isEqual(t.type,"epg")){const i=`${Math.floor(Date.now()/1e3)}`,r=await this.plex.tune(t.channelIdentifier,i);await this.playViaAndroidTV(n.value,r,e,s)}else await this.playViaAndroidTV(n.value,r.key,e,s);break;case"plexPlayer":await this.playViaPlexPlayer(n.value,r.key.split("/")[3]);break;case"cast":case"sonos":if(i.isEqual(t.type,"epg")){const e=`PlexMeetsHomeAssistant-${Math.floor(Date.now()/1e3)}`,i=await this.plex.tune(t.channelIdentifier,e);this.playViaCast(n.value,`${i}`,"epg")}else if(this.hass.services.plex){const t=i.isNil(r.librarySectionTitle)?this.libraryName:r.librarySectionTitle;try{switch(r.type){case"artist":await this.playViaCastPlex(n.value,"MUSIC",{library_name:t,artist_name:r.title,shuffle:this.shuffle?1:0});break;case"album":await this.playViaCastPlex(n.value,"MUSIC",{library_name:t,artist_name:r.parentTitle,album_name:r.title,shuffle:this.shuffle?1:0});break;case"track":await this.playViaCastPlex(n.value,"MUSIC",{library_name:t,artist_name:r.grandparentTitle,album_name:r.parentTitle,track_name:r.title,shuffle:this.shuffle?1:0});break;case"movie":await this.playViaCastPlex(n.value,"movie",{library_name:t,title:r.title});break;case"episode":await this.playViaCastPlex(n.value,"EPISODE",{library_name:t,show_name:r.grandparentTitle,season_number:r.parentIndex,episode_number:r.index});break;default:i.isNil(r.Media)?console.error("Casting this content directly is not possible. Consider using Plex integration."):this.playViaCast(n.value,r.Media[0].Part[0].key)}}catch(t){console.log(t),this.playViaCast(n.value,r.Media[0].Part[0].key)}}else{if(i.isNil(i.get(r,"Media[0].Part[0].key")))throw Error(`No service available to play ${r.title}!`);this.playViaCast(n.value,i.get(r,"Media[0].Part[0].key"))}break;default:throw Error(`No service available to play ${r.title}!`)}i.isArray(this.runAfter)&&await this.hass.callService(this.runAfter[0],this.runAfter[1],{})},this.plexPlayerCreateQueue=async(t,e,i,n=!1,s=!1,r=!1)=>{const a=`${e.getBasicURL()}/playQueues?type=${i}&shuffle=${n?"1":"0"}&repeat=${s?"1":"0"}&continuous=${r?"1":"0"}&own=1&uri=server://${await e.getServerID()}/com.plexapp.plugins.library${t}`,o=await j({method:"post",url:a,headers:{"X-Plex-Token":e.token,"X-Plex-Client-Identifier":"PlexMeetsHomeAssistant"}});if(200!==o.status)throw Error("Error reaching Plex to generate queue");return{playQueueID:o.data.MediaContainer.playQueueID,playQueueSelectedMetadataItemID:o.data.MediaContainer.playQueueSelectedMetadataItemID}},this.playViaPlexPlayer=async(t,e)=>{const n=this.getPlexPlayerMachineIdentifier(t);let{plex:s}=this;i.isObject(t)&&!i.isNil(t.plex)&&(s=t.plex);const{playQueueID:r,playQueueSelectedMetadataItemID:a}=await this.plexPlayerCreateQueue(`/library/metadata/${e}`,this.plex,"video");let o=s.getBasicURL();o+="/player/playback/playMedia",o+="?type=video",o+="&commandID=1",o+="&providerIdentifier=com.plexapp.plugins.library",o+=`&containerKey=/playQueues/${r}`,o+=`&key=/library/metadata/${a}`,o+="&offset=0",o+=`&machineIdentifier=${await this.plex.getServerID()}`,o+=`&protocol=${this.plex.protocol}`,o+=`&address=${this.plex.ip}`,o+=`&port=${this.plex.port}`,o+=`&token=${this.plex.token}`,o=s.authorizeURL(o);try{const t=await j({method:"get",url:o,headers:{"X-Plex-Target-Client-Identifier":n,"X-Plex-Client-Identifier":"PlexMeetsHomeAssistant"}});if(200!==t.status)throw Error("Error while asking plex to play a movie - server request error.");if(!i.includes(t.data,'status="OK"'))throw Error("Error while asking plex to play a movie - target device not available.")}catch(t){try{await this.hass.callService("rest_command","pmha_playmedia",{url:o,target_client_identifier:n,client_identifier:"PlexMeetsHomeAssistant"})}catch(t){}throw i.includes(t.message,"404")?Error("Defined plexPlayer is currently not available for playback."):t}},this.playViaKodi=async(t,e,n)=>{if("epg"===n)try{const n=await this.getKodiSearch(i.get(e,"channelCallSign"),!0);await this.hass.callService("kodi","call_method",{entity_id:t,method:"Player.Open",item:{channelid:n.channelid}})}catch(i){const n=`${this.plex.getBasicURL()}${await this.plex.tune(e.channelIdentifier,"todo")}`;await this.hass.callService("kodi","call_method",{entity_id:t,method:"Player.Open",item:{file:n}})}else if("movie"===n){const i=await this.getKodiSearch(e.title);await this.hass.callService("kodi","call_method",{entity_id:t,method:"Player.Open",item:{movieid:i.movieid}})}else{if("episode"!==n)throw Error(`Plex type ${n} is not supported in Kodi.`);{const n=await this.getKodiSearch(e.grandparentTitle),s=await this.getKodiTVShowSeason(n.tvshowid,e.parentIndex);let r={};if(i.forEach(s.episodes,(t=>{if(i.isEqual(t.episode,e.index))return r=t,!1})),i.isEmpty(r))throw Error(`Episode ${e.index} not found in Kodi for TV Show ${e.grandparentTitle} (id: ${n.tvshowid}) season ${e.parentIndex}.`);await this.hass.callService("kodi","call_method",{entity_id:t,method:"Player.Open",item:{episodeid:r.episodeid}})}}},this.playViaVLCTelnet=async(t,e,i)=>{switch(i){case"track":this.hass.callService("media_player","play_media",{entity_id:t,media_content_type:"music",media_content_id:this.plex.authorizeURL(`${this.plex.getBasicURL()}${e.Media[0].Part[0].key}`)});break;default:console.error(`Type ${i} is not supported on entity ${t}.`)}},this.playViaCast=(t,e,n="video")=>{if(i.isEqual(n,"video"))this.hass.callService("media_player","play_media",{entity_id:t,media_content_type:n,media_content_id:this.plex.authorizeURL(`${this.plex.getBasicURL()}${e}`)});else if(i.isEqual(n,"epg")){const i={entity_id:t,media_content_type:"application/vnd.apple.mpegurl",media_content_id:e=this.plex.authorizeURL(`${this.plex.getBasicURL()}${e}`)};this.hass.callService("media_player","play_media",i)}},this.playViaCastPlex=(t,e,n)=>{const s=i.get(this.plex,"serverInfo.friendlyName"),r=i.clone(n);return s&&(r.plex_server=s),this.hass.callService("media_player","play_media",{entity_id:t,media_content_type:e,media_content_id:`plex://${JSON.stringify(r)}`})},this.playViaAndroidTV=async(t,e,i=!1,n="com.plexapp.plugins.library")=>{let s="am start";i&&(s+=' --ez "android.intent.extra.START_PLAYBACK" true'),s+=` -a android.intent.action.VIEW 'plex://server://${await this.plex.getServerID()}/${n}${e}'`,this.hass.callService("androidtv","adb_command",{entity_id:t,command:"HOME"}),this.hass.callService("androidtv","adb_command",{entity_id:t,command:s})},this.getPlayButton=t=>{const e=document.createElement("button");return e.name="playButton",e.classList.add("disabled"),this.isTouchDevice()&&e.classList.add("touchDevice"),e.setAttribute("data-mediaType",t),this.playButtons.push(e),e},this.setPlayActionDisplay=t=>{this.updateDetailPlayAction().style.display=t},this.setPlayActionButtonType=t=>{const e=this.updateDetailPlayAction();e.setAttribute("data-mediaType",t);const n={type:t};i.isEmpty(this.getPlayService(n))?e.classList.add("disabled"):e.classList.remove("disabled")},this.updateDetailPlayAction=()=>(this.card.getElementsByClassName("detailPlayAction").length>0&&(this.playActionButton=this.card.getElementsByClassName("detailPlayAction")[0]),this.playActionButton),this.setPlayButtonClickFunction=t=>{const e=this.updateDetailPlayAction();this.playActionClickFunction&&e.removeEventListener("click",this.playActionClickFunction),e.addEventListener("click",t),this.playActionClickFunction=t},this.getPlayActionButton=()=>this.playActionButton,this.isTouchDevice=()=>"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,this.refreshAvailableServicesPeriodically=async()=>{const t=async t=>new Promise((e=>setTimeout(e,t)));for(;;){await this.refreshStates();const e=i.clone(this.readyPlayersForType);i.forEach(this.readyPlayersForType,((t,n)=>{const s={type:n};this.getPlayService(s,!0),i.isEqual(e,this.readyPlayersForType)||i.forEach(this.playButtons,(t=>{const e=t.getAttribute("data-mediaType");i.isEmpty(this.readyPlayersForType[e])?t.classList.add("disabled"):t.classList.remove("disabled")}));const r=this.getPlayActionButton(),a=r.getAttribute("data-mediaType");a&&(i.isEmpty(this.readyPlayersForType[a])?r.classList.add("disabled"):r.classList.remove("disabled"))})),await t(1e3)}},this.exportEntity=(t,e)=>{const n=[];if(i.isEqual(e,"inputSelect")||i.isEqual(e,"inputText"))if(i.isArray(t))for(let e=0;e{i.isEqual(t.entity_id,s)&&(r=t.platform)})),n.push({value:s,key:r})}else{const e=i.get(this.entityStates[t],"state");let s="plexPlayer";i.forEach(this.entityRegistry,(t=>{i.isEqual(t.entity_id,e)&&(s=t.platform)})),n.push({value:e,key:s})}else i.isArray(t)?i.forEach(t,(t=>{n.push({value:t,key:e})})):n.push({value:t,key:e});return n},this.getPlayService=(t,e=!1)=>{if(!i.isNil(this.readyPlayersForType[t.type])&&!1===e)return this.readyPlayersForType[t.type];let n={};return i.forEach(this.entity,((e,s)=>{if(i.isEmpty(n)){const r=this.exportEntity(e,s);i.forEach(r,(e=>{if(i.includes(this.supported[e.key],t.type)&&("kodi"===e.key&&this.isKodiSupported(e.value)||"androidtv"===e.key&&this.isAndroidTVSupported(e.value)||"plexPlayer"===e.key&&this.isPlexPlayerSupported(e.value)||"cast"===e.key&&this.isCastSupported(e.value)||"vlcTelnet"===e.key&&this.isVLCTelnetSupported(e.value)||"sonos"===e.key&&this.isSonosSupported(e.value)))return n={key:e.key,value:e.value},!1}))}})),this.readyPlayersForType[t.type]=n,this.readyPlayersForType[t.type]},this.init=async()=>{if(!i.isNil(this.entity.plexPlayer))if(i.isArray(this.entity.plexPlayer)){for(let t=0;t{for(const[,t]of Object.entries(this.entity)){const e=t;if(i.isArray(e)){for(const t of e)if(!i.isNil(this.hass.states[t]))try{this.entityStates[t]=await tt(this.hass,t)}catch(t){}}else try{i.isNil(this.hass.states[e])||(this.entityStates[e]=await tt(this.hass,e))}catch(t){}}try{this.hass.states["sensor.kodi_media_sensor_search"]&&(this.entityStates["sensor.kodi_media_sensor_search"]=await tt(this.hass,"sensor.kodi_media_sensor_search"))}catch(t){}for(const[t,e]of Object.entries(this.entity))if(i.isEqual(t,"inputSelect")||i.isEqual(t,"inputText")){const n=this.exportEntity(e,t);for(const t of n)if(!i.isNil(this.hass.states[t.value]))try{this.entityStates[t.value]=await tt(this.hass,t.value)}catch(t){}}return this.entityStates},this.getPlexPlayerMachineIdentifier=t=>{i.isString(t)&&i.isEqual(t.split(" | ").length,4)&&([,,,t]=t.split(" | "));let e="",{plex:n}=this,s="";return i.isString(t)?s=t.trim():i.isObjectLike(t)&&!i.isNil(t.identifier)&&(s=t.identifier.trim(),!i.isNil(t.plex)&&t.plex&&(n=t.plex)),i.forEach(n.clients,(t=>{if(i.isEqual(t.machineIdentifier,s)||i.isEqual(t.product,s)||i.isEqual(t.name,s)||i.isEqual(t.host,s)||i.isEqual(t.address,s))return e=t.machineIdentifier,!1})),e},this.isPlaySupported=t=>!i.isEmpty(this.getPlayService(t)),this.isPlexPlayerSupported=t=>{let e=!1;return this.getPlexPlayerMachineIdentifier(t)&&(e=!0),e||!i.isEqual(this.runBefore,!1)},this.isKodiSupported=t=>{if(t){const e=this.entityStates["sensor.kodi_media_sensor_search"]&&"unavailable"!==this.entityStates["sensor.kodi_media_sensor_search"].state;return this.entityStates[t]&&"off"!==this.entityStates[t].state&&"unavailable"!==this.entityStates[t].state&&e||!i.isEqual(this.runBefore,!1)&&e}return!1},this.isVLCTelnetSupported=t=>this.entityStates[t]&&!i.isNil(this.entityStates[t].attributes)&&"unavailable"!==this.entityStates[t].state||!i.isEqual(this.runBefore,!1),this.isSonosSupported=t=>this.entityStates[t]&&!i.isNil(this.entityStates[t].attributes)&&"unavailable"!==this.entityStates[t].state||!i.isEqual(this.runBefore,!1),this.isCastSupported=t=>this.entityStates[t]&&!i.isNil(this.entityStates[t].attributes)&&"unavailable"!==this.entityStates[t].state||!i.isEqual(this.runBefore,!1),this.isAndroidTVSupported=t=>this.entityStates[t]&&!i.isEqual(this.entityStates[t].state,"off")&&this.entityStates[t].attributes&&void 0!==this.entityStates[t].attributes.adb_response||!i.isEqual(this.runBefore,!1),this.entityRegistry=h,this.card=t,this.hass=e,this.plex=n,this.entity=r,this.shuffle=c,this.libraryName=l,!i.isEmpty(a)&&this.hass.states[a]&&(this.runBefore=a.split(".")),!i.isEmpty(o)&&this.hass.states[o]&&(this.runAfter=o.split(".")),this.refreshAvailableServicesPeriodically(),this.playActionButton.classList.add("detailPlayAction"),this.playActionButton.innerText="Play"}}class rt extends HTMLElement{constructor(){super(...arguments),this.plexPort=!1,this.plexProtocol="http",this.config={},this.ip=X(),this.token=X(),this.port=X(),this.maxCount=X(),this.maxRows=X(),this.displayTitleMain=document.createElement("select"),this.displaySubtitleMain=document.createElement("select"),this.useHorizontalScroll=document.createElement("select"),this.useShuffle=document.createElement("select"),this.minWidth=X(),this.minEpisodeWidth=X(),this.minExpandedWidth=X(),this.minExpandedHeight=X(),this.fontSize1=X(),this.fontSize2=X(),this.fontSize3=X(),this.fontSize4=X(),this.cardTitle=X(),this.libraryName=document.createElement("select"),this.protocol=document.createElement("select"),this.tabs=document.createElement("paper-tabs"),this.sort=document.createElement("select"),this.displayTypeData={},this.displayType=document.createElement("select"),this.sortOrder=document.createElement("select"),this.playTrailer=document.createElement("select"),this.showExtras=document.createElement("select"),this.showSearch=document.createElement("select"),this.runBefore=document.createElement("select"),this.runAfter=document.createElement("select"),this.entitiesSection=document.createElement("div"),this.devicesTabs=0,this.entities=[],this.scriptEntities=[],this.sections=[],this.collections=[],this.playlists=[],this.clients={},this.entitiesRegistry=!1,this.plexValidSection=document.createElement("div"),this.loaded=!1,this.livetv={},this.fireEvent=(t,e,i,n={})=>{i=null==i?{}:i;const s=new Event(e,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed});return s.detail=i,t.dispatchEvent(s),s},this.generateTitle=t=>{const e=document.createElement("h4");return e.innerText=t,e.style.marginBottom="0",e.style.marginTop="0",e.style.paddingTop="0",e.style.paddingBottom="0",e.style.color="rgb(225, 225, 225)",e.style.fontWeight="300",e.style.fontSize="12px",e},this.valueUpdated=()=>{const t=i.clone(this.config);if(this.config.protocol=this.protocol.value,this.config.ip=this.ip.value.replace(/^https?:\/\//i,"").replace(/\/$/,""),this.config.token=this.token.value,this.config.port=this.port.value,this.loaded&&(this.config.entity||(this.config.entity=[]),!i.isEmpty(this.libraryName.value))){this.config.libraryName=this.libraryName.value;let t="";i.isEqual(this.sortOrder.value,"Ascending")?t="asc":i.isEqual(this.sortOrder.value,"Descending")&&(t="desc"),i.isEmpty(t)||i.isEmpty(this.sort.value)?this.config.sort="":this.config.sort=`${this.sort.value}:${t}`,this.config.displayType=this.displayTypeData[this.displayType.value],i.isEmpty(this.maxCount.value)?this.config.maxCount="":this.config.maxCount=this.maxCount.value,i.isEmpty(this.maxRows.value)?this.config.maxRows="":this.config.maxRows=this.maxRows.value,i.isEmpty(this.useHorizontalScroll.value)?this.config.useHorizontalScroll="No":this.config.useHorizontalScroll=this.useHorizontalScroll.value,i.isEmpty(this.useShuffle.value)?this.config.useShuffle="No":this.config.useShuffle=this.useShuffle.value,i.isEmpty(this.displayTitleMain.value)?this.config.displayTitleMain="Yes":this.config.displayTitleMain=this.displayTitleMain.value,i.isEmpty(this.displaySubtitleMain.value)?this.config.displaySubtitleMain="Yes":this.config.displaySubtitleMain=this.displaySubtitleMain.value,i.isEmpty(this.minWidth.value)?this.config.minWidth="":this.config.minWidth=this.minWidth.value,i.isEmpty(this.minEpisodeWidth.value)?this.config.minEpisodeWidth="":this.config.minEpisodeWidth=this.minEpisodeWidth.value,i.isEmpty(this.minExpandedWidth.value)?this.config.minExpandedWidth="":this.config.minExpandedWidth=this.minExpandedWidth.value,i.isEmpty(this.fontSize1.value)?this.config.fontSize1="":this.config.fontSize1=this.fontSize1.value,i.isEmpty(this.fontSize2.value)?this.config.fontSize2="":this.config.fontSize2=this.fontSize2.value,i.isEmpty(this.fontSize3.value)?this.config.fontSize3="":this.config.fontSize3=this.fontSize3.value,i.isEmpty(this.fontSize4.value)?this.config.fontSize4="":this.config.fontSize4=this.fontSize4.value,i.isEmpty(this.minExpandedHeight.value)?this.config.minExpandedHeight="":this.config.minExpandedHeight=this.minExpandedHeight.value,i.isEmpty(this.cardTitle.value)?this.config.title="":this.config.title=this.cardTitle.value,i.isEmpty(this.entities)||(this.config.entity=[],i.forEach(this.entities,(t=>{i.isEmpty(t.value)||i.includes(this.config.entity,t.value)||this.config.entity.push(t.value)}))),i.isEqual(this.playTrailer.value,"Yes")?this.config.playTrailer=!0:i.isEqual(this.playTrailer.value,"No")?this.config.playTrailer=!1:i.isEqual(this.playTrailer.value,"Muted")&&(this.config.playTrailer="muted"),i.isEqual(this.showExtras.value,"Yes")?this.config.showExtras=!0:i.isEqual(this.showExtras.value,"No")&&(this.config.showExtras=!1),i.isEqual(this.showSearch.value,"Yes")?this.config.showSearch=!0:i.isEqual(this.showSearch.value,"No")&&(this.config.showSearch=!1),this.config.runBefore=this.runBefore.value,this.config.runAfter=this.runAfter.value}i.isEqual(this.config,t)||this.fireEvent(this,"config-changed",{config:this.config})},this.render=async()=>{const t=(t,e="",n=!1)=>{i.isEmpty(e)&&(e=t);const s=document.createElement("option");return s.innerHTML=e.replace(/ /g," "),s.label=t,s.value=t,n&&(s.disabled=!0),s},e=(e,n)=>{if(this.entitiesRegistry){const s=document.createElement("div"),r=document.createElement("select");r.appendChild(t(""));const a=[];return i.forEach(this.entitiesRegistry,(e=>{if(i.isEqual(e.platform,"cast")||i.isEqual(e.platform,"kodi")||i.isEqual(e.platform,"androidtv")||i.isEqual(e.platform,"input_select")||i.isEqual(e.platform,"input_text")||i.isEqual(e.platform,"vlc_telnet")||i.isEqual(e.platform,"sonos")){const i=`${e.platform} | ${e.entity_id}`;r.appendChild(t(i)),a.push(i)}})),i.forEach(this.clients,(e=>{const i=`plexPlayer | ${e.name} | ${e.address} | ${e.machineIdentifier}`;r.appendChild(t(i)),a.push(i)})),i.isArray(this.config.entity)&&i.forEach(this.config.entity,(e=>{i.includes(a,e)||(r.appendChild(t(e)),a.push(e))})),r.label="Entity",r.value=e,r.style.width="100%",r.style.height="40px",r.className="entitiesDropDown",r.addEventListener("change",n),this.entities.push(r),s.appendChild(this.generateTitle("Entity")),s.appendChild(r),s}return!1};this.content&&this.content.remove(),this.hassObj&&!this.entitiesRegistry&&(i.forOwn(this.hassObj.states,((t,e)=>{i.startsWith(e,"script.")&&this.scriptEntities.push(e)})),this.entitiesRegistry=await Y(this.hassObj.connection)),this.entities=[],this.content=document.createElement("div");const n=document.createElement("h2");n.innerHTML="Plex Configuration",n.style.margin="0px",n.style.padding="0px",this.content.appendChild(n),this.content.appendChild(this.generateTitle("Plex Protocol")),this.protocol.innerHTML="";const s=location.protocol;i.isEqual(s,"http:")&&this.protocol.appendChild(t("http")),this.protocol.appendChild(t("https")),this.protocol.style.width="100%",this.protocol.style.height="40px",this.protocol.addEventListener("change",this.valueUpdated),i.isEmpty(this.config.protocol)?i.isEqual(s,"http:")?this.protocol.value="http":this.protocol.value="https":this.protocol.value=this.config.protocol,this.content.appendChild(this.protocol),this.ip.style.width="100%",this.ip.style.marginTop="10px",this.ip.style.marginBottom="10px",this.ip.label="Plex IP Address / Hostname",this.config.ip?this.ip.value=this.config.ip.replace(/^https?:\/\//i,"").replace(/\/$/,""):this.ip.value=this.config.ip,this.ip.addEventListener("change",this.valueUpdated),this.content.appendChild(this.ip),this.port.label="Plex Port (Optional)",this.port.value=this.config.port,this.port.type="number",this.port.addEventListener("change",this.valueUpdated),this.content.appendChild(this.port),this.token.label="Plex Token",this.token.value=this.config.token,this.token.addEventListener("change",this.valueUpdated),this.content.appendChild(this.token),this.content.appendChild(this.generateTitle("Plex Library")),this.libraryName.innerHTML="",this.libraryName.appendChild(t("Smart Libraries","",!0)),this.libraryName.appendChild(t("Continue Watching")),this.libraryName.appendChild(t("Deck")),this.libraryName.appendChild(t("Recently Added")),this.libraryName.appendChild(t("Watch Next")),this.libraryName.disabled=!0,this.libraryName.style.width="100%",this.libraryName.style.height="40px",this.libraryName.addEventListener("change",this.valueUpdated);const r=document.createElement("div");r.style.color="red",this.content.appendChild(this.libraryName),this.content.appendChild(r),this.appendChild(this.content),this.plex=new V(this.config.ip.replace(/^https?:\/\//i,"").replace(/\/$/,""),this.plexPort,this.config.token,this.plexProtocol,this.config.sort),this.sections=await this.plex.getSections(),i.forEach(this.sections,(e=>!i.isEqual(e.title,this.config.libraryName)||!i.isEqual(e.type,"artist")||(this.content.appendChild(this.generateTitle("Use shuffle when playing")),this.useShuffle.innerHTML="",this.useShuffle.appendChild(t("Yes")),this.useShuffle.appendChild(t("No")),this.useShuffle.slot="dropdown-content",this.useShuffle.label="Use shuffle when playing",this.useShuffle.style.width="100%",this.useShuffle.style.height="40px",this.useShuffle.addEventListener("change",this.valueUpdated),i.isEmpty(this.config.useShuffle)?this.useShuffle.value="No":this.useShuffle.value=this.config.useShuffle,this.content.appendChild(this.useShuffle),!1))),this.livetv=await this.plex.getLiveTV(),this.collections=await this.plex.getCollections(),this.playlists=await this.plex.getPlaylists(),this.clients=await this.plex.getClients(),this.plexValidSection.style.display="none",this.plexValidSection.innerHTML="";let a=!0,o=!0;if(i.isArray(this.config.entity))i.forEach(this.config.entity,(t=>{if(i.isObjectLike(t))return o=!i.includes(i.keys(this.config.entity),"plexPlayer"),a=!1,!1}));else if(i.isObjectLike(this.config.entity)&&(o=!i.includes(i.keys(this.config.entity),"plexPlayer"),a=!1,o)){const t=[];a=!0,i.isObjectLike(this.config.entity)&&i.forOwn(this.config.entity,(e=>{i.isString(e)?t.push(e):i.isArray(e)&&i.forEach(e,(e=>{t.push(e)}))})),this.config.entity=t}const l=document.createElement("h2");if(l.innerHTML="Devices Configuration",l.style.lineHeight="29px",l.style.marginBottom="0px",l.style.marginTop="20px",a){const t=document.createElement("button");t.style.float="right",t.style.fontSize="20px",t.style.cursor="pointer",t.innerHTML="+",t.addEventListener("click",(()=>{const t=e("",this.valueUpdated);t&&this.entitiesSection.appendChild(t)})),l.appendChild(t)}if(this.plexValidSection.appendChild(l),this.entitiesSection.innerHTML="",this.plexValidSection.appendChild(this.entitiesSection),a)i.isString(this.config.entity)&&(this.config.entity=[this.config.entity]),i.isArray(this.config.entity)&&i.forEach(this.config.entity,(t=>{if(i.isString(t)){const i=e(t,this.valueUpdated);i&&this.entitiesSection.appendChild(i)}}));else{const t=document.createElement("div");t.innerHTML="Devices configuration is not available when using plexPlayer client device.
You can edit any other settings through UI and use Show code editor to edit entities.

If you are not using server settings for plexPlayer with identifier and server key, you can migrate your settings to UI by removing plexPlayer section and readd through UI.",this.plexValidSection.appendChild(t)}const h=document.createElement("h2");if(h.innerHTML="View Configuration",h.style.lineHeight="29px",h.style.marginBottom="0px",h.style.marginTop="20px",this.plexValidSection.appendChild(h),this.displayType.innerHTML="",this.displayType.style.width="100%",this.displayType.style.height="40px",this.displayType.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.generateTitle("Display Type (Optional)")),this.plexValidSection.appendChild(this.displayType),this.cardTitle.label="Card title (Optional)",this.cardTitle.value=this.config.title,this.cardTitle.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.cardTitle),this.maxCount.label="Maximum number of items to display (Optional)",this.maxCount.value=this.config.maxCount,this.maxCount.type="number",this.maxCount.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.maxCount),this.useHorizontalScroll.innerHTML="",this.plexValidSection.appendChild(this.generateTitle("Use horizontal scroll")),this.useHorizontalScroll.appendChild(t("Yes")),this.useHorizontalScroll.appendChild(t("No")),this.useHorizontalScroll.style.width="100%",this.useHorizontalScroll.style.height="40px",this.useHorizontalScroll.addEventListener("change",this.valueUpdated),i.isEmpty(this.config.useHorizontalScroll)?this.useHorizontalScroll.value="No":this.useHorizontalScroll.value=this.config.useHorizontalScroll,this.plexValidSection.appendChild(this.useHorizontalScroll),this.maxRows.label="Maximum number of rows to display (Optional)",this.maxRows.value=this.config.maxRows,this.maxRows.type="number",this.maxRows.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.maxRows),this.sort.innerHTML="",this.sort.style.width="100%",this.sort.style.height="40px",this.sort.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.generateTitle("Sort")),this.plexValidSection.appendChild(this.sort),this.sortOrder.innerHTML="",this.sortOrder.appendChild(t("Ascending")),this.sortOrder.appendChild(t("Descending")),this.plexValidSection.appendChild(this.generateTitle("Sort Order")),this.sortOrder.style.width="100%",this.sortOrder.style.height="40px",this.sortOrder.addEventListener("change",this.valueUpdated),i.isEmpty(this.config.sort))this.sortOrder.value="Ascending";else{const t=this.config.sort.split(":")[1];i.isEmpty(t)||i.isEqual(t,"asc")?this.sortOrder.value="Ascending":i.isEqual(t,"desc")&&(this.sortOrder.value="Descending")}this.plexValidSection.appendChild(this.sortOrder),this.plexValidSection.appendChild(this.generateTitle("Play Trailer")),this.playTrailer.innerHTML="",this.playTrailer.appendChild(t("Yes")),this.playTrailer.appendChild(t("Muted")),this.playTrailer.appendChild(t("No")),this.playTrailer.style.width="100%",this.playTrailer.style.height="40px",this.playTrailer.addEventListener("change",this.valueUpdated);let c="Yes";i.isEqual(this.config.playTrailer,"muted")?c="Muted":this.config.playTrailer||(c="No"),this.playTrailer.value=c,this.plexValidSection.appendChild(this.playTrailer),this.showExtras.innerHTML="",this.showExtras.appendChild(t("Yes")),this.showExtras.appendChild(t("No")),this.plexValidSection.appendChild(this.generateTitle("Show Extras")),this.showExtras.style.width="100%",this.showExtras.style.height="40px",this.showExtras.addEventListener("change",this.valueUpdated);let u="Yes";this.config.showExtras||(u="No"),this.showExtras.value=u,this.plexValidSection.appendChild(this.showExtras),this.showSearch.innerHTML="",this.showSearch.appendChild(t("Yes")),this.showSearch.appendChild(t("No")),this.plexValidSection.appendChild(this.generateTitle("Show Search")),this.showSearch.style.width="100%",this.showSearch.style.height="40px",this.showSearch.addEventListener("change",this.valueUpdated);let d="Yes";this.config.showSearch||(d="No"),this.showSearch.value=d,this.plexValidSection.appendChild(this.showSearch),this.runBefore.innerHTML="",this.runBefore.appendChild(t("")),i.forEach(this.scriptEntities,(e=>{this.runBefore.appendChild(t(e))})),this.plexValidSection.appendChild(this.generateTitle("Script to execute before starting the media (Optional)")),this.runBefore.style.width="100%",this.runBefore.style.height="40px",this.runBefore.addEventListener("change",this.valueUpdated),this.runBefore.value=this.config.runBefore,this.plexValidSection.appendChild(this.runBefore),this.runAfter.innerHTML="",this.runAfter.appendChild(t("")),i.forEach(this.scriptEntities,(e=>{this.runAfter.appendChild(t(e))})),this.plexValidSection.appendChild(this.generateTitle("Script to execute after starting the media (Optional)")),this.runAfter.style.width="100%",this.runAfter.style.height="40px",this.runAfter.addEventListener("change",this.valueUpdated),this.runAfter.value=this.config.runAfter,this.plexValidSection.appendChild(this.runAfter);const p=document.createElement("h2");if(p.innerHTML="Style Configuration",p.style.lineHeight="29px",p.style.marginBottom="0px",p.style.marginTop="20px",this.plexValidSection.appendChild(p),this.minWidth.label="Minimum width of the card (Optional)",this.minWidth.value=this.config.minWidth,this.minWidth.type="number",this.minWidth.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.minWidth),this.minExpandedWidth.label="Expanded width of the card (Optional)",this.minExpandedWidth.value=this.config.minExpandedWidth,this.minExpandedWidth.type="number",this.minExpandedWidth.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.minExpandedWidth),this.minExpandedHeight.label="Expanded height of the card (Optional)",this.minExpandedHeight.value=this.config.minExpandedHeight,this.minExpandedHeight.type="number",this.minExpandedHeight.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.minExpandedHeight),this.minEpisodeWidth.label="Minimum width of the episode card (Optional)",this.minEpisodeWidth.value=this.config.minEpisodeWidth,this.minEpisodeWidth.type="number",this.minEpisodeWidth.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.minEpisodeWidth),this.displayTitleMain.innerHTML="",this.displayTitleMain.appendChild(t("Yes")),this.displayTitleMain.appendChild(t("No")),this.plexValidSection.appendChild(this.generateTitle("Display title under poster")),this.displayTitleMain.style.width="100%",this.displayTitleMain.style.height="40px",this.displayTitleMain.addEventListener("change",this.valueUpdated),i.isEmpty(this.config.displayTitleMain)?this.displayTitleMain.value="Yes":this.displayTitleMain.value=this.config.displayTitleMain,this.plexValidSection.appendChild(this.displayTitleMain),this.fontSize1.label="Font size used in titles under cards (Optional)",this.fontSize1.value=this.config.fontSize1,this.fontSize1.type="number",this.fontSize1.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.fontSize1),this.displaySubtitleMain.innerHTML="",this.displaySubtitleMain.appendChild(t("Yes")),this.displaySubtitleMain.appendChild(t("No")),this.plexValidSection.appendChild(this.generateTitle("Display sub-title under poster")),this.displaySubtitleMain.style.width="100%",this.displaySubtitleMain.style.height="40px",this.displaySubtitleMain.addEventListener("change",this.valueUpdated),i.isEmpty(this.config.displaySubtitleMain)?this.displaySubtitleMain.value="Yes":this.displaySubtitleMain.value=this.config.displaySubtitleMain,this.plexValidSection.appendChild(this.displaySubtitleMain),this.fontSize2.label="Font size used in sub-titles under cards (Optional)",this.fontSize2.value=this.config.fontSize2,this.fontSize2.type="number",this.fontSize2.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.fontSize2),this.fontSize3.label="Font size used in title of the opened content (Optional)",this.fontSize3.value=this.config.fontSize3,this.fontSize3.type="number",this.fontSize3.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.fontSize3),this.fontSize4.label="Font size used in sub-titles, to-view count and description of the opened content (Optional)",this.fontSize4.value=this.config.fontSize4,this.fontSize4.type="number",this.fontSize4.addEventListener("change",this.valueUpdated),this.plexValidSection.appendChild(this.fontSize4),i.isEmpty(this.livetv)||(this.libraryName.appendChild(t("Live TV","",!0)),i.forEach(i.keys(this.livetv),(e=>{i.isEqual(this.config.libraryName,e)&&(r.innerHTML=`Warning: ${this.config.libraryName} play action currently only supported with Kodi.
You might also need custom build of kodi-media-sensors, see detailed configuration for more information.`),this.libraryName.appendChild(t(e))}))),!i.isEmpty(this.sections)){this.libraryName.appendChild(t("Libraries","",!0)),i.forEach(this.sections,(e=>{this.libraryName.appendChild(t(e.title))})),i.isEmpty(this.collections)||(this.libraryName.appendChild(t("Collections","",!0)),i.forEach(this.collections,(e=>{this.libraryName.appendChild(t(e.title))}))),i.isEmpty(this.playlists)||(this.libraryName.appendChild(t("Playlists","",!0)),i.forEach(this.playlists,(e=>{this.libraryName.appendChild(t(e.title))}))),this.libraryName.disabled=!1,this.libraryName.value=this.config.libraryName;let e="";if(i.forEach(this.sections,(t=>{if(i.isEqual(t.title,this.libraryName.value))return e=t.key,!1})),i.isEmpty(e))this.displayType.style.display="none",this.config.displayType="",this.displayType.value="",this.sort.style.display="none",this.sortOrder.style.display="none",this.config.sort="";else{const n=await this.plex.getSectionData(e),s=i.get(n,"[0].Meta.Type");if(!i.isNil(s)&&s.length>1){let e=0;this.displayType.appendChild(t("",""));let r=!1;i.forEach(s,(s=>{if("track"!==s.type&&"episode"!==s.type&&("folder"!==s.type||"folder"===s.type&&i.isEqual(i.get(n,"[0].viewGroup"),"artist"))){let n=s.key.split("type=")[1];"folder"===s.type&&(n="folder"),i.isEqual(n,this.config.displayType)&&(r=!0),this.displayTypeData[s.title]=n,this.displayType.appendChild(t(s.title)),e+=1}})),e>1?(this.displayType.style.display="block",i.isEmpty(this.config.displayType)||!r?this.displayType.value="":i.forEach(this.displayTypeData,((t,e)=>{i.isEqual(t,this.config.displayType)&&(this.displayType.value=e)}))):(this.displayType.style.display="none",this.config.displayType="",this.displayType.value="")}else this.displayType.style.display="none",this.config.displayType="",this.displayType.value="";let r=0;this.config.displayType&&i.forEach(s,((t,e)=>{t.key.split("type=")[1]===parseInt(this.config.displayType,10)&&(r=parseInt(e,10))}));const a=i.get(n,`[0].Meta.Type[${r}].Sort`);!i.isNil(a)&&a.length>0&&"folder"!==this.config.displayType?(i.forEach(a,(e=>{this.sort.appendChild(t(e.key))})),this.sort.style.display="block",this.sortOrder.style.display="block"):(this.sort.style.display="none",this.sortOrder.style.display="none",this.config.sort="")}if(i.isEmpty(this.config.sort))this.sort.value="",this.sortOrder.value="";else{this.sort.value=this.config.sort.split(":")[0];const t=this.config.sort.split(":")[1];i.isEmpty(t)||i.isEqual(t,"asc")?this.sortOrder.value="Ascending":i.isEqual(t,"desc")&&(this.sortOrder.value="Descending")}this.plexValidSection.style.display="block"}this.loaded=!0,this.content.appendChild(this.plexValidSection)},this.setConfig=t=>{this.config=JSON.parse(JSON.stringify(t)),t.port&&!i.isEqual(t.port,"")?this.plexPort=t.port:this.plexPort=!1;const e=location.protocol;t.protocol?this.plexProtocol=t.protocol:i.isEqual(e,"http:")?this.config.protocol="http":this.config.protocol="https",t.sort||(this.config.sort="titleSort:asc"),t.displayType||(this.config.displayType=""),i.isNil(t.playTrailer)?this.config.playTrailer=!0:this.config.playTrailer=t.playTrailer,i.isNil(t.showExtras)?this.config.showExtras=!0:this.config.showExtras=t.showExtras,i.isNil(t.showSearch)?this.config.showSearch=!0:this.config.showSearch=t.showSearch,i.isNil(t.runBefore)||(this.config.runBefore=t.runBefore),i.isNil(t.runAfter)||(this.config.runAfter=t.runAfter),i.isNil(t.title)||(this.config.title=t.title),i.isNumber(this.config.maxCount)&&(this.config.maxCount=`${this.config.maxCount}`),i.isNumber(this.config.maxRows)&&(this.config.maxRows=`${this.config.maxRows}`),i.isNil(this.config.useHorizontalScroll)||(this.config.useHorizontalScroll=`${this.config.useHorizontalScroll}`),i.isNil(this.config.useShuffle)||(this.config.useShuffle=`${this.config.useShuffle}`),i.isNil(this.config.displayTitleMain)||(this.config.displayTitleMain=`${this.config.displayTitleMain}`),i.isNil(this.config.displaySubtitleMain)||(this.config.displaySubtitleMain=`${this.config.displaySubtitleMain}`),i.isNumber(this.config.minWidth)&&(this.config.minWidth=`${this.config.minWidth}`),i.isNumber(this.config.minEpisodeWidth)&&(this.config.minEpisodeWidth=`${this.config.minEpisodeWidth}`),i.isNumber(this.config.minExpandedWidth)&&(this.config.minExpandedWidth=`${this.config.minExpandedWidth}`),i.isNumber(this.config.fontSize1)&&(this.config.fontSize1=`${this.config.fontSize1}`),i.isNumber(this.config.fontSize2)&&(this.config.fontSize2=`${this.config.fontSize2}`),i.isNumber(this.config.fontSize3)&&(this.config.fontSize3=`${this.config.fontSize3}`),i.isNumber(this.config.fontSize4)&&(this.config.fontSize4=`${this.config.fontSize4}`),i.isNumber(this.config.minExpandedHeight)&&(this.config.minExpandedHeight=`${this.config.minExpandedHeight}`),this.render()},this.configChanged=t=>{const e=new Event("config-changed",{bubbles:!0,composed:!0});e.detail={config:t},this.dispatchEvent(e)}}set hass(t){this.hassObj=t}} /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -39,7 +39,7 @@ window.trustedTypes&&trustedTypes.createPolicy("lit-html",{createHTML:t=>t}); * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -let rt=!1;(()=>{try{const t={get capture(){return rt=!0,!1}};window.addEventListener("test",t,t),window.removeEventListener("test",t,t)}catch(t){}})(), +let at=!1;(()=>{try{const t={get capture(){return at=!0,!1}};window.addEventListener("test",t,t),window.removeEventListener("test",t,t)}catch(t){}})(), /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -89,7 +89,7 @@ http://polymer.github.io/AUTHORS.txt The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt -*/;const at=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,ot=Symbol();class lt{constructor(t,e){if(e!==ot)throw new Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t}get styleSheet(){return void 0===this._styleSheet&&(at?(this._styleSheet=new CSSStyleSheet,this._styleSheet.replaceSync(this.cssText)):this._styleSheet=null),this._styleSheet}toString(){return this.cssText}} +*/;const ot=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,lt=Symbol();class ht{constructor(t,e){if(e!==lt)throw new Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t}get styleSheet(){return void 0===this._styleSheet&&(ot?(this._styleSheet=new CSSStyleSheet,this._styleSheet.replaceSync(this.cssText)):this._styleSheet=null),this._styleSheet}toString(){return this.cssText}} /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. @@ -103,7 +103,7 @@ found at http://polymer.github.io/PATENTS.txt * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -(window.litElementVersions||(window.litElementVersions=[])).push("2.5.0");const ht=document.createElement("style");ht.textContent=((t,...e)=>{const i=e.reduce(((e,i,n)=>e+(t=>{if(t instanceof lt)return t.cssText;if("number"==typeof t)return t;throw new Error(`Value passed to 'css' function must be a 'css' function result: ${t}. Use 'unsafeCSS' to pass non-literal values, but\n take care to ensure page security.`)})(i)+t[n+1]),t[0]);return new lt(i,ot)})` +(window.litElementVersions||(window.litElementVersions=[])).push("2.5.0");const ct=document.createElement("style");ct.textContent=((t,...e)=>{const i=e.reduce(((e,i,n)=>e+(t=>{if(t instanceof ht)return t.cssText;if("number"==typeof t)return t;throw new Error(`Value passed to 'css' function must be a 'css' function result: ${t}. Use 'unsafeCSS' to pass non-literal values, but\n take care to ensure page security.`)})(i)+t[n+1]),t[0]);return new ht(i,lt)})` .maxZIndex { z-index: 6 !important; } @@ -663,5 +663,5 @@ found at http://polymer.github.io/PATENTS.txt button[name='playButton']:focus:after { border-color: transparent transparent transparent black !important; } -`.cssText;class ct extends HTMLElement{constructor(){super(...arguments),this.renderPageRetries=0,this.searchInputElem=document.createElement("input"),this.plexProtocol="http",this.displayType=!1,this.useHorizontalScroll=!1,this.useShuffle=!1,this.displayTitleMain=!0,this.displaySubtitleMain=!0,this.plexPort=!1,this.epgData={},this.detailsShown=!1,this.entityRegistry=[],this.runBefore="",this.playTrailer=!0,this.showExtras=!0,this.isVisible=!0,this.showSearch=!0,this.previousPageWidth=0,this.runAfter="",this.columnsCount=0,this.renderedRows=0,this.renderedItems=0,this.maxRenderCount=!1,this.minWidth=n.minimumWidth,this.minEpisodeWidth=n.minimumEpisodeWidth,this.minExpandedWidth=n.expandedWidth,this.minExpandedHeight=n.expandedHeight,this.fontSize1=14,this.fontSize2=14,this.fontSize3=28,this.fontSize4=16,this.seasonContainerClickEnabled=!0,this.looseSearch=!1,this.movieElems=[],this.searchValue="",this.activeMovieElemData={},this.seasonElemFreshlyLoaded=!1,this.episodesElemFreshlyLoaded=!1,this.seasonsElemHidden=!0,this.episodesElemHidden=!0,this.data={},this.config={},this.loading=!1,this.maxCount=!1,this.maxRows=!1,this.error="",this.contentBGHeight=0,this.initialDataLoaded=!1,this.haWindow=ct.querySelectorAllShadows("hui-view")[0],this.renderNewElementsIfNeeded=()=>{console.log("renderNewElementsIfNeeded");const t=Y(this.content);let{scrollTop:e}=this.haWindow;et-300&&this.renderedItems>0&&this.renderedItems{if(this.isVisible){if(!this.detailsShown){let t=!1;if(this.getElementsByClassName("videoPlayer")[0].children.length>0&&(t=G(this)),this.card&&this.movieElems.length>0&&!t&&this.previousPageWidth!==this.card.offsetWidth){this.previousPageWidth=this.card.offsetWidth,this.renderPage();const t=this.getElementsByClassName("contentbg");this.contentBGHeight=Y(t[0])}}this.renderNewElementsIfNeeded()}},this.loadInitialData=async()=>{this.initialDataLoaded=!0,setInterval((()=>{const t=!i.isNull(this.offsetParent);t&&!this.isVisible&&this.renderPage(),this.isVisible=t}),100),this.hassObj&&(this.entityRegistry=await X(this.hassObj.connection));const t=()=>{if(this.detailsShown&&this.activeMovieElem&&!G(this)&&this.isVisible){const t=this.getElementsByClassName("seasonContainer"),e=this.getElementsByClassName("episodeContainer"),n=this.getElementsByClassName("seasonElem");let s=this.activeMovieElem;i.forEach(n,(t=>{if(i.isEqual(t.dataset.clicked,"true"))return s=t,!1}));const r=parseInt(K(s).top,10)-70,a=((t,e,i)=>{const n=t[t.length-1],s=e[e.length-1];let r=!1;return t.length>0&&parseInt(i.style.top,10)>0?r=Y(n)+parseInt(K(n).top,10)+10:e.length>0&&(r=Y(s)+parseInt(K(s).top,10)+10),r})(t,e,s);this.getTop()a&&(window.scroll({top:a-window.innerHeight}),this.children[0].classList.add("stop-scrolling")):-70!==r&&-10!==a&&(window.scroll({top:r}),this.children[0].classList.add("stop-scrolling")))}this.renderNewElementsIfNeeded()};this.haWindow.addEventListener("scroll",t),window.addEventListener("scroll",t),window.addEventListener("wheel",t),window.addEventListener("touchmove",t),window.addEventListener("resize",(()=>{this.resizeHandler()})),this.card&&(this.previousPageWidth=this.card.offsetWidth),this.resizeBackground()},this.renderInitialData=async()=>{let{entity:t}=JSON.parse(JSON.stringify(this.config));const e=(t,e)=>{let n=e,s=!1;i.startsWith(e,"plexPlayer | ")?(n=e.split(" | ")[3],s=!0):i.isPlainObject(e)?n=e[Object.keys(e)[0]]:(i.startsWith(e,"androidtv | ")||i.startsWith(e,"kodi | ")||i.startsWith(e,"cast | ")||i.startsWith(e,"input_select | ")||i.startsWith(e,"input_text | ")||i.startsWith(e,"vlc_telnet | ")||i.startsWith(e,"sonos | "))&&(n=e.split(" | ")[1],s=!1),s?(i.isNil(t.plexPlayer)&&(t.plexPlayer=[]),t.plexPlayer.push(n)):i.forEach(this.entityRegistry,(e=>{if(i.isEqual(e.entity_id,n))switch(e.platform){case"cast":i.isNil(t.cast)&&(t.cast=[]),t.cast.push(e.entity_id);break;case"androidtv":i.isNil(t.androidtv)&&(t.androidtv=[]),t.androidtv.push(e.entity_id);break;case"kodi":i.isNil(t.kodi)&&(t.kodi=[]),t.kodi.push(e.entity_id);break;case"input_select":i.isNil(t.inputSelect)&&(t.inputSelect=[]),t.inputSelect.push(e.entity_id);break;case"input_text":i.isNil(t.inputText)&&(t.inputText=[]),t.inputText.push(e.entity_id);break;case"vlc_telnet":i.isNil(t.vlcTelnet)&&(t.vlcTelnet=[]),t.vlcTelnet.push(e.entity_id);break;case"sonos":i.isNil(t.sonos)&&(t.sonos=[]),t.sonos.push(e.entity_id);break;default:console.error(`Entity ${e.entity_id} is not supported.`)}}))},n=t;i.isString(n)?(t={},e(t,n)):i.isArray(n)&&(t={},i.forEach(n,(i=>{e(t,i)}))),this.loading=!0,this.renderPage();try{if(this.plex&&this.hassObj){this.playController=new nt(this,this.hassObj,this.plex,t,this.runBefore,this.runAfter,this.config.libraryName,this.entityRegistry,this.useShuffle),this.playController&&await this.playController.init(),await this.plex.init();const e=await this.plex.getSections(),n=async()=>{if(this.plex)try{const t=await this.plex.getOnDeck();this.data.Deck=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(Z("Deck"))}},s=async()=>{if(this.plex)try{const t=await this.plex.getContinueWatching();this.data["Continue Watching"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(Z("Continue Watching"))}},r=async()=>{if(this.plex)try{const t=await this.plex.getWatchNext();this.data["Watch Next"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(Z("Watch Next"))}},a=async()=>{if(this.plex)try{const t=await this.plex.getRecentyAdded();this.data["Recently Added"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;try{console.warn("PlexMeetsHomeAssistant: Using old endpoint for recently added tv shows. Consider updating your Plex server.");const t=await this.plex.getRecentyAdded(!0);this.data["Recently Added"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(Z("Recently Added"))}}},o=async()=>{if(this.plex){const t=await this.plex.getLiveTV();i.forEach(t,((t,e)=>{this.data[e]=t,i.forEach(this.data[e],((t,i)=>{this.data[e][i].type="epg"}))}))}},l=async()=>{this.plex&&(this.epgData=await this.plex.getEPG())};let h=!1;i.forEach(e,(t=>!i.isEqual(t.title,this.config.libraryName)||(h=t.key,!1)));const c=[];h&&c.push(this.plex.getSectionData(h,this.displayType)),i.isEqual(this.config.libraryName,"Deck")?c.push(n()):i.isEqual(this.config.libraryName,"Continue Watching")?c.push(s()):i.isEqual(this.config.libraryName,"Watch Next")?c.push(r()):i.isEqual(this.config.libraryName,"Recently Added")&&c.push(a()),c.push(o()),c.push(l());const[u]=await Promise.all(c);i.forEach(this.epgData,((t,e)=>{i.forEach(this.data[e],((t,n)=>{i.isNil(this.epgData[e][t.channelCallSign])||(this.data[e][n].epg=this.epgData[e][t.channelCallSign])}))})),u&&h&&i.forEach(u,(t=>{this.data[t.librarySectionTitle]=t.Metadata}));const d=await this.plex.getCollections();let p={};i.forEach(d,(t=>{this.plex&&i.isEqual(t.title,this.config.libraryName)&&(p=t)})),i.isNil(p.key)||(this.data[p.title]=await this.plex.getCollectionData(p.key));const f=await this.plex.getPlaylists();let y={};i.forEach(f,(t=>{this.plex&&i.isEqual(t.title,this.config.libraryName)&&(y=t)})),i.isNil(y.key)||(this.data[y.title]=await this.plex.getPlaylistData(y.key)),void 0===this.data[this.config.libraryName]&&(this.error=`Library name ${this.config.libraryName} does not exist.`),this.loading=!1,this.render()}else setTimeout((()=>{this.renderInitialData()}),250)}catch(t){this.error=`Plex server did not respond.
Details of the error: ${F(t.message)}`,this.renderPage()}},this.render=()=>{this.renderPage()},this.searchInput=()=>{const t=document.createElement("div");return t.className="searchContainer",this.searchInputElem=document.createElement("input"),this.searchInputElem.type="text",this.searchInputElem.value=this.searchValue,this.searchInputElem.placeholder=`Search ${this.config.libraryName}...`,this.searchInputElem.addEventListener("keyup",(()=>{i.isEqual(this.searchInputElem.value,this.searchValue)||(this.searchValue=this.searchInputElem.value,this.renderPage(),this.focus())})),t.appendChild(this.searchInputElem),t},this.renderMovieElems=()=>{const t=(t,e,n,s)=>{const r=this.renderedRows,a=this.renderedItems,o=this.columnsCount;let l=0;this.contentContainer.style.width="";let h=0,c=(!this.maxCount||this.renderedItems{if(c=(!this.maxCount||this.renderedItems{if(!i.isEmpty(e)&&i.includes(i.toUpper(r.title),i.toUpper(e))||i.includes(i.toUpper(r.parentTitle),i.toUpper(e))||i.includes(i.toUpper(r.grandparentTitle),i.toUpper(e)))return t=!0,!1})),(t||i.isEmpty(n[0]))&&(o=!0)}else(i.includes(i.toUpper(r.title),i.toUpper(this.searchValue))||i.includes(i.toUpper(r.parentTitle),i.toUpper(this.searchValue))||i.includes(i.toUpper(r.grandparentTitle),i.toUpper(this.searchValue))||i.includes(i.toUpper(r.tag),i.toUpper(this.searchValue))||i.includes(i.toUpper(i.get(r,"epg.title")),i.toUpper(this.searchValue)))&&(o=!0);if(o&&(u+=1,u>this.renderedItems)){if(t&&this.contentContainer.appendChild(a),this.useHorizontalScroll){this.renderedItems>0&&this.renderedItems%s==0&&(this.renderedRows+=1,a.style.clear="both");const t=10;(1===this.renderedRows||!this.maxRows||this.maxRows<2)&&(h+=parseFloat(a.style.width)+t)}this.renderedItems+=1}return t&&o&&l!==a.getBoundingClientRect().top&&!this.useHorizontalScroll&&(this.renderedRows+=1,0!==l&&0===this.columnsCount&&(this.columnsCount=this.renderedItems-1),l=a.getBoundingClientRect().top,!(t=>{const e=t.getBoundingClientRect(),i=e.top,n=e.bottom;return i>=0&&n<=window.innerHeight})(a)&&!this.maxRenderCount&&this.renderedItems>0&&(this.maxRenderCount=this.renderedItems-1+2*this.columnsCount)),this.maxRows&&this.renderedRows>this.maxRows&&!this.useHorizontalScroll&&a.remove(),!0}return!1}));const d={renderedItems:this.renderedItems};return t||(this.renderedRows=r,this.renderedItems=a,this.columnsCount=o),t&&h>0&&(this.contentContainer.style.width=`${h}px`),d},e=(!this.maxCount||this.renderedItems{let e=!1;return i.forEach(t,(t=>{if(i.isEqual(t.type,"episode"))return e=!0,!1})),e})(this.data[this.config.libraryName]),{renderedItems:a}=t(!1,r,s,n);n=a,this.maxRows&&(n=Math.ceil(a/this.maxRows)),t(!0,r,s,n)}const n=this.getElementsByClassName("contentbg")[0];this.contentBGHeight=Y(n)},this.renderPage=()=>{if(this.searchInputElem.placeholder=`Search ${this.config.libraryName}...`,this.showSearch?this.searchInputElem.style.display="block":this.searchInputElem.style.display="none",this.card){const t=()=>this.card?this.card.getBoundingClientRect().width-parseInt(this.card.style.paddingRight,10)-parseInt(this.card.style.paddingLeft,10):0,e=t(),i=Math.floor(e/this.minWidth);if(e>0){const s=Math.floor(e/this.minEpisodeWidth);let r=11;i>7?r=10.3:i>3&&(r=10.7),n.width=e/i-r,n.height=n.width*n.ratio,n.episodeWidth=Math.floor(e/s-r),n.episodeHeight=Math.round(n.episodeWidth*n.episodeRatio),setTimeout((()=>{if(this.card){t()!==e&&this.renderPage()}}),1)}else this.renderPageRetries<10&&setTimeout((()=>{this.renderPageRetries+=1,this.renderPage()}),250)}this.renderedItems=0,this.renderedRows=0;const t=document.createElement("div");if(t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",t.innerHTML='
',this.content&&this.content.remove(),!this.card){this.card=document.createElement("ha-card"),this.card.style.transition="0.5s",this.card.style.overflow="hidden",this.card.style.padding="16px",this.card.style.paddingRight="6px";const t=document.createElement("h1");t.classList.add("card-header"),t.style.paddingRight="0px",t.style.paddingLeft="0px",t.style.paddingTop="0px",t.style.paddingBottom="0px";const e=document.createElement("div");e.classList.add("name"),e.textContent=this.config.title,t.appendChild(e),i.isNil(this.config.title)||i.isEmpty(this.config.title)?t.style.display="none":t.style.display="block",this.card.appendChild(t),this.card.appendChild(this.searchInput()),this.showSearch?this.searchInputElem.style.display="block":this.searchInputElem.style.display="none",this.appendChild(this.card)}this.content=document.createElement("div"),this.content.innerHTML=this.loadCustomStyles(),this.useHorizontalScroll&&(this.content.style.overflowX="auto",this.content.style.whiteSpace="nowrap"),""!==this.error?this.content.innerHTML+=`Error: ${this.error}`:this.data[this.config.libraryName]&&0===this.data[this.config.libraryName].length?this.content.innerHTML+=`Library ${F(this.config.libraryName)} has no items.`:this.loading&&(this.content.style.padding="16px 16px 16px",this.content.appendChild(t)),this.card.appendChild(this.content),this.contentContainer=document.createElement("div"),this.contentContainer.className="contentContainer",this.content.appendChild(this.contentContainer);const e=document.createElement("div");e.className="contentbg",this.contentContainer.appendChild(e);const s=document.createElement("div");s.className="contentArt";const r=document.createElement("div");r.className="videobg1",s.appendChild(r);const a=document.createElement("div");if(a.className="videobg2",s.appendChild(a),this.contentContainer.appendChild(s),this.detailElem=document.createElement("div"),this.detailElem.className="detail",this.detailElem.innerHTML="

\n\t\t\t

\n\t\t\t",this.playController){const t=this.playController.getPlayActionButton();t.style.fontSize=`${this.fontSize4}px`,t.style.lineHeight=`${this.fontSize4}px`,t.style.marginTop=this.fontSize4/4+"px",t.style.marginBottom=this.fontSize4/4+"px",t.style.marginRight=this.fontSize4/4+"px",t.style.padding=`${this.fontSize4/2}px ${this.fontSize4}px`,this.detailElem.appendChild(t)}this.detailElem.innerHTML+=`\n\t\t\t\n\t\t\t
\n\t\t\t\n\t\t\t
\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t
\n\t\t\t\t\t\tDirected by\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
\n\t\t\t\t\t\tWritten by\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
\n\t\t\t\t\t\tStudio\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
\n\t\t\t\t\t\tGenre\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
`,this.detailElem.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),this.contentContainer.appendChild(this.detailElem);this.getElementsByClassName("detailPlayTrailerAction")[0].addEventListener("click",(t=>{if(t.stopPropagation(),this.videoElem){const t=this.getElementsByClassName("videoPlayer")[0].children[0];if(t.requestFullscreen)t.requestFullscreen();else if(t.webkitRequestFullscreen)t.webkitRequestFullscreen();else if(t.msRequestFullscreen)t.msRequestFullscreen();else{const e=this.getElementsByClassName("videobg1"),i=this.getElementsByClassName("videobg2");for(const t of e)t.classList.add("transparent");for(const t of i)t.classList.add("transparent");this.videoElem.classList.add("maxZIndex"),this.videoElem.classList.add("simulatedFullScreen"),t.controls=!0}}})),this.seasonsElem=document.createElement("div"),this.seasonsElem.className="seasons",this.seasonsElem.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),this.contentContainer.appendChild(this.seasonsElem),this.episodesElem=document.createElement("div"),this.episodesElem.className="episodes",this.episodesElem.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),this.contentContainer.appendChild(this.episodesElem),this.videoElem=document.createElement("div"),this.videoElem.className="video",this.videoElem.addEventListener("click",(t=>{const e=this.getElementsByClassName("videoPlayer")[0].children[0];if(G(this)){t.stopPropagation(),this.videoElem&&(this.videoElem.classList.remove("maxZIndex"),this.videoElem.classList.remove("simulatedFullScreen"));const i=this.getElementsByClassName("videobg1"),n=this.getElementsByClassName("videobg2");for(const t of i)t.classList.remove("transparent");for(const t of n)t.classList.remove("transparent");e.controls=!1}else this.hideBackground(),this.minimizeAll()}));const o=document.createElement("div");o.className="videobg1",this.videoElem.appendChild(o);const l=document.createElement("div");l.className="videobg2",this.videoElem.appendChild(l);const h=document.createElement("div");h.className="videoPlayer",this.videoElem.appendChild(h),this.contentContainer.appendChild(this.videoElem),setTimeout((()=>{e.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),s.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()}))}),1);const c=document.createElement("div");c.className="clear",this.contentContainer.appendChild(c),this.renderMovieElems(),this.calculatePositions(),this.loadCustomStyles()},this.calculatePositions=()=>{const t=setInterval((()=>{this.movieElems=this.getElementsByClassName("movieElem");for(let e=0;e{this.seasonsElemHidden=!1,this.seasonsElem&&i.forEach(this.seasonsElem.childNodes,(t=>{const e=t.children[0],s=t.children[1],r=t.children[2];e.style.display="block",void 0!==e.children[0].children[0]&&(e.children[0].children[0].style.display="block");const a=t=>{const a=t;a.style.marginTop="0",i.isEqual(e.dataset.type,"album")?(a.style.width=`${n.width}px`,a.style.height=`${n.width}px`):(a.style.width=`${n.width}px`,a.style.height=n.height-3+"px"),a.style.zIndex="3",a.style.marginLeft="0px",a.dataset.clicked="false",s.style.display="block",r.style.display="block",this.seasonTitleColorTimeout=setTimeout((()=>{s.style.color="rgba(255,255,255,1)",r.style.color="rgba(255,255,255,1)"}),500)};"true"===e.dataset.clicked?a(e):this.moveElemTimeout=setTimeout((()=>{a(e)}),100)}))},this.hideVideo=()=>{if(this.videoElem){this.getElementsByClassName("videoPlayer")[0].innerHTML="",this.videoElem.classList.remove("maxZIndex"),this.videoElem.classList.remove("simulatedFullScreen");const t=this.getElementsByClassName("videobg1"),e=this.getElementsByClassName("videobg2");for(const e of t)e.classList.remove("transparent");for(const t of e)t.classList.remove("transparent")}},this.minimizeAll=()=>{this.detailsShown=!1,this.activeMovieElem&&(this.activeMovieElem.style.display="block"),this.activeMovieElem=void 0;for(let t=0;t{this.movieElems[t].style.transition="0s",this.movieElems[t].style["z-index"]=1,this.movieElems[t].style.position="relative",this.movieElems[t].style.left="0px",this.movieElems[t].style.top="0px",this.movieElems[t].dataset.clicked=!1,setTimeout((()=>{this.movieElems[t].style.transition="0.5s"}),10)}),510));this.hideSeasons(),this.hideEpisodes(),this.hideDetails(),this.hideVideo(),clearInterval(this.showDetailsTimeout),clearInterval(this.showSeasonElemTimeout),clearInterval(this.seasonTitleColorTimeout),clearInterval(this.moveElemTimeout),clearInterval(this.scrollDownInactiveSeasonsTimeout),clearInterval(this.episodesLoadTimeout),clearInterval(this.episodesElemFreshlyLoadedTimeout),clearInterval(this.seasonElemFreshlyLoadedTimeout)},this.hideSeasons=()=>{if(this.seasonsElem){this.seasonsElemHidden=!0;const t=this.getTop();this.seasonsElem.style.top=`${t+2e3}px`,clearInterval(this.hideSeasonsTimeout),this.hideSeasonsTimeout=setTimeout((()=>{this.seasonsElem&&!this.seasonElemFreshlyLoaded&&(this.seasonsElem.innerHTML="",this.seasonsElem.style.display="none",this.resizeBackground())}),700)}},this.hideEpisodes=()=>{if(this.episodesElem){this.episodesElemHidden=!0;const t=this.getTop();this.episodesElem.style.top=`${t+2e3}px`,clearInterval(this.hideEpisodesTimeout),this.hideEpisodesTimeout=setTimeout((()=>{this.episodesElem&&!this.episodesElemFreshlyLoaded&&(this.episodesElem.innerHTML="",this.episodesElem.style.display="none",this.resizeBackground())}),700)}},this.scrollDownInactiveSeasons=()=>{this.seasonsElem&&(this.seasonsElemHidden=!0,i.forEach(this.seasonsElem.childNodes,(t=>{const e=t.children[0],i=t.children[1],n=t.children[2];"false"===e.dataset.clicked&&(e.style.marginTop="1000px",e.style.marginLeft="0px",this.scrollDownInactiveSeasonsTimeout=setTimeout((()=>{e.style.display="none",i.style.display="none",n.style.display="none"}),500))})))},this.hideDetails=()=>{const t=this.getTop();this.detailElem&&(this.detailElem.style.top=t-1e3+"px",this.detailElem.style.color="rgba(255,255,255,0)",this.detailElem.style.zIndex="0",this.detailElem.style.visibility="hidden"),clearTimeout(this.renderNewElementsIfNeededTimeout),this.renderNewElementsIfNeededTimeout=setTimeout((()=>{this.renderNewElementsIfNeeded()}),1e3);this.getElementsByClassName("detailPlayTrailerAction")[0].style.visibility="hidden"},this.showDetails=async t=>{this.detailsShown=!0;const e=this.getTop();if(this.detailElem&&(this.playController&&(this.playController.setPlayActionButtonType(t.type),this.playController.setPlayButtonClickFunction((e=>{e.preventDefault(),e.stopPropagation(),this.playController&&this.playController.play(t,!0)}))),this.detailElem.style.transition="0s",this.detailElem.style.top=e-1e3+"px",i.isEmpty(i.get(t,"thumb"))?this.detailElem.style.left="16px":this.detailElem.style.left=`${this.minExpandedWidth+30}px`,clearInterval(this.showDetailsTimeout),this.showDetailsTimeout=setTimeout((async()=>{if(this.detailElem&&this.plex){this.detailElem.style.visibility="visible",this.detailElem.style.transition="0.7s",this.detailElem.style.top=`${e}px`;let n=t;i.isEqual(t.type,"season")&&(n=await this.plex.getDetails(t.parentKey.split("/")[3]),n.title=`${n.title} - ${t.title}`);const s=this.getElementsByClassName("metaInfoDetailsData")[0];s.style.fontSize=`${this.fontSize4}px`,s.style.lineHeight=`${this.fontSize4}px`,s.style.marginTop=this.fontSize4/4+"px",s.style.marginBottom=this.fontSize4/4+"px",s.style.display="block",s.parentElement&&(n.Director&&n.Director.length>0?(s.innerHTML=F(n.Director[0].tag),s.parentElement.style.display="table-row"):s.parentElement.style.display="none");const r=this.getElementsByClassName("metaInfoDetailsData")[1];r.style.fontSize=`${this.fontSize4}px`,r.style.lineHeight=`${this.fontSize4}px`,r.style.marginTop=this.fontSize4/4+"px",r.style.marginBottom=this.fontSize4/4+"px",r.style.display="block",r.parentElement&&(n.Writer&&n.Writer.length>0?(r.innerHTML=F(n.Writer[0].tag),r.parentElement.style.display="table-row"):r.parentElement.style.display="none");const a=this.getElementsByClassName("metaInfoDetailsData")[2];a.style.fontSize=`${this.fontSize4}px`,a.style.lineHeight=`${this.fontSize4}px`,a.style.marginTop=this.fontSize4/4+"px",a.style.marginBottom=this.fontSize4/4+"px",a.style.display="block",a.parentElement&&(n.studio?(a.innerHTML=F(n.studio),a.parentElement.style.display="table-row"):a.parentElement.style.display="none");const o=this.getElementsByClassName("metaInfoDetailsData")[3];if(o.style.fontSize=`${this.fontSize4}px`,o.style.lineHeight=`${this.fontSize4}px`,o.style.marginTop=this.fontSize4/4+"px",o.style.marginBottom=this.fontSize4/4+"px",o.style.display="block",o.parentElement)if(n.Genre&&n.Genre.length>0){let t="";i.forEach(n.Genre,(e=>{t+=`${e.tag}, `})),o.innerHTML=F(t.slice(0,-2)),o.parentElement.style.display="table-row"}else o.parentElement.style.display="none";const l=this.getElementsByClassName("detailsTitle")[0];i.isNil(n.channelCallSign)?l.innerHTML=F(n.title):l.innerHTML=F(n.channelCallSign),l.style.lineHeight=`${this.fontSize3}px`,l.style.fontSize=`${this.fontSize3}px`,l.style.marginBottom=this.fontSize3/4+"px";const h=this.getElementsByClassName("detailsYear")[0];h.style.display="block",h.style.fontSize=`${this.fontSize4}px`,h.style.lineHeight=`${this.fontSize4}px`,h.style.marginTop="0px",h.style.marginBottom=this.fontSize4/4+"px",i.isNil(n.year)?i.isNil(n.epg)||i.isNil(n.epg.title)?(h.style.display="none",h.innerHTML=""):h.innerHTML=F(n.epg.title):h.innerHTML=F(n.year),this.getElementsByClassName("metaInfo")[0].innerHTML=(void 0!==n.duration?`${Math.round(parseInt(F(n.duration),10)/60/1e3)} min`:"")+(void 0!==n.contentRating?`${F(n.contentRating)}`:"")+(void 0!==n.rating?`${n.rating<5?"🗑":"⭐"} ${Math.round(10*parseFloat(F(n.rating)))/10}`:"")+"
";const c=this.getElementsByClassName("detailDesc")[0];c.style.fontSize=`${this.fontSize4}px`,c.style.lineHeight=`${this.fontSize4}px`,c.style.marginTop=this.fontSize4/4+"px",c.style.marginBottom=this.fontSize4/4+"px",c.style.display="block",i.isNil(n.summary)?i.isNil(n.epg)||i.isNil(n.epg.summary)?(c.innerHTML="",c.style.display="none"):c.innerHTML=F(n.epg.summary):c.innerHTML=F(n.summary),this.detailElem.style.color="rgba(255,255,255,1)",this.detailElem.style.zIndex="4",this.detailElem.style.width=`calc(100% - ${this.minExpandedWidth+30+20}px)`,this.activeMovieElem?this.detailElem.style.maxHeight=`${Y(this.activeMovieElem)+40}px`:this.detailElem.style.maxHeight=`${this.minExpandedHeight+20}px`}}),200)),this.plex){let s={};i.isEqual(t.type,"episode")?s=await this.plex.getLibraryData(`${t.grandparentKey}/children`):(t.childCount>0||i.isEqual(t.type,"artist")||i.isEqual(t.type,"album")||i.includes(t.key,"folder"))&&(s=await this.plex.getLibraryData(t.key)),this.playController&&(i.includes(t.key,"folder")?this.playController.setPlayActionDisplay("none"):this.playController.setPlayActionDisplay("block"));let r={};if(!i.isNil(t.key)&&(i.includes(t.key,"folder")||(r=await this.plex.getDetails(t.key.split("/")[3])),this.videoElem)){const n=this.plex.authorizeURL(this.plex.getBasicURL()+t.art);if(""===(t=>{let e="";return t.Extras&&t.Extras.Metadata&&t.Extras.Metadata.length>0&&i.forEach(t.Extras.Metadata,(t=>{if("trailer"===t.subtype)return e=t.Media[0].Part[0].key,!1})),e})(r)||i.isEqual(this.playTrailer,!1)){if(!i.isEmpty(n)){const t=this.getElementsByClassName("contentArt")[0],i=this.getElementsByClassName("contentbg")[0];t.style.width=`${window.innerWidth}px`,t.style.height=`${window.innerHeight}px`,t.style.backgroundImage=`url('${n}')`,t.style.top=e-8+"px",t.style.transition="0.5s",t.style.display="block",i.classList.add("no-transparency")}}else{const t=this.getElementsByClassName("videoPlayer")[0],n=document.createElement("video");n.style.height="100%",n.style.width="100%",n.controls=!1,i.isEqual(this.playTrailer,"muted")&&(n.muted=!0);const s=document.createElement("source");s.type="video/mp4",s.src=this.plex.authorizeURL(`${this.plex.getBasicURL()}${r.Extras.Metadata[0].Media[0].Part[0].key}`),n.appendChild(s),t.appendChild(n),n.load(),n.play();let a=!1;const o=this.getElementsByClassName("videobg1"),l=this.getElementsByClassName("videobg2");n.addEventListener("click",(t=>{G(this)&&t.stopPropagation()}));const h=()=>{if(this.videoElem)if(G(this)){for(const t of o)t.classList.add("transparent");for(const t of l)t.classList.add("transparent");this.videoElem.classList.add("maxZIndex"),n.controls=!0,n.muted=!1}else{for(const t of o)t.classList.remove("transparent");for(const t of l)t.classList.remove("transparent");this.videoElem.classList.remove("maxZIndex"),n.controls=!1,window.scroll({top:K(this.activeMovieElem).top-70,behavior:"smooth"}),i.isEqual(this.playTrailer,"muted")&&(n.muted=!0)}};n.addEventListener("fullscreenchange",h),n.addEventListener("mozfullscreenchange",h),n.addEventListener("webkitfullscreenchange",h),n.addEventListener("msfullscreenchange",h),n.addEventListener("playing",(()=>{if(this.videoElem&&!a){const t=this.getElementsByClassName("contentbg")[0],i=this.getElementsByClassName("detailPlayTrailerAction")[0];i.style.fontSize=`${this.fontSize4}px`,i.style.lineHeight=`${this.fontSize4}px`,i.style.marginTop=this.fontSize4/4+"px",i.style.marginBottom=this.fontSize4/4+"px",i.style.marginRight=this.fontSize4/4+"px",i.style.padding=`${this.fontSize4/2}px ${this.fontSize4}px`,i.style.visibility="visible",t.classList.add("no-transparency"),a=!0,this.videoElem.style.width=`${this.getElementsByClassName("searchContainer")[0].offsetWidth}px`,this.videoElem.style.visibility="visible",this.videoElem.style.top=`${e}px`}}))}}if(i.isEmpty(s)){if(this.episodesElemFreshlyLoaded=!0,this.episodesElem){if(this.episodesElemHidden=!1,this.episodesElem.style.display="block",this.episodesElem.innerHTML="",this.episodesElem.style.transition="0s",this.episodesElem.style.top=`${e+2e3}px`,i.isEqual(t.type,"season")){const e=await this.plex.getLibraryData(t.key);i.forEach(e,(t=>{this.episodesElem&&this.playController&&this.plex&&this.episodesElem.append(it(this.playController,this.plex,t,this.fontSize1,this.fontSize2))}))}else if(this.showExtras&&!i.isNil(r.Extras)){const t=r.Extras.Metadata;i.forEach(t,(t=>{this.episodesElem&&this.playController&&this.plex&&this.episodesElem.append(it(this.playController,this.plex,t,this.fontSize1,this.fontSize2))}))}clearInterval(this.episodesLoadTimeout),this.episodesLoadTimeout=setTimeout((()=>{this.episodesElem&&(this.episodesElem.style.transition="0.7s",this.episodesElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200),clearInterval(this.episodesElemFreshlyLoadedTimeout),this.episodesElemFreshlyLoadedTimeout=setTimeout((()=>{this.episodesElemFreshlyLoaded=!1}),700)}}else if(this.seasonElemFreshlyLoaded=!0,this.seasonsElem&&(this.seasonsElem.style.display="block",this.seasonsElem.innerHTML="",this.seasonsElem.style.transition="0s",this.seasonsElem.style.top=`${e+2e3}px`),i.isEqual(i.get(s[0],"type"),"track")){if(this.episodesElem){this.episodesElemHidden=!1,this.episodesElem.style.display="block",this.episodesElem.innerHTML="",this.episodesElem.style.transition="0s",this.episodesElem.style.top=`${e+2e3}px`;const n=document.createElement("table");n.style.width="calc(100% - 10px)",n.style.border="none",n.cellSpacing="0",n.cellPadding="0",this.episodesElem.append(n);let r=!1;i.forEach(s,(t=>{this.episodesElem&&this.playController&&this.plex&&(i.isEqual(t.type,"track")?(n.append(et(this.playController,this.plex,t,this.fontSize1,this.fontSize2,r)),r=!r):this.episodesElem.append(it(this.playController,this.plex,t,this.fontSize1,this.fontSize2)))})),clearInterval(this.episodesLoadTimeout),this.episodesLoadTimeout=setTimeout((()=>{this.episodesElem&&(this.episodesElem.style.transition="0.7s",this.activeMovieElem?i.isEmpty(i.get(t,"thumb"))?this.detailElem?this.episodesElem.style.top=`${e+Y(this.detailElem)}px`:this.episodesElem.style.top=`${e}px`:this.episodesElem.style.top=`${e+Y(this.activeMovieElem)+32}px`:this.episodesElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200),clearInterval(this.episodesElemFreshlyLoadedTimeout),this.episodesElemFreshlyLoadedTimeout=setTimeout((()=>{this.episodesElemFreshlyLoaded=!1}),700)}}else i.forEach(s,(t=>{if(this.seasonsElem&&this.plex){this.seasonsElemHidden=!1;const s=document.createElement("div");s.className="seasonContainer",s.style.width=`${n.width}px`;const r=`${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight}&minSize=1&upscale=1&url=${t.thumb}&X-Plex-Token=${this.config.token}`,a=document.createElement("div");a.className="seasonElem",a.style.width=`${n.width}px`,i.isEqual(t.type,"album")?a.style.height=`${n.width}px`:a.style.height=n.height-3+"px",a.style.backgroundImage=`url('${r}')`,a.dataset.clicked="false",this.playController&&!this.playController.isPlaySupported(t)&&(a.style.cursor="pointer");const o=document.createElement("div");if(o.className="interactiveArea",t.leafCount-t.viewedLeafCount>0){const e=document.createElement("div");e.className="toViewSeason",e.innerHTML=(t.leafCount-t.viewedLeafCount).toString(),e.style.fontSize=`${this.fontSize4}px`,e.style.lineHeight=`${this.fontSize4}px`,e.style.padding=this.fontSize4/2+"px",o.appendChild(e)}if(this.playController){const e=this.playController.getPlayButton(t.type);this.playController.isPlaySupported(t)&&e.classList.remove("disabled"),e.addEventListener("click",(e=>{e.stopPropagation(),this.plex&&this.playController&&this.playController.play(t,!0)})),o.append(e)}a.append(o),s.append(a);const l=document.createElement("div");l.className="seasonTitleElem",l.innerHTML=F(t.title),l.style.fontSize=`${this.fontSize1}px`,l.style.lineHeight=`${this.fontSize1}px`,s.append(l);const h=document.createElement("div");h.className="seasonEpisodesCount",t.leafCount>0?h.innerHTML=`${F(t.leafCount)} episodes`:i.isNil(t.year)||(h.innerHTML=`${F(t.year)} `),h.style.fontSize=`${this.fontSize2}px`,h.style.lineHeight=`${this.fontSize2}px`,s.append(h),s.addEventListener("click",(n=>{if(n.stopPropagation(),this.seasonContainerClickEnabled&&(this.seasonContainerClickEnabled=!1,setTimeout((()=>{this.seasonContainerClickEnabled=!0}),500),this.activeMovieElem))if("false"===a.dataset.clicked)this.playController&&(this.playController.setPlayActionButtonType(t.type),this.playController.setPlayButtonClickFunction((e=>{e.preventDefault(),e.stopPropagation(),this.playController&&this.playController.play(t,!0)}))),void 0!==a.children[0].children[0]&&(a.children[0].children[0].style.display="none"),a.dataset.clicked="true",this.activeMovieElem.style.top=e-1e3+"px",setTimeout((()=>{this.activeMovieElem&&(this.activeMovieElem.style.display="none")}),500),this.scrollDownInactiveSeasons(),this.activeMovieElem?s.style.top=-Y(this.activeMovieElem)+"px":s.style.top=-this.minExpandedHeight+"px",a.dataset.type=t.type,a.style.width=`${this.minExpandedWidth}px`,i.isEqual(t.type,"album")?a.style.height=`${this.minExpandedWidth}px`:a.style.height=this.minExpandedHeight-6+"px",a.style.zIndex="3",a.style.marginLeft=`-${K(a).left-K(this.activeMovieElem).left}px`,l.style.color="rgba(255,255,255,0)",h.style.color="rgba(255,255,255,0)",this.detailElem&&(this.detailElem.children[1].innerHTML=t.title),(async()=>{if(this.plex&&(t.leafCount>0||i.isEqual(t.type,"album"))){this.episodesElemFreshlyLoaded=!0;const n=await this.plex.getLibraryData(t.key);if(this.episodesElem){this.episodesElemHidden=!1,this.episodesElem.style.display="block",this.episodesElem.innerHTML="",this.episodesElem.style.transition="0s",this.episodesElem.style.top=`${e+2e3}px`;const s=document.createElement("table");s.style.width="calc(100% - 10px)",s.style.border="none",s.cellSpacing="0",s.cellPadding="0",i.isEqual(t.type,"album")&&this.episodesElem.append(s);let r=!1;i.forEach(n,(t=>{this.episodesElem&&this.playController&&this.plex&&(i.isEqual(t.type,"track")?(s.append(et(this.playController,this.plex,t,this.fontSize1,this.fontSize2,r)),r=!r):this.episodesElem.append(it(this.playController,this.plex,t,this.fontSize1,this.fontSize2)))})),clearInterval(this.episodesLoadTimeout),this.episodesLoadTimeout=setTimeout((()=>{this.episodesElem&&(this.episodesElem.style.transition="0.7s",this.activeMovieElem?this.episodesElem.style.top=`${e+Y(this.activeMovieElem)+32}px`:this.episodesElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200),clearInterval(this.episodesElemFreshlyLoadedTimeout),this.episodesElemFreshlyLoadedTimeout=setTimeout((()=>{this.episodesElemFreshlyLoaded=!1}),700)}}})();else if(this.playController&&this.playController.setPlayActionButtonType(t.type),s.style.top=`${s.dataset.top}px`,this.minimizeSeasons(),this.hideEpisodes(),this.activeMovieElem.style.display="block",setTimeout((()=>{this.activeMovieElem&&(this.activeMovieElem.style.top=`${e+16}px`)}),10),this.detailElem&&this.detailElem.children[1]){const{year:t}=this.detailElem.children[1].dataset;t&&(this.detailElem.children[1].innerHTML=t)}})),this.seasonsElem.append(s)}})),i.forEach(this.seasonsElem.children,(t=>{const e=t,i=e.offsetLeft,n=e.offsetTop;e.style.left=`${i}px`,e.dataset.left=`${i}`,e.style.top=`${n}px`,e.dataset.top=`${n}`})),i.forEach(this.seasonsElem.children,(t=>{t.style.position="absolute"})),clearInterval(this.seasonElemFreshlyLoadedTimeout),this.seasonElemFreshlyLoadedTimeout=setTimeout((()=>{this.seasonElemFreshlyLoaded=!1}),700),clearInterval(this.showSeasonElemTimeout),this.showSeasonElemTimeout=setTimeout((()=>{this.seasonsElem&&(this.seasonsElem.style.transition="0.7s",this.activeMovieElem?this.seasonsElem.style.top=`${e+Y(this.activeMovieElem)+32}px`:this.seasonsElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200)}},this.resizeBackground=()=>{if(this.seasonsElem&&this.episodesElem&&this.card){const t=this.getElementsByClassName("contentbg")[0];this.contentBGHeight=Y(t);const e=parseInt(this.seasonsElem.style.top.replace("px",""),10)+this.seasonsElem.scrollHeight,i=parseInt(this.episodesElem.style.top.replace("px",""),10)+this.episodesElem.scrollHeight;e>this.contentBGHeight&&!this.seasonsElemHidden?this.card.style.height=`${e+16}px`:i>this.contentBGHeight&&!this.episodesElemHidden?this.card.style.height=`${i+16}px`:this.card.style.height="100%"}},this.showBackground=()=>{const t=this.getElementsByClassName("contentbg");t[0].style.zIndex="2",t[0].style.backgroundColor="rgba(0,0,0,0.9)",t[0].style.display="block"},this.hideBackground=()=>{const t=this.getElementsByClassName("contentbg")[0];t.classList.remove("no-transparency"),t.style.zIndex="1",t.style.backgroundColor="rgba(0,0,0,0)",t.style.display="none";this.getElementsByClassName("contentArt")[0].style.display="none"},this.activateMovieElem=t=>{const e=t;if("true"===t.dataset.clicked)this.minimizeAll(),this.activeMovieElem=void 0,this.hideDetails(),setTimeout((()=>{e.dataset.clicked="false"}),500),this.hideBackground();else{const n=this.getTop();e.style.transition="0s",e.style.left=e.offsetLeft-this.content.scrollLeft+"px",e.style.top=`${e.offsetTop}px`,e.style.position="absolute",e.dataset.left=`${e.offsetLeft}`,e.dataset.top=`${e.offsetTop}`,e.style.zIndex="3",setTimeout((()=>{e.style.transition="0.5s",this.showDetails(this.activeMovieElemData),this.showBackground(),i.isEqual(t.style.width,t.style.height)?(e.style.width=`${this.minExpandedWidth}px`,e.style.height=`${this.minExpandedWidth}px`):(e.style.width=`${this.minExpandedWidth}px`,e.style.height=`${this.minExpandedHeight}px`),e.style.left="16px",e.style.top=`${n+16}px`,e.dataset.clicked="true",this.activeMovieElem=e}),1)}},this.getTop=()=>{if(this.card){const t=document.documentElement,e=(window.pageYOffset||t.scrollTop)-(t.clientTop||0),i=K(this.card).top;return e{let s="";this.plex&&(s=i.isEqual(t.type,"episode")?`${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight}&minSize=1&upscale=1&url=${t.grandparentThumb}&X-Plex-Token=${this.config.token}`:`${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight}&minSize=1&upscale=1&url=${t.thumb}&X-Plex-Token=${this.config.token}`);const r=document.createElement("div");r.className="plexMeetsContainer",r.style.width=`${n.width}px`,this.displayTitleMain||this.displaySubtitleMain?r.style.marginBottom="10px":r.style.marginBottom="5px",i.isNil(t.channelCallSign)||(r.style.marginBottom="10px");const a=document.createElement("div");a.className="movieElem",a.style.width=`${n.width}px`,a.style.height=`${n.height}px`,(!i.isNil(t.channelCallSign)||i.isEqual(t.type,"artist")||i.isEqual(t.type,"album")||i.includes(t.key,"folder"))&&(i.isEqual(t.type,"artist")||i.isEqual(t.type,"album")||i.includes(t.key,"folder")||(a.style.backgroundSize="80%"),a.style.backgroundColor="rgba(0,0,0,0.2)",a.style.backgroundPosition="center",a.style.height=`${n.width}px`),a.style.backgroundImage=`url('${s}')`,this.playController&&!this.playController.isPlaySupported(t)&&(a.style.cursor="pointer"),a.addEventListener("click",(()=>{this.activeMovieElemData=t,this.activateMovieElem(a)}));const o=document.createElement("div");if(!(t.viewCount&&t.viewCount>0)&&"movie"===t.type){const t=document.createElement("div");t.className="toViewEpisode",o.appendChild(t)}if(t.leafCount-t.viewedLeafCount>0&&"show"===t.type){const e=document.createElement("div");e.className="toViewSeason",e.innerHTML=(t.leafCount-t.viewedLeafCount).toString(),e.style.fontSize=`${this.fontSize4}px`,e.style.lineHeight=`${this.fontSize4}px`,e.style.padding=this.fontSize4/2+"px",o.appendChild(e)}if(t.viewOffset>0&&t.duration>0){const e=document.createElement("div");e.className="viewProgress",e.style.width=t.viewOffset/t.duration*100+"%",o.appendChild(e)}if(o.className="interactiveArea",this.playController){const e=this.playController.getPlayButton(t.type);this.playController.isPlaySupported(t)&&e.classList.remove("disabled"),o.append(e),((t,e,i)=>{let n=!1,s=null;const r=t=>{t.stopPropagation(),null!==s&&(clearTimeout(s),s=null)},a=t=>{t.stopPropagation(),"click"===t.type&&0!==t.button||(n=!1,s=setTimeout((()=>{i(t),n=!0}),1e3))};t.addEventListener("mousedown",a),t.addEventListener("touchstart",a),t.addEventListener("click",(t=>(t.stopPropagation(),null!==s&&(clearTimeout(s),s=null),!n&&(e(t),!0)))),t.addEventListener("mouseout",r),t.addEventListener("touchend",r),t.addEventListener("touchleave",r),t.addEventListener("touchcancel",r)})(e,(e=>{e.stopPropagation(),this.hassObj&&this.playController&&this.playController.play(t,!0)}),(t=>{console.log("Play version... will be here!"),t.stopPropagation()}))}a.append(o);const l=document.createElement("div");i.isEqual(t.type,"episode")?l.innerHTML=F(t.grandparentTitle):i.isNil(t.channelCallSign)?l.innerHTML=F(t.title):l.innerHTML=F(t.channelCallSign);const h=this.fontSize1/4,c=this.fontSize2/4;l.className="titleElem",i.isNil(t.channelCallSign)?l.style.marginTop=`${h}px`:l.style.marginTop="0px",l.style.fontSize=`${this.fontSize1}px`,l.style.marginBottom=`${h}px`,l.style.lineHeight=`${this.fontSize1}px`;const u=document.createElement("div");i.isEqual(t.type,"episode")?u.innerHTML=F(t.title):i.isNil(t.year)?i.isNil(t.epg)?u.innerHTML=" ":u.innerHTML=F(t.epg.title):u.innerHTML=F(t.year),u.className="yearElem",u.style.fontSize=`${this.fontSize2}px`,u.style.lineHeight=`${this.fontSize2}px`,u.style.marginTop=`${c}px`,u.style.marginBottom=`${c}px`;const d=document.createElement("div");return i.isEqual(t.type,"episode")&&(d.innerHTML=F(`S${t.parentIndex} E${t.index}`),d.className="additionalElem",d.style.fontSize=`${this.fontSize2}px`,d.style.lineHeight=`${this.fontSize2}px`,d.style.marginTop=`${c}px`,d.style.marginBottom=`${c}px`),r.appendChild(a),this.displayTitleMain&&r.appendChild(l),this.displaySubtitleMain&&(r.appendChild(u),r.appendChild(d)),r},this.loadCustomStyles=()=>``,this.setConfig=t=>{if(this.plexProtocol="http",!t.ip)throw new Error("You need to define a Plex IP Address");if(!t.token)throw new Error("You need to define a Plex Token");if(!t.libraryName)throw new Error("You need to define a libraryName");if(!t.entity||0===t.entity.length)throw new Error("You need to define at least one entity");if(i.isPlainObject(t.entity)){let e=!1;if(i.forEach(t.entity,((t,i)=>{if(s[i])return e=!0,!1})),!e)throw new Error("You need to define at least one supported entity")}else if(!i.isString(t.entity)&&!i.isArray(t.entity))throw new Error("You need to define at least one supported entity");this.config=t,t.protocol&&(this.plexProtocol=t.protocol),t.displayType&&!i.isEmpty(t.displayType)&&(this.displayType=t.displayType),t.useHorizontalScroll&&i.isEqual(t.useHorizontalScroll,"Yes")&&(this.useHorizontalScroll=!0),t.useShuffle&&i.isEqual(t.useShuffle,"Yes")&&(this.useShuffle=!0),t.displayTitleMain&&i.isEqual(t.displayTitleMain,"No")&&(this.displayTitleMain=!1),t.displaySubtitleMain&&i.isEqual(t.displaySubtitleMain,"No")&&(this.displaySubtitleMain=!1),t.port&&!i.isEqual(t.port,"")?this.plexPort=t.port:this.plexPort=!1,t.maxCount&&""!==t.maxCount&&(this.maxCount=t.maxCount),t.maxRows&&""!==t.maxRows&&"0"!==t.maxRows&&0!==t.maxRows?this.maxRows=t.maxRows:this.maxRows=!1,t.minWidth&&""!==t.minWidth&&"0"!==t.minWidth&&0!==t.minWidth&&(this.minWidth=parseInt(t.minWidth,10)),t.minEpisodeWidth&&""!==t.minEpisodeWidth&&"0"!==t.minEpisodeWidth&&0!==t.minEpisodeWidth&&(this.minEpisodeWidth=parseInt(t.minEpisodeWidth,10)),t.minExpandedWidth&&""!==t.minExpandedWidth&&"0"!==t.minExpandedWidth&&0!==t.minExpandedWidth&&(this.minExpandedWidth=parseInt(t.minExpandedWidth,10)),t.fontSize1&&""!==t.fontSize1&&"0"!==t.fontSize1&&0!==t.fontSize1&&(this.fontSize1=parseInt(t.fontSize1,10)),t.fontSize2&&""!==t.fontSize2&&"0"!==t.fontSize2&&0!==t.fontSize2&&(this.fontSize2=parseInt(t.fontSize2,10)),t.fontSize3&&""!==t.fontSize3&&"0"!==t.fontSize3&&0!==t.fontSize3&&(this.fontSize3=parseInt(t.fontSize3,10)),t.fontSize4&&""!==t.fontSize4&&"0"!==t.fontSize4&&0!==t.fontSize4&&(this.fontSize4=parseInt(t.fontSize4,10)),t.minExpandedHeight&&""!==t.minExpandedHeight&&"0"!==t.minExpandedHeight&&0!==t.minExpandedHeight&&(this.minExpandedHeight=parseInt(t.minExpandedHeight,10)),t.runBefore&&!i.isEqual(t.runBefore,"")&&(this.runBefore=t.runBefore),t.runAfter&&!i.isEqual(t.runAfter,"")&&(this.runAfter=t.runAfter),i.isNil(t.playTrailer)||(this.playTrailer=t.playTrailer),i.isNil(t.showExtras)||(this.showExtras=t.showExtras),i.isNil(t.showSearch)||(this.showSearch=t.showSearch),this.plex=new V(this.config.ip,this.plexPort,this.config.token,this.plexProtocol,this.config.sort),this.data={},this.error="",this.renderInitialData()},this.getCardSize=()=>3}set hass(t){this.hassObj=t,this.initialDataLoaded||this.loadInitialData()}static getConfigElement(){return document.createElement("plex-meets-homeassistant-editor")}}ct.querySelectorAllShadows=(t,e=document.body)=>{const i=Array.from(e.querySelectorAll("*")).map((t=>t.shadowRoot)).filter(Boolean).map((e=>ct.querySelectorAllShadows(t,e)));return Array.from(e.querySelectorAll(t)).concat(i).flat()},customElements.define("plex-meets-homeassistant-editor",st),customElements.define("plex-meets-homeassistant",ct),window.customCards=window.customCards||[],window.customCards.push({type:"plex-meets-homeassistant",name:"Plex meets Home Assistant",preview:!1,description:"Integrates Plex into Home Assistant. Browse and launch media with a simple click."}); +`.cssText;class ut extends HTMLElement{constructor(){super(...arguments),this.renderPageRetries=0,this.searchInputElem=document.createElement("input"),this.plexProtocol="http",this.displayType=!1,this.useHorizontalScroll=!1,this.useShuffle=!1,this.displayTitleMain=!0,this.displaySubtitleMain=!0,this.plexPort=!1,this.epgData={},this.detailsShown=!1,this.entityRegistry=[],this.runBefore="",this.playTrailer=!0,this.showExtras=!0,this.isVisible=!0,this.showSearch=!0,this.previousPageWidth=0,this.runAfter="",this.columnsCount=0,this.renderedRows=0,this.renderedItems=0,this.maxRenderCount=!1,this.minWidth=n.minimumWidth,this.minEpisodeWidth=n.minimumEpisodeWidth,this.minExpandedWidth=n.expandedWidth,this.minExpandedHeight=n.expandedHeight,this.fontSize1=14,this.fontSize2=14,this.fontSize3=28,this.fontSize4=16,this.seasonContainerClickEnabled=!0,this.looseSearch=!1,this.movieElems=[],this.searchValue="",this.activeMovieElemData={},this.seasonElemFreshlyLoaded=!1,this.episodesElemFreshlyLoaded=!1,this.seasonsElemHidden=!0,this.episodesElemHidden=!0,this.data={},this.config={},this.loading=!1,this.maxCount=!1,this.maxRows=!1,this.error="",this.contentBGHeight=0,this.initialDataLoaded=!1,this.haWindow=ut.querySelectorAllShadows("hui-view")[0],this.renderNewElementsIfNeeded=()=>{const t=K(this.content);let{scrollTop:e}=this.haWindow;et-300&&this.renderedItems>0&&this.renderedItems{if(this.isVisible){if(!this.detailsShown){let t=!1;if(this.getElementsByClassName("videoPlayer")[0].children.length>0&&(t=Z(this)),this.card&&this.movieElems.length>0&&!t&&this.previousPageWidth!==this.card.offsetWidth){this.previousPageWidth=this.card.offsetWidth,this.renderPage();const t=this.getElementsByClassName("contentbg");this.contentBGHeight=K(t[0])}}this.renderNewElementsIfNeeded()}},this.loadInitialData=async()=>{this.initialDataLoaded=!0,setInterval((()=>{const t=!i.isNull(this.offsetParent);t&&!this.isVisible&&this.renderPage(),this.isVisible=t}),100),this.hassObj&&(this.entityRegistry=await Y(this.hassObj.connection));const t=()=>{if(this.detailsShown&&this.activeMovieElem&&!Z(this)&&this.isVisible){const t=this.getElementsByClassName("seasonContainer"),e=this.getElementsByClassName("episodeContainer"),n=this.getElementsByClassName("seasonElem");let s=this.activeMovieElem;i.forEach(n,(t=>{if(i.isEqual(t.dataset.clicked,"true"))return s=t,!1}));const r=parseInt(G(s).top,10)-70,a=((t,e,i)=>{const n=t[t.length-1],s=e[e.length-1];let r=!1;return t.length>0&&parseInt(i.style.top,10)>0?r=K(n)+parseInt(G(n).top,10)+10:e.length>0&&(r=K(s)+parseInt(G(s).top,10)+10),r})(t,e,s);this.getTop()a&&(window.scroll({top:a-window.innerHeight}),this.children[0].classList.add("stop-scrolling")):-70!==r&&-10!==a&&(window.scroll({top:r}),this.children[0].classList.add("stop-scrolling")))}this.renderNewElementsIfNeeded()};this.haWindow.addEventListener("scroll",t),window.addEventListener("scroll",t),window.addEventListener("wheel",t),window.addEventListener("touchmove",t),window.addEventListener("resize",(()=>{this.resizeHandler()})),this.card&&(this.previousPageWidth=this.card.offsetWidth),this.resizeBackground()},this.renderInitialData=async()=>{let{entity:t}=JSON.parse(JSON.stringify(this.config));const e=(t,e)=>{let n=e,s=!1;i.startsWith(e,"plexPlayer | ")?(n=e.split(" | ")[3],s=!0):i.isPlainObject(e)?n=e[Object.keys(e)[0]]:(i.startsWith(e,"androidtv | ")||i.startsWith(e,"kodi | ")||i.startsWith(e,"cast | ")||i.startsWith(e,"input_select | ")||i.startsWith(e,"input_text | ")||i.startsWith(e,"vlc_telnet | ")||i.startsWith(e,"sonos | "))&&(n=e.split(" | ")[1],s=!1),s?(i.isNil(t.plexPlayer)&&(t.plexPlayer=[]),t.plexPlayer.push(n)):i.forEach(this.entityRegistry,(e=>{if(i.isEqual(e.entity_id,n))switch(e.platform){case"cast":i.isNil(t.cast)&&(t.cast=[]),t.cast.push(e.entity_id);break;case"androidtv":i.isNil(t.androidtv)&&(t.androidtv=[]),t.androidtv.push(e.entity_id);break;case"kodi":i.isNil(t.kodi)&&(t.kodi=[]),t.kodi.push(e.entity_id);break;case"input_select":i.isNil(t.inputSelect)&&(t.inputSelect=[]),t.inputSelect.push(e.entity_id);break;case"input_text":i.isNil(t.inputText)&&(t.inputText=[]),t.inputText.push(e.entity_id);break;case"vlc_telnet":i.isNil(t.vlcTelnet)&&(t.vlcTelnet=[]),t.vlcTelnet.push(e.entity_id);break;case"sonos":i.isNil(t.sonos)&&(t.sonos=[]),t.sonos.push(e.entity_id);break;default:console.error(`Entity ${e.entity_id} is not supported.`)}}))},n=t;i.isString(n)?(t={},e(t,n)):i.isArray(n)&&(t={},i.forEach(n,(i=>{e(t,i)}))),this.loading=!0,this.renderPage();try{if(this.plex&&this.hassObj){this.playController=new st(this,this.hassObj,this.plex,t,this.runBefore,this.runAfter,this.config.libraryName,this.entityRegistry,this.useShuffle),this.playController&&await this.playController.init(),await this.plex.init();const e=await this.plex.getSections(),n=async()=>{if(this.plex)try{const t=await this.plex.getOnDeck();this.data.Deck=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(J("Deck"))}},s=async()=>{if(this.plex)try{const t=await this.plex.getContinueWatching();this.data["Continue Watching"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(J("Continue Watching"))}},r=async()=>{if(this.plex)try{const t=await this.plex.getWatchNext();this.data["Watch Next"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(J("Watch Next"))}},a=async()=>{if(this.plex)try{const t=await this.plex.getRecentyAdded();this.data["Recently Added"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;try{console.warn("PlexMeetsHomeAssistant: Using old endpoint for recently added tv shows. Consider updating your Plex server.");const t=await this.plex.getRecentyAdded(!0);this.data["Recently Added"]=t.Metadata}catch(t){if(!i.includes(t.message,"Request failed with status code 404"))throw t;console.warn(J("Recently Added"))}}},o=async()=>{if(this.plex){const t=await this.plex.getLiveTV();i.forEach(t,((t,e)=>{this.data[e]=t,i.forEach(this.data[e],((t,i)=>{this.data[e][i].type="epg"}))}))}},l=async()=>{this.plex&&(this.epgData=await this.plex.getEPG())};let h=!1;i.forEach(e,(t=>!i.isEqual(t.title,this.config.libraryName)||(h=t.key,!1)));const c=[];h&&c.push(this.plex.getSectionData(h,this.displayType)),i.isEqual(this.config.libraryName,"Deck")?c.push(n()):i.isEqual(this.config.libraryName,"Continue Watching")?c.push(s()):i.isEqual(this.config.libraryName,"Watch Next")?c.push(r()):i.isEqual(this.config.libraryName,"Recently Added")&&c.push(a()),c.push(o()),c.push(l());const[u]=await Promise.all(c);i.forEach(this.epgData,((t,e)=>{i.forEach(this.data[e],((t,n)=>{i.isNil(this.epgData[e][t.channelCallSign])||(this.data[e][n].epg=this.epgData[e][t.channelCallSign])}))})),u&&h&&i.forEach(u,(t=>{this.data[t.librarySectionTitle]=t.Metadata}));const d=await this.plex.getCollections();let p={};i.forEach(d,(t=>{this.plex&&i.isEqual(t.title,this.config.libraryName)&&(p=t)})),i.isNil(p.key)||(this.data[p.title]=await this.plex.getCollectionData(p.key));const f=await this.plex.getPlaylists();let y={};i.forEach(f,(t=>{this.plex&&i.isEqual(t.title,this.config.libraryName)&&(y=t)})),i.isNil(y.key)||(this.data[y.title]=await this.plex.getPlaylistData(y.key)),void 0===this.data[this.config.libraryName]&&(this.error=`Library name ${this.config.libraryName} does not exist.`),this.loading=!1,this.render()}else setTimeout((()=>{this.renderInitialData()}),250)}catch(t){this.error=`Plex server did not respond.
Details of the error: ${F(t.message)}`,this.renderPage()}},this.render=()=>{this.renderPage()},this.searchInput=()=>{const t=document.createElement("div");return t.className="searchContainer",this.searchInputElem=document.createElement("input"),this.searchInputElem.type="text",this.searchInputElem.value=this.searchValue,this.searchInputElem.placeholder=`Search ${this.config.libraryName}...`,this.searchInputElem.addEventListener("keyup",(()=>{i.isEqual(this.searchInputElem.value,this.searchValue)||(this.searchValue=this.searchInputElem.value,this.renderPage(),this.focus())})),t.appendChild(this.searchInputElem),t},this.renderMovieElems=()=>{const t=(t,e,n,s)=>{const r=this.renderedRows,a=this.renderedItems,o=this.columnsCount;let l=0;this.contentContainer.style.width="";let h=0,c=(!this.maxCount||this.renderedItems{if(c=(!this.maxCount||this.renderedItems{if(!i.isEmpty(e)&&i.includes(i.toUpper(r.title),i.toUpper(e))||i.includes(i.toUpper(r.parentTitle),i.toUpper(e))||i.includes(i.toUpper(r.grandparentTitle),i.toUpper(e)))return t=!0,!1})),(t||i.isEmpty(n[0]))&&(o=!0)}else(i.includes(i.toUpper(r.title),i.toUpper(this.searchValue))||i.includes(i.toUpper(r.parentTitle),i.toUpper(this.searchValue))||i.includes(i.toUpper(r.grandparentTitle),i.toUpper(this.searchValue))||i.includes(i.toUpper(r.tag),i.toUpper(this.searchValue))||i.includes(i.toUpper(i.get(r,"epg.title")),i.toUpper(this.searchValue)))&&(o=!0);if(o&&(u+=1,u>this.renderedItems)){if(t&&this.contentContainer.appendChild(a),this.useHorizontalScroll){this.renderedItems>0&&this.renderedItems%s==0&&(this.renderedRows+=1,a.style.clear="both");const t=10;(1===this.renderedRows||!this.maxRows||this.maxRows<2)&&(h+=parseFloat(a.style.width)+t)}this.renderedItems+=1}return t&&o&&l!==a.getBoundingClientRect().top&&!this.useHorizontalScroll&&(this.renderedRows+=1,0!==l&&0===this.columnsCount&&(this.columnsCount=this.renderedItems-1),l=a.getBoundingClientRect().top,!(t=>{const e=t.getBoundingClientRect(),i=e.top,n=e.bottom;return i>=0&&n<=window.innerHeight})(a)&&!this.maxRenderCount&&this.renderedItems>0&&(this.maxRenderCount=this.renderedItems-1+2*this.columnsCount)),this.maxRows&&this.renderedRows>this.maxRows&&!this.useHorizontalScroll&&a.remove(),!0}return!1}));const d={renderedItems:this.renderedItems};return t||(this.renderedRows=r,this.renderedItems=a,this.columnsCount=o),t&&h>0&&(this.contentContainer.style.width=`${h}px`),d},e=(!this.maxCount||this.renderedItems{let e=!1;return i.forEach(t,(t=>{if(i.isEqual(t.type,"episode"))return e=!0,!1})),e})(this.data[this.config.libraryName]),{renderedItems:a}=t(!1,r,s,n);n=a,this.maxRows&&(n=Math.ceil(a/this.maxRows)),t(!0,r,s,n)}const n=this.getElementsByClassName("contentbg")[0];this.contentBGHeight=K(n)},this.renderPage=()=>{if(this.searchInputElem.placeholder=`Search ${this.config.libraryName}...`,this.showSearch?this.searchInputElem.style.display="block":this.searchInputElem.style.display="none",this.card){const t=()=>this.card?this.card.getBoundingClientRect().width-parseInt(this.card.style.paddingRight,10)-parseInt(this.card.style.paddingLeft,10):0,e=t(),i=Math.floor(e/this.minWidth);if(e>0){const s=Math.floor(e/this.minEpisodeWidth);let r=11;i>7?r=10.3:i>3&&(r=10.7),n.width=e/i-r,n.height=n.width*n.ratio,n.episodeWidth=Math.floor(e/s-r),n.episodeHeight=Math.round(n.episodeWidth*n.episodeRatio),setTimeout((()=>{if(this.card){t()!==e&&this.renderPage()}}),1)}else this.renderPageRetries<10&&setTimeout((()=>{this.renderPageRetries+=1,this.renderPage()}),250)}this.renderedItems=0,this.renderedRows=0;const t=document.createElement("div");if(t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",t.innerHTML='
',this.content&&this.content.remove(),!this.card){this.card=document.createElement("ha-card"),this.card.style.transition="0.5s",this.card.style.overflow="hidden",this.card.style.padding="16px",this.card.style.paddingRight="6px";const t=document.createElement("h1");t.classList.add("card-header"),t.style.paddingRight="0px",t.style.paddingLeft="0px",t.style.paddingTop="0px",t.style.paddingBottom="0px";const e=document.createElement("div");e.classList.add("name"),e.textContent=this.config.title,t.appendChild(e),i.isNil(this.config.title)||i.isEmpty(this.config.title)?t.style.display="none":t.style.display="block",this.card.appendChild(t),this.card.appendChild(this.searchInput()),this.showSearch?this.searchInputElem.style.display="block":this.searchInputElem.style.display="none",this.appendChild(this.card)}this.content=document.createElement("div"),this.content.innerHTML=this.loadCustomStyles(),this.useHorizontalScroll&&(this.content.style.overflowX="auto",this.content.style.whiteSpace="nowrap"),""!==this.error?this.content.innerHTML+=`Error: ${this.error}`:this.data[this.config.libraryName]&&0===this.data[this.config.libraryName].length?this.content.innerHTML+=`Library ${F(this.config.libraryName)} has no items.`:this.loading&&(this.content.style.padding="16px 16px 16px",this.content.appendChild(t)),this.card.appendChild(this.content),this.contentContainer=document.createElement("div"),this.contentContainer.className="contentContainer",this.content.appendChild(this.contentContainer);const e=document.createElement("div");e.className="contentbg",this.contentContainer.appendChild(e);const s=document.createElement("div");s.className="contentArt";const r=document.createElement("div");r.className="videobg1",s.appendChild(r);const a=document.createElement("div");if(a.className="videobg2",s.appendChild(a),this.contentContainer.appendChild(s),this.detailElem=document.createElement("div"),this.detailElem.className="detail",this.detailElem.innerHTML="

\n\t\t\t

\n\t\t\t",this.playController){const t=this.playController.getPlayActionButton();t.style.fontSize=`${this.fontSize4}px`,t.style.lineHeight=`${this.fontSize4}px`,t.style.marginTop=this.fontSize4/4+"px",t.style.marginBottom=this.fontSize4/4+"px",t.style.marginRight=this.fontSize4/4+"px",t.style.padding=`${this.fontSize4/2}px ${this.fontSize4}px`,this.detailElem.appendChild(t)}this.detailElem.innerHTML+=`\n\t\t\t\n\t\t\t
\n\t\t\t\n\t\t\t
\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t
\n\t\t\t\t\t\tDirected by\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
\n\t\t\t\t\t\tWritten by\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
\n\t\t\t\t\t\tStudio\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
\n\t\t\t\t\t\tGenre\n\t\t\t\t\t\n\t\t\t\t\t\t...\n\t\t\t\t\t
`,this.detailElem.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),this.contentContainer.appendChild(this.detailElem);this.getElementsByClassName("detailPlayTrailerAction")[0].addEventListener("click",(t=>{if(t.stopPropagation(),this.videoElem){const t=this.getElementsByClassName("videoPlayer")[0].children[0];if(t.requestFullscreen)t.requestFullscreen();else if(t.webkitRequestFullscreen)t.webkitRequestFullscreen();else if(t.msRequestFullscreen)t.msRequestFullscreen();else{const e=this.getElementsByClassName("videobg1"),i=this.getElementsByClassName("videobg2");for(const t of e)t.classList.add("transparent");for(const t of i)t.classList.add("transparent");this.videoElem.classList.add("maxZIndex"),this.videoElem.classList.add("simulatedFullScreen"),t.controls=!0}}})),this.seasonsElem=document.createElement("div"),this.seasonsElem.className="seasons",this.seasonsElem.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),this.contentContainer.appendChild(this.seasonsElem),this.episodesElem=document.createElement("div"),this.episodesElem.className="episodes",this.episodesElem.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),this.contentContainer.appendChild(this.episodesElem),this.videoElem=document.createElement("div"),this.videoElem.className="video",this.videoElem.addEventListener("click",(t=>{const e=this.getElementsByClassName("videoPlayer")[0].children[0];if(Z(this)){t.stopPropagation(),this.videoElem&&(this.videoElem.classList.remove("maxZIndex"),this.videoElem.classList.remove("simulatedFullScreen"));const i=this.getElementsByClassName("videobg1"),n=this.getElementsByClassName("videobg2");for(const t of i)t.classList.remove("transparent");for(const t of n)t.classList.remove("transparent");e.controls=!1}else this.hideBackground(),this.minimizeAll()}));const o=document.createElement("div");o.className="videobg1",this.videoElem.appendChild(o);const l=document.createElement("div");l.className="videobg2",this.videoElem.appendChild(l);const h=document.createElement("div");h.className="videoPlayer",this.videoElem.appendChild(h),this.contentContainer.appendChild(this.videoElem),setTimeout((()=>{e.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()})),s.addEventListener("click",(()=>{this.hideBackground(),this.minimizeAll()}))}),1);const c=document.createElement("div");c.className="clear",this.contentContainer.appendChild(c),this.renderMovieElems(),this.calculatePositions(),this.loadCustomStyles()},this.calculatePositions=()=>{const t=setInterval((()=>{this.movieElems=this.getElementsByClassName("movieElem");for(let e=0;e{this.seasonsElemHidden=!1,this.seasonsElem&&i.forEach(this.seasonsElem.childNodes,(t=>{const e=t.children[0],s=t.children[1],r=t.children[2];e.style.display="block",void 0!==e.children[0].children[0]&&(e.children[0].children[0].style.display="block");const a=t=>{const a=t;a.style.marginTop="0",i.isEqual(e.dataset.type,"album")?(a.style.width=`${n.width}px`,a.style.height=`${n.width}px`):(a.style.width=`${n.width}px`,a.style.height=n.height-3+"px"),a.style.zIndex="3",a.style.marginLeft="0px",a.dataset.clicked="false",s.style.display="block",r.style.display="block",this.seasonTitleColorTimeout=setTimeout((()=>{s.style.color="rgba(255,255,255,1)",r.style.color="rgba(255,255,255,1)"}),500)};"true"===e.dataset.clicked?a(e):this.moveElemTimeout=setTimeout((()=>{a(e)}),100)}))},this.hideVideo=()=>{if(this.videoElem){this.getElementsByClassName("videoPlayer")[0].innerHTML="",this.videoElem.classList.remove("maxZIndex"),this.videoElem.classList.remove("simulatedFullScreen");const t=this.getElementsByClassName("videobg1"),e=this.getElementsByClassName("videobg2");for(const e of t)e.classList.remove("transparent");for(const t of e)t.classList.remove("transparent")}},this.minimizeAll=()=>{this.detailsShown=!1,this.activeMovieElem&&(this.activeMovieElem.style.display="block"),this.activeMovieElem=void 0;for(let t=0;t{this.movieElems[t].style.transition="0s",this.movieElems[t].style["z-index"]=1,this.movieElems[t].style.position="relative",this.movieElems[t].style.left="0px",this.movieElems[t].style.top="0px",this.movieElems[t].dataset.clicked=!1,setTimeout((()=>{this.movieElems[t].style.transition="0.5s"}),10)}),510));this.hideSeasons(),this.hideEpisodes(),this.hideDetails(),this.hideVideo(),clearInterval(this.showDetailsTimeout),clearInterval(this.showSeasonElemTimeout),clearInterval(this.seasonTitleColorTimeout),clearInterval(this.moveElemTimeout),clearInterval(this.scrollDownInactiveSeasonsTimeout),clearInterval(this.episodesLoadTimeout),clearInterval(this.episodesElemFreshlyLoadedTimeout),clearInterval(this.seasonElemFreshlyLoadedTimeout)},this.hideSeasons=()=>{if(this.seasonsElem){this.seasonsElemHidden=!0;const t=this.getTop();this.seasonsElem.style.top=`${t+2e3}px`,clearInterval(this.hideSeasonsTimeout),this.hideSeasonsTimeout=setTimeout((()=>{this.seasonsElem&&!this.seasonElemFreshlyLoaded&&(this.seasonsElem.innerHTML="",this.seasonsElem.style.display="none",this.resizeBackground())}),700)}},this.hideEpisodes=()=>{if(this.episodesElem){this.episodesElemHidden=!0;const t=this.getTop();this.episodesElem.style.top=`${t+2e3}px`,clearInterval(this.hideEpisodesTimeout),this.hideEpisodesTimeout=setTimeout((()=>{this.episodesElem&&!this.episodesElemFreshlyLoaded&&(this.episodesElem.innerHTML="",this.episodesElem.style.display="none",this.resizeBackground())}),700)}},this.scrollDownInactiveSeasons=()=>{this.seasonsElem&&(this.seasonsElemHidden=!0,i.forEach(this.seasonsElem.childNodes,(t=>{const e=t.children[0],i=t.children[1],n=t.children[2];"false"===e.dataset.clicked&&(e.style.marginTop="1000px",e.style.marginLeft="0px",this.scrollDownInactiveSeasonsTimeout=setTimeout((()=>{e.style.display="none",i.style.display="none",n.style.display="none"}),500))})))},this.hideDetails=()=>{const t=this.getTop();this.detailElem&&(this.detailElem.style.top=t-1e3+"px",this.detailElem.style.color="rgba(255,255,255,0)",this.detailElem.style.zIndex="0",this.detailElem.style.visibility="hidden"),clearTimeout(this.renderNewElementsIfNeededTimeout),this.renderNewElementsIfNeededTimeout=setTimeout((()=>{this.renderNewElementsIfNeeded()}),1e3);this.getElementsByClassName("detailPlayTrailerAction")[0].style.visibility="hidden"},this.showDetails=async t=>{this.detailsShown=!0;const e=this.getTop();if(this.detailElem&&(this.playController&&(this.playController.setPlayActionButtonType(t.type),this.playController.setPlayButtonClickFunction((e=>{e.preventDefault(),e.stopPropagation(),this.playController&&this.playController.play(t,!0)}))),this.detailElem.style.transition="0s",this.detailElem.style.top=e-1e3+"px",i.isEmpty(i.get(t,"thumb"))?this.detailElem.style.left="16px":this.detailElem.style.left=`${this.minExpandedWidth+30}px`,clearInterval(this.showDetailsTimeout),this.showDetailsTimeout=setTimeout((async()=>{if(this.detailElem&&this.plex){this.detailElem.style.visibility="visible",this.detailElem.style.transition="0.7s",this.detailElem.style.top=`${e}px`;let n=t;i.isEqual(t.type,"season")&&(n=await this.plex.getDetails(t.parentKey.split("/")[3]),n.title=`${n.title} - ${t.title}`);const s=this.getElementsByClassName("metaInfoDetailsData")[0];s.style.fontSize=`${this.fontSize4}px`,s.style.lineHeight=`${this.fontSize4}px`,s.style.marginTop=this.fontSize4/4+"px",s.style.marginBottom=this.fontSize4/4+"px",s.style.display="block",s.parentElement&&(n.Director&&n.Director.length>0?(s.innerHTML=F(n.Director[0].tag),s.parentElement.style.display="table-row"):s.parentElement.style.display="none");const r=this.getElementsByClassName("metaInfoDetailsData")[1];r.style.fontSize=`${this.fontSize4}px`,r.style.lineHeight=`${this.fontSize4}px`,r.style.marginTop=this.fontSize4/4+"px",r.style.marginBottom=this.fontSize4/4+"px",r.style.display="block",r.parentElement&&(n.Writer&&n.Writer.length>0?(r.innerHTML=F(n.Writer[0].tag),r.parentElement.style.display="table-row"):r.parentElement.style.display="none");const a=this.getElementsByClassName("metaInfoDetailsData")[2];a.style.fontSize=`${this.fontSize4}px`,a.style.lineHeight=`${this.fontSize4}px`,a.style.marginTop=this.fontSize4/4+"px",a.style.marginBottom=this.fontSize4/4+"px",a.style.display="block",a.parentElement&&(n.studio?(a.innerHTML=F(n.studio),a.parentElement.style.display="table-row"):a.parentElement.style.display="none");const o=this.getElementsByClassName("metaInfoDetailsData")[3];if(o.style.fontSize=`${this.fontSize4}px`,o.style.lineHeight=`${this.fontSize4}px`,o.style.marginTop=this.fontSize4/4+"px",o.style.marginBottom=this.fontSize4/4+"px",o.style.display="block",o.parentElement)if(n.Genre&&n.Genre.length>0){let t="";i.forEach(n.Genre,(e=>{t+=`${e.tag}, `})),o.innerHTML=F(t.slice(0,-2)),o.parentElement.style.display="table-row"}else o.parentElement.style.display="none";const l=this.getElementsByClassName("detailsTitle")[0];i.isNil(n.channelCallSign)?l.innerHTML=F(n.title):l.innerHTML=F(n.channelCallSign),l.style.lineHeight=`${this.fontSize3}px`,l.style.fontSize=`${this.fontSize3}px`,l.style.marginBottom=this.fontSize3/4+"px";const h=this.getElementsByClassName("detailsYear")[0];h.style.display="block",h.style.fontSize=`${this.fontSize4}px`,h.style.lineHeight=`${this.fontSize4}px`,h.style.marginTop="0px",h.style.marginBottom=this.fontSize4/4+"px",i.isNil(n.year)?i.isNil(n.epg)||i.isNil(n.epg.title)?(h.style.display="none",h.innerHTML=""):h.innerHTML=F(n.epg.title):h.innerHTML=F(n.year),this.getElementsByClassName("metaInfo")[0].innerHTML=(void 0!==n.duration?`${Math.round(parseInt(F(n.duration),10)/60/1e3)} min`:"")+(void 0!==n.contentRating?`${F(n.contentRating)}`:"")+(void 0!==n.rating?`${n.rating<5?"🗑":"⭐"} ${Math.round(10*parseFloat(F(n.rating)))/10}`:"")+"
";const c=this.getElementsByClassName("detailDesc")[0];c.style.fontSize=`${this.fontSize4}px`,c.style.lineHeight=`${this.fontSize4}px`,c.style.marginTop=this.fontSize4/4+"px",c.style.marginBottom=this.fontSize4/4+"px",c.style.display="block",i.isNil(n.summary)?i.isNil(n.epg)||i.isNil(n.epg.summary)?(c.innerHTML="",c.style.display="none"):c.innerHTML=F(n.epg.summary):c.innerHTML=F(n.summary),this.detailElem.style.color="rgba(255,255,255,1)",this.detailElem.style.zIndex="4",this.detailElem.style.width=`calc(100% - ${this.minExpandedWidth+30+20}px)`,this.activeMovieElem?this.detailElem.style.maxHeight=`${K(this.activeMovieElem)+40}px`:this.detailElem.style.maxHeight=`${this.minExpandedHeight+20}px`}}),200)),this.plex){let s={};i.isEqual(t.type,"episode")?s=await this.plex.getLibraryData(`${t.grandparentKey}/children`):(t.childCount>0||i.isEqual(t.type,"artist")||i.isEqual(t.type,"album")||i.includes(t.key,"folder"))&&(s=await this.plex.getLibraryData(t.key)),this.playController&&(i.includes(t.key,"folder")?this.playController.setPlayActionDisplay("none"):this.playController.setPlayActionDisplay("block"));let r={};if(!i.isNil(t.key)&&(i.includes(t.key,"folder")||(r=await this.plex.getDetails(t.key.split("/")[3])),this.videoElem)){const n=this.plex.authorizeURL(this.plex.getBasicURL()+t.art);if(""===(t=>{let e="";return t.Extras&&t.Extras.Metadata&&t.Extras.Metadata.length>0&&i.forEach(t.Extras.Metadata,(t=>{if("trailer"===t.subtype)return e=t.Media[0].Part[0].key,!1})),e})(r)||i.isEqual(this.playTrailer,!1)){if(!i.isEmpty(n)){const t=this.getElementsByClassName("contentArt")[0],i=this.getElementsByClassName("contentbg")[0];t.style.width=`${window.innerWidth}px`,t.style.height=`${window.innerHeight}px`,t.style.backgroundImage=`url('${n}')`,t.style.top=e-8+"px",t.style.transition="0.5s",t.style.display="block",i.classList.add("no-transparency")}}else{const t=this.getElementsByClassName("videoPlayer")[0],n=document.createElement("video");n.style.height="100%",n.style.width="100%",n.controls=!1,i.isEqual(this.playTrailer,"muted")&&(n.muted=!0);const s=document.createElement("source");s.type="video/mp4",s.src=this.plex.authorizeURL(`${this.plex.getBasicURL()}${r.Extras.Metadata[0].Media[0].Part[0].key}`),n.appendChild(s),t.appendChild(n),n.load(),n.play();let a=!1;const o=this.getElementsByClassName("videobg1"),l=this.getElementsByClassName("videobg2");n.addEventListener("click",(t=>{Z(this)&&t.stopPropagation()}));const h=()=>{if(this.videoElem)if(Z(this)){for(const t of o)t.classList.add("transparent");for(const t of l)t.classList.add("transparent");this.videoElem.classList.add("maxZIndex"),n.controls=!0,n.muted=!1}else{for(const t of o)t.classList.remove("transparent");for(const t of l)t.classList.remove("transparent");this.videoElem.classList.remove("maxZIndex"),n.controls=!1,window.scroll({top:G(this.activeMovieElem).top-70,behavior:"smooth"}),i.isEqual(this.playTrailer,"muted")&&(n.muted=!0)}};n.addEventListener("fullscreenchange",h),n.addEventListener("mozfullscreenchange",h),n.addEventListener("webkitfullscreenchange",h),n.addEventListener("msfullscreenchange",h),n.addEventListener("playing",(()=>{if(this.videoElem&&!a){const t=this.getElementsByClassName("contentbg")[0],i=this.getElementsByClassName("detailPlayTrailerAction")[0];i.style.fontSize=`${this.fontSize4}px`,i.style.lineHeight=`${this.fontSize4}px`,i.style.marginTop=this.fontSize4/4+"px",i.style.marginBottom=this.fontSize4/4+"px",i.style.marginRight=this.fontSize4/4+"px",i.style.padding=`${this.fontSize4/2}px ${this.fontSize4}px`,i.style.visibility="visible",t.classList.add("no-transparency"),a=!0,this.videoElem.style.width=`${this.getElementsByClassName("searchContainer")[0].offsetWidth}px`,this.videoElem.style.visibility="visible",this.videoElem.style.top=`${e}px`}}))}}if(i.isEmpty(s)){if(this.episodesElemFreshlyLoaded=!0,this.episodesElem){if(this.episodesElemHidden=!1,this.episodesElem.style.display="block",this.episodesElem.innerHTML="",this.episodesElem.style.transition="0s",this.episodesElem.style.top=`${e+2e3}px`,i.isEqual(t.type,"season")){const e=await this.plex.getLibraryData(t.key);i.forEach(e,(t=>{this.episodesElem&&this.playController&&this.plex&&this.episodesElem.append(nt(this.playController,this.plex,t,this.fontSize1,this.fontSize2))}))}else if(this.showExtras&&!i.isNil(r.Extras)){const t=r.Extras.Metadata;i.forEach(t,(t=>{this.episodesElem&&this.playController&&this.plex&&this.episodesElem.append(nt(this.playController,this.plex,t,this.fontSize1,this.fontSize2))}))}clearInterval(this.episodesLoadTimeout),this.episodesLoadTimeout=setTimeout((()=>{this.episodesElem&&(this.episodesElem.style.transition="0.7s",this.episodesElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200),clearInterval(this.episodesElemFreshlyLoadedTimeout),this.episodesElemFreshlyLoadedTimeout=setTimeout((()=>{this.episodesElemFreshlyLoaded=!1}),700)}}else if(this.seasonElemFreshlyLoaded=!0,this.seasonsElem&&(this.seasonsElem.style.display="block",this.seasonsElem.innerHTML="",this.seasonsElem.style.transition="0s",this.seasonsElem.style.top=`${e+2e3}px`),i.isEqual(i.get(s[0],"type"),"track")){if(this.episodesElem){this.episodesElemHidden=!1,this.episodesElem.style.display="block",this.episodesElem.innerHTML="",this.episodesElem.style.transition="0s",this.episodesElem.style.top=`${e+2e3}px`;const n=document.createElement("table");n.style.width="calc(100% - 10px)",n.style.border="none",n.cellSpacing="0",n.cellPadding="0",this.episodesElem.append(n);let r=!1;i.forEach(s,(t=>{this.episodesElem&&this.playController&&this.plex&&(i.isEqual(t.type,"track")?(n.append(it(this.playController,this.plex,t,this.fontSize1,this.fontSize2,r)),r=!r):this.episodesElem.append(nt(this.playController,this.plex,t,this.fontSize1,this.fontSize2)))})),clearInterval(this.episodesLoadTimeout),this.episodesLoadTimeout=setTimeout((()=>{this.episodesElem&&(this.episodesElem.style.transition="0.7s",this.activeMovieElem?i.isEmpty(i.get(t,"thumb"))?this.detailElem?this.episodesElem.style.top=`${e+K(this.detailElem)}px`:this.episodesElem.style.top=`${e}px`:this.episodesElem.style.top=`${e+K(this.activeMovieElem)+32}px`:this.episodesElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200),clearInterval(this.episodesElemFreshlyLoadedTimeout),this.episodesElemFreshlyLoadedTimeout=setTimeout((()=>{this.episodesElemFreshlyLoaded=!1}),700)}}else i.forEach(s,(t=>{if(this.seasonsElem&&this.plex){this.seasonsElemHidden=!1;const s=document.createElement("div");s.className="seasonContainer",s.style.width=`${n.width}px`;const r=`${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight}&minSize=1&upscale=1&url=${t.thumb}&X-Plex-Token=${this.config.token}`,a=document.createElement("div");a.className="seasonElem",a.style.width=`${n.width}px`,i.isEqual(t.type,"album")?a.style.height=`${n.width}px`:a.style.height=n.height-3+"px",a.style.backgroundImage=`url('${r}')`,a.dataset.clicked="false",this.playController&&!this.playController.isPlaySupported(t)&&(a.style.cursor="pointer");const o=document.createElement("div");if(o.className="interactiveArea",t.leafCount-t.viewedLeafCount>0){const e=document.createElement("div");e.className="toViewSeason",e.innerHTML=(t.leafCount-t.viewedLeafCount).toString(),e.style.fontSize=`${this.fontSize4}px`,e.style.lineHeight=`${this.fontSize4}px`,e.style.padding=this.fontSize4/2+"px",o.appendChild(e)}if(this.playController){const e=this.playController.getPlayButton(t.type);this.playController.isPlaySupported(t)&&e.classList.remove("disabled"),e.addEventListener("click",(e=>{e.stopPropagation(),this.plex&&this.playController&&this.playController.play(t,!0)})),o.append(e)}a.append(o),s.append(a);const l=document.createElement("div");l.className="seasonTitleElem",l.innerHTML=F(t.title),l.style.fontSize=`${this.fontSize1}px`,l.style.lineHeight=`${this.fontSize1}px`,s.append(l);const h=document.createElement("div");h.className="seasonEpisodesCount",t.leafCount>0?h.innerHTML=`${F(t.leafCount)} episodes`:i.isNil(t.year)||(h.innerHTML=`${F(t.year)} `),h.style.fontSize=`${this.fontSize2}px`,h.style.lineHeight=`${this.fontSize2}px`,s.append(h),s.addEventListener("click",(n=>{if(n.stopPropagation(),this.seasonContainerClickEnabled&&(this.seasonContainerClickEnabled=!1,setTimeout((()=>{this.seasonContainerClickEnabled=!0}),500),this.activeMovieElem))if("false"===a.dataset.clicked)this.playController&&(this.playController.setPlayActionButtonType(t.type),this.playController.setPlayButtonClickFunction((e=>{e.preventDefault(),e.stopPropagation(),this.playController&&this.playController.play(t,!0)}))),void 0!==a.children[0].children[0]&&(a.children[0].children[0].style.display="none"),a.dataset.clicked="true",this.activeMovieElem.style.top=e-1e3+"px",setTimeout((()=>{this.activeMovieElem&&(this.activeMovieElem.style.display="none")}),500),this.scrollDownInactiveSeasons(),this.activeMovieElem?s.style.top=-K(this.activeMovieElem)+"px":s.style.top=-this.minExpandedHeight+"px",a.dataset.type=t.type,a.style.width=`${this.minExpandedWidth}px`,i.isEqual(t.type,"album")?a.style.height=`${this.minExpandedWidth}px`:a.style.height=this.minExpandedHeight-6+"px",a.style.zIndex="3",a.style.marginLeft=`-${G(a).left-G(this.activeMovieElem).left}px`,l.style.color="rgba(255,255,255,0)",h.style.color="rgba(255,255,255,0)",this.detailElem&&(this.detailElem.children[1].innerHTML=t.title),(async()=>{if(this.plex&&(t.leafCount>0||i.isEqual(t.type,"album"))){this.episodesElemFreshlyLoaded=!0;const n=await this.plex.getLibraryData(t.key);if(this.episodesElem){this.episodesElemHidden=!1,this.episodesElem.style.display="block",this.episodesElem.innerHTML="",this.episodesElem.style.transition="0s",this.episodesElem.style.top=`${e+2e3}px`;const s=document.createElement("table");s.style.width="calc(100% - 10px)",s.style.border="none",s.cellSpacing="0",s.cellPadding="0",i.isEqual(t.type,"album")&&this.episodesElem.append(s);let r=!1;i.forEach(n,(t=>{this.episodesElem&&this.playController&&this.plex&&(i.isEqual(t.type,"track")?(s.append(it(this.playController,this.plex,t,this.fontSize1,this.fontSize2,r)),r=!r):this.episodesElem.append(nt(this.playController,this.plex,t,this.fontSize1,this.fontSize2)))})),clearInterval(this.episodesLoadTimeout),this.episodesLoadTimeout=setTimeout((()=>{this.episodesElem&&(this.episodesElem.style.transition="0.7s",this.activeMovieElem?this.episodesElem.style.top=`${e+K(this.activeMovieElem)+32}px`:this.episodesElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200),clearInterval(this.episodesElemFreshlyLoadedTimeout),this.episodesElemFreshlyLoadedTimeout=setTimeout((()=>{this.episodesElemFreshlyLoaded=!1}),700)}}})();else if(this.playController&&this.playController.setPlayActionButtonType(t.type),s.style.top=`${s.dataset.top}px`,this.minimizeSeasons(),this.hideEpisodes(),this.activeMovieElem.style.display="block",setTimeout((()=>{this.activeMovieElem&&(this.activeMovieElem.style.top=`${e+16}px`)}),10),this.detailElem&&this.detailElem.children[1]){const{year:t}=this.detailElem.children[1].dataset;t&&(this.detailElem.children[1].innerHTML=t)}})),this.seasonsElem.append(s)}})),i.forEach(this.seasonsElem.children,(t=>{const e=t,i=e.offsetLeft,n=e.offsetTop;e.style.left=`${i}px`,e.dataset.left=`${i}`,e.style.top=`${n}px`,e.dataset.top=`${n}`})),i.forEach(this.seasonsElem.children,(t=>{t.style.position="absolute"})),clearInterval(this.seasonElemFreshlyLoadedTimeout),this.seasonElemFreshlyLoadedTimeout=setTimeout((()=>{this.seasonElemFreshlyLoaded=!1}),700),clearInterval(this.showSeasonElemTimeout),this.showSeasonElemTimeout=setTimeout((()=>{this.seasonsElem&&(this.seasonsElem.style.transition="0.7s",this.activeMovieElem?this.seasonsElem.style.top=`${e+K(this.activeMovieElem)+32}px`:this.seasonsElem.style.top=`${e+this.minExpandedHeight+16}px`,this.resizeBackground())}),200)}},this.resizeBackground=()=>{if(this.seasonsElem&&this.episodesElem&&this.card){const t=this.getElementsByClassName("contentbg")[0];this.contentBGHeight=K(t);const e=parseInt(this.seasonsElem.style.top.replace("px",""),10)+this.seasonsElem.scrollHeight,i=parseInt(this.episodesElem.style.top.replace("px",""),10)+this.episodesElem.scrollHeight;e>this.contentBGHeight&&!this.seasonsElemHidden?this.card.style.height=`${e+16}px`:i>this.contentBGHeight&&!this.episodesElemHidden?this.card.style.height=`${i+16}px`:this.card.style.height="100%"}},this.showBackground=()=>{const t=this.getElementsByClassName("contentbg");t[0].style.zIndex="2",t[0].style.backgroundColor="rgba(0,0,0,0.9)",t[0].style.display="block"},this.hideBackground=()=>{const t=this.getElementsByClassName("contentbg")[0];t.classList.remove("no-transparency"),t.style.zIndex="1",t.style.backgroundColor="rgba(0,0,0,0)",t.style.display="none";this.getElementsByClassName("contentArt")[0].style.display="none"},this.activateMovieElem=t=>{const e=t;if("true"===t.dataset.clicked)this.minimizeAll(),this.activeMovieElem=void 0,this.hideDetails(),setTimeout((()=>{e.dataset.clicked="false"}),500),this.hideBackground();else{const n=this.getTop();e.style.transition="0s",e.style.left=e.offsetLeft-this.content.scrollLeft+"px",e.style.top=`${e.offsetTop}px`,e.style.position="absolute",e.dataset.left=`${e.offsetLeft}`,e.dataset.top=`${e.offsetTop}`,e.style.zIndex="3",setTimeout((()=>{e.style.transition="0.5s",this.showDetails(this.activeMovieElemData),this.showBackground(),i.isEqual(t.style.width,t.style.height)?(e.style.width=`${this.minExpandedWidth}px`,e.style.height=`${this.minExpandedWidth}px`):(e.style.width=`${this.minExpandedWidth}px`,e.style.height=`${this.minExpandedHeight}px`),e.style.left="16px",e.style.top=`${n+16}px`,e.dataset.clicked="true",this.activeMovieElem=e}),1)}},this.getTop=()=>{if(this.card){const t=document.documentElement,e=(window.pageYOffset||t.scrollTop)-(t.clientTop||0),i=G(this.card).top;return e{let s="";this.plex&&(s=i.isEqual(t.type,"episode")?`${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight}&minSize=1&upscale=1&url=${t.grandparentThumb}&X-Plex-Token=${this.config.token}`:`${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight}&minSize=1&upscale=1&url=${t.thumb}&X-Plex-Token=${this.config.token}`);const r=document.createElement("div");r.className="plexMeetsContainer",r.style.width=`${n.width}px`,this.displayTitleMain||this.displaySubtitleMain?r.style.marginBottom="10px":r.style.marginBottom="5px",i.isNil(t.channelCallSign)||(r.style.marginBottom="10px");const a=document.createElement("div");a.className="movieElem",a.style.width=`${n.width}px`,a.style.height=`${n.height}px`,(!i.isNil(t.channelCallSign)||i.isEqual(t.type,"artist")||i.isEqual(t.type,"album")||i.includes(t.key,"folder"))&&(i.isEqual(t.type,"artist")||i.isEqual(t.type,"album")||i.includes(t.key,"folder")||(a.style.backgroundSize="80%"),a.style.backgroundColor="rgba(0,0,0,0.2)",a.style.backgroundPosition="center",a.style.height=`${n.width}px`),a.style.backgroundImage=`url('${s}')`,this.playController&&!this.playController.isPlaySupported(t)&&(a.style.cursor="pointer"),a.addEventListener("click",(()=>{this.activeMovieElemData=t,this.activateMovieElem(a)}));const o=document.createElement("div");if(!(t.viewCount&&t.viewCount>0)&&"movie"===t.type){const t=document.createElement("div");t.className="toViewEpisode",o.appendChild(t)}if(t.leafCount-t.viewedLeafCount>0&&"show"===t.type){const e=document.createElement("div");e.className="toViewSeason",e.innerHTML=(t.leafCount-t.viewedLeafCount).toString(),e.style.fontSize=`${this.fontSize4}px`,e.style.lineHeight=`${this.fontSize4}px`,e.style.padding=this.fontSize4/2+"px",o.appendChild(e)}if(t.viewOffset>0&&t.duration>0){const e=document.createElement("div");e.className="viewProgress",e.style.width=t.viewOffset/t.duration*100+"%",o.appendChild(e)}if(o.className="interactiveArea",this.playController){const e=this.playController.getPlayButton(t.type);this.playController.isPlaySupported(t)&&e.classList.remove("disabled"),o.append(e),((t,e,i)=>{let n=!1,s=null;const r=t=>{t.stopPropagation(),null!==s&&(clearTimeout(s),s=null)},a=t=>{t.stopPropagation(),"click"===t.type&&0!==t.button||(n=!1,s=setTimeout((()=>{i(t),n=!0}),1e3))};t.addEventListener("mousedown",a),t.addEventListener("touchstart",a),t.addEventListener("click",(t=>(t.stopPropagation(),null!==s&&(clearTimeout(s),s=null),!n&&(e(t),!0)))),t.addEventListener("mouseout",r),t.addEventListener("touchend",r),t.addEventListener("touchleave",r),t.addEventListener("touchcancel",r)})(e,(e=>{e.stopPropagation(),this.hassObj&&this.playController&&this.playController.play(t,!0)}),(t=>{console.log("Play version... will be here!"),t.stopPropagation()}))}a.append(o);const l=document.createElement("div");i.isEqual(t.type,"episode")?l.innerHTML=F(t.grandparentTitle):i.isNil(t.channelCallSign)?l.innerHTML=F(t.title):l.innerHTML=F(t.channelCallSign);const h=this.fontSize1/4,c=this.fontSize2/4;l.className="titleElem",i.isNil(t.channelCallSign)?l.style.marginTop=`${h}px`:l.style.marginTop="0px",l.style.fontSize=`${this.fontSize1}px`,l.style.marginBottom=`${h}px`,l.style.lineHeight=`${this.fontSize1}px`;const u=document.createElement("div");i.isEqual(t.type,"episode")?u.innerHTML=F(t.title):i.isNil(t.year)?i.isNil(t.epg)?u.innerHTML=" ":u.innerHTML=F(t.epg.title):u.innerHTML=F(t.year),u.className="yearElem",u.style.fontSize=`${this.fontSize2}px`,u.style.lineHeight=`${this.fontSize2}px`,u.style.marginTop=`${c}px`,u.style.marginBottom=`${c}px`;const d=document.createElement("div");return i.isEqual(t.type,"episode")&&(d.innerHTML=F(`S${t.parentIndex} E${t.index}`),d.className="additionalElem",d.style.fontSize=`${this.fontSize2}px`,d.style.lineHeight=`${this.fontSize2}px`,d.style.marginTop=`${c}px`,d.style.marginBottom=`${c}px`),r.appendChild(a),this.displayTitleMain&&r.appendChild(l),this.displaySubtitleMain&&(r.appendChild(u),r.appendChild(d)),r},this.loadCustomStyles=()=>``,this.setConfig=t=>{if(this.plexProtocol="http",!t.ip)throw new Error("You need to define a Plex IP Address");if(!t.token)throw new Error("You need to define a Plex Token");if(!t.libraryName)throw new Error("You need to define a libraryName");if(!t.entity||0===t.entity.length)throw new Error("You need to define at least one entity");if(i.isPlainObject(t.entity)){let e=!1;if(i.forEach(t.entity,((t,i)=>{if(s[i])return e=!0,!1})),!e)throw new Error("You need to define at least one supported entity")}else if(!i.isString(t.entity)&&!i.isArray(t.entity))throw new Error("You need to define at least one supported entity");this.config=t,t.protocol&&(this.plexProtocol=t.protocol),t.displayType&&!i.isEmpty(t.displayType)&&(this.displayType=t.displayType),t.useHorizontalScroll&&i.isEqual(t.useHorizontalScroll,"Yes")&&(this.useHorizontalScroll=!0),t.useShuffle&&i.isEqual(t.useShuffle,"Yes")&&(this.useShuffle=!0),t.displayTitleMain&&i.isEqual(t.displayTitleMain,"No")&&(this.displayTitleMain=!1),t.displaySubtitleMain&&i.isEqual(t.displaySubtitleMain,"No")&&(this.displaySubtitleMain=!1),t.port&&!i.isEqual(t.port,"")?this.plexPort=t.port:this.plexPort=!1,t.maxCount&&""!==t.maxCount&&(this.maxCount=t.maxCount),t.maxRows&&""!==t.maxRows&&"0"!==t.maxRows&&0!==t.maxRows?this.maxRows=t.maxRows:this.maxRows=!1,t.minWidth&&""!==t.minWidth&&"0"!==t.minWidth&&0!==t.minWidth&&(this.minWidth=parseInt(t.minWidth,10)),t.minEpisodeWidth&&""!==t.minEpisodeWidth&&"0"!==t.minEpisodeWidth&&0!==t.minEpisodeWidth&&(this.minEpisodeWidth=parseInt(t.minEpisodeWidth,10)),t.minExpandedWidth&&""!==t.minExpandedWidth&&"0"!==t.minExpandedWidth&&0!==t.minExpandedWidth&&(this.minExpandedWidth=parseInt(t.minExpandedWidth,10)),t.fontSize1&&""!==t.fontSize1&&"0"!==t.fontSize1&&0!==t.fontSize1&&(this.fontSize1=parseInt(t.fontSize1,10)),t.fontSize2&&""!==t.fontSize2&&"0"!==t.fontSize2&&0!==t.fontSize2&&(this.fontSize2=parseInt(t.fontSize2,10)),t.fontSize3&&""!==t.fontSize3&&"0"!==t.fontSize3&&0!==t.fontSize3&&(this.fontSize3=parseInt(t.fontSize3,10)),t.fontSize4&&""!==t.fontSize4&&"0"!==t.fontSize4&&0!==t.fontSize4&&(this.fontSize4=parseInt(t.fontSize4,10)),t.minExpandedHeight&&""!==t.minExpandedHeight&&"0"!==t.minExpandedHeight&&0!==t.minExpandedHeight&&(this.minExpandedHeight=parseInt(t.minExpandedHeight,10)),t.runBefore&&!i.isEqual(t.runBefore,"")&&(this.runBefore=t.runBefore),t.runAfter&&!i.isEqual(t.runAfter,"")&&(this.runAfter=t.runAfter),i.isNil(t.playTrailer)||(this.playTrailer=t.playTrailer),i.isNil(t.showExtras)||(this.showExtras=t.showExtras),i.isNil(t.showSearch)||(this.showSearch=t.showSearch),this.plex=new V(this.config.ip,this.plexPort,this.config.token,this.plexProtocol,this.config.sort),this.data={},this.error="",this.renderInitialData()},this.getCardSize=()=>3}set hass(t){this.hassObj=t,this.initialDataLoaded||this.loadInitialData()}static getConfigElement(){return document.createElement("plex-meets-homeassistant-editor")}}ut.querySelectorAllShadows=(t,e=document.body)=>{const i=Array.from(e.querySelectorAll("*")).map((t=>t.shadowRoot)).filter(Boolean).map((e=>ut.querySelectorAllShadows(t,e)));return Array.from(e.querySelectorAll(t)).concat(i).flat()},customElements.define("plex-meets-homeassistant-editor",rt),customElements.define("plex-meets-homeassistant",ut),window.customCards=window.customCards||[],window.customCards.push({type:"plex-meets-homeassistant",name:"Plex meets Home Assistant",preview:!1,description:"Integrates Plex into Home Assistant. Browse and launch media with a simple click."}); //# sourceMappingURL=plex-meets-homeassistant.js.map diff --git a/src/editor.ts b/src/editor.ts index 7f13bea..16c3c99 100755 --- a/src/editor.ts +++ b/src/editor.ts @@ -3,7 +3,7 @@ import _ from 'lodash'; import { HomeAssistant } from 'custom-card-helpers'; import Plex from './modules/Plex'; -import { fetchEntityRegistry } from './modules/utils'; +import { fetchEntityRegistry, createTextElement } from './modules/utils'; class PlexMeetsHomeAssistantEditor extends HTMLElement { content: any; @@ -16,15 +16,15 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { config: Record = {}; - ip: any = document.createElement('paper-input'); + ip: any = createTextElement(); - token: any = document.createElement('paper-input'); + token: any = createTextElement(); - port: any = document.createElement('paper-input'); + port: any = createTextElement(); - maxCount: any = document.createElement('paper-input'); + maxCount: any = createTextElement(); - maxRows: any = document.createElement('paper-input'); + maxRows: any = createTextElement(); displayTitleMain: any = document.createElement('select'); @@ -34,23 +34,23 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { useShuffle: any = document.createElement('select'); - minWidth: any = document.createElement('paper-input'); + minWidth: any = createTextElement(); - minEpisodeWidth: any = document.createElement('paper-input'); + minEpisodeWidth: any = createTextElement(); - minExpandedWidth: any = document.createElement('paper-input'); + minExpandedWidth: any = createTextElement(); - minExpandedHeight: any = document.createElement('paper-input'); + minExpandedHeight: any = createTextElement(); - fontSize1: any = document.createElement('paper-input'); + fontSize1: any = createTextElement(); - fontSize2: any = document.createElement('paper-input'); + fontSize2: any = createTextElement(); - fontSize3: any = document.createElement('paper-input'); + fontSize3: any = createTextElement(); - fontSize4: any = document.createElement('paper-input'); + fontSize4: any = createTextElement(); - cardTitle: any = document.createElement('paper-input'); + cardTitle: any = createTextElement(); libraryName: any = document.createElement('select'); @@ -391,6 +391,10 @@ class PlexMeetsHomeAssistantEditor extends HTMLElement { } this.content.appendChild(this.protocol); + this.ip.style.width = '100%'; + this.ip.style.marginTop = '10px'; + this.ip.style.marginBottom = '10px'; + this.ip.label = 'Plex IP Address / Hostname'; if (this.config.ip) { this.ip.value = this.config.ip.replace(/^https?:\/\//i, '').replace(/\/$/, ''); diff --git a/src/modules/utils.ts b/src/modules/utils.ts index 6f43022..5baca5c 100644 --- a/src/modules/utils.ts +++ b/src/modules/utils.ts @@ -19,6 +19,15 @@ const escapeHtml = (unsafe: any): string => { return ''; }; +const createTextElement = () => { + const textElem = document.createElement('ha-textfield'); + + textElem.style.width = "100%" + textElem.style.marginTop = "10px" + textElem.style.marginBottom = "10px" + return textElem; +} + const fetchEntityRegistry = (conn: Connection): Promise>> => conn.sendMessagePromise({ type: 'config/entity_registry/list' @@ -275,8 +284,7 @@ const createEpisodesView = ( episodeContainer.className = 'episodeContainer'; episodeContainer.style.width = `${CSS_STYLE.episodeWidth}px`; const episodeThumbURL = plex.authorizeURL( - `${plex.getBasicURL()}/photo/:/transcode?width=${CSS_STYLE.episodeWidth}&height=${ - CSS_STYLE.episodeHeight + `${plex.getBasicURL()}/photo/:/transcode?width=${CSS_STYLE.episodeWidth}&height=${CSS_STYLE.episodeHeight }&minSize=1&upscale=1&url=${data.thumb}` ); @@ -388,5 +396,6 @@ export { fetchEntityRegistry, waitUntilState, getState, - createTrackView + createTrackView, + createTextElement }; diff --git a/src/plex-meets-homeassistant.ts b/src/plex-meets-homeassistant.ts index 4da0b81..d9c71c5 100644 --- a/src/plex-meets-homeassistant.ts +++ b/src/plex-meets-homeassistant.ts @@ -944,7 +944,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
+ .fontSize4 / 4}px; margin-bottom:${this.fontSize4 / 4}px; margin-right:${this.fontSize4 / 4}px;'> Directed by @@ -953,7 +953,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
+ .fontSize4 / 4}px; margin-bottom:${this.fontSize4 / 4}px; margin-right:${this.fontSize4 / 4}px;'> Written by @@ -962,7 +962,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
+ .fontSize4 / 4}px; margin-bottom:${this.fontSize4 / 4}px; margin-right:${this.fontSize4 / 4}px;'> Studio @@ -971,7 +971,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
+ .fontSize4 / 4}px; margin-bottom:${this.fontSize4 / 4}px; margin-right:${this.fontSize4 / 4}px;'> Genre @@ -1425,24 +1425,28 @@ class PlexMeetsHomeAssistant extends HTMLElement { } (this.getElementsByClassName('metaInfo')[0] as HTMLElement).innerHTML = `${(mainData.duration !== undefined - ? `${Math.round( + ? `${Math.round( parseInt(escapeHtml(mainData.duration), 10) / 60 / 1000 - )} min` + )} min` : '') + (mainData.contentRating !== undefined - ? `${escapeHtml( + ? `${escapeHtml( mainData.contentRating - )}` + )}` : '') + (mainData.rating !== undefined - ? `${mainData.rating < 5 ? '🗑' : '⭐' - } ${Math.round(parseFloat(escapeHtml(mainData.rating)) * 10) / 10}` + ? `${ + mainData.rating < 5 ? '🗑' : '⭐' + } ${Math.round(parseFloat(escapeHtml(mainData.rating)) * 10) / 10}` : '')}
`; const detailDesc = this.getElementsByClassName('detailDesc')[0] as HTMLElement; @@ -1582,8 +1586,9 @@ class PlexMeetsHomeAssistant extends HTMLElement { fullscreenTrailer.style.visibility = 'visible'; contentbg.classList.add('no-transparency'); playingFired = true; - this.videoElem.style.width = `${(this.getElementsByClassName('searchContainer')[0] as HTMLElement).offsetWidth - }px`; + this.videoElem.style.width = `${ + (this.getElementsByClassName('searchContainer')[0] as HTMLElement).offsetWidth + }px`; this.videoElem.style.visibility = 'visible'; this.videoElem.style.top = `${top}px`; } @@ -1670,8 +1675,9 @@ class PlexMeetsHomeAssistant extends HTMLElement { const seasonContainer = document.createElement('div'); seasonContainer.className = 'seasonContainer'; seasonContainer.style.width = `${CSS_STYLE.width}px`; - const thumbURL = `${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight - }&minSize=1&upscale=1&url=${childData.thumb}&X-Plex-Token=${this.config.token}`; + const thumbURL = `${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${ + this.minExpandedHeight + }&minSize=1&upscale=1&url=${childData.thumb}&X-Plex-Token=${this.config.token}`; const seasonElem = document.createElement('div'); seasonElem.className = 'seasonElem'; @@ -2068,11 +2074,13 @@ class PlexMeetsHomeAssistant extends HTMLElement { let thumbURL = ''; if (this.plex) { if (_.isEqual(data.type, 'episode')) { - thumbURL = `${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight - }&minSize=1&upscale=1&url=${data.grandparentThumb}&X-Plex-Token=${this.config.token}`; + thumbURL = `${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${ + this.minExpandedHeight + }&minSize=1&upscale=1&url=${data.grandparentThumb}&X-Plex-Token=${this.config.token}`; } else { - thumbURL = `${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${this.minExpandedHeight - }&minSize=1&upscale=1&url=${data.thumb}&X-Plex-Token=${this.config.token}`; + thumbURL = `${this.plex.getBasicURL()}/photo/:/transcode?width=${this.minExpandedWidth}&height=${ + this.minExpandedHeight + }&minSize=1&upscale=1&url=${data.thumb}&X-Plex-Token=${this.config.token}`; } }