{{template "base" .}}

{{define "title"}}{{.Title}}{{end}}

{{define "page_body"}}
<div class="card shadow mb-4">
    <div class="card-header py-3">
        <h6 class="m-0 font-weight-bold text-primary">{{.Title}}</h6>
    </div>
    <div class="card-body">
        {{if .Error}}
        <div class="card mb-4 border-left-warning">
            <div class="card-body text-form-error">{{.Error}}</div>
        </div>
        {{end}}
        {{if eq .Mode 3}}
        <div class="card mb-4 border-left-info">
            <div class="card-body">
                Generate a data provider independent JSON file to create new folders or update existing ones.
                <br>
                The following placeholder is supported:
                <br><br>
                <ul>
                    <li><span class="text-success">%name%</span> will be replaced with the specified folder name</li>
                </ul>
                The generated folders file can be imported from the "Maintenance" section.
            </div>
        </div>
        {{end}}
        <form id="folder_form" enctype="multipart/form-data" action="{{.CurrentURL}}" method="POST" autocomplete="off" {{if eq .Mode 3}}target="_blank"{{end}}>
            {{if eq .Mode 3}}
            <div class="form-group row">
                <label for="idFolders" class="col-sm-2 col-form-label">Folders</label>
                <div class="col-sm-10">
                    <textarea class="form-control" id="idFolders" name="folders" rows="5" required
                        aria-describedby="foldersHelpBlock"></textarea>
                    <small id="foldersHelpBlock" class="form-text text-muted">
                        Specify the folder names, one for line.
                    </small>
                </div>
            </div>
            <input type="hidden" name="name" id="idFolderName" value="{{.Folder.Name}}">
            {{else}}
            <div class="form-group row">
                <label for="idFolderName" class="col-sm-2 col-form-label">Name</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="idFolderName" name="name" placeholder=""
                        value="{{.Folder.Name}}" maxlength="255" autocomplete="nope" required {{if ge .Mode 2}}readonly{{end}}>
                </div>
            </div>
            {{end}}
            <div class="form-group row">
                <label for="idDescription" class="col-sm-2 col-form-label">Description</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="idDescription" name="description" placeholder=""
                        value="{{.Folder.Description}}" maxlength="255" aria-describedby="descriptionHelpBlock">
                    <small id="descriptionHelpBlock" class="form-text text-muted">
                        Optional description
                    </small>
                </div>
            </div>
            <div class="form-group row">
                <label for="idMappedPath" class="col-sm-2 col-form-label">Absolute Path</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="idMappedPath" name="mapped_path" placeholder=""
                        value="{{.Folder.MappedPath}}" maxlength="512" aria-describedby="mappedPathHelpBlock">
                    <small id="descriptionHelpBlock" class="form-text text-muted">
                        Required for local providers. For Cloud providers, if set, it will store temporary files
                    </small>
                </div>
            </div>

            {{template "fshtml" .Folder.FsConfig}}

            <input type="hidden" name="_form_token" value="{{.CSRFToken}}">
            <button type="submit" class="btn btn-primary float-right mt-3 px-5 px-3">{{if eq .Mode 3}}Generate and export folders{{else}}Submit{{end}}</button>
        </form>
    </div>
</div>
{{end}}

{{define "extra_js"}}
<script type="text/javascript">
    $(document).ready(function () {
        onFilesystemChanged('{{.Folder.FsConfig.Provider}}');
    });

    {{template "fsjs"}}
</script>
{{end}}