@extends('layouts.admin')

@section('title', 'Edit '.$gateway->display_name)

@section('content')
<div class="admin-top">
    <div>
        <h1>{{ $gateway->display_name }}</h1>
        <p class="sub">Public key / Client ID is stored as plain text. Secret keys are encrypted at rest.</p>
    </div>
    <a href="{{ route('admin.payments.index') }}" class="btn btn-ghost">Back</a>
</div>

<form method="POST" action="{{ route('admin.payments.update', $gateway) }}" class="card">
    @csrf
    @method('PUT')

    <div class="form-row">
        <label for="display_name">Display name</label>
        <input type="text" id="display_name" name="display_name" value="{{ old('display_name', $gateway->display_name) }}" required>
    </div>

    <div class="form-row">
        <label>
            <input type="checkbox" name="status" value="1" @checked(old('status', $gateway->status))> Enabled
        </label>
    </div>

    <div class="form-row">
        <label for="environment">Environment</label>
        <select id="environment" name="environment">
            <option value="sandbox" @selected(old('environment', $gateway->environment) === 'sandbox')>Sandbox</option>
            <option value="live" @selected(old('environment', $gateway->environment) === 'live')>Live</option>
        </select>
    </div>

    <div class="form-row">
        <label for="public_key">Public key / Client ID</label>
        <textarea id="public_key" name="public_key" rows="2" placeholder="pk_test_… or PayPal client id">{{ old('public_key', $gateway->public_key) }}</textarea>
    </div>

    <div class="form-row">
        <label for="secret_key">Secret key</label>
        <textarea id="secret_key" name="secret_key" rows="2" placeholder="Leave blank to keep current">{{ old('secret_key') }}</textarea>
        @error('secret_key')<div class="error">{{ $message }}</div>@enderror
    </div>

    <div class="form-row">
        <label for="webhook_secret">Webhook signing secret</label>
        <textarea id="webhook_secret" name="webhook_secret" rows="2" placeholder="Stripe whsec_… — leave blank to keep">{{ old('webhook_secret') }}</textarea>
        <small class="sub">Stripe: endpoint signing secret. PayPal/Square: optional verification keys.</small>
    </div>

    @if($gateway->name === 'square')
        <div class="form-row">
            <label for="location_id">Square location ID</label>
            <input type="text" id="location_id" name="location_id" value="{{ old('location_id', $gateway->location_id) }}">
        </div>
    @endif

    <button type="submit" class="btn btn-primary">Save</button>
</form>
@endsection
