@extends('admin.layouts.app')

@section('title', '메일 템플릿')
@section('page_title', '메일 템플릿')
@section('page_desc', '스킨 + 제목/본문 템플릿 관리')

@push('head')
    <style>
        .bar{display:flex; gap:10px; flex-wrap:wrap; align-items:end;}
        .btn{padding:8px 12px;font-size:13px;border-radius:12px;line-height:1.1;text-decoration:none;display:inline-flex;align-items:center;justify-content:center;gap:6px;
            border:1px solid rgba(255,255,255,.10);background:rgba(255,255,255,.06);color:inherit;cursor:pointer;}
        .btn:hover{background:rgba(255,255,255,.10);}
        .btn--primary{background:rgba(59,130,246,.88);border-color:rgba(59,130,246,.95);color:#fff;}
        .mono{padding:4px 8px;border-radius:10px;background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.10);
            font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;font-size:12px;}
    </style>
@endpush

@section('content')
    <div class="a-card" style="padding:16px; margin-bottom:16px;">
        <form method="GET" action="{{ route('admin.mail.templates.index') }}" class="bar">
            <div style="min-width:140px;">
                <div class="a-muted" style="margin-bottom:6px;">활성</div>
                <select class="a-input" name="active" style="width:140px;">
                    <option value="">전체</option>
                    <option value="1" @selected(request('active')==='1')>활성</option>
                    <option value="0" @selected(request('active')==='0')>비활성</option>
                </select>
            </div>

            <div style="min-width:200px;">
                <div class="a-muted" style="margin-bottom:6px;">검색</div>
                <input class="a-input" name="q" value="{{ request('q') }}" placeholder="code/title/subject/body" style="width:320px; max-width:100%;">
            </div>

            <div style="display:flex; gap:8px; align-items:center;">
                <button class="btn btn--primary" type="submit">조회</button>
                <a class="btn" href="{{ route('admin.mail.templates.create') }}">새 템플릿</a>
            </div>
        </form>
    </div>

    <div class="a-card" style="padding:16px;">
        <div class="a-muted" style="margin-bottom:10px;">총 {{ $templates->total() }}건</div>

        <div style="overflow:auto;">
            <table class="a-table" style="width:100%; min-width:1050px;">
                <thead>
                <tr>
                    <th style="width:80px;">ID</th>
                    <th style="width:70px;">활성</th>
                    <th style="width:160px;">Code</th>
                    <th style="width:180px;">Title</th>
                    <th style="width:220px;">Subject</th>
                    <th style="width:140px;">Skin</th>
                    <th>Body</th>
                    <th style="width:90px;"></th>
                </tr>
                </thead>
                <tbody>
                @forelse($templates as $t)
                    <tr>
                        <td class="a-muted">{{ $t->id }}</td>
                        <td>{{ (int)$t->is_active === 1 ? 'Y' : 'N' }}</td>
                        <td><span class="mono">{{ $t->code }}</span></td>
                        <td>{{ $t->title }}</td>
                        <td style="max-width:220px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">
                            {{ $t->subject_tpl ?? '-' }}
                        </td>
                        <td><span class="mono">{{ $t->skin_key ?? '-' }}</span></td>
                        <td style="max-width:420px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">{{ $t->body_tpl }}</td>
                        <td style="text-align:right;">
                            <a class="btn" href="{{ route('admin.mail.templates.edit', ['id'=>$t->id]) }}">수정</a>
                        </td>
                    </tr>
                @empty
                    <tr><td colspan="8" class="a-muted">데이터가 없습니다.</td></tr>
                @endforelse
                </tbody>
            </table>
        </div>

        <div style="margin-top:12px;">
            {{ $templates->links() }}
        </div>
    </div>
@endsection
