import React, { Fragment, useEffect } from 'react';
import { List, ListItem, Toggle, BlockTitle, Navbar, NavRight, Link, Page } from 'framework7-react';
import { SearchController, SearchView, SearchSettingsView } from '../../../../common/mobile/lib/controller/Search';
import { f7 } from 'framework7-react';
import { withTranslation } from 'react-i18next';
import { Dom7 } from 'framework7';
import { Device } from '../../../../common/mobile/utils/device';
import { observer, inject } from "mobx-react";
class SearchSettings extends SearchSettingsView {
constructor(props) {
super(props);
this.onToggleMarkResults = this.onToggleMarkResults.bind(this);
}
onToggleMarkResults(checked) {
const api = Common.EditorApi.get();
api.asc_selectSearchingResults(checked);
}
extraSearchOptions() {
const anc_markup = super.extraSearchOptions();
const show_popover = !Device.phone;
const { t } = this.props;
const _t = t("View.Settings", { returnObjects: true });
const storeAppOptions = this.props.storeAppOptions;
const isEdit = storeAppOptions.isEdit;
const markup = (
{!show_popover &&
{_t.textDone}
}
this.onFindReplaceClick('find')} />
{isEdit ? [
this.onFindReplaceClick('replace')} />,
this.onFindReplaceClick('replace-all')}>]
: null}
{_t.textSearchIn}
this.setState({
searchIn: 0
})} />
this.setState({
searchIn: 1
})} />
{_t.textSearchBy}
this.setState({
searchBy: 0
})} />
this.setState({
searchBy: 1
})} />
{_t.textLookIn}
this.setState({
lookIn: 0
})} />
this.setState({
lookIn: 1
})} />
this.setState({
isMatchCase: !this.state.isMatchCase
})} />
this.setState({
isMatchCell: !this.state.isMatchCell
})} />
)
return {...anc_markup, ...markup};
}
}
class SESearchView extends SearchView {
constructor(props) {
super(props);
}
searchParams() {
let params = super.searchParams();
const $$ = Dom7;
const checkboxMatchCase = f7.toggle.get('.toggle-match-case'),
checkboxMatchCell = f7.toggle.get('.toggle-match-cell'),
checkboxMarkResults = f7.toggle.get('.toggle-mark-results'),
checkboxSearchIn = $$('[name="search-in-checkbox"]:checked')[0],
checkboxSearchBy = $$('[name="search-by-checkbox"]:checked')[0],
checkboxLookIn = $$('[name="look-in-checkbox"]:checked')[0];
const searchOptions = {
caseSensitive: checkboxMatchCase.checked,
highlight: checkboxMarkResults.checked,
matchCell: checkboxMatchCell.checked,
searchIn: checkboxSearchIn.value,
searchBy: checkboxSearchBy.value,
lookIn: checkboxLookIn.value,
};
return {...params, ...searchOptions};
}
onSearchbarShow(isshowed, bar) {
// super.onSearchbarShow(isshowed, bar);
const api = Common.EditorApi.get();
if ( isshowed && this.state.searchQuery.length ) {
const checkboxMarkResults = f7.toggle.get('.toggle-mark-results');
api.asc_selectSearchingResults(checkboxMarkResults.checked);
} else api.asc_selectSearchingResults(false);
}
}
const Search = withTranslation()(props => {
const { t } = props;
const _t = t('View.Settings', {returnObjects: true});
useEffect(() => {
if (f7.searchbar.get('.searchbar')?.enabled && Device.phone) {
const api = Common.EditorApi.get();
$$('.searchbar-input').focus();
api.asc_enableKeyEvents(false);
}
});
const onSearchQuery = params => {
const api = Common.EditorApi.get();
let lookIn = +params.lookIn === 0;
let searchIn = +params.searchIn === 1;
let searchBy = +params.searchBy === 0;
if (params.find && params.find.length) {
let options = new Asc.asc_CFindOptions();
options.asc_setFindWhat(params.find);
options.asc_setScanForward(params.forward);
options.asc_setIsMatchCase(params.caseSensitive);
options.asc_setIsWholeCell(params.matchCell);
options.asc_setScanOnOnlySheet(searchIn);
options.asc_setScanByRows(searchBy);
options.asc_setLookIn(lookIn ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value);
if (params.highlight) api.asc_selectSearchingResults(true);
api.asc_findText(options, function(resultCount) {
!resultCount && f7.dialog.alert(null, _t.textNoTextFound);
});
}
};
const onchangeSearchQuery = params => {
const api = Common.EditorApi.get();
if(params.length === 0) api.asc_selectSearchingResults(false);
}
const onReplaceQuery = params => {
const api = Common.EditorApi.get();
let lookIn = +params.lookIn === 0;
let searchIn = +params.searchIn === 1;
let searchBy = +params.searchBy === 0;
// if (params.find && params.find.length) {
api.isReplaceAll = false;
let options = new Asc.asc_CFindOptions();
options.asc_setFindWhat(params.find);
options.asc_setReplaceWith(params.replace || '');
options.asc_setIsMatchCase(params.caseSensitive);
options.asc_setIsWholeCell(params.matchCell);
options.asc_setScanOnOnlySheet(searchIn);
options.asc_setScanByRows(searchBy);
options.asc_setLookIn(lookIn ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value);
options.asc_setIsReplaceAll(false);
api.asc_replaceText(options);
// }
}
const onReplaceAllQuery = params => {
const api = Common.EditorApi.get();
let lookIn = +params.lookIn === 0;
let searchIn = +params.searchIn === 1;
let searchBy = +params.searchBy === 0;
// if (params.find && params.find.length) {
api.isReplaceAll = true;
let options = new Asc.asc_CFindOptions();
options.asc_setFindWhat(params.find);
options.asc_setReplaceWith(params.replace || '');
options.asc_setIsMatchCase(params.caseSensitive);
options.asc_setIsWholeCell(params.matchCell);
options.asc_setScanOnOnlySheet(searchIn);
options.asc_setScanByRows(searchBy);
options.asc_setLookIn(lookIn ? Asc.c_oAscFindLookIn.Formulas : Asc.c_oAscFindLookIn.Value);
options.asc_setIsReplaceAll(true);
api.asc_replaceText(options);
// }
}
return
});
const SearchSettingsWithTranslation = inject("storeAppOptions")(observer(withTranslation()(SearchSettings)));
export {Search, SearchSettingsWithTranslation as SearchSettings}