@extends('layouts.app')

@section('content')

<style>
    @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800;900&display=swap');

    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    .em-page {
        min-height: 100vh;
        background: #ffffff;
        font-family: 'Poppins', sans-serif;
        display: flex;
        align-items: flex-start;
        justify-content: center;
        padding: 48px 20px 64px;
    }

    .em-card {
        width: 100%;
        max-width: 820px;
        background: #fff;
        border-radius: 28px;
        overflow: hidden;
        box-shadow:
            0 0 0 1px rgba(0,0,0,0.06),
            0 8px 24px rgba(0,0,0,0.07),
            0 40px 80px rgba(0,0,0,0.09);
    }

    /* ── HEADER ── */
    .em-header {
        background: #0a0a0a;
        padding: 44px 52px 40px;
        position: relative;
        overflow: hidden;
    }

    .em-header-accent {
        position: absolute;
        top: -40px; right: -40px;
        width: 220px; height: 220px;
        border-radius: 50%;
        background: radial-gradient(circle, rgba(255,214,0,0.18) 0%, transparent 70%);
    }

    .em-header-accent2 {
        position: absolute;
        bottom: -60px; left: 20%;
        width: 180px; height: 180px;
        border-radius: 50%;
        background: radial-gradient(circle, rgba(255,214,0,0.08) 0%, transparent 70%);
    }

    .em-header-dot-grid {
        position: absolute;
        top: 0; right: 0;
        width: 260px; height: 100%;
        background-image: radial-gradient(circle, rgba(255,214,0,0.15) 1px, transparent 1px);
        background-size: 18px 18px;
        opacity: 0.6;
    }

    .em-badge {
        display: inline-flex;
        align-items: center;
        gap: 7px;
        background: rgba(255,214,0,0.12);
        border: 1px solid rgba(255,214,0,0.3);
        border-radius: 100px;
        padding: 5px 16px;
        font-size: 10px;
        font-weight: 600;
        letter-spacing: 0.12em;
        text-transform: uppercase;
        color: #ffd600;
        margin-bottom: 18px;
        position: relative;
        z-index: 1;
    }

    .em-badge-dot {
        width: 6px; height: 6px;
        border-radius: 50%;
        background: #ffd600;
        box-shadow: 0 0 6px #ffd600;
        animation: pulse 2s infinite;
    }

    @keyframes pulse {
        0%, 100% { opacity: 1; transform: scale(1); }
        50% { opacity: 0.5; transform: scale(0.8); }
    }

    .em-title {
        font-size: 36px;
        font-weight: 800;
        color: #ffffff;
        line-height: 1.1;
        letter-spacing: -0.02em;
        position: relative;
        z-index: 1;
        margin-bottom: 10px;
    }

    .em-title span { color: #ffd600; }

    .em-subtitle {
        font-size: 13px;
        color: rgba(255,255,255,0.4);
        font-weight: 300;
        position: relative;
        z-index: 1;
    }

    /* ── YELLOW STRIPE ── */
    .em-stripe {
        height: 4px;
        background: linear-gradient(90deg, #ffd600 0%, #ffec6e 40%, #ffd600 100%);
    }

    /* ── BODY ── */
    .em-body {
        padding: 44px 52px 52px;
        background: #fff;
    }

    /* Section Labels */
    .em-section {
        display: flex;
        align-items: center;
        gap: 12px;
        margin-bottom: 24px;
        margin-top: 8px;
    }

    .em-section-icon {
        width: 32px; height: 32px;
        background: #ffd600;
        border-radius: 8px;
        display: flex; align-items: center; justify-content: center;
        flex-shrink: 0;
    }

    .em-section-icon svg {
        width: 15px; height: 15px;
        color: #0a0a0a;
    }

    .em-section-title {
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.12em;
        text-transform: uppercase;
        color: #0a0a0a;
    }

    .em-section-line {
        flex: 1;
        height: 1.5px;
        background: linear-gradient(90deg, #0a0a0a 0%, #e5e5e5 100%);
    }

    /* Grid */
    .em-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 20px 28px;
        margin-bottom: 36px;
    }

    .em-field { display: flex; flex-direction: column; gap: 8px; }
    .em-field.full { grid-column: 1 / -1; }

    .em-label {
        font-size: 11px;
        font-weight: 600;
        color: #0a0a0a;
        letter-spacing: 0.06em;
        text-transform: uppercase;
    }

    .em-input,
    .em-select {
        width: 100%;
        padding: 13px 18px;
        border: 2px solid #e8e8e8;
        border-radius: 12px;
        font-size: 14px;
        font-family: 'Poppins', sans-serif;
        font-weight: 400;
        color: #0a0a0a;
        background: #fafafa;
        transition: all 0.2s ease;
        outline: none;
        appearance: none;
        -webkit-appearance: none;
    }

    .em-input:hover, .em-select:hover {
        border-color: #c0c0c0;
        background: #f5f5f5;
    }

    .em-input:focus, .em-select:focus {
        border-color: #ffd600;
        background: #fff;
        box-shadow: 0 0 0 4px rgba(255,214,0,0.15);
    }

    .em-input::placeholder { color: #c0c0c0; font-weight: 300; }

    .em-select-wrap { position: relative; }
    .em-select-wrap::after {
        content: '';
        position: absolute;
        right: 16px; top: 50%;
        transform: translateY(-50%);
        width: 0; height: 0;
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
        border-top: 6px solid #0a0a0a;
        pointer-events: none;
    }
    .em-select-wrap .em-select { padding-right: 42px; }

    .em-fee-wrap { position: relative; }
    .em-fee-prefix {
        position: absolute;
        left: 18px; top: 50%;
        transform: translateY(-50%);
        font-size: 13px;
        font-weight: 700;
        color: #0a0a0a;
        pointer-events: none;
        z-index: 1;
    }
    .em-fee-wrap .em-input {
        padding-left: 52px;
        font-weight: 600;
        font-size: 15px;
    }

    @keyframes feeFlash {
        0%   { border-color: #ffd600; background: #fffde7; box-shadow: 0 0 0 4px rgba(255,214,0,0.2); }
        100% { border-color: #e8e8e8; background: #fafafa; box-shadow: none; }
    }
    .fee-updated { animation: feeFlash 0.8s ease-out forwards; }

    /* Info bar */
    .em-info-bar {
        display: flex;
        align-items: center;
        gap: 10px;
        background: #0a0a0a;
        border-radius: 12px;
        padding: 13px 20px;
        margin-bottom: 36px;
    }
    .em-info-bar svg { width: 14px; height: 14px; color: #ffd600; flex-shrink: 0; }
    .em-info-bar p { font-size: 12px; color: rgba(255,255,255,0.5); font-weight: 300; }
    .em-info-bar strong { color: #ffd600; font-weight: 600; }

    /* Actions */
    .em-actions {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-top: 32px;
        border-top: 2px solid #f0f0f0;
        gap: 12px;
    }

    .em-btn-cancel {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        font-family: 'Poppins', sans-serif;
        font-size: 13px;
        font-weight: 500;
        color: #888;
        background: none;
        border: 2px solid #e8e8e8;
        border-radius: 12px;
        padding: 12px 22px;
        cursor: pointer;
        text-decoration: none;
        transition: all 0.2s;
    }
    .em-btn-cancel:hover { border-color: #0a0a0a; color: #0a0a0a; background: #f5f5f5; }

    .em-btn-submit {
        display: inline-flex;
        align-items: center;
        gap: 10px;
        background: #ffd600;
        color: #0a0a0a;
        border: 2px solid #ffd600;
        border-radius: 12px;
        padding: 13px 32px;
        font-size: 14px;
        font-family: 'Poppins', sans-serif;
        font-weight: 700;
        cursor: pointer;
        transition: all 0.2s ease;
        box-shadow: 0 4px 20px rgba(255,214,0,0.4);
        letter-spacing: 0.02em;
        position: relative;
        overflow: hidden;
    }

    .em-btn-submit::before {
        content: '';
        position: absolute; inset: 0;
        background: #0a0a0a;
        transform: translateX(-101%);
        transition: transform 0.3s ease;
        z-index: 0;
    }
    .em-btn-submit:hover::before { transform: translateX(0); }
    .em-btn-submit:hover { color: #ffd600; border-color: #0a0a0a; box-shadow: 0 6px 24px rgba(0,0,0,0.2); }
    .em-btn-submit:active { transform: scale(0.98); }
    .em-btn-submit span, .em-btn-submit svg { position: relative; z-index: 1; }
    .em-btn-submit svg { width: 16px; height: 16px; transition: transform 0.2s; }
    .em-btn-submit:hover svg { transform: translateX(2px); }

    @media (max-width: 620px) {
        .em-header, .em-body { padding: 32px 24px; }
        .em-grid { grid-template-columns: 1fr; }
        .em-title { font-size: 28px; }
        .em-actions { flex-direction: column-reverse; }
        .em-btn-cancel, .em-btn-submit { width: 100%; justify-content: center; }
    }
</style>

<div class="em-page">
    <div class="em-card">

        <div class="em-header">
            <div class="em-header-dot-grid"></div>
            <div class="em-header-accent"></div>
            <div class="em-header-accent2"></div>
            <div class="em-badge"><span class="em-badge-dot"></span> Member Record</div>
            <h1 class="em-title">Edit <span>Member</span></h1>
            <p class="em-subtitle">Update the details below and save your changes</p>
        </div>

        <div class="em-stripe"></div>

        <div class="em-body">

            <div class="em-info-bar">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                    <circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/>
                </svg>
                <p>Admission fee <strong>auto-updates</strong> when you change the membership or package type</p>
            </div>

            <form action="{{ route('members.update', $member->id) }}" method="POST">
                @csrf
                @method('PUT')

                <div class="em-section">
                    <div class="em-section-icon">
                        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/>
                        </svg>
                    </div>
                    <span class="em-section-title">Personal Information</span>
                    <div class="em-section-line"></div>
                </div>

                <div class="em-grid">
                    <div class="em-field">
                        <label class="em-label" for="first_name">First Name</label>
                        <input id="first_name" type="text" name="first_name" value="{{ old('first_name', $member->first_name) }}" class="em-input" placeholder="e.g. Kasun">
                    </div>
                    <div class="em-field">
                        <label class="em-label" for="surname">Surname</label>
                        <input id="surname" type="text" name="surname" value="{{ old('surname', $member->surname) }}" class="em-input" placeholder="e.g. Perera">
                    </div>
                    <div class="em-field">
                        <label class="em-label" for="mobile">Mobile</label>
                        <input id="mobile" type="text" name="mobile" value="{{ old('mobile', $member->mobile) }}" class="em-input" placeholder="07X XXX XXXX">
                    </div>
                    <div class="em-field">
                        <label class="em-label" for="email">Email Address</label>
                        <input id="email" type="email" name="email" value="{{ old('email', $member->email) }}" class="em-input" placeholder="example@mail.com">
                    </div>
                </div>

                <div class="em-section">
                    <div class="em-section-icon">
                        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
                            <rect x="2" y="7" width="20" height="14" rx="2"/><path d="M16 7V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v2"/>
                        </svg>
                    </div>
                    <span class="em-section-title">Membership Details</span>
                    <div class="em-section-line"></div>
                </div>

                <div class="em-grid">
                    <div class="em-field">
                        <label class="em-label" for="membership_type">Membership Type</label>
                        <div class="em-select-wrap">
                            <select id="membership_type" name="membership_type" class="em-select">
                                @foreach($membershipTypes as $type)
                                    <option value="{{ $type }}" {{ $member->membership_type == $type ? 'selected' : '' }}>{{ $type }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="em-field">
                        <label class="em-label" for="package_type">Package Type</label>
                        <div class="em-select-wrap">
                            <select id="package_type" name="package_type" class="em-select">
                                @foreach($packageTypes as $type)
                                    <option value="{{ $type }}" {{ $member->package_type == $type ? 'selected' : '' }}>{{ $type }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="em-field full">
                        <label class="em-label" for="admission_fee">Admission Fee</label>
                        <div class="em-fee-wrap">
                            <span class="em-fee-prefix">Rs.</span>
                            <input id="admission_fee" type="number" name="admission_fee" value="{{ old('admission_fee', $member->admission_fee) }}" class="em-input">
                        </div>
                    </div>
                </div>

                <div class="em-actions">
                    <a href="javascript:history.back()" class="em-btn-cancel">← Cancel</a>
                    <button type="submit" class="em-btn-submit">
                        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                            <polyline points="20 6 9 17 4 12"/>
                        </svg>
                        <span>Save Changes</span>
                    </button>
                </div>

            </form>
        </div>
    </div>
</div>

<script>
    const prices = {
        'Male':   { '1 Month': 3500, '3 Months': 9000, '6 Months': 18000, '12 Months': 25000, 'Annual': 25000, 'Personal Training': 20000 },
        'Female': { '1 Month': 3000, '3 Months': 7500, '6 Months': 15000, '12 Months': 20000, 'Annual': 20000, 'Personal Training': 15000 },
        'Couple': { '1 Month': 6000, '3 Months': 15000, '6 Months': 25000, '12 Months': 35000, 'Annual': 35000 },
        'Family': { '1 Month': 8000, '3 Months': 20000, '6 Months': 30000, '12 Months': 50000, 'Annual': 50000 }
    };

    function updateFee() {
        const membership = document.getElementById('membership_type').value;
        const pkg = document.getElementById('package_type').value;
        const feeInput = document.getElementById('admission_fee');
        if (prices[membership] && prices[membership][pkg]) {
            feeInput.value = prices[membership][pkg];
            feeInput.classList.remove('fee-updated');
            void feeInput.offsetWidth;
            feeInput.classList.add('fee-updated');
        }
    }

    document.getElementById('package_type').addEventListener('change', updateFee);
    document.getElementById('membership_type').addEventListener('change', updateFee);
</script>

@endsection