@extends('layouts.app')
@section('title', 'インボイス設定')

@section('content')

@if (session('success'))
    <div class="alert alert-success">
        {{ session('success') }}
    </div>
@endif
@if (session('error'))
    <div class="alert alert-danger">
        {{ session('error') }}
    </div>
@endif

<!-- Content Header -->
<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <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 active">インボイス設定</li>
                </ol>
            </div>
        </div>
    </div>
</div>

<!-- Main Content -->
<section class="content">
    <div class="container-fluid">

        <!-- ▼ ボタン + ページネーション -->
        <div class="container-fluid mb20">
            <button type="button" class="btn btn-sm btn-default mr10" onclick="location.href='{{ route('inv_settings_add') }}'">新規</button>
            <button type="button" class="btn btn-sm btn-default mr10" id="delete">削除</button>
            <div class="d-flex justify-content-end">
                {{ $list->appends(['sort' => $sort ?? '', 'sort_type' => $sort_type ?? ''])->links('pagination') }}
            </div>
        </div>

        <form id="list-form" action="{{ route('inv_settings') }}" method="GET" class="d-none"> <input type="hidden" name="sort" value="{{ $sort ?? '' }}"> <input type="hidden" name="sort_type" value="{{ $sort_type ?? '' }}"> </form>
        <!-- ▼ 単一テーブル構成 -->
        <div class="col-lg-12 mb20">
            <div class="table-responsive">
                <form method="post" action="{{ route('inv_settings_delete') }}" id="form_delete">
                    @csrf
                    <table id="inv-settings-list" class="table table-bordered dataTable text-nowrap">
                        <thead class="thead-light">
                            <tr>
                                 <th style="width:140px; border-left:1px solid #dcdcdc;" class="text-left">
                                    <input type="checkbox" onclick="$('input[name*=\'pk\']').prop('checked', this.checked);">
                                </th>
                                <th class="sorting {{ ($sort=='management_id') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="management_id"><span>運営元ID</span></th>
                                <th class="sorting {{ ($sort=='t_number') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="t_number"><span>適格請求書発行事業者番号</span></th>
                                <th class="sorting {{ ($sort=='t_name') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="t_name"><span>適格事業者名</span></th>
                                <th class="sorting {{ ($sort=='zipcode') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="zipcode"><span>郵便番号</span></th>
                                <th class="sorting {{ ($sort=='adrs') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="adrs"><span>表示住所</span></th>
                                <th class="sorting {{ ($sort=='bldg') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="bldg"><span>建物名</span></th>
                                <th class="sorting {{ ($sort=='tel_num') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="tel_num"><span>表示電話番号</span></th>
                                <th class="sorting {{ ($sort=='fax_num') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}" sort="fax_num"><span>表示FAX番号</span></th>
                            </tr>
                        </thead>
                        <tbody class="bg-white">
                            @foreach($list as $item)
                                <tr>
                                    <td style="background-color:#faebd7;">
                                        <div class="d-flex align-items-center">
                                            <input type="checkbox" class="m-0 checkbox" name="id[]" value="{{ $item->seq }}">
                                            <a href="{{ route('inv_settings_edit', ['id' => $item->seq]) }}" 
                                            class="btn btn-sm btn-outline-primary ml10">編集</a>
                                        </div>
                                    </td>
                                    <td class="sm-item text-left align-middle">{{ $item->management_id }}</td>
                                    <td class="sm-item text-left align-middle">{{ $item->t_number }}</td>
                                    <td class="sm-item text-left align-middle">{{ $item->t_name }}</td>
                                    <td class="sm-item text-center align-middle">{{ $item->zipcode }}</td>
                                    <td class="sm-item text-left align-middle">{{ $item->adrs }}</td>
                                    <td class="sm-item text-left align-middle">{{ $item->bldg }}</td>
                                    <td class="sm-item text-center align-middle">{{ $item->tel_num }}</td>
                                    <td class="sm-item text-center align-middle">{{ $item->fax_num }}</td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
        <!-- ▲ 単一テーブル構成ここまで -->
    </div>
</section>
@endsection
