// @ts-ignore
import React, {useEffect} from 'react';
import { View, Image, Text, StyleSheet } from 'react-native';
import {getAlbumByArtist, getArtistInfo} from "../../redux/actions/action";
import {useDispatch} from "react-redux";
import ArtistList from "../Album/AlbumList";

export default function ArtistPage({ route }) {
    const artist = route.params.artist;
    const dispatch = useDispatch();

    useEffect(() => {
        const load = async () => {
            // @ts-ignore
            await dispatch(getArtistInfo(artist));
            // @ts-ignore
            await dispatch(getAlbumByArtist(artist));
        };
        load();
    })

    return (
        <View style={styles.container}>
            <Image source={{ uri: artist.image }} style={styles.image} />
            <Text style={styles.name}>{artist.name}</Text>
            <Text style={styles.bio}>{artist.bio}</Text>

            <Text style={styles.titre}>Liste Album</Text>
            <ArtistList ALBUM_LIST={artist.listAlbum}/>
        </View>
    );
};

const styles = StyleSheet.create({
    container: {
        marginTop:10,
        alignItems: 'center'
    },
    image: {
        width: 100,
        height: 100,
        marginBottom: 10,
        borderRadius: 100,
        borderWidth: 2,
        borderColor: 'black'
    },
    name: {
        fontSize: 30,
        fontWeight: 'bold',
        textAlign: 'center',
    },
    bio:{

    },
    titre:{
        fontSize: 20,
        fontWeight: "bold"
    }
});