@extends('layouts.app')
@section('title', '定期契約マスタ - 編集')

@section('content')
<style>
  .rc-edit,
  .rc-edit .card,
  .rc-edit .form-control,
  .rc-edit .btn,
  .rc-edit .breadcrumb {
    font-size: 13px;
  }
  .rc-toolbar{
    display:flex;align-items:center;justify-content:space-between;gap:.75rem;
    margin-top:.25rem;margin-bottom:.75rem;
  }
  .rc-toolbar .left .btn{margin-right:.5rem}
  .card .card-header{background:#f5f5f5}
</style>

<div class="rc-edit">
  <div class="content-header">
    <div class="container-fluid">
      <div class="row mb-1">
        <div class="col-lg-6"><h1 class="m-0 text-dark">編集</h1></div>
        <div class="col-lg-6">
          <ol class="breadcrumb float-sm-right text-sm">
            <li class="breadcrumb-item"><a href="{{ route('home') }}">ホーム</a></li>
            <li class="breadcrumb-item"><a href="{{ route('regularcontracts') }}">定期契約マスタ</a></li>
            <li class="breadcrumb-item active"></li>
          </ol>
        </div>
      </div>

      {{-- ← ここが “目標” のボタン帯 --}}
      <div class="rc-toolbar">
        <div class="left">
          {{-- 登録：edit-form を submit --}}
          <button form="edit-form" type="submit" class="btn btn-success btn-sm">登録</button>
          {{-- 領収書発行：後で好きなルートに差し替えてOK（今はダミー） --}}
          <button type="button" class="btn btn-success btn-sm" id="btnReceipt">領収書発行</button>
        </div>

        {{-- 右側：削除 --}}
        <form id="del-form" method="post" action="{{ route('regularcontracts_delete') }}" class="m-0">
          @csrf
          <input type="hidden" name="ids[]" value="{{ $row->contract_id }}">
          <button type="submit" class="btn btn-danger btn-sm">削除</button>
        </form>
      </div>
      {{-- /ボタン帯 --}}
    </div>
  </div>

  <section class="content">
    <div class="container-fluid">
      <div class="card">
        {{-- 本体フォーム（登録はこの form を submit） --}}
        <form id="edit-form" method="post" action="{{ route('regularcontracts_edit', ['contract_id'=>$row->contract_id]) }}">
          @csrf
          @include('admin.regularcontracts._form', array_merge(
            ['isEdit'=>1,'isInfo'=>0],
            (array) $row
          ))
        </form>
      </div>
    </div>
  </section>
</div>

<script>
  // 領収書発行はとりあえずダミー動作
  document.getElementById('btnReceipt')?.addEventListener('click', function(){
    alert('領収書発行の処理をここに実装してください。');
  });
</script>
@endsection
