import { useState } from 'react'
import { MediaInfoEditModel } from '../../../common/edit/MediaInfoTypes'
import MediaInfoEditComponent from '../../../common/edit/MediaInfoEditComponent'

export interface IAnimeSeasonEditShortComponentProps {
    // titleId?: MediaInfoEditModel | null,
    preview?: MediaInfoEditModel | null,
}

export default function AnimeSeasonEditShortComponent(props: IAnimeSeasonEditShortComponentProps) {
    const [ isEditing, setIsEditingValue ] = useState<Array<string>>([]);
	const setEditing = (elementName: string, value: boolean) => {
		const alreadyEditing = isEditing.find(q => q == elementName) != null;
		if (value){
			if (!alreadyEditing){
				setIsEditingValue(isEditing.concat([elementName]))
			}
		}
		else{
			if (alreadyEditing){
				setIsEditingValue(isEditing.filter(q => q != elementName))
			}
		}
	}

    const [ isDeleting, setIsDeletingValue ] = useState<Array<string>>([]);
	const setDeleting = (elementName: string, value: boolean) => {
		const alreadyDeleting = isDeleting.find(q => q == elementName) != null;
		if (value){
			if (!alreadyDeleting){
				setIsDeletingValue(isDeleting.concat([elementName]))
			}
		}
		else{
			if (alreadyDeleting){
				setIsDeletingValue(isDeleting.filter(q => q != elementName))
			}
		}
	}

    return (
        <div>
            <MediaInfoEditComponent 
                mediaInfo={props.preview != null ? {
                        type: props.preview.type,
                        objectId: props.preview.objectId,
                        data: null,
                        // url: GetUrl(data?.commonProperties.preview.objectId),
                        url: props.preview.url,
                        isNew: (props.preview.url != null && props.preview.url != ''),
                    } as MediaInfoEditModel : null}
                classes={'card-img-top rounded-3 border border-5 border-secondary'}
                
                isEditing={isEditing.find(q => q == 'preview') != null}
                setEditing={(_, value) => setEditing('preview', value)}
                editMediaInfo={(mediaInfo, newUrl, newFile) =>
                    // data == null ? Promise.reject(dataLoadingError) : SetAnimeTitlePreview({
                    //     animeTitleId: data.id,
                    //     animeSeasonId: null,
                    //     animeEpisodeId: null,
                    //     newType: mediaInfo?.type ?? MediaInfoType.Image,
                    //     newUrl: newUrl,
                    //     newFile: newFile,
                    // } as CreateMediaInfoModel, client)}
                { console.log('asdadssa'); return Promise.reject(); } }
                isDeleting={isDeleting.find(q => q == 'preview') != null}
                // setDeleting={(mediaInfo, value) => setDeleting('preview', value)}
                setDeleting={(_, value) => setDeleting('preview', value)}
                
                deleteMediaInfo={(mediaInfo) =>
                    // data == null ? Promise.reject(dataLoadingError) : ClearAnimeTitlePreview({
                    //     animeTitleId: data.id,
                    //     animeSeasonId: null,
                    //     animeEpisodeId: null,
                    //     objectId: mediaInfo.objectId,
                    // } as DeleteMediaInfoModel, client)}
                    { console.log('asdkjsanjksdnsad2432324324324'); return Promise.reject();}}
                // dataLoadingError={dataLoadingError}
                dataLoadingError={null}
                // forceRefresh={fetchData}
                forceRefresh={() => {console.log('r')}}
                />
        </div>
    )
}
