import variables from 'modules/variables';
import { PureComponent } from 'react';
import { MenuItem } from '@mui/material';
import { MdSource, MdOutlineKeyboardArrowRight, MdOutlineAutoAwesome } from 'react-icons/md';
import Header from '../../Header';
import Checkbox from '../../Checkbox';
import ChipSelect from '../../ChipSelect';
import Dropdown from '../../Dropdown';
import Slider from '../../Slider';
import Radio from '../../Radio';
import SettingsItem from '../../SettingsItem';
import ColourSettings from './Colour';
import CustomSettings from './Custom';
import { values } from 'modules/helpers/settings/modals';
export default class BackgroundSettings extends PureComponent {
constructor() {
super();
this.state = {
backgroundType: localStorage.getItem('backgroundType') || 'api',
backgroundFilter: localStorage.getItem('backgroundFilter') || 'none',
backgroundCategories: [variables.getMessage('modals.main.loading')],
backgroundAPI: localStorage.getItem('backgroundAPI') || 'mue',
marketplaceEnabled: localStorage.getItem('photo_packs'),
effects: false,
backgroundSettingsSection: false,
};
this.controller = new AbortController();
}
async getBackgroundCategories() {
const data = await (
await fetch(variables.constants.API_URL + '/images/categories', {
signal: this.controller.signal,
})
).json();
if (this.controller.signal.aborted === true) {
return;
}
this.setState({
backgroundCategories: data,
});
}
componentDidMount() {
if (navigator.onLine === false || localStorage.getItem('offlineMode') === 'true') {
return this.setState({
backgroundCategories: [variables.getMessage('modals.update.offline.title')],
});
}
this.getBackgroundCategories();
}
componentWillUnmount() {
// stop making requests
this.controller.abort();
}
render() {
/* const interval = (
);*/
const APISettings = (
<>
{this.state.backgroundCategories[0] === variables.getMessage('modals.main.loading') ? (
<>
>
) : (
<>
{/*
{this.state.backgroundCategories.map((category) => (
))}
*/}
>
)}
this.setState({ backgroundAPI: e })}
/>
>
);
let backgroundSettings = APISettings;
switch (this.state.backgroundType) {
case 'custom':
backgroundSettings = ;
break;
case 'colour':
backgroundSettings = ;
break;
case 'random_colour':
case 'random_gradient':
backgroundSettings = <>>;
break;
default:
break;
}
if (
localStorage.getItem('photo_packs') &&
this.state.backgroundType !== 'custom' &&
this.state.backgroundType !== 'colour' &&
this.state.backgroundType !== 'api'
) {
backgroundSettings = null;
}
const usingImage =
this.state.backgroundType !== 'colour' &&
this.state.backgroundType !== 'random_colour' &&
this.state.backgroundType !== 'random_gradient';
let header;
if (this.state.effects === true) {
header = (
this.setState({ effects: false })}>
{variables.getMessage('modals.main.settings.sections.background.title')}
{' '}
{variables.getMessage('modals.main.settings.sections.background.effects.title')}
);
} else if (this.state.backgroundSettingsSection === true) {
header = (
this.setState({ backgroundSettingsSection: false })}
>
{variables.getMessage('modals.main.settings.sections.background.title')}{' '}
{' '}
{variables.getMessage('modals.main.settings.sections.background.source.title')}
);
} else {
header = (
);
}
return (
<>
{header}
{this.state.backgroundSettingsSection !== true && this.state.effects !== true ? (
<>
this.setState({ backgroundSettingsSection: true })}
>
{variables.getMessage('modals.main.settings.sections.background.source.title')}
{variables.getMessage(
'modals.main.settings.sections.background.source.subtitle',
)}
this.setState({ backgroundType: value })}
category="background"
>
{this.state.marketplaceEnabled ? (
) : null}
{this.state.backgroundType === 'api' ||
this.state.backgroundType === 'custom' ||
this.state.marketplaceEnabled ? (
<>
this.setState({ effects: true })}>
{variables.getMessage(
'modals.main.settings.sections.background.effects.title',
)}
{variables.getMessage(
'modals.main.settings.sections.background.effects.subtitle',
)}
{' '}
>
) : null}
>
) : null}
{this.state.backgroundSettingsSection !== true &&
this.state.effects !== true &&
(this.state.backgroundType === 'api' ||
this.state.backgroundType === 'custom' ||
this.state.marketplaceEnabled) ? (
) : null}
{this.state.backgroundSettingsSection ? (
<>
this.setState({ backgroundType: value })}
category="background"
>
{this.state.marketplaceEnabled ? (
) : null}
{/* // todo: ideally refactor all of this file, but we need interval to appear on marketplace too */}
{/*{this.state.backgroundType === 'api' ||
this.state.backgroundType === 'custom' ||
this.state.marketplaceEnabled
? interval
: null}*/}
{backgroundSettings}
>
) : null}
{(this.state.backgroundType === 'api' ||
this.state.backgroundType === 'custom' ||
this.state.marketplaceEnabled) &&
this.state.effects ? (
this.setState({ backgroundFilter: value })}
category="background"
element="#backgroundImage"
>
{this.state.backgroundFilter !== 'none' ? (
) : null}
) : null}
>
);
}
}