!function(e,t,n,a,r,o,i,l,s){"use strict";let c={DEFAULT_APP_NAME:"Music",DEFAULT_TIME_INTERVAL:5,APPLICATION_ID:"1054951789318909972",LFM_API_KEY:"615322f0047e12aedbc610d9d71f7430",LFM_DEFAULT_COVER_HASHES:["2a96cbd8b46e442fc41c2b86b821562f","c6f59c1e5e7240a4c0d427abd71f3dbb"]},u=n.findByProps("getAssetIds");async function g(){let e=new URLSearchParams({method:"user.getrecenttracks",user:S.username,api_key:c.LFM_API_KEY,format:"json",limit:"1",extended:"1"}).toString(),t=await fetch(`https://ws.audioscrobbler.com/2.0/?${e}`);if(!t.ok)throw Error(`Failed to fetch the latest scrobble: ${t.statusText}`);let n=await t.json(),a=n?.recenttracks?.track?.[0];if(!a)throw n;return{name:a.name,artist:a.artist.name,album:a.album["#text"],albumArt:await m(a.image[3]["#text"]),url:a.url,date:a.date?.["#text"]??"now",nowPlaying:Boolean(a["@attr"]?.nowplaying),loved:"1"===a.loved}}async function m(e){return c.LFM_DEFAULT_COVER_HASHES.some(function(t){return e.includes(t)})?null:e}function d(){return R.lastActivity&&F("--> Clearing activity..."),f(null)}function f(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})}async function p(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c.APPLICATION_ID;if(!e)return null;if("string"==typeof e){let n=await u.getAssetIds(t,[e]);return n[0]}return await u.getAssetIds(t,e)}async function h(){if(F("--> Fetching last track..."),!S.username)throw s.showToast("Last.fm username is not set!",i.getAssetIDByName("Small")),y(),Error("Username is not set");let e=await g().catch(async function(e){throw F("--> An error occurred while fetching the last track, aborting..."),d(),e});if(!e.nowPlaying){F("--> Last track is not currently playing, aborting..."),d();return}if(F("--> Track fetched!"),R.lastTrackUrl===e.url){F("--> Last track is the same as the previous one, aborting...");return}let t={name:S.appName||c.DEFAULT_APP_NAME,flags:0,type:S.listeningTo?2:0,details:e.name,state:`by ${e.artist}`,application_id:c.APPLICATION_ID};if(R.lastTrackUrl=e.url,t.name.includes("{{"))for(let n in e)t.name=t.name.replace(`{{${n}}}`,e[n]);S.showTimestamp&&(t.timestamps={start:Date.now()/1e3|0}),e.album&&(t.assets={large_image:await p(e.albumArt),large_text:`on ${e.album}`}),F("--> Setting activity..."),F(t);try{f(t)}catch(e){throw F("--> An error occurred while setting the activity"),d(),e}F("--> Successfully set activity!")}function y(){console.log("--> Flushing..."),R.lastActivity=null,R.lastTrackUrl=null,R.updateInterval&&clearInterval(R.updateInterval),d()}async function T(){if(console.log("--> Initializing..."),R.pluginStopped)throw Error("Plugin is already stopped!");y();let e=0;await h().catch(function(t){console.error(t),e++}),R.updateInterval=setInterval(function(){return h().then(function(){e=0}).catch(function(t){console.error(t),++e>3&&(console.error("Failed to fetch/set activity 3 times, aborting..."),y())})},1e3*(S.timeInterval||c.DEFAULT_TIME_INTERVAL))}let{ScrollView:E,TouchableOpacity:v,Text:A}=a.ReactNative,{FormInput:I,FormDivider:b,FormSwitchRow:_,FormText:L,FormIcon:w}=l.Forms;function N(){async function e(){for(let e in r.storage)(!1===r.storage[e]||r.storage[e])&&(S[e]=r.storage[e]);console.log("Applying settings..."),await T(),s.showToast("Settings updated!",i.getAssetIDByName("Check"))}return a.React.createElement(v,{onPress:e},a.React.createElement(L,{style:{marginRight:12}},"UPDATE"))}function P(){let e=o.useProxy(r.storage),t=a.NavigationNative.useNavigation();return a.React.useEffect(function(){t.setOptions({title:"Last.fm Configuration",headerRight:N})},[]),a.React.createElement(E,null,a.React.createElement(I,{value:e.appName||void 0,onChangeText:function(t){return e.appName=t.trim()},title:"Discord Application Name",placeholder:c.DEFAULT_APP_NAME,returnKeyType:"done"}),a.React.createElement(b,null),a.React.createElement(I,{required:!0,value:e.username||void 0,onChangeText:function(t){return e.username=t.trim()},title:"Last.fm username",helpText:!e.username&&a.React.createElement(A,{style:{color:"#FF0000"}},"This field is required!"),placeholder:"wumpus123",returnKeyType:"done"}),a.React.createElement(b,null),a.React.createElement(I,{value:e.timeInterval,onChangeText:function(t){return e.timeInterval=Number(t)},title:"Update interval (in seconds)",placeholder:c.DEFAULT_TIME_INTERVAL.toString(),keyboardType:"numeric",returnKeyType:"done"}),a.React.createElement(b,null),a.React.createElement(_,{label:"Show time elapsed",subLabel:"Show the time elapsed since the song started playing",leading:a.React.createElement(w,{source:i.getAssetIDByName("clock")}),value:e.showTimestamp,onValueChange:function(t){return e.showTimestamp=t}}),a.React.createElement(b,null),a.React.createElement(_,{label:"Set status as listening",subLabel:'Set your status as "Listening to" instead of "Playing"',leading:a.React.createElement(w,{source:i.getAssetIDByName("ic_headset_neutral")}),value:e.listeningTo,onValueChange:function(t){return e.listeningTo=t}}),a.React.createElement(b,null),a.React.createElement(_,{label:"Verbose logging",subLabel:"Log more information to the console for debugging purposes",leading:a.React.createElement(w,{source:i.getAssetIDByName("pencil")}),value:e.verboseLogging,onValueChange:function(t){return e.verboseLogging=t}}))}let R={},S={...t.plugin.storage},C=n.findByStoreName("UserStore"),D=n.findByProps("SET_ACTIVITY").SET_ACTIVITY,F=function(){for(var e=arguments.length,t=Array(e),n=0;n