blob: 2d0422e6bb85778a5b2cb7bef322599ec49c3731 [file] [log] [blame]
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +02001import './languages-editor';
2
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +02003import {css, html, LitElement} from 'lit';
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +02004import {customElement, property} from 'lit/decorators.js';
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +02005import {map} from 'lit/directives/map.js';
6
Adrià Vilanova Martínez5bdc4732022-05-31 20:12:21 +02007import {msg} from '../../../common/i18n';
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +02008import {OptionsV0, TAB_OPTIONS, TabOptionValue} from '../../../common/options';
Adrià Vilanova Martínez5bdc4732022-05-31 20:12:21 +02009import {SHARED_STYLES} from '../../shared/shared-styles';
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020010
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +020011@customElement('options-editor')
12export default class OptionsEditor extends LitElement {
13 @property({type: Object}) storageData: OptionsV0;
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020014
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
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020027 render() {
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +020028 const currentTabOption = this.storageData?.uniquetab;
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020029
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +020030 const otherOptions = map(TAB_OPTIONS, (option, i) => {
31 const checked = option.value == currentTabOption ||
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020032 option.deprecatedValues.includes(currentTabOption);
33 return html`
34 <p>
35 <input type="radio" name="uniquetab" id="uniquetab_${i}"
Adrià Vilanova Martínez53f7a7f2022-05-30 13:59:59 +020036 value="${option?.value}" .checked="${checked}"
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020037 @change="${() => this.changeTabOption(option.value)}">
38 <label for="uniquetab_${i}">${msg(option.labelMsg)}</label></p>
39 `;
40 });
41
42 return html`
43 <languages-editor .languages="${this.storageData?.translateinto}">
44 </languages-editor>
45
46 <h2 id="otheroptionsheader">${msg('options_otheroptionsheader')}</h2>
47
48 <div id="otheroptions">
49 ${otherOptions}
50 </div>
51 `;
52 }
53
Adrià Vilanova Martínez2b50e912022-06-01 00:05:40 +020054 changeTabOption(value: TabOptionValue) {
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020055 chrome.storage.sync.set({uniquetab: value}, function() {
Adrià Vilanova Martínez86fda492022-05-31 15:05:21 +020056 chrome.runtime.sendMessage({action: 'clearTranslatorTab'});
Adrià Vilanova Martíneze5263f12022-05-29 19:22:13 +020057 });
58 }
59}