@php
$pciAuthWizardStep = (int) ($pciAuthWizardStep ?? 1);
$pciAuthStepTitle = $pciAuthStepTitle ?? '3. Authorities responsible';
$pciAuthNavKey = $pciAuthNavKey ?? 'authorities';
$pciAuthCollapseId = $pciAuthCollapseId ?? 'pci-sect-auth-body';
$pciAuthToggleId = $pciAuthToggleId ?? 'pci-sect-auth-toggle';
$pciAuthHideFederalMinistry = (bool) ($pciAuthHideFederalMinistry ?? false);
$pciAuthSponsoringLabel = (string) ($pciAuthSponsoringLabel ?? 'Sponsoring Agency');
$pciAuthHideFinancialPlan = (bool) ($pciAuthHideFinancialPlan ?? false);
$pciAuthSingleRowOnly = (bool) ($pciAuthSingleRowOnly ?? false);
$pciAuthHasSavedRow = (bool) ($pciAuthHasSavedRow ?? false);
$authShowSponsoring = canField('pc-forms', 'sponsoring_agency', 'view');
$authShowExecuting = canField('pc-forms', 'executing_agency', 'view');
$authShowOpm = canField('pc-forms', 'operation_maintenance_agency', 'view');
$authShowFederal = ! $pciAuthHideFederalMinistry && (
canField('pc-forms', 'concerned_federal_ministry', 'view')
|| $authShowSponsoring
|| $authShowExecuting
|| $authShowOpm
);
$authAnyView = $authShowSponsoring || $authShowExecuting || $authShowOpm || $authShowFederal
|| canField('pc-forms', 'project_financial_plan', 'view');
$authEditSponsoring = canField('pc-forms', 'sponsoring_agency', 'edit');
$authEditExecuting = canField('pc-forms', 'executing_agency', 'edit');
$authEditOpm = canField('pc-forms', 'operation_maintenance_agency', 'edit');
$authEditFederal = ! $pciAuthHideFederalMinistry && canField('pc-forms', 'concerned_federal_ministry', 'edit');
$authAnyEdit = $authEditSponsoring || $authEditExecuting || $authEditOpm || $authEditFederal;
$authFieldKeys = $pciAuthHideFederalMinistry
? ['sponsoring_agency', 'executing_agency', 'operation_maintenance_agency']
: ['sponsoring_agency', 'executing_agency', 'operation_maintenance_agency', 'concerned_federal_ministry'];
@endphp
@if($authAnyView)
@php
$authRows = old('authorities_rows');
if ($authRows === null || ! is_array($authRows) || $authRows === []) {
$authRows = [[
'sponsoring_agency' => old('sponsoring_agency', $pcForm?->sponsoring_agency ?? ($pciCrudDraftFill['sponsoring_agency'] ?? '')),
'executing_agency' => old('executing_agency', $pcForm?->executing_agency ?? ($pciCrudDraftFill['executing_agency'] ?? '')),
'operation_maintenance_agency' => old('operation_maintenance_agency', $pcForm?->operation_maintenance_agency ?? ($pciCrudDraftFill['operation_maintenance_agency'] ?? '')),
'concerned_federal_ministry' => old('concerned_federal_ministry', $pcForm?->concerned_federal_ministry ?? ($pciCrudDraftFill['concerned_federal_ministry'] ?? '')),
]];
}
if (empty($authRows)) {
$authRows = [[
'sponsoring_agency' => '',
'executing_agency' => '',
'operation_maintenance_agency' => '',
'concerned_federal_ministry' => '',
]];
}
foreach ($authRows as &$pciAuthRow) {
foreach ($authFieldKeys as $pciAuthKey) {
if (! isset($pciAuthRow[$pciAuthKey])) {
continue;
}
$pciAuthRow[$pciAuthKey] = is_string($pciAuthRow[$pciAuthKey]) ? trim($pciAuthRow[$pciAuthKey]) : $pciAuthRow[$pciAuthKey];
$pciV = (string) ($pciAuthRow[$pciAuthKey] ?? '');
if ($pciV !== '' && ! array_key_exists($pciV, $agencyOptions)) {
$agencyOptions = [$pciV => $pciV] + $agencyOptions;
}
}
}
unset($pciAuthRow);
@endphp
@foreach($authRows as $idx => $row)
@if($authShowSponsoring)
@if(!$authEditSponsoring)@endif
@endif
@if($authShowExecuting)
@if(!$authEditExecuting)@endif
@endif
@if($authShowOpm)
@if(!$authEditOpm)@endif
@endif
@if($authShowFederal)
@if(!$authEditFederal)@endif
@endif
@if($authAnyEdit && ! $pciAuthSingleRowOnly)@endif
@endforeach
@if($authAnyEdit && ! $pciAuthSingleRowOnly)
@endif
@unless($pciAuthHideFinancialPlan)
@include('pc-forms.partials.pci-project-financial-plan-subsection', [
'pcForm' => $pcForm,
'pciCrudDraftFill' => $pciCrudDraftFill ?? [],
])
@endunless
@endif