{{template "org/settings/layout_head" (dict "pageClass" "organization settings")}}
<div class="org-setting-content">

	{{/* ── Section 1: Licensing ── */}}
	<h4 class="ui top attached header">
		{{svg "octicon-key" 16}} {{ctx.Locale.Tr "org.settings.licensing"}}
	</h4>
	<div class="ui attached segment">
		<form class="ui form" method="post" action="{{.OrgLink}}/settings/update-streams">
			{{.CsrfTokenHtml}}

			<p>{{ctx.Locale.Tr "org.settings.licensing_desc"}}</p>

			<div class="inline field">
				<div class="ui checkbox">
					<input name="licensing_enabled" type="checkbox" {{if .StreamConfig.LicensingEnabled}}checked{{end}}>
					<label><strong>{{ctx.Locale.Tr "org.settings.enable_licensing"}}</strong></label>
				</div>
				<p class="help">{{ctx.Locale.Tr "org.settings.enable_licensing_help"}}</p>
			</div>

			{{if and (ne .StreamConfig.Platform "joomla") (ne .StreamConfig.Platform "both") (ne .StreamConfig.Platform "")}}
			<div class="inline field">
				<div class="ui checkbox">
					<input name="require_key" type="checkbox" {{if .StreamConfig.RequireKey}}checked{{end}}>
					<label><strong>{{ctx.Locale.Tr "org.settings.require_key"}}</strong></label>
				</div>
				<p class="help">{{ctx.Locale.Tr "org.settings.require_key_help"}}</p>
			</div>
			{{end}}

			<div class="field">
				<label>{{ctx.Locale.Tr "org.settings.feed_visibility"}}</label>
				<select name="feed_visibility" class="ui dropdown">
					<option value="public" {{if or (eq .StreamConfig.FeedVisibility "") (eq .StreamConfig.FeedVisibility "public")}}selected{{end}}>{{ctx.Locale.Tr "org.settings.feed_visibility_public"}}</option>
					<option value="no-download" {{if eq .StreamConfig.FeedVisibility "no-download"}}selected{{end}}>{{ctx.Locale.Tr "org.settings.feed_visibility_no_download"}}</option>
					<option value="hidden" {{if eq .StreamConfig.FeedVisibility "hidden"}}selected{{end}}>{{ctx.Locale.Tr "org.settings.feed_visibility_hidden"}}</option>
				</select>
				<p class="help">{{ctx.Locale.Tr "org.settings.feed_visibility_help"}}</p>
			</div>

			<div class="field">
				<label>{{ctx.Locale.Tr "org.settings.key_prefix"}}</label>
				<input name="key_prefix" value="{{.StreamConfig.KeyPrefix}}" placeholder="MOKO" maxlength="20">
				<p class="help">{{ctx.Locale.Tr "org.settings.key_prefix_help"}}</p>
			</div>

			<div class="field">
				<label>{{ctx.Locale.Tr "org.settings.download_gating"}}</label>
				<select name="download_gating" class="ui dropdown">
					<option value="none" {{if or (eq .StreamConfig.DownloadGating "") (eq .StreamConfig.DownloadGating "none")}}selected{{end}}>{{ctx.Locale.Tr "org.settings.download_gating_none"}}</option>
					<option value="prerelease" {{if eq .StreamConfig.DownloadGating "prerelease"}}selected{{end}}>{{ctx.Locale.Tr "org.settings.download_gating_prerelease"}}</option>
					<option value="all" {{if eq .StreamConfig.DownloadGating "all"}}selected{{end}}>{{ctx.Locale.Tr "org.settings.download_gating_all"}}</option>
				</select>
				<p class="help">{{ctx.Locale.Tr "org.settings.download_gating_help"}}</p>
			</div>

			<div class="field">
				<label>{{ctx.Locale.Tr "org.settings.support_url"}}</label>
				<input name="support_url" value="{{.StreamConfig.SupportURL}}" placeholder="https://mokoconsulting.tech/support">
				<p class="help">{{ctx.Locale.Tr "org.settings.support_url_help"}}</p>
			</div>

			<div class="ui divider"></div>

			{{/* ── Section 2: Extension Metadata ── */}}
			<h5>{{svg "octicon-package" 14}} {{ctx.Locale.Tr "org.settings.extension_metadata"}}</h5>
			<p>{{ctx.Locale.Tr "org.settings.extension_metadata_desc"}}</p>

			<div class="field">
				<label>{{ctx.Locale.Tr "org.settings.update_platform"}}</label>
				<select name="platform" class="ui dropdown">
					<option value="joomla" {{if or (eq .StreamConfig.Platform "") (eq .StreamConfig.Platform "joomla")}}selected{{end}}>Joomla</option>
					<option value="dolibarr" {{if eq .StreamConfig.Platform "dolibarr"}}selected{{end}}>Dolibarr</option>
					<option value="wordpress" {{if eq .StreamConfig.Platform "wordpress"}}selected{{end}}>WordPress</option>
					<option value="prestashop" {{if eq .StreamConfig.Platform "prestashop"}}selected{{end}}>PrestaShop</option>
					<option value="drupal" {{if eq .StreamConfig.Platform "drupal"}}selected{{end}}>Drupal</option>
					<option value="composer" {{if eq .StreamConfig.Platform "composer"}}selected{{end}}>Composer (PHP)</option>
					<option value="both" {{if eq .StreamConfig.Platform "both"}}selected{{end}}>Joomla + Dolibarr</option>
				</select>
			</div>

			<div class="two fields">
				<div class="field">
					<label>{{ctx.Locale.Tr "org.settings.extension_name"}}</label>
					<input name="extension_name" value="{{.StreamConfig.ExtensionName}}" placeholder="pkg_mokowaas">
					<p class="help">{{ctx.Locale.Tr "org.settings.extension_name_help"}}</p>
				</div>
			</div>

			<div class="field">
				<label>{{ctx.Locale.Tr "repo.licenses.description"}}</label>
				<input name="feed_description" value="{{.StreamConfig.Description}}" placeholder="MokoWaaS stable build.">
			</div>

			<div class="two fields">
				<div class="field">
					<label>{{ctx.Locale.Tr "org.settings.extension_type"}}</label>
					<select name="extension_type" class="ui dropdown">
						<option value="package" {{if eq .StreamConfig.ExtensionType "package"}}selected{{end}}>Package</option>
						<option value="component" {{if or (eq .StreamConfig.ExtensionType "") (eq .StreamConfig.ExtensionType "component")}}selected{{end}}>Component</option>
						<option value="module" {{if eq .StreamConfig.ExtensionType "module"}}selected{{end}}>Module</option>
						<option value="plugin" {{if eq .StreamConfig.ExtensionType "plugin"}}selected{{end}}>Plugin</option>
						<option value="template" {{if eq .StreamConfig.ExtensionType "template"}}selected{{end}}>Template</option>
						<option value="library" {{if eq .StreamConfig.ExtensionType "library"}}selected{{end}}>Library</option>
					</select>
				</div>
				<div class="field">
					<label>{{ctx.Locale.Tr "org.settings.target_version"}}</label>
					<input name="target_version" value="{{.StreamConfig.TargetVersion}}" placeholder="(5|6)\..*">
					<p class="help">{{ctx.Locale.Tr "org.settings.target_version_help"}}</p>
				</div>
			</div>

			<div class="two fields">
				<div class="field">
					<label>{{ctx.Locale.Tr "org.settings.maintainer"}}</label>
					<input name="maintainer" value="{{.StreamConfig.Maintainer}}" placeholder="Moko Consulting">
				</div>
				<div class="field">
					<label>{{ctx.Locale.Tr "org.settings.maintainer_url"}}</label>
					<input name="maintainer_url" value="{{.StreamConfig.MaintainerURL}}" placeholder="https://mokoconsulting.tech">
				</div>
			</div>

			<div class="two fields">
				<div class="field">
					<label>{{ctx.Locale.Tr "org.settings.info_url"}}</label>
					<input name="info_url" value="{{.StreamConfig.InfoURL}}" placeholder="https://mokoconsulting.tech/products/mokowaas">
					<p class="help">{{ctx.Locale.Tr "org.settings.info_url_help"}}</p>
				</div>
				<div class="field">
					<label>{{ctx.Locale.Tr "org.settings.php_minimum"}}</label>
					<input name="php_minimum" value="{{.StreamConfig.PHPMinimum}}" placeholder="8.1">
				</div>
			</div>

			<div class="ui divider"></div>

			{{/* ── Section 3: Update Streams ── */}}
			<h5>{{svg "octicon-rss" 14}} {{ctx.Locale.Tr "org.settings.update_streams_heading"}}</h5>
			<p>{{ctx.Locale.Tr "org.settings.update_streams_desc"}}</p>

			<div class="grouped fields">
				<label>{{ctx.Locale.Tr "org.settings.stream_mode"}}</label>
				<div class="field">
					<div class="ui radio checkbox">
						<input name="stream_mode" type="radio" value="joomla" {{if or (eq .StreamConfig.StreamMode "") (eq .StreamConfig.StreamMode "joomla")}}checked{{end}}>
						<label>{{ctx.Locale.Tr "org.settings.stream_mode_joomla"}}</label>
					</div>
				</div>
				<div class="field">
					<div class="ui radio checkbox">
						<input name="stream_mode" type="radio" value="custom" {{if eq .StreamConfig.StreamMode "custom"}}checked{{end}}>
						<label>{{ctx.Locale.Tr "org.settings.stream_mode_custom"}}</label>
					</div>
				</div>
			</div>

			<div class="field">
				<label>{{ctx.Locale.Tr "org.settings.default_streams"}}</label>
				<table class="ui small compact table">
					<thead>
						<tr>
							<th>{{ctx.Locale.Tr "org.settings.stream_name"}}</th>
							<th>{{ctx.Locale.Tr "org.settings.stream_suffix"}}</th>
							<th>{{ctx.Locale.Tr "repo.licenses.description"}}</th>
						</tr>
					</thead>
					<tbody>
						{{range .EffectiveStreams}}
							<tr>
								<td><code>{{.Name}}</code></td>
								<td>{{if .Suffix}}<code>{{.Suffix}}</code>{{else}}<span class="text grey">{{ctx.Locale.Tr "org.settings.no_suffix"}}</span>{{end}}</td>
								<td>{{.Description}}</td>
							</tr>
						{{end}}
					</tbody>
				</table>
				<p class="help">{{ctx.Locale.Tr "org.settings.streams_tag_help"}}</p>
			</div>

			<div class="field">
				<label>{{ctx.Locale.Tr "org.settings.custom_streams"}}</label>
				<textarea name="custom_streams" rows="6" placeholder='[{"name":"lts","suffix":"-lts","description":"Long-term support"}]'>{{.StreamConfig.CustomStreams}}</textarea>
				<p class="help">{{ctx.Locale.Tr "org.settings.custom_streams_help"}}</p>
			</div>

			<div class="field">
				<button class="ui primary button">{{ctx.Locale.Tr "save"}}</button>
			</div>
		</form>
	</div>
</div>
{{template "org/settings/layout_footer" .}}
