import { TimeFormat } from "@labir/core";
import { t } from "i18next";
import { css, html, nothing } from "lit";
import { customElement } from "lit/decorators.js";
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
import { FileConsumer } from "../../hierarchy/consumers/FileConsumer";
import { T } from "../../translations/Languages";
@customElement("file-info-button")
export class FileInfoButton extends FileConsumer {
protected onFileLoaded(): void {}
public onInstanceCreated(): void {}
public onFailure(): void {}
static styles = css`
table {
width: 100%;
}
td {
padding: calc( var( --thermal-gap ) * .5 ) 0;
}
tr:not(:last-child) {
td {
border-bottom: 1px solid var( --thermal-slate );
}
}
.small,
small {
font-size: calc( var( --thermal-fs-sm ) * .8 );
}
.opaque {
opacity: .5;
}
h2 {
font-size: calc( var( --thermal-fs ) * 1.4 );
}
h3 {
font-size: var( --thermal-fs-small );
margin: .2rem 0 .1rem 0;
padding: 0;
font-weight: normal;
}
ul {
margin: 0;
padding: 0;
padding-left: var( --thermal-fs-small );
}
a {
color: var( --thermal-primary );
}
.download {
width: var( --thermal-fs );
display: inline-block;
margin-left: var( --thermal-gap );
transition: color .2s ease-in-out;
&:hover {
color: var( --thermal-foreground );
}
}
`;
protected renderRow(
label: string,
value: string
) {
return `
| ${label} |
${value} |
`;
}
protected renderNumericalRow(
label: string,
value: number,
fixed: number = 4,
unit?: string
) {
const val = value.toFixed( fixed );
const output = unit !== undefined
? val + " " + unit
: val;
return this.renderRow( label, output );
}
protected renderDownloadRow(
label: string,
text: string,
href: string,
title: string
) {
return this.renderRow(
label,
`${text}
`
);
}
protected render(): unknown {
if ( ! this.file ) {
return nothing;
}
return html`
${t(T.fileinfo)}
${ unsafeHTML( this.renderRow( t(T.thermalfilename), this.file.fileName ) ) }
${ unsafeHTML( this.renderDownloadRow(
t(T.thermalfileurl),
this.file.thermalUrl,
this.file.thermalUrl,
t(T.thermalfiledownload)
) ) }
${ this.file.visibleUrl
? unsafeHTML( this.renderDownloadRow(
t(T.visiblefileurl),
this.file.visibleUrl,
this.file.visibleUrl,
t(T.visiblefiledownload)
) )
: nothing
}
${ unsafeHTML( this.renderRow(
t(T.time),
TimeFormat.human( this.file.timestamp )
) ) }
${ unsafeHTML( this.renderNumericalRow(
t(T.duration),
this.file.duration,
0,
"ms"
) ) }
${ unsafeHTML( this.renderRow(
t(T.resolution),
`${this.file.width} x ${this.file.height}${this.file.pixels.length} pixels`
) ) }
${ unsafeHTML( this.renderNumericalRow(
t(T.bytesize),
this.file.bytesize,
0
) ) }
${ unsafeHTML( this.renderNumericalRow(
t(T.minimaltemperature),
this.file.min,
10,
"°C"
) ) }
${ unsafeHTML( this.renderNumericalRow(
t(T.maximaltemperature),
this.file.max,
10,
"°C"
) ) }
${t(T.filetype)}
${ unsafeHTML( this.renderRow(
t(T.type),
this.file.reader.parser.name
) ) }
${ unsafeHTML( this.renderRow(
t(T.description),
this.file.reader.parser.description
) ) }
| ${t(T.supporteddevices)} |
|
`
}
}