{{$queryLink := QueryBuild "?" "q" $.Keyword "type" $.ViewType "sort" $.SortType "state" $.State "labels" $.SelectLabels "milestone" $.MilestoneID "project" $.ProjectID "assignee" $.AssigneeID "poster" $.PosterUsername "archived_labels" (Iif $.ShowArchivedLabels "true")}}

{{template "repo/issue/filter_item_label" dict "Labels" .Labels "QueryLink" $queryLink "SupportArchivedLabel" true}}

{{if not .Milestone}}
{{template "repo/issue/filter_item_milestone" dict
	"QueryLink" $queryLink
	"MilestoneID" $.MilestoneID
	"OpenMilestones" .OpenMilestones
	"ClosedMilestones" .ClosedMilestones
}}
{{end}}

<!-- Project -->
<div class="item ui dropdown jump {{if not (or .OpenProjects .ClosedProjects)}}disabled{{end}}">
	<span class="text">
		{{ctx.Locale.Tr "repo.issues.filter_project"}}
	</span>
	{{svg "octicon-triangle-down" 14 "dropdown icon"}}
	<div class="menu">
		<div class="ui icon search input">
			<i class="icon">{{svg "octicon-search" 16}}</i>
			<input type="text" placeholder="{{ctx.Locale.Tr "repo.issues.filter_project"}}">
		</div>
		<a class="{{if not .ProjectID}}active selected {{end}}item" href="{{QueryBuild $queryLink "project" NIL}}">{{ctx.Locale.Tr "repo.issues.filter_project_all"}}</a>
		<a class="{{if eq .ProjectID -1}}active selected {{end}}item" href="{{QueryBuild $queryLink "project" -1}}">{{ctx.Locale.Tr "repo.issues.filter_project_none"}}</a>
		{{if .OpenProjects}}
			<div class="divider"></div>
			<div class="header">
				{{ctx.Locale.Tr "repo.issues.new.open_projects"}}
			</div>
			{{range .OpenProjects}}
				<a class="{{if $.ProjectID}}{{if eq $.ProjectID .ID}}active selected{{end}}{{end}} item tw-flex" href="{{QueryBuild $queryLink "project" .ID}}">
					{{svg .IconName 18 "tw-mr-2 tw-shrink-0"}}<span class="gt-ellipsis">{{.Title}}</span>
				</a>
			{{end}}
		{{end}}
		{{if .ClosedProjects}}
			<div class="divider"></div>
			<div class="header">
				{{ctx.Locale.Tr "repo.issues.new.closed_projects"}}
			</div>
			{{range .ClosedProjects}}
				<a class="{{if $.ProjectID}}{{if eq $.ProjectID .ID}}active selected{{end}}{{end}} item" href="{{QueryBuild $queryLink "project" .ID}}">
					{{svg .IconName 18 "tw-mr-2"}}{{.Title}}
				</a>
			{{end}}
		{{end}}
	</div>
</div>

{{/* TODO: the UserSearchUrl is old logic but not right, milestone could also have "pull request" posters */}}
{{template "repo/issue/filter_item_user_fetch" dict
	"QueryParamKey" "poster"
	"QueryLink" $queryLink
	"UserSearchUrl" (Iif .Milestone (print $.RepoLink "/issues/posters") (print $.Link "/posters"))
	"SelectedUsername" $.PosterUsername
	"TextFilterTitle" (ctx.Locale.Tr "repo.issues.filter_poster")
}}

{{template "repo/issue/filter_item_user_assign" dict
	"QueryParamKey" "assignee"
	"QueryLink" $queryLink
	"UserSearchList" $.Assignees
	"SelectedUserId" $.AssigneeID
	"TextFilterTitle" (ctx.Locale.Tr "repo.issues.filter_assignee")
	"TextFilterMatchNone" (ctx.Locale.Tr "repo.issues.filter_assignee_no_assignee")
	"TextFilterMatchAny" (ctx.Locale.Tr "repo.issues.filter_assignee_any_assignee")
}}

