<?php

/**
 * Single-theme tenant-logo slot. Uses the standard app-file-upload.phtml
 * partial for the drop-zone UI (upload + current preview + replace + delete),
 * wired to a pair of barrier forms via the HTML5 form attribute.
 *
 * Required view vars:
 *   $tenantUuid, $logoTheme ('light'|'dark'), $hasLogo (bool),
 *   $fieldLabel, $uploadFormId, $deleteFormId, $canUpdate (bool)
 */

$tenantUuid = (string) ($tenantUuid ?? '');
$logoTheme = (string) ($logoTheme ?? 'light');
$hasLogo = (bool) ($hasLogo ?? false);
$fieldLabel = (string) ($fieldLabel ?? '');
$uploadFormId = (string) ($uploadFormId ?? '');
$deleteFormId = (string) ($deleteFormId ?? '');
$canUpdate = (bool) ($canUpdate ?? false);
$previewUrl = $hasLogo
    ? 'admin/tenants/logo-file?uuid=' . rawurlencode($tenantUuid) . '&theme=' . rawurlencode($logoTheme) . '&size=256'
    : '';
?>
<div class="tenant-logo-slot">
    <label><?php e($fieldLabel); ?></label>
    <?php if ($canUpdate && $uploadFormId !== ''): ?>
        <?php
        $fileUpload = [
            'name' => 'logo',
            'accept' => 'image/svg+xml,image/png,image/jpeg,image/webp',
            'hint' => t('Allowed file types: SVG, PNG, JPG, WEBP'),
            'currentSrc' => $previewUrl,
            'currentLabel' => $fieldLabel,
            'formId' => $uploadFormId,
            'deleteFormId' => $hasLogo && $deleteFormId !== '' ? $deleteFormId : '',
            'deleteConfirm' => t('Delete this logo?'),
        ];
        require templatePath('partials/app-file-upload.phtml');
        ?>
        <div class="tenant-logo-actions">
            <button type="submit" form="<?php e($uploadFormId); ?>" class="secondary outline small">
                <?php e(t('Save')); ?>
            </button>
        </div>
    <?php elseif ($hasLogo): ?>
        <img class="tenant-logo-readonly-preview" src="<?php e($previewUrl); ?>" alt="<?php e($fieldLabel); ?>">
    <?php endif; ?>
</div>
