import React, { useState } from 'react'
import Table from '@material-ui/core/Table'
import TableBody from '@material-ui/core/TableBody'
import TableCell from '@material-ui/core/TableCell'
import TableContainer from '@material-ui/core/TableContainer'
import TableRow from '@material-ui/core/TableRow'
import {
BooleanField,
DateField,
TextField,
NumberField,
FunctionField,
useTranslate,
useRecordContext,
} from 'react-admin'
import { humanize, underscore } from 'inflection'
import {
ArtistLinkField,
BitrateField,
ParticipantsInfo,
PathField,
SizeField,
} from './index'
import { MultiLineTextField } from './MultiLineTextField'
import { makeStyles } from '@material-ui/core/styles'
import config from '../config'
import { AlbumLinkField } from '../song/AlbumLinkField'
import { Tab, Tabs } from '@material-ui/core'
const useStyles = makeStyles({
gain: {
'&:after': {
content: (props) => (props.gain ? " ' db'" : ''),
},
},
tableCell: {
width: '17.5%',
},
value: {
whiteSpace: 'pre-line',
},
})
export const SongInfo = (props) => {
const classes = useStyles({ gain: config.enableReplayGain })
const translate = useTranslate()
const record = useRecordContext(props)
const [tab, setTab] = useState(0)
// These are already displayed in other fields or are album-level tags
const excludedTags = [
'genre',
'disctotal',
'tracktotal',
'releasetype',
'recordlabel',
'media',
'albumversion',
]
const data = {
path: ,
libraryName: ,
album: (
),
discSubtitle: ,
albumArtist: (
),
artist: (
),
genre: (
r.genres?.map((g) => g.name).join(' • ')} />
),
compilation: ,
bitRate: ,
bitDepth: ,
sampleRate: ,
channels: ,
size: ,
updatedAt: ,
playCount: ,
bpm: ,
comment: ,
}
const roles = []
for (const name of Object.keys(record.participants)) {
if (name === 'albumartist' || name === 'artist') {
continue
}
roles.push([name, record.participants[name].length])
}
const optionalFields = [
'discSubtitle',
'comment',
'bpm',
'genre',
'bitDepth',
'sampleRate',
]
optionalFields.forEach((field) => {
!record[field] && delete data[field]
})
if (record.playCount > 0) {
data.playDate =
}
if (config.enableReplayGain) {
data.albumGain = (
)
data.trackGain = (
)
}
const tags = Object.entries(record.tags ?? {}).filter(
(tag) => !excludedTags.includes(tag[0]),
)
return (
{record.rawTags && (
setTab(value)}>
)}
{Object.keys(data).map((key) => {
return (
{translate(`resources.song.fields.${key}`, {
_: humanize(underscore(key)),
})}
:
{data[key]}
)
})}
{tags.length > 0 && (
{translate(`resources.song.fields.tags`)}
)}
{tags.map(([name, values]) => (
{name}:
{values.join(' • ')}
))}
{record.rawTags && (
{translate(`resources.song.fields.path`)}:
{data.path}
{Object.entries(record.rawTags).map(([key, value]) => (
{key}:
{value.join(' • ')}
))}
)}
)
}