{{if .IsSigned}}
	<!-- Type -->
	<div class="item ui dropdown jump">
		<span class="text">
			{{ctx.Locale.Tr "repo.issues.filter_type"}}
		</span>
		{{svg "octicon-triangle-down" 14 "dropdown icon"}}
		<div class="menu">
			<a class="{{if eq .ViewType "all"}}active {{end}}item" href="{{QueryBuild $queryLink "type" "all"}}">{{if .PageIsPullList}}{{ctx.Locale.Tr "repo.issues.filter_type.all_pull_requests"}}{{else}}{{ctx.Locale.Tr "repo.issues.filter_type.all_issues"}}{{end}}</a>
			<a class="{{if eq .ViewType "assigned"}}active {{end}}item" href="{{QueryBuild $queryLink "type" "assigned"}}">{{ctx.Locale.Tr "repo.issues.filter_type.assigned_to_you"}}</a>
			<a class="{{if eq .ViewType "created_by"}}active {{end}}item" href="{{QueryBuild $queryLink "type" "created_by"}}">{{ctx.Locale.Tr "repo.issues.filter_type.created_by_you"}}</a>
			{{if .PageIsPullList}}
				<a class="{{if eq .ViewType "review_requested"}}active {{end}}item" href="{{QueryBuild $queryLink "type" "review_requested"}}">{{ctx.Locale.Tr "repo.issues.filter_type.review_requested"}}</a>
				<a class="{{if eq .ViewType "reviewed_by"}}active {{end}}item" href="{{QueryBuild $queryLink "type" "reviewed_by"}}">{{ctx.Locale.Tr "repo.issues.filter_type.reviewed_by_you"}}</a>
			{{end}}
			<a class="{{if eq .ViewType "mentioned"}}active {{end}}item" href="{{QueryBuild $queryLink "type" "mentioned"}}">{{ctx.Locale.Tr "repo.issues.filter_type.mentioning_you"}}</a>
		</div>
	</div>
{{end}}

<!-- Sort -->
<div class="item ui dropdown jump">
	<span class="text">
		{{ctx.Locale.Tr "repo.issues.filter_sort"}}
	</span>
	{{svg "octicon-triangle-down" 14 "dropdown icon"}}
	<div class="menu">
		<a class="{{if or (eq .SortType "latest") (not .SortType)}}active {{end}}item" href="{{QueryBuild $queryLink "sort" "latest"}}">{{ctx.Locale.Tr "repo.issues.filter_sort.latest"}}</a>
		<a class="{{if eq .SortType "oldest"}}active {{end}}item" href="{{QueryBuild $queryLink "sort" "oldest"}}">{{ctx.Locale.Tr "repo.issues.filter_sort.oldest"}}</a>
		<a class="{{if eq .SortType "recentupdate"}}active {{end}}item" href="{{QueryBuild $queryLink "sort" "recentupdate"}}">{{ctx.Locale.Tr "repo.issues.filter_sort.recentupdate"}}</a>
		<a class="{{if eq .SortType "leastupdate"}}active {{end}}item" href="{{QueryBuild $queryLink "sort" "leastupdate"}}">{{ctx.Locale.Tr "repo.issues.filter_sort.leastupdate"}}</a>
		<a class="{{if eq .SortType "mostcomment"}}active {{end}}item" href="{{QueryBuild $queryLink "sort" "mostcomment"}}">{{ctx.Locale.Tr "repo.issues.filter_sort.mostcomment"}}</a>
		<a class="{{if eq .SortType "leastcomment"}}active {{end}}item" href="{{QueryBuild $queryLink "sort" "leastcomment"}}">{{ctx.Locale.Tr "repo.issues.filter_sort.leastcomment"}}</a>
		<a class="{{if eq .SortType "nearduedate"}}active {{end}}item" href="{{QueryBuild $queryLink "sort" "nearduedate"}}">{{ctx.Locale.Tr "repo.issues.filter_sort.nearduedate"}}</a>
		<a class="{{if eq .SortType "farduedate"}}active {{end}}item" href="{{QueryBuild $queryLink "sort" "farduedate"}}">{{ctx.Locale.Tr "repo.issues.filter_sort.farduedate"}}</a>
		{{if .ExclusiveLabelScopes}}
			<div class="divider"></div>
			<div class="header">{{ctx.Locale.Tr "repo.issues.filter_label"}}</div>
			{{range $scope := .ExclusiveLabelScopes}}
				{{$sortType := (printf "scope-%s" $scope)}}
				<a class="{{if eq $.SortType $sortType}}active {{end}}item" href="{{QueryBuild $queryLink "sort" $sortType}}">{{$scope}}</a>
			{{end}}
		{{end}}
	</div>
</div>
