(function(o,_,p,a,u,L,g,S,A){"use strict";functionN(e,t){if(!(einstanceoft))thrownewTypeError("Cannot call a class as a function")}constc={DEFAULT_APP_NAME:"Music",DEFAULT_TIME_INTERVAL:5,APPLICATION_ID:"1054951789318909972",LFM_API_KEY:"615322f0047e12aedbc610d9d71f7430",LFM_DEFAULT_COVER_HASHES:["2a96cbd8b46e442fc41c2b86b821562f","c6f59c1e5e7240a4c0d427abd71f3dbb"]},E=p.findByProps("getAssetIds");asyncfunctionR(){conste=newURLSearchParams({method:"user.getrecenttracks",user:l.username,api_key:c.LFM_API_KEY,format:"json",limit:"1",extended:"1"}).toString(),t=awaitfetch(`https://ws.audioscrobbler.com/2.0/?${e}`);if(!t.ok)thrownewError(`Failed to fetch the latest scrobble: ${t.statusText}`);constn=awaitt.json(),s=n?.recenttracks?.track?.[0];if(!s)thrown;return{name:s.name,artist:s.artist.name,album:s.album["#text"],albumArt:awaitP(s.image[3]["#text"]),url:s.url,date:s.date?.["#text"]??"now",nowPlaying:!!s["@attr"]?.nowplaying,loved:s.loved==="1"}}asyncfunctionP(e){returnc.LFM_DEFAULT_COVER_HASHES.some(function(t){returne.includes(t)})?null:e}functionf(){returnr.lastActivity&&i("--> Clearing activity..."),I(null)}functionI(e){r.pluginStopped&&(console.log("--> Plugin is unloaded, aborting..."),r.updateInterval&&clearInterval(r.updateInterval),e=null),r.lastActivity=e,a.FluxDispatcher.dispatch({type:"LOCAL_ACTIVITY_UPDATE",activity:e})}asyncfunctionC(e){lett=arguments.length>1&&arguments[1]!==void0?arguments[1]:c.APPLICATION_ID;returne?typeofe=="string"?(awaitE.getAssetIds(t,[e]))[0]:awaitE.getAssetIds(t,e):null}asyncfunctionb(){if(i("--> Fetching last track..."),!l.username)throwA.showToast("Last.fm username is not set!",g.getAssetIDByName("Small")),h(),newError("Username is not set");conste=awaitR().catch(asyncfunction(n){throwi("--> An error occurred while fetching the last track, aborting..."),f(),n});if(!e.nowPlaying){i("--> Last track is not currently playing, aborting..."),f();return}if(i("--> Track fetched!"),r.lastTrackUrl===e.url){i("--> Last track is the same as the previous one, aborting...");return}constt={name:l.appName||c.DEFAULT_APP_NAME,flags:0,type:l.listeningTo?2:0,details:e.name,state:`by ${e.artist}`,application_id:c.APPLICATION_ID};if(r.lastTrackUrl=e.url,t.name.includes("{{"))for(constnine)t.name=t.name.replace(`{{${n}}}`,e[n]);l.showTimestamp&&(t.timestamps={start:Date.now()/1e3|0}),e.album&&(t.assets={large_image:awaitC(e.albumArt),large_text:`on ${e.album}`}),i("--> Setting activity..."),i(t);try{I(t)}catch(n){throwi("--> An error occurred while setting the activity"),f(),n}i("--> Successfully set activity!")}functionh(){console.log("--> Flushing..."),r.lastActivity=null,r.lastTrackUrl=null,r.updateInterval&&clearInterval(r.updateInterval),f()}asyncfunctionT(){if(console.log("--> Initializing..."),r.pluginStopped)thrownewError("Plugin is already stopped!");h();lete=0;awaitb().catch(function(t){console.error(t),e++}),r.updateInterval=setInterval(function(){returnb().then(function(){e=0}).catch(function(t){console.error(t),++e>3&&(console.error("Failed to fetch/set activity 3 times, aborting..."),h())})},(l.timeInterval||c.DEFAULT_TIME_INTERVAL)*1e3)}const{ScrollView:F,TouchableOpacity:D,Text:U}=a.ReactNative,{FormInput:y,FormDivider:d,FormSwitchRow:m,FormText:k,FormIcon:v}=S.Forms;functionV(){asyncfunctione(){for(consttinu.storage)(u.storage[t]===!1||u.storage[t])&&(l[t]=u.storage[t]);console.log("Applying settings..."),awaitT(),A.showToast("Settings updated!",g.getAssetIDByName("Check"))}returna.React.createElement(D,{onPress:e},a.React.createElement(k,{style:{marginRight:12}},"UPDATE"))}functionM(){conste=L.useProxy(u.storage),t=a.NavigationNative.useNavigation();returna.React.useEffect(function(){t.setOptions({title:"Last.fm Configuration",headerRight:V})},[]),a.React.createElement(F,null,a.React.createElement(y,{value:e.appName||void0,onChangeText:function(n){returne.appName=n.trim()},title:"Discord Application Name",placeholder:c.DEFAULT_APP_NAME,returnKeyType:"done"}),a.React.createElement(d,null),a.React.createElement(y,{requi