<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="search">
            <group id="engine">
                <label>Search engine configuration</label>

                <field id="host" translate="label comment tooltip" type="text" sortOrder="20" showInDefault="1">
                    <label>Sphinx server hostname</label>
                    <comment><![CDATA[Specify the server where Sphinx is installed.]]></comment>
                    <tooltip><![CDATA[To use the default value, set it to <b>localhost</b>]]></tooltip>
                    <config_path>search/engine/host</config_path>
                    <depends>
                        <field id="engine">sphinx</field>
                    </depends>
                </field>

                <field id="port" translate="label comment tooltip" type="text" sortOrder="30" showInDefault="1">
                    <label>Sphinx server port </label>
                    <comment><![CDATA[Define the port used to connect to the Sphinx search service.]]></comment>
                    <tooltip><![CDATA[To use the default value, set it to <b>9315</b>]]></tooltip>
                    <config_path>search/engine/port</config_path>
                    <depends>
                        <field id="engine">sphinx</field>
                    </depends>
                </field>

                <field id="same_server" translate="label comment" type="select" sortOrder="35" showInDefault="1">
                    <label>Sphinx installed on the same server</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <config_path>search/engine/same_server</config_path>
                    <depends>
                        <field id="engine">sphinx</field>
                    </depends>
                </field>

                <field id="bin_path" translate="label comment tooltip" type="text" sortOrder="40" showInDefault="1">
                    <label>Sphinx daemon path</label>
                    <comment><![CDATA[Path to the Sphinx search daemon binary.]]></comment>
                    <tooltip><![CDATA[To use the default value, set it to <b>searchd</b>]]></tooltip>
                    <config_path>search/engine/bin_path</config_path>
                    <depends>
                        <field id="engine">sphinx</field>
                        <field id="same_server">1</field>
                    </depends>
                </field>

                <field id="auto_restart" translate="label comment" type="select" sortOrder="45" showInDefault="1">
                    <label>Enable automatic Sphinx startup</label>
                    <comment><![CDATA[Automatically starts the Sphinx search engine after a server restart or unexpected stop.]]></comment>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <config_path>search/engine/auto_restart</config_path>
                    <depends>
                        <field id="engine">sphinx</field>
                        <field id="same_server">1</field>
                    </depends>
                </field>

                <field id="status" translate="label comment" type="text" sortOrder="70" showInDefault="1">
                    <button_label>Check the search engine status</button_label>
                    <comment><![CDATA[Verify the current status of the configured search engine to ensure it is running and accessible.]]></comment>
                    <frontend_model>Mirasvit\SearchSphinx\Block\Adminhtml\Config\Form\Field\Command\Status</frontend_model>
                    <config_path>search/engine/status</config_path>
                    <depends>
                        <field id="engine">sphinx</field>
                        <field id="same_server">1</field>
                    </depends>
                </field>

                <group id="management" translate="label comment" type="text" sortOrder="75" showInDefault="1">
                    <label>Sphinx service management</label>
                    <fieldset_css>mst_config_expanded</fieldset_css>
                    <comment><![CDATA[Control the Sphinx search service with these options. Restart the daemon to apply changes or stop the service to reset it when needed.]]></comment>
                    <depends>
                        <field id="engine">sphinx</field>
                        <field id="same_server">1</field>
                    </depends>

                    <field id="restart" translate="label comment" type="text" sortOrder="80" showInDefault="1">
                        <button_label>Restart Sphinx service</button_label>
                        <comment><![CDATA[Restarting the search daemon, applying configuration changes and ensuring smooth search functionality.]]></comment>
                        <frontend_model>Mirasvit\SearchSphinx\Block\Adminhtml\Config\Form\Field\Command\Restart</frontend_model>
                        <config_path>search/engine/restart</config_path>
                        <depends>
                            <field id="engine">sphinx</field>
                            <field id="same_server">1</field>
                        </depends>
                    </field>

                    <field id="clear" translate="label comment" type="text" sortOrder="85" showInDefault="1">
                        <button_label>Reset</button_label>
                        <comment><![CDATA[Resetting the Sphinx service stops the search daemon for troubleshooting or maintenance. Search functionality is unavailable until the service is restarted.]]></comment>
                        <frontend_model>Mirasvit\SearchSphinx\Block\Adminhtml\Config\Form\Field\Command\Reset</frontend_model>
                        <config_path>search/engine/clear</config_path>
                        <depends>
                            <field id="engine">sphinx</field>
                            <field id="same_server">1</field>
                        </depends>
                    </field>
                </group>

                <field id="config" translate="label comment" type="text" sortOrder="85" showInDefault="1">
                    <button_label>Generate Sphinx configuration</button_label>
                    <comment><![CDATA[Create a new configuration file for Sphinx search based on your current settings. The generated file should be copied to the server where Sphinx is located (the same path to the file is required).]]></comment>
                    <frontend_model>Mirasvit\SearchSphinx\Block\Adminhtml\Config\Form\Field\Command\Config</frontend_model>
                    <config_path>search/engine/config</config_path>
                    <depends>
                        <field id="engine">sphinx</field>
                        <field id="same_server">0</field>
                    </depends>
                </field>

                <group id="extended" translate="label comment" type="text" sortOrder="100" showInDefault="1" showInWebsite="0"
                       showInStore="0">
                    <label>Sphinx customizations</label>
                    <fieldset_css>mst_config_expanded</fieldset_css>
                    <comment><![CDATA[Optimize engine for better performance and behavior.]]></comment>

                    <depends>
                        <field id="engine">sphinx</field>
                    </depends>

                    <field id="custom_base_path" translate="label comment tooltip" type="text" sortOrder="40" showInDefault="1">
                        <label>Sphinx base path</label>
                        <comment><![CDATA[Set a custom storage path for Sphinx search data.]]></comment>
                        <tooltip><![CDATA[To use the default value, set it to <b>[magento_root_directory]/var/sphinx/</b>]]></tooltip>
                    </field>

                    <field id="custom_searchd" translate="label comment tooltip" type="textarea" sortOrder="41" showInDefault="1">
                        <label>Search daemon settings</label>
                        <comment><![CDATA[Define <a href="https://sphinxsearch.com/docs/current.html#confgroup-searchd" target="_blank">extra settings</a> for the Sphinx search daemon.]]></comment>
                        <tooltip><![CDATA[For example, to log only queries with execution times that exceed 500 ms, set <b>query_log_min_msec = 500</b>]]></tooltip>
                    </field>

                    <field id="custom_index" translate="label comment tooltip" type="textarea" sortOrder="41" showInDefault="1">
                        <label>Index settings</label>
                        <comment><![CDATA[<a href="https://sphinxsearch.com/docs/current.html#confgroup-index" target="_blank">Modify index parameters</a> for fine-tuning search behavior.]]></comment>
                        <tooltip><![CDATA[For example, to set 4 as the minimum word length at which to enable stemming, set <b>min_stemming_len = 4</b>]]></tooltip>
                    </field>

                    <field id="custom_charset_table" translate="label comment tooltip" type="textarea" sortOrder="42" showInDefault="1">
                        <label>Charset mapping table</label>
                        <comment><![CDATA[<a href="https://sphinxsearch.com/docs/current.html#conf-charset-table" target="_blank">Define custom character</a> mappings for search indexing.]]></comment>
                        <tooltip><![CDATA[For example, to ignore the soft hyphen symbol `-`, set <b>ignore_chars = U+AD</b>]]></tooltip>
                    </field>
                </group>
            </group>
        </section>

        <section id="searchautocomplete">
            <group id="general">
                <field id="fast_mode" translate="label comment tooltip" type="select" sortOrder="25" showInDefault="1">
                    <label>Enable fast mode</label>
                    <comment><![CDATA[Speeds up autocomplete search. <i>Note:</i> This option increases the indexing time of the search index and is not available for the MySQL search engine.]]></comment>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                    <config_path>searchautocomplete/general/fast_mode</config_path>
                </field>
            </group>
        </section>
    </system>
</config>