@extends('layouts.app')
@section('title', '設定マスタ')

@section('content')
<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>

<section class="content">
    <div class="container-fluid">

        {{-- ソート用フォーム --}}
        <form action="{{ route('settings') }}" method="post" id="list-form" class="d-none">
            @csrf
            <input type="hidden" name="sort" id="sort" value="{{ $sort }}">
            <input type="hidden" name="sort_type" id="sort_type" value="{{ $sort_type }}">
        </form>

        <!-- ツールバー -->
        <div class="container-fluid mb20 d-flex justify-content-between align-items-center">
            <div>
                <button type="button" class="btn btn-sm btn-default mr10" onclick="location.href='{{ route('settings_add') }}'">
                    {{ __('新規') }}
                </button>
                <button type="button" class="btn btn-sm btn-default mr10" id="delete">{{ __('削除') }}</button>
            </div>
            <div>
                {{ $list->appends(['sort'=>$sort,'sort_type'=>$sort_type])->links('pagination') }}
            </div>
        </div>

        {{-- フラッシュメッセージ --}}
        <div class="form col-lg-12">
            @if(Session::has('success'))
                <div class="alert alert-success alert-dismissible" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    {{ Session::get('success') }}
                </div>
            @elseif(Session::has('error'))
                <div class="alert alert-danger alert-dismissible">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <h4><i class="icon fa fa-ban"></i> {{__('入力内容に不備があります')}}:</h4>
                    {!! Session::get('error') !!}
                </div>
            @elseif(isset($errorMsg))
                <div class="alert alert-danger alert-dismissible">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <h4><i class="icon fa fa-ban"></i> {{__('入力内容に不備があります')}}:</h4>
                    {!! $errorMsg !!}
                </div>
            @endif
        </div>

        <!-- ▼ 単一テーブル構成 ----------------------------------------- -->
        <div class="col-lg-12 mb20">
            <div class="table-responsive">
                <form action="{{ route('settings_delete') }}" method="POST" id="form_delete">
                    @csrf
                    <table class="table table-bordered dataTable text-nowrap">
                        <thead class="thead-light">
                            <tr>
                                <th style="width:120px;" class="text-left">
                                <input type="checkbox" onclick="$('input[name*=\'ids\']').prop('checked', this.checked);">
                            </th>
                                <th sort="setting_id" class="sorting {{ ($sort=='setting_id') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}"><span>{{ __('設定ID') }}</span></th>
                                <th sort="edit_master" class="sorting {{ ($sort=='edit_master') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}"><span>{{ __('編集マスタ') }}</span></th>
                                <th sort="web_master" class="sorting {{ ($sort=='web_master') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}"><span>{{ __('ウェブ参照マスタ') }}</span></th>
                                <th sort="auto_change_date" class="sorting {{ ($sort=='auto_change_date') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}"><span>{{ __('自動切替日時') }}</span></th>
                                <th><span>{{ __('自動切換え参照マスタ') }}</span></th>
                                <th sort="printable_alert_flag" class="sorting {{ ($sort=='printable_alert_flag') ? ($sort_type=='asc'?'sorting_asc':'sorting_desc') : '' }}"><span>{{ __('印字残警告') }}</span></th>
                                <th class="text-right"><span>{{ __('ロール紙印字可能数') }}</span></th>
                                <th class="text-right"><span>{{ __('ロール紙印字残警告数') }}</span></th>
                                <th class="text-right"><span>{{ __('キープアライブ(分)') }}</span></th>
                            </tr>
                        </thead>
                        <tbody class="bg-white">
                            {{-- データ表示 --}}
                            @foreach($list as $row)
                                <tr>
                                    <td class="align-middle" style="background-color:#faebd7;">
                                        <div class="d-flex align-items-center">
                                            <input type="checkbox" class="m-0 checkbox" name="ids[]" value="{{ $row->setting_id }}">
                                            <a href="{{ route('settings_edit', ['id' => $row->setting_id]) }}" class="btn btn-sm btn-default ml10">{{ __('編集') }}</a>
                                        </div>
                                    </td>

                                    <td class="sm-item text-right align-middle">{{ $row->setting_id }}</td>
                                    <td class="sm-item text-left align-middle">{{ $row->edit_master }}</td>
                                    <td class="sm-item text-left align-middle">{{ $row->web_master }}</td>
                                    <td class="sm-item text-right align-middle">
                                        @php
                                            $dt = $row->auto_change_date instanceof \Carbon\Carbon
                                                    ? $row->auto_change_date->format('Y/m/d H:i')
                                                    : ($row->auto_change_date ? \Carbon\Carbon::parse($row->auto_change_date)->format('Y/m/d H:i') : '');
                                        @endphp
                                        {{ $dt }}
                                    </td>
                                    <td class="sm-item text-left align-middle">{{ $row->auto_chage_master }}</td>
                                    <td class="sm-item text-left align-middle">{{ $row->printable_alert_flag ? '○' : '' }}</td>
                                    <td class="sm-item text-right align-middle">{{ $row->printable_number }}</td>
                                    <td class="sm-item text-right align-middle">{{ $row->printable_alert_number }}</td>
                                    <td class="sm-item text-right align-middle">{{ $row->printer_keep_alive }}</td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
        <!-- ▲ 単一テーブル構成ここまで ----------------------------------------- -->
    </div>
</section>
@endsection

