<?= $this->extend('admin/layout/main') ?>
<?= $this->section('content') ?>
<h3 class="mb-3"><?= $product ? lang('App.edit') : lang('App.add_new') ?> - <?= lang('App.products') ?></h3>
<div class="card p-4" style="max-width:500px;">
<form method="post" action="<?= $product ? '/admin/products/' . $product['id'] : '/admin/products' ?>">
    <?= csrf_field() ?>
    <div class="mb-3">
        <label class="form-label"><?= lang('App.name') ?></label>
        <input type="text" name="name" class="form-control" placeholder="مثال: شهادة SSL، رسوم تركيب" value="<?= esc($product['name'] ?? '') ?>" required>
    </div>
    <div class="mb-3">
        <label class="form-label">الوصف (اختياري)</label>
        <textarea name="description" class="form-control"><?= esc($product['description'] ?? '') ?></textarea>
    </div>
    <div class="row">
        <div class="col-6 mb-3">
            <label class="form-label">سعر الشراء (التكلفة)</label>
            <input type="number" step="0.01" name="cost_price" class="form-control" value="<?= esc($product['cost_price'] ?? 0) ?>">
            <div class="form-text">اتركه صفر لو مفيش تكلفة شراء (خدمة بدون تكلفة مباشرة)</div>
        </div>
        <div class="col-6 mb-3">
            <label class="form-label">سعر البيع</label>
            <input type="number" step="0.01" name="price" class="form-control" value="<?= esc($product['price'] ?? '') ?>" required>
        </div>
    </div>
    <div class="mb-3">
        <label class="form-label"><?= lang('App.currency') ?></label>
        <select name="currency" class="form-select">
            <?php foreach ($currencies as $curr): $cur = $curr['code']; ?>
                    <option <?= ($product['currency'] ?? $currencies[0]['code']) === $cur ? 'selected' : '' ?>><?= $cur ?><?= !empty($curr['name']) ? ' - ' . esc($curr['name']) : '' ?></option>
                <?php endforeach; ?>
        </select>
    </div>
    <div class="form-check mb-3">
        <input type="checkbox" name="is_active" class="form-check-input" value="1" <?= ($product['is_active'] ?? 1) ? 'checked' : '' ?>>
        <label class="form-check-label"><?= lang('App.status') ?></label>
    </div>
    <button class="btn btn-dark"><?= lang('App.save') ?></button>
    <a href="/admin/products" class="btn btn-light"><?= lang('App.cancel') ?></a>
</form>
</div>
<?= $this->endSection() ?>
