<?= $this->extend('admin/layout/main') ?>
<?= $this->section('content') ?>
<h3 class="mb-3"><?= $company ? lang('App.edit') : lang('App.add_new') ?> - <?= lang('App.companies') ?></h3>
<div class="card p-4" style="max-width:600px;">
<form method="post" action="<?= $company ? '/admin/companies/' . $company['id'] : '/admin/companies' ?>">
    <?= csrf_field() ?>
    <div class="mb-3">
        <label class="form-label"><?= lang('App.name') ?></label>
        <input type="text" name="name" class="form-control" value="<?= esc($company['name'] ?? '') ?>" required>
    </div>
    <div class="mb-3">
        <label class="form-label"><?= lang('App.base_currency') ?></label>
        <select name="base_currency" class="form-select">
            <?php foreach (['USD', 'EGP', 'SAR', 'EUR'] as $cur): ?>
                <option <?= ($company['base_currency'] ?? 'USD') === $cur ? 'selected' : '' ?>><?= $cur ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="mb-3">
        <label class="form-label">الرقم الضريبي</label>
        <input type="text" name="tax_number" class="form-control" value="<?= esc($company['tax_number'] ?? '') ?>">
    </div>
    <div class="mb-3">
        <label class="form-label"><?= lang('App.address') ?></label>
        <textarea name="address" class="form-control"><?= esc($company['address'] ?? '') ?></textarea>
    </div>
    <div class="row">
        <div class="col-6 mb-3">
            <label class="form-label"><?= lang('App.phone') ?></label>
            <input type="text" name="phone" class="form-control" value="<?= esc($company['phone'] ?? '') ?>">
        </div>
        <div class="col-6 mb-3">
            <label class="form-label"><?= lang('App.email') ?></label>
            <input type="email" name="email" class="form-control" value="<?= esc($company['email'] ?? '') ?>">
        </div>
    </div>
    <div class="mb-3">
        <label class="form-label">أيام التنبيه الافتراضية</label>
        <input type="number" name="notify_before_days_default" class="form-control" value="<?= esc($company['notify_before_days_default'] ?? 7) ?>">
    </div>
    <div class="form-check mb-3">
        <input type="checkbox" name="is_active" class="form-check-input" value="1" <?= ($company['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/companies" class="btn btn-light"><?= lang('App.cancel') ?></a>
</form>
</div>
<?= $this->endSection() ?>
