{{--
# ────────────── lee_gwena ──────────────
# Code by: ashley_gwena
# Created: 2026-03-31
# Notes: Subaccount edit form scoped to parent
# ───────────────────────────────────────
--}}
@extends('layouts.master')

@section('title', 'Edit Subaccount')

@section('content')
@include('chart_of_accounts.partials.form-styles')
<div class="container py-4 coa-form">
    <div class="coa-header">
        <div>
            <h1 class="h3 mb-1">Edit Subaccount</h1>
            <p>Parent: {{ $parent->account_code }} — {{ $parent->account_name }}</p>
        </div>
        <div class="coa-actions">
            <a href="{{ route('subaccounts.index', $parent) }}" class="btn btn-outline-secondary">Back</a>
        </div>
    </div>
    @if ($errors->any())
        <div class="alert alert-danger mb-3">
            @foreach ($errors->all() as $error)
                <div>{{ $error }}</div>
            @endforeach
        </div>
    @endif

    <form method="POST" action="{{ route('subaccounts.update', [$parent, $subaccount]) }}" class="card p-4 coa-card">
        @csrf
        @method('PUT')
        <input type="hidden" name="parent_id" value="{{ $parent->id }}">
        <div class="row g-3">
            <div class="col-md-4">
                <label class="form-label">Sub Code</label>
                <input type="text" name="sub_code" value="{{ old('sub_code', $subaccount->sub_code) }}" class="form-control" required>
            </div>
            <div class="col-md-8">
                <label class="form-label">Account Name</label>
                <input type="text" name="account_name" value="{{ old('account_name', $subaccount->account_name) }}" class="form-control" required>
            </div>
            <div class="col-md-3">
                <label class="form-label">Parent Account</label>
                <input type="text" class="form-control" value="{{ $parent->account_code }} - {{ $parent->account_name }}" disabled>
            </div>
            <div class="col-md-4 form-check">
                <input type="checkbox" class="form-check-input" id="is_active" name="is_active" value="1" {{ old('is_active', $subaccount->is_active) ? 'checked' : '' }}>
                <label class="form-check-label" for="is_active">Active</label>
            </div>
        </div>
        <div class="mt-4 d-flex gap-2">
            <button class="btn btn-primary" type="submit">Update Subaccount</button>
        </div>
    </form>

</div>
@endsection
