<?php $title = isset($link) ? 'Edit Link' : 'Add Link'; ?>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-white font-weight-bold"><?= isset($link) ? 'Edit Link' : 'Add Link' ?></h1>
</div>
<div class="glass-card">
    <form method="POST" action="<?= $baseUrl ?>/links/<?= isset($link) ? $link->id . '/update' : 'store' ?>">
        <div class="row">
            <div class="col-md-6 form-group">
                <label style="color: rgba(255,255,255,0.7);">Title</label>
                <input type="text" name="title" class="form-control glass-input" value="<?= htmlspecialchars($link->title ?? '') ?>" required>
            </div>
            <div class="col-md-6 form-group">
                <label style="color: rgba(255,255,255,0.7);">URL</label>
                <input type="url" name="url" class="form-control glass-input" value="<?= htmlspecialchars($link->url ?? '') ?>" required placeholder="https://...">
            </div>
        </div>
        <div class="form-group">
            <label style="color: rgba(255,255,255,0.7);">Description</label>
            <textarea name="description" class="form-control glass-input" rows="2"><?= htmlspecialchars($link->description ?? '') ?></textarea>
        </div>
        <div class="row">
            <div class="col-md-4 form-group">
                <label style="color: rgba(255,255,255,0.7);">Icon (Font Awesome class)</label>
                <input type="text" name="icon" class="form-control glass-input" value="<?= htmlspecialchars($link->icon ?? 'fas fa-link') ?>" placeholder="fas fa-link">
            </div>
            <div class="col-md-4 form-group">
                <label style="color: rgba(255,255,255,0.7);">Target</label>
                <select name="target" class="form-control glass-input">
                    <option value="_blank" <?= (($link->target ?? '') === '_blank') ? 'selected' : '' ?>>New Tab</option>
                    <option value="_self" <?= (($link->target ?? '') === '_self') ? 'selected' : '' ?>>Same Tab</option>
                </select>
            </div>
            <div class="col-md-4 form-group">
                <label style="color: rgba(255,255,255,0.7);">Category</label>
                <input type="text" name="category" class="form-control glass-input" value="<?= htmlspecialchars($link->category ?? '') ?>" placeholder="e.g. Resources, Partners">
            </div>
        </div>
        <div class="custom-control custom-checkbox mb-3">
            <input type="checkbox" class="custom-control-input" id="is_active" name="is_active" value="1" <?= (!isset($link) || $link->is_active) ? 'checked' : '' ?>>
            <label class="custom-control-label" for="is_active" style="color: rgba(255,255,255,0.7);">Active</label>
        </div>
        <div class="text-right">
            <a href="<?= $baseUrl ?>/links" class="glass-btn mr-2">Cancel</a>
            <button type="submit" class="glass-btn glass-btn-primary"><?= isset($link) ? 'Update' : 'Create' ?></button>
        </div>
    </form>
</div>
