@extends('admin.layouts.app')
@section('title', isset($ticker) ? 'Editar Ítem Ticker' : 'Nuevo Ítem Ticker')
@section('styles')
<style>
:root{--m:#881337;--mg:#f43f5e;}
.mod-hero{background:linear-gradient(135deg,#881337,#be123c,#f43f5e);border-radius:20px;padding:22px 28px;display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:16px;margin-bottom:22px;box-shadow:0 8px 32px rgba(136,19,55,.28);}
.mod-hero h1{font-size:1.3rem;font-weight:800;color:#fff;margin:0;display:flex;align-items:center;gap:10px;}
.mod-hero p{color:rgba(255,255,255,.5);margin:0;font-size:.82rem;}
.btn-back{display:inline-flex;align-items:center;gap:7px;padding:10px 18px;background:rgba(255,255,255,.12);border:1.5px solid rgba(255,255,255,.3);color:#fff;border-radius:12px;font-weight:700;font-size:.85rem;text-decoration:none;transition:all .2s;}
.btn-back:hover{background:rgba(255,255,255,.22);}
.form-card{background:#fff;border-radius:18px;box-shadow:0 4px 24px rgba(0,0,0,.07);overflow:hidden;margin-bottom:20px;}
.form-card-hd{background:linear-gradient(135deg,#881337,#f43f5e);padding:14px 22px;display:flex;align-items:center;gap:10px;}
.form-card-hd .ic{width:32px;height:32px;border-radius:9px;background:rgba(255,255,255,.15);display:flex;align-items:center;justify-content:center;}
.form-card-hd .ic i{color:#fda4af;font-size:15px;}
.form-card-hd span{color:#fff;font-weight:800;font-size:.92rem;}
.form-card-body{padding:24px 28px;}
.fl{font-size:.82rem;font-weight:700;color:#475569;margin-bottom:6px;display:block;}
.fl .req{color:#ef4444;}
.fi{width:100%;border:1.5px solid #e2e8f0;border-radius:10px;padding:10px 14px;font-size:.88rem;color:#1e293b;transition:border-color .2s,box-shadow .2s;outline:none;background:#fff;}
.fi:focus{border-color:#be123c;box-shadow:0 0 0 3px rgba(190,18,60,.1);}
.fi-row{display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-bottom:18px;}
.fg{margin-bottom:18px;}
.toggle-lbl{display:flex;align-items:center;gap:10px;cursor:pointer;background:#fff;padding:10px 16px;border-radius:10px;border:1.5px solid #e2e8f0;transition:border-color .2s;width:fit-content;}
.toggle-lbl:hover{border-color:#be123c;}
.toggle-lbl input{width:18px;height:18px;cursor:pointer;accent-color:#be123c;}
.toggle-lbl span{font-weight:700;color:#334155;font-size:.88rem;}
.submit-bar{background:#fff1f2;border-top:1.5px solid #fecdd3;padding:18px 28px;display:flex;gap:12px;justify-content:flex-end;align-items:center;}
.btn-cancel{display:inline-flex;align-items:center;gap:7px;padding:11px 20px;background:#f1f5f9;color:#64748b;border-radius:12px;font-weight:700;text-decoration:none;font-size:.88rem;transition:all .2s;}
.btn-cancel:hover{background:#e2e8f0;}
.btn-save{display:inline-flex;align-items:center;gap:8px;padding:12px 28px;background:linear-gradient(135deg,#881337,#f43f5e);color:#fff;border:none;border-radius:14px;font-weight:800;font-size:.9rem;cursor:pointer;box-shadow:0 4px 16px rgba(136,19,55,.3);transition:all .2s;}
.btn-save:hover{transform:translateY(-2px);}
.ticker-live{background:linear-gradient(90deg,#881337,#f43f5e);border-radius:10px;padding:10px 16px;font-size:.85rem;font-weight:700;color:#fff;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-top:8px;}
</style>
@endsection
@section('content')
<div class="mod-hero">
    <div>
        <h1>
            <div style="width:38px;height:38px;border-radius:12px;background:rgba(255,255,255,.15);border:1.5px solid rgba(255,255,255,.25);display:flex;align-items:center;justify-content:center;">
                <i class="bi bi-megaphone-fill" style="color:#fda4af;font-size:18px;"></i>
            </div>
            {{ isset($ticker) ? 'Editar Ítem Ticker' : 'Nuevo Ítem Ticker' }}
        </h1>
        <p>{{ isset($ticker) ? 'Modifica el mensaje del ticker' : 'Agrega un nuevo mensaje a la barra deslizante' }}</p>
    </div>
    <a href="{{ route('admin.ticker.index') }}" class="btn-back"><i class="bi bi-arrow-left"></i> Volver</a>
</div>

<form action="{{ isset($ticker) ? route('admin.ticker.update', $ticker) : route('admin.ticker.store') }}" method="POST" id="frmTicker">
    @csrf @if(isset($ticker)) @method('PUT') @endif

    <div class="form-card">
        <div class="form-card-hd"><div class="ic"><i class="bi bi-chat-quote-fill"></i></div><span>Contenido del Mensaje</span></div>
        <div class="form-card-body">
            <div class="fg">
                <label class="fl">Texto del Ticker <span class="req">*</span></label>
                <input type="text" name="texto" id="inTexto" class="fi" value="{{ old('texto',$ticker->texto??'') }}" placeholder="🎉 Texto del ticker que verán los visitantes..." required>
                <div style="font-size:.78rem;color:#94a3b8;margin-top:4px;"><i class="bi bi-emoji-smile me-1"></i>Puedes usar emojis para hacerlo más llamativo</div>
                {{-- Vista previa --}}
                <div class="ticker-live" id="tickerPreview">📢 {{ old('texto',$ticker->texto??'Vista previa del ticker...') }}</div>
            </div>
            <div class="fi-row">
                <div>
                    <label class="fl">URL (opcional)</label>
                    <input type="text" name="url" class="fi" value="{{ old('url',$ticker->url??'') }}" placeholder="https://...">
                    <div style="font-size:.78rem;color:#94a3b8;margin-top:4px;">Al hacer clic en el ticker, redirigirá a esta URL</div>
                </div>
                <div>
                    <label class="fl">Orden <span style="font-weight:400;color:#94a3b8;font-size:.78rem;">(0 = primero)</span></label>
                    <input type="number" name="orden" class="fi" value="{{ old('orden',$ticker->orden??0) }}" min="0">
                    <div style="margin-top:16px;">
                        <label class="toggle-lbl">
                            <input type="checkbox" name="activo" value="1" {{ old('activo',$ticker->activo??true) ? 'checked' : '' }}>
                            <i class="bi bi-toggle-on" style="color:#10b981;"></i>
                            <span>Activo / Visible</span>
                        </label>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="submit-bar">
        <a href="{{ route('admin.ticker.index') }}" class="btn-cancel"><i class="bi bi-x-lg"></i> Cancelar</a>
        <button type="submit" class="btn-save"><i class="bi bi-save-fill"></i> {{ isset($ticker) ? 'Actualizar' : 'Guardar Ítem' }}</button>
    </div>
</form>
@endsection
@section('scripts')
<script>
document.getElementById('inTexto').addEventListener('input', function() {
    document.getElementById('tickerPreview').textContent = '📢 ' + (this.value || 'Vista previa del ticker...');
});
</script>
@endsection
