<?php

/** @var yii\web\View $this */
/** @var common\models\Lead $model */

use common\models\Lead;
use yii\bootstrap5\Html;
use yii\helpers\Url;

$this->title = 'Lead: ' . $model->name;
$statusColors = ['new' => 'primary', 'contacted' => 'info', 'converted' => 'success', 'lost' => 'secondary'];
?>

<div class="d-flex justify-content-between align-items-center mb-3">
    <a href="<?= Url::to(['/lead/index']) ?>" class="btn btn-sm btn-outline-secondary">
        <i class="bi bi-arrow-left"></i> Back
    </a>
    <div class="d-flex gap-2">
        <a href="<?= Url::to(['/lead/update', 'id' => $model->id]) ?>" class="btn btn-sm btn-outline-primary">
            <i class="bi bi-pencil"></i> Edit
        </a>
        <?php if ($model->status !== Lead::STATUS_CONVERTED): ?>
            <?= Html::a('<i class="bi bi-arrow-right-circle"></i> Convert to Customer',
                ['/lead/convert', 'id' => $model->id],
                [
                    'class'       => 'btn btn-sm btn-success',
                    'data-method' => 'post',
                    'data-confirm'=> 'Convert this lead to a customer?',
                ]
            ) ?>
        <?php endif; ?>
    </div>
</div>

<div class="row g-3">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header bg-white fw-semibold">Lead Details</div>
            <div class="card-body">
                <dl class="row mb-0">
                    <dt class="col-sm-3 text-muted">Name</dt>
                    <dd class="col-sm-9"><?= Html::encode($model->name) ?></dd>
                    <dt class="col-sm-3 text-muted">Phone</dt>
                    <dd class="col-sm-9"><?= Html::encode($model->phone) ?></dd>
                    <dt class="col-sm-3 text-muted">Email</dt>
                    <dd class="col-sm-9"><?= $model->email ? Html::encode($model->email) : '<span class="text-muted">—</span>' ?></dd>
                    <dt class="col-sm-3 text-muted">Source</dt>
                    <dd class="col-sm-9"><?= $model->source ? Html::encode($model->source) : '—' ?></dd>
                    <dt class="col-sm-3 text-muted">Interest</dt>
                    <dd class="col-sm-9"><?= $model->interest ? Html::encode($model->interest) : '—' ?></dd>
                    <dt class="col-sm-3 text-muted">Status</dt>
                    <dd class="col-sm-9">
                        <span class="badge bg-<?= $statusColors[$model->status] ?>">
                            <?= ucfirst($model->status) ?>
                        </span>
                    </dd>
                    <dt class="col-sm-3 text-muted">Created</dt>
                    <dd class="col-sm-9"><?= date('d M Y, H:i', $model->created_at) ?></dd>
                </dl>
            </div>
        </div>
        <?php if ($model->message): ?>
        <div class="card mt-3">
            <div class="card-header bg-white fw-semibold">Message</div>
            <div class="card-body"><?= nl2br(Html::encode($model->message)) ?></div>
        </div>
        <?php endif; ?>
    </div>
</div>
