<?php
/** @var yii\web\View $this */
/** @var app\models\Tenant $tenant */

use yii\helpers\Html;
use yii\helpers\Url;

$this->title = $tenant->tenant_name;
?>

<div class="page-title">
    <i class="fas fa-building"></i> <?= Html::encode($tenant->tenant_name) ?>
    <div style="margin-left:auto; display:flex; gap:8px;">
        <a href="<?= Url::to(['tenant/update', 'id' => $tenant->id]) ?>" class="lms-btn lms-btn-primary lms-btn-sm">
            <i class="fas fa-edit"></i> Edit
        </a>
        <a href="<?= Url::to(['tenant/index']) ?>" class="lms-btn lms-btn-secondary lms-btn-sm">
            <i class="fas fa-arrow-left"></i> Back
        </a>
    </div>
</div>

<div style="display:grid; grid-template-columns:1fr 260px; gap:20px; align-items:start;">

    <div class="lms-card">
        <div class="lms-card-header"><i class="fas fa-building"></i> Tenant Information</div>
        <div class="lms-card-body">
            <table style="width:100%; border-collapse:collapse; font-size:14px;">
                <tr style="border-bottom:1px solid #f0f0f0;">
                    <td style="padding:10px 0; color:#888; width:160px;">Name</td>
                    <td style="padding:10px 0; font-weight:600;"><?= Html::encode($tenant->tenant_name) ?></td>
                </tr>
                <tr style="border-bottom:1px solid #f0f0f0;">
                    <td style="padding:10px 0; color:#888;">Phone</td>
                    <td style="padding:10px 0;"><?= Html::encode($tenant->tenant_phone) ?: '<span style="color:#ccc;">—</span>' ?></td>
                </tr>
                <tr style="border-bottom:1px solid #f0f0f0;">
                    <td style="padding:10px 0; color:#888;">Email</td>
                    <td style="padding:10px 0;">
                        <?php if ($tenant->tenant_email): ?>
                            <a href="mailto:<?= Html::encode($tenant->tenant_email) ?>"><?= Html::encode($tenant->tenant_email) ?></a>
                        <?php else: ?>
                            <span style="color:#ccc;">—</span>
                        <?php endif; ?>
                    </td>
                </tr>
                <tr style="border-bottom:1px solid #f0f0f0;">
                    <td style="padding:10px 0; color:#888; vertical-align:top;">Address</td>
                    <td style="padding:10px 0; white-space:pre-line;"><?= Html::encode($tenant->tenant_addess) ?: '<span style="color:#ccc;">—</span>' ?></td>
                </tr>
                <tr style="border-bottom:1px solid #f0f0f0;">
                    <td style="padding:10px 0; color:#888;">Status</td>
                    <td style="padding:10px 0;">
                        <span class="lms-badge <?= $tenant->isActive === 'Y' ? 'lms-badge-success' : 'lms-badge-danger' ?>">
                            <?= $tenant->isActive === 'Y' ? 'Active' : 'Inactive' ?>
                        </span>
                    </td>
                </tr>
                <tr style="border-bottom:1px solid #f0f0f0;">
                    <td style="padding:10px 0; color:#888; vertical-align:top;">Notes</td>
                    <td style="padding:10px 0; white-space:pre-line; color:#555;"><?= Html::encode($tenant->tenant_notes) ?: '<span style="color:#ccc;">—</span>' ?></td>
                </tr>
                <tr>
                    <td style="padding:10px 0; color:#888;">Created</td>
                    <td style="padding:10px 0; font-size:13px; color:#888;">
                        <?= ($tenant->created_date_time && $tenant->created_date_time !== '0000-00-00 00:00:00')
                            ? date('d M Y, H:i', strtotime($tenant->created_date_time)) : '—' ?>
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <div class="lms-card">
        <div class="lms-card-header" style="background:#f8f9fa;"><i class="fas fa-image"></i> Logo</div>
        <div class="lms-card-body" style="text-align:center; padding:24px 16px;">
            <?php if ($tenant->getLogoUrl()): ?>
                <img src="<?= Html::encode($tenant->getLogoUrl()) ?>"
                     alt="<?= Html::encode($tenant->tenant_name) ?>"
                     style="max-width:160px; max-height:120px; object-fit:contain; border-radius:8px; border:1px solid #e2e8f0;">
                <div style="font-size:12px; color:#aaa; margin-top:8px;"><?= Html::encode($tenant->tenant_logo_name ?: $tenant->tenant_logo) ?></div>
            <?php else: ?>
                <div class="tenant-logo-preview-placeholder" style="margin:0 auto;">
                    <i class="fas fa-building" style="font-size:32px; color:#c8d0e0;"></i>
                </div>
                <div style="font-size:12px; color:#ccc; margin-top:8px;">No logo uploaded</div>
            <?php endif; ?>
            <div style="margin-top:16px;">
                <a href="<?= Url::to(['tenant/update', 'id' => $tenant->id]) ?>" class="lms-btn lms-btn-primary lms-btn-sm">
                    <i class="fas fa-edit"></i> Edit Tenant
                </a>
            </div>
        </div>
    </div>

</div>
