{{!
    This file is part of Moodle - http://moodle.org/

    Moodle is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Moodle is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
}}
{{!
    @template mod_forum/big_search_form

    Big search form.

    Example context (json):
    {
        "actionurl": "https://example.com/mod/forum/search.php",
        "courseid": "2",
        "words": "apples",
        "phrase": "Lorem ipsum dolor",
        "notwords": "Not these words",
        "showfullwords": [
            {
                "fullwords": "Exactly"
            }
        ],
        "datefromchecked": 1,
        "datetochecked": "",
        "forumoptions": [
            {
                "name": "Forum One",
                "value": "23"
            },
            {
                "name": "Forum Two",
                "value": "34"
            }
        ],
        "subject": "Help me please",
        "user": "Helpy McUser"
    }
}}

<div class="mb-4">
    {{#str}}searchforumintro, forum{{/str}}
</div>

    <form id="searchform" action="{{actionurl}}" method="get">
        <div class="rui-searchbox" id="form">
            <div class="mb-4">
                <label for="words">{{#str}}searchwords, forum{{/str}}</label>
                <input type="hidden" value="{{courseid}}" name="id">
                <input type="text" class="form-control" name="words" id="words" value="{{words}}">
            </div>
            <div class="mb-4">
                <label for="phrase">{{#str}}searchphrase, forum{{/str}}</label>
                <input type="text" class="form-control" name="phrase" id="phrase" value="{{phrase}}">
            </div>
            <div class="mb-4">
                <label for="notwords">{{#str}}searchnotwords, forum{{/str}}</label>
                <input type="text" class="form-control" name="notwords" id="notwords" value="{{notwords}}">
            </div>
            {{#showfullwords}}
                <div class="mb-4">
                    <label for="fullwords">{{#str}}searchfullwords, forum{{/str}}</label>
                    <input type="text" class="form-control" name="fullwords" id="fullwords" value="{{fullwords}}">
                </div>
            {{/showfullwords}}
            <div class="alert alert-light mb-1 d-inline-flex align-items-center w-100">
                    <div class="custom-control custom-switch">
                        <input type="checkbox" class="custom-control-input" id="timefromrestrict" name="timefromrestrict" value="1" {{#datefromchecked}}checked{{/datefromchecked}}>
                        <label class="custom-control-label" for="timefromrestrict">
                            {{#str}}searchdatefrom, forum{{/str}}
                        </label>
                    </div>
                    {{{datefromfields}}}
                    <input type="hidden" name="hfromday" value="0">
                    <input type="hidden" name="hfrommonth" value="0">
                    <input type="hidden" name="hfromyear" value="0">
                    <input type="hidden" name="hfromhour" value="0">
                    <input type="hidden" name="hfromminute" value="0">
            </div>
            <div class="alert alert-light mb-1 d-inline-flex align-items-center w-100">
                    <div class="d-inline-flex align-items-center">
                        <div class="custom-control custom-switch">
                            <input type="checkbox" class="custom-control-input" name="timetorestrict" value="1" {{#datetochecked}}checked{{/datetochecked}}>
                            <label class="custom-control-label" for="timetorestrict">
                                {{#str}}searchdateto, forum{{/str}}
                            </label>
                        </div>
                        {{{datetofields}}}
                        <input type="hidden" name="htoday" value="0">
                        <input type="hidden" name="htomonth" value="0">
                        <input type="hidden" name="htoyear" value="0">
                        <input type="hidden" name="htohour" value="0">
                        <input type="hidden" name="htominute" value="0">
                    </div>
            </div>
            <div class="mb-4 alert alert-light">
                    <label for="menuforumid">{{#str}}searchwhichforums, forum{{/str}}</label>
                    <select name="forumid" id="menuforumid" class="ml-3 custom-select w-100">
                        {{#forumoptions}}
                            <option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
                        {{/forumoptions}}
                    </select>
            </div>
            <div class="mb-4">
                    <label for="subject">{{#str}}searchsubject, forum{{/str}}</label>
                    <input type="text" class="form-control" name="subject" id="subject" value="{{subject}}">
            </div>
            <div class="mb-4">
                <label for="user">
                     <svg class="mr-1" width="24" height="24" fill="none" viewBox="0 0 24 24">
                        <circle cx="12" cy="8" r="3.25" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></circle>
                        <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12.25 19.25H6.94953C5.77004 19.25 4.88989 18.2103 5.49085 17.1954C6.36247 15.7234 8.23935 14 12.25 14"></path>
                        <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M14.75 17.75L16 19.25L19.25 14.75"></path>
                    </svg>
                    {{#str}}searchuser, forum{{/str}}
                </label>
                <input type="text" class="form-control" name="user" id="user" value="{{user}}">
            </div>
            {{^guestuser}}
            <div class="mb-4 alert alert-light">
                    <div class="custom-control custom-switch">
                        <input type="checkbox" class="custom-control-input" name="starredonly" id="starredonly" value="1" {{#starredonly}}checked{{/starredonly}}>
                        <label class="custom-control-label" for="starredonly">
                            {{#str}}starredonly, forum{{/str}}
                        </label>
                    </div>
            </div>
            {{/guestuser}}
            {{#tagsenabled}}
                <div class="mb-4">
                        <label class="mr-3" for="tags">
                            <svg width="24" height="24" fill="none" viewBox="0 0 24 24">
                                <circle cx="15" cy="9" r="1" fill="currentColor"></circle>
                                <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 4.75H19.25V12L12.5535 18.6708C11.7544 19.4668 10.4556 19.445 9.68369 18.6226L5.28993 13.941C4.54041 13.1424 4.57265 11.8895 5.36226 11.1305L12 4.75Z"></path>
                            </svg>
                            {{#str}}searchtags, forum{{/str}}
                        </label>
                        <select class="custom-select" name="tags[]"
                                id="tags" multiple>
                            {{#tagoptions}}
                                <option value="{{value}}" {{#selected}}selected{{/selected}}>{{{text}}}</option>
                            {{/tagoptions}}
                        </select>
                </div>
            {{/tagsenabled}}
            <div>
                <button type="submit" class="btn btn-primary">{{#str}}searchforums, forum{{/str}}</button>
            </div>
        </div>
    </form>

{{#js}}
require(['jquery'], function($) {
    var toggleDateFields = function(prefix, disabled) {
        $('#searchform select[name^=' + prefix + ']').prop('disabled', disabled);
        $('#searchform input[name^=h' + prefix + ']').val(disabled ? 1 : 0);
    };

    toggleDateFields('from', !$("#searchform input[name='timefromrestrict']").prop('checked'));
    $("#searchform input[name='timefromrestrict']").click(function() {
        toggleDateFields('from', !this.checked);
    });

    toggleDateFields('to', !$("#searchform input[name='timetorestrict']").prop('checked'));
    $("#searchform input[name='timetorestrict']").click(function() {
        toggleDateFields('to', !this.checked);
    });
});
{{/js}}
