{{define "body"}}
<h2 class="form-categories-heading">Categories</h2>
{{template "flashes" .}}


{{range $category := .categories}}
            {{template "row-category" dict "category" $category "categories" $.categories}}
{{end}}

{{end}}

{{define "row-category"}}
    <div class="row">
    
    
        <div class="col-xs-2">
            {{stringTimes .category.Depth "- "}}
              
           
            {{.category.Name}}
        </div>
        <div class="col-xs-1">
            <a href="/categories/delete?id={{.category.Id}}">delete</a>
        </div>
        <div class="col-xs-3">
    <select class="form-control category-change-parent" name="category-change-parent-{{.category.Id}}" >
        <option value="-1" {{if not .category.Parent.Valid}} selected="true"{{end}}>-- None --</option>
        {{range $category := .categories}}
            {{if $.category.Parent.Valid }}
                {{template "option-category" dict "category" $category "id" $.category.Parent.Value}}
            {{else}}
                {{template "option-category" dict "category" $category "id" -1}}
            {{end}}
        {{end}}
    </select>
        </div>
    </div>

    {{range $child := .category.Children}}
        {{template "row-category" dict "category" $child "categories" $.categories}}
     {{end}}    

{{end}}

{{define "option-category"}}
    <option value="{{.category.Id}}" {{if eq .id .category.Id}}selected="true"{{end}}>{{.category.ToString}}</option>
    {{range $child := .category.Children}}
        {{template "option-category" dict "category" $child "id" $.id}}
     {{end}}            
{{end}}