{{template "repo/settings/layout_head" (dict "ctxData" . "pageClass" "repository settings metadata")}}
<h4 class="ui top attached header">
	{{svg "octicon-file-code" 16}} Project Identity
</h4>
<div class="ui attached segment">
	<form class="ui form" method="post" action="{{.RepoLink}}/settings/metadata?action=manifest">
		{{.CsrfTokenHtml}}

		<div class="two fields">
			<div class="field">
				{{if eq .Manifest.Platform "joomla"}}
					<label>Element Name</label>
					<input name="name" value="{{.Manifest.Name}}" placeholder="e.g. mokowaas">
				{{else}}
					<label>Project Name</label>
					<input name="name" value="{{.Manifest.Name}}" placeholder="Project name">
				{{end}}
			</div>
			<div class="field">
				<label>Organization</label>
				<input name="org" value="{{.Manifest.Org}}" placeholder="Organization">
			</div>
		</div>
		<div class="four fields">
			<div class="field">
				<label>Version</label>
				<input name="version" value="{{.Manifest.Version}}" placeholder="e.g. 06.00.00">
			</div>
			<div class="field">
				<label>Version Prefix</label>
				<input name="version_prefix" value="{{.Manifest.VersionPrefix}}" placeholder="e.g. v1.26.1-moko.">
			</div>
			<div class="field">
				<label>License</label>
				<select name="license_spdx" class="ui dropdown">
					<option value="">—</option>
					{{$lic := .Manifest.LicenseSPDX}}
					<option value="GPL-3.0-or-later" {{if eq $lic "GPL-3.0-or-later"}}selected{{end}}>GPL-3.0-or-later</option>
					<option value="GPL-2.0-or-later" {{if eq $lic "GPL-2.0-or-later"}}selected{{end}}>GPL-2.0-or-later</option>
					<option value="MIT" {{if eq $lic "MIT"}}selected{{end}}>MIT</option>
					<option value="Apache-2.0" {{if eq $lic "Apache-2.0"}}selected{{end}}>Apache-2.0</option>
					<option value="BSD-3-Clause" {{if eq $lic "BSD-3-Clause"}}selected{{end}}>BSD-3-Clause</option>
					<option value="BSD-2-Clause" {{if eq $lic "BSD-2-Clause"}}selected{{end}}>BSD-2-Clause</option>
					<option value="LGPL-3.0-or-later" {{if eq $lic "LGPL-3.0-or-later"}}selected{{end}}>LGPL-3.0-or-later</option>
					<option value="MPL-2.0" {{if eq $lic "MPL-2.0"}}selected{{end}}>MPL-2.0</option>
					<option value="ISC" {{if eq $lic "ISC"}}selected{{end}}>ISC</option>
					<option value="AGPL-3.0-or-later" {{if eq $lic "AGPL-3.0-or-later"}}selected{{end}}>AGPL-3.0-or-later</option>
					<option value="Unlicense" {{if eq $lic "Unlicense"}}selected{{end}}>Unlicense</option>
					<option value="proprietary" {{if eq $lic "proprietary"}}selected{{end}}>Proprietary</option>
				</select>
			</div>
		</div>

		<h5 class="ui dividing header">Governance</h5>
		<div class="two fields">
			<div class="field">
				<label>Platform</label>
				<select name="platform" class="ui dropdown">
					<option value="">—</option>
					{{$platform := .Manifest.Platform}}
					{{range $val := StringUtils.Split "joomla,wordpress,dolibarr,go,mcp,platform,generic" ","}}
						<option value="{{$val}}" {{if eq $val $platform}}selected{{end}}>{{$val}}</option>
					{{end}}
				</select>
			</div>
			<div class="field">
				<label>Info URL</label>
				<input name="info_url" value="{{.Manifest.InfoURL}}" placeholder="https://mokoconsulting.tech/product/...">
			</div>
		</div>

		{{if or (eq .Manifest.Platform "joomla") (eq .Manifest.Platform "wordpress")}}
		<div class="two fields">
			<div class="field">
				<label>Target Platform Version</label>
				<input name="target_version" value="{{.Manifest.TargetVersion}}" placeholder="e.g. (5|6)\..*">
			</div>
			<div class="field">
				<label>PHP Minimum</label>
				<input name="php_minimum" value="{{.Manifest.PHPMinimum}}" placeholder="e.g. 8.1">
			</div>
		</div>
		{{end}}

		{{if eq .Manifest.Platform "joomla"}}
		<h5 class="ui dividing header">Build</h5>
		<div class="two fields">
			<div class="field">
				<label>Extension Type</label>
				<select name="extension_type" class="ui dropdown">
					<option value="">—</option>
					{{$pkgType := .Manifest.ExtensionType}}
					{{range $val := StringUtils.Split "component,module,plugin,package,template,library,file" ","}}
						<option value="{{$val}}" {{if eq $val $pkgType}}selected{{end}}>{{$val}}</option>
					{{end}}
				</select>
			</div>
			<div class="field">
				<label>Entry Point</label>
				<input name="entry_point" value="{{.Manifest.EntryPoint}}" placeholder="e.g. ./ or src/index.ts">
			</div>
		</div>
		{{end}}

		<button class="ui primary button" type="submit">Save Project Identity</button>
	</form>
</div>

{{if .CustomFieldDefs}}
<h4 class="ui top attached header">
	{{svg "octicon-list-unordered" 16}} Custom Fields
</h4>
<div class="ui attached segment">
	<form class="ui form" method="post" action="{{.RepoLink}}/settings/metadata?action=customfields">
		{{.CsrfTokenHtml}}
		{{$values := .CustomFieldValues}}
		{{$options := .CustomFieldOptions}}
		{{range .CustomFieldDefs}}
			{{$currentVal := index $values .ID}}
			<div class="field">
				<label>{{.Name}}{{if .Required}} <span class="tw-text-red">*</span>{{end}}{{if .Description}} <small class="text grey">({{.Description}})</small>{{end}}</label>
				{{if .Options}}
					{{$opts := index $options .ID}}
					<select name="field_{{.ID}}" class="ui dropdown" {{if .Required}}required{{end}}>
						<option value="">—</option>
						{{range $opts}}
							<option value="{{.}}" {{if eq . $currentVal}}selected{{end}}>{{.}}</option>
						{{end}}
					</select>
				{{else if eq (printf "%s" .FieldType) "checkbox"}}
					<div class="ui checkbox">
						<input type="checkbox" name="field_{{.ID}}" value="true" {{if eq $currentVal "true"}}checked{{end}}>
						<label></label>
					</div>
				{{else if eq (printf "%s" .FieldType) "number"}}
					<input type="number" name="field_{{.ID}}" value="{{$currentVal}}" {{if .Required}}required{{end}}>
				{{else if eq (printf "%s" .FieldType) "url"}}
					<input type="url" name="field_{{.ID}}" value="{{$currentVal}}" placeholder="https://..." {{if .Required}}required{{end}}>
				{{else if eq (printf "%s" .FieldType) "date"}}
					<input type="date" name="field_{{.ID}}" value="{{$currentVal}}" {{if .Required}}required{{end}}>
				{{else}}
					<input type="text" name="field_{{.ID}}" value="{{$currentVal}}" {{if .Required}}required{{end}}>
				{{end}}
			</div>
		{{end}}
		<div class="field tw-mt-4">
			<button class="ui primary button" type="submit">Save Custom Fields</button>
		</div>
	</form>
</div>
{{end}}

{{template "repo/settings/layout_footer" .}}
