blob: 9592d271acbedc815de339143c08fb45fa0f43cd [file] [log] [blame]
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +02001import {css, html, LitElement} from 'lit';
2import {map} from 'lit/directives/map.js';
3
4import {msg} from '../../../common/i18n.js';
Adrià Vilanova Martínez53f7a7f2022-05-30 13:59:59 +02005import {TAB_OPTIONS} from '../../../common/options.js';
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +02006import {SHARED_STYLES} from '../../shared/shared-styles.js';
7
8import LanguagesEditor from './languages-editor.js';
9
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020010export class OptionsEditor extends LitElement {
11 static properties = {
12 storageData: {type: Object},
13 };
14
15 static get styles() {
16 return [
17 SHARED_STYLES,
18 css`
19 #otheroptions p {
20 margin-top: 0;
21 margin-bottom: 8px;
22 }
23 `,
24 ];
25 }
26
27 constructor() {
28 super();
29 this.addEventListener('show-credits-dialog', this.showDialog);
30 }
31
32 render() {
33 let currentTabOption = this.storageData?.uniquetab;
34
35 let otherOptions = map(TAB_OPTIONS, (option, i) => {
36 let checked = option.value == currentTabOption ||
37 option.deprecatedValues.includes(currentTabOption);
38 return html`
39 <p>
40 <input type="radio" name="uniquetab" id="uniquetab_${i}"
Adrià Vilanova Martínez53f7a7f2022-05-30 13:59:59 +020041 value="${option?.value}" .checked="${checked}"
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020042 @change="${() => this.changeTabOption(option.value)}">
43 <label for="uniquetab_${i}">${msg(option.labelMsg)}</label></p>
44 `;
45 });
46
47 return html`
48 <languages-editor .languages="${this.storageData?.translateinto}">
49 </languages-editor>
50
51 <h2 id="otheroptionsheader">${msg('options_otheroptionsheader')}</h2>
52
53 <div id="otheroptions">
54 ${otherOptions}
55 </div>
56 `;
57 }
58
59 changeTabOption(value) {
60 chrome.storage.sync.set({uniquetab: value}, function() {
Adrià Vilanova Martínez86fda492022-05-31 15:05:21 +020061 chrome.runtime.sendMessage({action: 'clearTranslatorTab'});
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020062 });
63 }
64}
65customElements.define('options-editor', OptionsEditor);