@extends('admin.clients.tabs._layout')

@section('tab-content')
<div class="card border-0 shadow-sm">
    <div class="card-header border-0 pt-3 pb-2">
        <div class="d-flex justify-content-between align-items-center">
            <h6 class="mb-0">
                <i class="fas fa-plus text-primary me-2"></i>{{ __('admin/clients.products_buttons_create') }}
            </h6>
            <a href="{{ route('admin.clients.products', $client) }}" class="btn btn-outline-secondary btn-sm">
                <i class="fas fa-arrow-left me-1"></i>{{ __('admin/common.back') }}
            </a>
        </div>
    </div>

    <div class="card-body">
        @if ($errors->any())
            <div class="alert alert-danger">
                <ul class="mb-0">
                    @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif

        <form method="POST" action="{{ route('admin.clients.products.store', $client) }}">
            @csrf

            <div class="mb-3">
                <label class="form-label">{{ __('admin/clients.products_detail_product_name') }} <span class="text-danger">*</span></label>
                <select name="product_id" class="form-control @error('product_id') is-invalid @enderror" required>
                    <option value="">{{ __('admin/common.select') }}</option>
                    @foreach ($products as $p)
                        <option value="{{ $p->id }}" @selected(old('product_id') == $p->id)>
                            [{{ strtoupper($p->type) }}] {{ $p->name }} ({{ $p->module ?? '—' }})
                        </option>
                    @endforeach
                </select>
                @error('product_id') <div class="invalid-feedback">{{ $message }}</div> @enderror
            </div>

            <div class="mb-3">
                <label class="form-label">{{ __('admin/clients.products_detail_domain') }}</label>
                <input type="text" name="domain" value="{{ old('domain') }}"
                       class="form-control @error('domain') is-invalid @enderror" placeholder="example.com">
                @error('domain') <div class="invalid-feedback">{{ $message }}</div> @enderror
            </div>

            <div class="mb-3">
                <label class="form-label">{{ __('admin/clients.products_detail_billing_cycle') }} <span class="text-danger">*</span></label>
                <select name="billingcycle" class="form-control @error('billingcycle') is-invalid @enderror" required>
                    @foreach (['monthly','quarterly','semiannually','annually','biennially','triennially','onetime'] as $bc)
                        <option value="{{ $bc }}" @selected(old('billingcycle','monthly') === $bc)>{{ ucfirst($bc) }}</option>
                    @endforeach
                </select>
                @error('billingcycle') <div class="invalid-feedback">{{ $message }}</div> @enderror
            </div>

            <div class="mb-3">
                <label class="form-label">{{ __('admin/clients.products_detail_status') }} <span class="text-danger">*</span></label>
                <select name="status" class="form-control @error('status') is-invalid @enderror" required>
                    @foreach (['pending','active','suspended','terminated'] as $st)
                        <option value="{{ $st }}" @selected(old('status','pending') === $st)>{{ ucfirst($st) }}</option>
                    @endforeach
                </select>
                @error('status') <div class="invalid-feedback">{{ $message }}</div> @enderror
            </div>

            <div class="form-check mb-4">
                <input type="hidden" name="provision_now" value="0">
                <input type="checkbox" class="form-check-input" id="provision_now" name="provision_now" value="1"
                       @checked(old('provision_now'))>
                <label class="form-check-label" for="provision_now">
                    {{ __('admin/clients.product_provision_now') }}
                </label>
            </div>

            <div class="d-flex gap-2">
                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-save me-1"></i>{{ __('admin/common.save') }}
                </button>
                <a href="{{ route('admin.clients.products', $client) }}" class="btn btn-outline-secondary">
                    {{ __('admin/common.cancel') }}
                </a>
            </div>
        </form>
    </div>
</div>
@endsection
