<templates>
  <t t-name="o-spreadsheet-FindAndReplacePanel">
    <div class="o-find-and-replace" t-on-keydown="this.onKeydownPanel">
      <Section title.translate="Search">
        <div class="o-input-search-container d-flex align-items-center">
          <input
            type="text"
            t-ref="this.searchInputRef"
            class="o-input o-input-with-count o-search"
            t-on-input="this.onSearchInput"
            t-on-focus="this.onFocusSearch"
            t-on-keydown="this.onKeydownSearch"
            placeholder="e.g. 'search me'"
          />
          <div class="o-input-count" t-if="this.hasSearchResult">
            <t t-out="this.store.selectedMatchIndex+1"/>
            /
            <t t-out="this.store.searchMatches.length"/>
          </div>
          <div t-elif="!this.pendingSearch and this.store.toSearch !== ''" class="o-input-count">
            0 / 0
          </div>
          <div
            class="d-flex flex-row o-result-buttons align-items-center"
            t-if="this.hasSearchResult">
            <button
              t-on-click="() => this.store.selectPreviousMatch()"
              class="o-button ms-2 d-flex justify-content-center align-items-center">
              <t t-call="o-spreadsheet-Icon.ARROW_UP"/>
            </button>
            <button
              t-on-click="() => this.store.selectNextMatch()"
              class="o-button ms-1 d-flex justify-content-center align-items-center">
              <t t-call="o-spreadsheet-Icon.ARROW_DOWN"/>
            </button>
          </div>
        </div>
        <Select
          class="'o-type-range-selector mt-3 mb-3'"
          values="this.searchScopeOptions"
          selectedValue="this.searchOptions.searchScope"
          onChange.bind="this.changeSearchScope"
        />

        <div t-if="this.searchOptions.searchScope === 'specificRange'">
          <SelectionInput
            t-key="this.selectionInputKey"
            ranges="[this.specificRange]"
            onSelectionChanged="(ranges) => this.onSearchRangeChanged(ranges)"
            onSelectionConfirmed.bind="this.updateDataRange"
            hasSingleRange="true"
            required="true"
          />
        </div>
        <div>
          <t t-set="matchCaseLabel">Match case</t>
          <Checkbox
            value="this.searchOptions.matchCase"
            label="matchCaseLabel"
            onChange.bind="this.searchMatchCase"
            className="'mb-1'"
          />
          <t t-set="exactMatchLabel">Match entire cell content</t>
          <Checkbox
            value="this.searchOptions.exactMatch"
            label="exactMatchLabel"
            onChange.bind="this.searchExactMatch"
            className="'mb-1'"
          />
          <t t-set="searchFormulasLabel">Search in formulas</t>
          <Checkbox
            value="this.searchOptions.searchFormulas"
            label="searchFormulasLabel"
            onChange.bind="this.searchFormulas"
            className="'mb-1'"
          />
          <t t-set="includeHiddenLabel">Include hidden results</t>
          <Checkbox
            value="this.searchOptions.includeHidden"
            label="includeHiddenLabel"
            onChange.bind="this.searchIncludeHidden"
          />
        </div>
        <div class="o-matches-count mt-4" t-if="this.searchInfo.length">
          <ValidationMessages msgType="'info'">
            <t t-set-slot="info-text">
              <div class="ps-2" t-foreach="this.searchInfo" t-as="infoLine" t-key="infoLine">
                <span t-out="infoLine"/>
              </div>
            </t>
          </ValidationMessages>
        </div>
        <div
          class="o-matches-count mt-4"
          t-if="this.searchOptions.includeHidden and this.hiddenSheetsWithMatchesInfo.length">
          <ValidationMessages msgType="'info'">
            <t t-set-slot="info-text">
              <div class="ps-2">
                Matches in the following hidden sheets:
                <ul class="mb-0">
                  <li
                    t-foreach="this.hiddenSheetsWithMatchesInfo"
                    t-as="sheetName"
                    t-key="sheetName">
                    <span t-out="sheetName"/>
                  </li>
                </ul>
              </div>
            </t>
          </ValidationMessages>
        </div>
      </Section>
      <t t-if="!this.env.model.getters.isReadonly()">
        <Section class="'pt-0'" title.translate="Replace">
          <div class="o-input-search-container d-flex align-items-center">
            <input
              type="text"
              class="o-input o-input-without-count o-replace"
              t-on-keydown="this.onKeydownReplace"
              t-att-value="this.store.toReplace"
              t-on-input="this.onReplaceInput"
              placeholder="e.g. 'replace me'"
            />
          </div>
        </Section>
        <Section>
          <div class="o-sidePanelButtons">
            <button
              t-att-disabled="this.store.selectedMatchIndex === null"
              t-on-click="() => this.store.replace()"
              class="o-button o-replace">
              Replace
            </button>
            <button
              t-att-disabled="this.store.selectedMatchIndex === null"
              t-on-click="() => this.store.replaceAll()"
              class="o-button o-replace-all">
              Replace all
            </button>
          </div>
        </Section>
      </t>
    </div>
  </t>
</templates>
