<?php
//Developer: core tech web designTechnology
//Whatsapp: +2349162671360
//Telegram: @jeditech
include ('include/header.php');
$page_title = WEB_NAME . " | Country Flags Reference";

// Complete list of all countries with their flags
$countries = [
    // A
    ['code' => 'af', 'name' => 'Afghanistan',              'flag' => 'https://flagcdn.com/w160/af.png'],
    ['code' => 'al', 'name' => 'Albania',                  'flag' => 'https://flagcdn.com/w160/al.png'],
    ['code' => 'dz', 'name' => 'Algeria',                  'flag' => 'https://flagcdn.com/w160/dz.png'],
    ['code' => 'ad', 'name' => 'Andorra',                  'flag' => 'https://flagcdn.com/w160/ad.png'],
    ['code' => 'ao', 'name' => 'Angola',                   'flag' => 'https://flagcdn.com/w160/ao.png'],
    ['code' => 'ag', 'name' => 'Antigua and Barbuda',      'flag' => 'https://flagcdn.com/w160/ag.png'],
    ['code' => 'ar', 'name' => 'Argentina',                'flag' => 'https://flagcdn.com/w160/ar.png'],
    ['code' => 'am', 'name' => 'Armenia',                  'flag' => 'https://flagcdn.com/w160/am.png'],
    ['code' => 'au', 'name' => 'Australia',                'flag' => 'https://flagcdn.com/w160/au.png'],
    ['code' => 'at', 'name' => 'Austria',                  'flag' => 'https://flagcdn.com/w160/at.png'],
    ['code' => 'az', 'name' => 'Azerbaijan',               'flag' => 'https://flagcdn.com/w160/az.png'],
    // B
    ['code' => 'bs', 'name' => 'Bahamas',                  'flag' => 'https://flagcdn.com/w160/bs.png'],
    ['code' => 'bh', 'name' => 'Bahrain',                  'flag' => 'https://flagcdn.com/w160/bh.png'],
    ['code' => 'bd', 'name' => 'Bangladesh',               'flag' => 'https://flagcdn.com/w160/bd.png'],
    ['code' => 'bb', 'name' => 'Barbados',                 'flag' => 'https://flagcdn.com/w160/bb.png'],
    ['code' => 'by', 'name' => 'Belarus',                  'flag' => 'https://flagcdn.com/w160/by.png'],
    ['code' => 'be', 'name' => 'Belgium',                  'flag' => 'https://flagcdn.com/w160/be.png'],
    ['code' => 'bz', 'name' => 'Belize',                   'flag' => 'https://flagcdn.com/w160/bz.png'],
    ['code' => 'bj', 'name' => 'Benin',                    'flag' => 'https://flagcdn.com/w160/bj.png'],
    ['code' => 'bt', 'name' => 'Bhutan',                   'flag' => 'https://flagcdn.com/w160/bt.png'],
    ['code' => 'bo', 'name' => 'Bolivia',                  'flag' => 'https://flagcdn.com/w160/bo.png'],
    ['code' => 'ba', 'name' => 'Bosnia and Herzegovina',   'flag' => 'https://flagcdn.com/w160/ba.png'],
    ['code' => 'bw', 'name' => 'Botswana',                 'flag' => 'https://flagcdn.com/w160/bw.png'],
    ['code' => 'br', 'name' => 'Brazil',                   'flag' => 'https://flagcdn.com/w160/br.png'],
    ['code' => 'bn', 'name' => 'Brunei',                   'flag' => 'https://flagcdn.com/w160/bn.png'],
    ['code' => 'bg', 'name' => 'Bulgaria',                 'flag' => 'https://flagcdn.com/w160/bg.png'],
    ['code' => 'bf', 'name' => 'Burkina Faso',             'flag' => 'https://flagcdn.com/w160/bf.png'],
    ['code' => 'bi', 'name' => 'Burundi',                  'flag' => 'https://flagcdn.com/w160/bi.png'],
    // C
    ['code' => 'kh', 'name' => 'Cambodia',                 'flag' => 'https://flagcdn.com/w160/kh.png'],
    ['code' => 'cm', 'name' => 'Cameroon',                 'flag' => 'https://flagcdn.com/w160/cm.png'],
    ['code' => 'ca', 'name' => 'Canada',                   'flag' => 'https://flagcdn.com/w160/ca.png'],
    ['code' => 'cv', 'name' => 'Cape Verde',               'flag' => 'https://flagcdn.com/w160/cv.png'],
    ['code' => 'cf', 'name' => 'Central African Republic', 'flag' => 'https://flagcdn.com/w160/cf.png'],
    ['code' => 'td', 'name' => 'Chad',                     'flag' => 'https://flagcdn.com/w160/td.png'],
    ['code' => 'cl', 'name' => 'Chile',                    'flag' => 'https://flagcdn.com/w160/cl.png'],
    ['code' => 'cn', 'name' => 'China',                    'flag' => 'https://flagcdn.com/w160/cn.png'],
    ['code' => 'co', 'name' => 'Colombia',                 'flag' => 'https://flagcdn.com/w160/co.png'],
    ['code' => 'km', 'name' => 'Comoros',                  'flag' => 'https://flagcdn.com/w160/km.png'],
    ['code' => 'cg', 'name' => 'Congo',                    'flag' => 'https://flagcdn.com/w160/cg.png'],
    ['code' => 'cd', 'name' => 'Congo (DRC)',              'flag' => 'https://flagcdn.com/w160/cd.png'],
    ['code' => 'cr', 'name' => 'Costa Rica',               'flag' => 'https://flagcdn.com/w160/cr.png'],
    ['code' => 'ci', 'name' => "Côte d'Ivoire",            'flag' => 'https://flagcdn.com/w160/ci.png'],
    ['code' => 'hr', 'name' => 'Croatia',                  'flag' => 'https://flagcdn.com/w160/hr.png'],
    ['code' => 'cu', 'name' => 'Cuba',                     'flag' => 'https://flagcdn.com/w160/cu.png'],
    ['code' => 'cy', 'name' => 'Cyprus',                   'flag' => 'https://flagcdn.com/w160/cy.png'],
    ['code' => 'cz', 'name' => 'Czech Republic',           'flag' => 'https://flagcdn.com/w160/cz.png'],
    // D
    ['code' => 'dk', 'name' => 'Denmark',                  'flag' => 'https://flagcdn.com/w160/dk.png'],
    ['code' => 'dj', 'name' => 'Djibouti',                 'flag' => 'https://flagcdn.com/w160/dj.png'],
    ['code' => 'dm', 'name' => 'Dominica',                 'flag' => 'https://flagcdn.com/w160/dm.png'],
    ['code' => 'do', 'name' => 'Dominican Republic',       'flag' => 'https://flagcdn.com/w160/do.png'],
    // E
    ['code' => 'ec', 'name' => 'Ecuador',                  'flag' => 'https://flagcdn.com/w160/ec.png'],
    ['code' => 'eg', 'name' => 'Egypt',                    'flag' => 'https://flagcdn.com/w160/eg.png'],
    ['code' => 'sv', 'name' => 'El Salvador',              'flag' => 'https://flagcdn.com/w160/sv.png'],
    ['code' => 'gq', 'name' => 'Equatorial Guinea',        'flag' => 'https://flagcdn.com/w160/gq.png'],
    ['code' => 'er', 'name' => 'Eritrea',                  'flag' => 'https://flagcdn.com/w160/er.png'],
    ['code' => 'ee', 'name' => 'Estonia',                  'flag' => 'https://flagcdn.com/w160/ee.png'],
    ['code' => 'sz', 'name' => 'Eswatini',                 'flag' => 'https://flagcdn.com/w160/sz.png'],
    ['code' => 'et', 'name' => 'Ethiopia',                 'flag' => 'https://flagcdn.com/w160/et.png'],
    // F
    ['code' => 'fj', 'name' => 'Fiji',                     'flag' => 'https://flagcdn.com/w160/fj.png'],
    ['code' => 'fi', 'name' => 'Finland',                  'flag' => 'https://flagcdn.com/w160/fi.png'],
    ['code' => 'fr', 'name' => 'France',                   'flag' => 'https://flagcdn.com/w160/fr.png'],
    // G
    ['code' => 'ga', 'name' => 'Gabon',                    'flag' => 'https://flagcdn.com/w160/ga.png'],
    ['code' => 'gm', 'name' => 'Gambia',                   'flag' => 'https://flagcdn.com/w160/gm.png'],
    ['code' => 'ge', 'name' => 'Georgia',                  'flag' => 'https://flagcdn.com/w160/ge.png'],
    ['code' => 'de', 'name' => 'Germany',                  'flag' => 'https://flagcdn.com/w160/de.png'],
    ['code' => 'gh', 'name' => 'Ghana',                    'flag' => 'https://flagcdn.com/w160/gh.png'],
    ['code' => 'gr', 'name' => 'Greece',                   'flag' => 'https://flagcdn.com/w160/gr.png'],
    ['code' => 'gd', 'name' => 'Grenada',                  'flag' => 'https://flagcdn.com/w160/gd.png'],
    ['code' => 'gt', 'name' => 'Guatemala',                'flag' => 'https://flagcdn.com/w160/gt.png'],
    ['code' => 'gn', 'name' => 'Guinea',                   'flag' => 'https://flagcdn.com/w160/gn.png'],
    ['code' => 'gw', 'name' => 'Guinea-Bissau',            'flag' => 'https://flagcdn.com/w160/gw.png'],
    ['code' => 'gy', 'name' => 'Guyana',                   'flag' => 'https://flagcdn.com/w160/gy.png'],
    // H
    ['code' => 'ht', 'name' => 'Haiti',                    'flag' => 'https://flagcdn.com/w160/ht.png'],
    ['code' => 'hn', 'name' => 'Honduras',                 'flag' => 'https://flagcdn.com/w160/hn.png'],
    ['code' => 'hk', 'name' => 'Hong Kong',                'flag' => 'https://flagcdn.com/w160/hk.png'],
    ['code' => 'hu', 'name' => 'Hungary',                  'flag' => 'https://flagcdn.com/w160/hu.png'],
    // I
    ['code' => 'is', 'name' => 'Iceland',                  'flag' => 'https://flagcdn.com/w160/is.png'],
    ['code' => 'in', 'name' => 'India',                    'flag' => 'https://flagcdn.com/w160/in.png'],
    ['code' => 'id', 'name' => 'Indonesia',                'flag' => 'https://flagcdn.com/w160/id.png'],
    ['code' => 'ir', 'name' => 'Iran',                     'flag' => 'https://flagcdn.com/w160/ir.png'],
    ['code' => 'iq', 'name' => 'Iraq',                     'flag' => 'https://flagcdn.com/w160/iq.png'],
    ['code' => 'ie', 'name' => 'Ireland',                  'flag' => 'https://flagcdn.com/w160/ie.png'],
    ['code' => 'il', 'name' => 'Israel',                   'flag' => 'https://flagcdn.com/w160/il.png'],
    ['code' => 'it', 'name' => 'Italy',                    'flag' => 'https://flagcdn.com/w160/it.png'],
    // J
    ['code' => 'jm', 'name' => 'Jamaica',                  'flag' => 'https://flagcdn.com/w160/jm.png'],
    ['code' => 'jp', 'name' => 'Japan',                    'flag' => 'https://flagcdn.com/w160/jp.png'],
    ['code' => 'jo', 'name' => 'Jordan',                   'flag' => 'https://flagcdn.com/w160/jo.png'],
    // K
    ['code' => 'kz', 'name' => 'Kazakhstan',               'flag' => 'https://flagcdn.com/w160/kz.png'],
    ['code' => 'ke', 'name' => 'Kenya',                    'flag' => 'https://flagcdn.com/w160/ke.png'],
    ['code' => 'ki', 'name' => 'Kiribati',                 'flag' => 'https://flagcdn.com/w160/ki.png'],
    ['code' => 'kp', 'name' => 'North Korea',              'flag' => 'https://flagcdn.com/w160/kp.png'],
    ['code' => 'kr', 'name' => 'South Korea',              'flag' => 'https://flagcdn.com/w160/kr.png'],
    ['code' => 'kw', 'name' => 'Kuwait',                   'flag' => 'https://flagcdn.com/w160/kw.png'],
    ['code' => 'kg', 'name' => 'Kyrgyzstan',               'flag' => 'https://flagcdn.com/w160/kg.png'],
    // L
    ['code' => 'la', 'name' => 'Laos',                     'flag' => 'https://flagcdn.com/w160/la.png'],
    ['code' => 'lv', 'name' => 'Latvia',                   'flag' => 'https://flagcdn.com/w160/lv.png'],
    ['code' => 'lb', 'name' => 'Lebanon',                  'flag' => 'https://flagcdn.com/w160/lb.png'],
    ['code' => 'ls', 'name' => 'Lesotho',                  'flag' => 'https://flagcdn.com/w160/ls.png'],
    ['code' => 'lr', 'name' => 'Liberia',                  'flag' => 'https://flagcdn.com/w160/lr.png'],
    ['code' => 'ly', 'name' => 'Libya',                    'flag' => 'https://flagcdn.com/w160/ly.png'],
    ['code' => 'li', 'name' => 'Liechtenstein',            'flag' => 'https://flagcdn.com/w160/li.png'],
    ['code' => 'lt', 'name' => 'Lithuania',                'flag' => 'https://flagcdn.com/w160/lt.png'],
    ['code' => 'lu', 'name' => 'Luxembourg',               'flag' => 'https://flagcdn.com/w160/lu.png'],
    // M
    ['code' => 'mo', 'name' => 'Macau',                    'flag' => 'https://flagcdn.com/w160/mo.png'],
    ['code' => 'mg', 'name' => 'Madagascar',               'flag' => 'https://flagcdn.com/w160/mg.png'],
    ['code' => 'mw', 'name' => 'Malawi',                   'flag' => 'https://flagcdn.com/w160/mw.png'],
    ['code' => 'my', 'name' => 'Malaysia',                 'flag' => 'https://flagcdn.com/w160/my.png'],
    ['code' => 'mv', 'name' => 'Maldives',                 'flag' => 'https://flagcdn.com/w160/mv.png'],
    ['code' => 'ml', 'name' => 'Mali',                     'flag' => 'https://flagcdn.com/w160/ml.png'],
    ['code' => 'mt', 'name' => 'Malta',                    'flag' => 'https://flagcdn.com/w160/mt.png'],
    ['code' => 'mh', 'name' => 'Marshall Islands',         'flag' => 'https://flagcdn.com/w160/mh.png'],
    ['code' => 'mr', 'name' => 'Mauritania',               'flag' => 'https://flagcdn.com/w160/mr.png'],
    ['code' => 'mu', 'name' => 'Mauritius',                'flag' => 'https://flagcdn.com/w160/mu.png'],
    ['code' => 'mx', 'name' => 'Mexico',                   'flag' => 'https://flagcdn.com/w160/mx.png'],
    ['code' => 'fm', 'name' => 'Micronesia',               'flag' => 'https://flagcdn.com/w160/fm.png'],
    ['code' => 'md', 'name' => 'Moldova',                  'flag' => 'https://flagcdn.com/w160/md.png'],
    ['code' => 'mc', 'name' => 'Monaco',                   'flag' => 'https://flagcdn.com/w160/mc.png'],
    ['code' => 'mn', 'name' => 'Mongolia',                 'flag' => 'https://flagcdn.com/w160/mn.png'],
    ['code' => 'me', 'name' => 'Montenegro',               'flag' => 'https://flagcdn.com/w160/me.png'],
    ['code' => 'ma', 'name' => 'Morocco',                  'flag' => 'https://flagcdn.com/w160/ma.png'],
    ['code' => 'mz', 'name' => 'Mozambique',               'flag' => 'https://flagcdn.com/w160/mz.png'],
    ['code' => 'mm', 'name' => 'Myanmar',                  'flag' => 'https://flagcdn.com/w160/mm.png'],
    // N
    ['code' => 'na', 'name' => 'Namibia',                  'flag' => 'https://flagcdn.com/w160/na.png'],
    ['code' => 'nr', 'name' => 'Nauru',                    'flag' => 'https://flagcdn.com/w160/nr.png'],
    ['code' => 'np', 'name' => 'Nepal',                    'flag' => 'https://flagcdn.com/w160/np.png'],
    ['code' => 'nl', 'name' => 'Netherlands',              'flag' => 'https://flagcdn.com/w160/nl.png'],
    ['code' => 'nz', 'name' => 'New Zealand',              'flag' => 'https://flagcdn.com/w160/nz.png'],
    ['code' => 'ni', 'name' => 'Nicaragua',                'flag' => 'https://flagcdn.com/w160/ni.png'],
    ['code' => 'ne', 'name' => 'Niger',                    'flag' => 'https://flagcdn.com/w160/ne.png'],
    ['code' => 'ng', 'name' => 'Nigeria',                  'flag' => 'https://flagcdn.com/w160/ng.png'],
    ['code' => 'mk', 'name' => 'North Macedonia',          'flag' => 'https://flagcdn.com/w160/mk.png'],
    ['code' => 'no', 'name' => 'Norway',                   'flag' => 'https://flagcdn.com/w160/no.png'],
    // O
    ['code' => 'om', 'name' => 'Oman',                     'flag' => 'https://flagcdn.com/w160/om.png'],
    // P
    ['code' => 'pk', 'name' => 'Pakistan',                 'flag' => 'https://flagcdn.com/w160/pk.png'],
    ['code' => 'pw', 'name' => 'Palau',                    'flag' => 'https://flagcdn.com/w160/pw.png'],
    ['code' => 'ps', 'name' => 'Palestine',                'flag' => 'https://flagcdn.com/w160/ps.png'],
    ['code' => 'pa', 'name' => 'Panama',                   'flag' => 'https://flagcdn.com/w160/pa.png'],
    ['code' => 'pg', 'name' => 'Papua New Guinea',         'flag' => 'https://flagcdn.com/w160/pg.png'],
    ['code' => 'py', 'name' => 'Paraguay',                 'flag' => 'https://flagcdn.com/w160/py.png'],
    ['code' => 'pe', 'name' => 'Peru',                     'flag' => 'https://flagcdn.com/w160/pe.png'],
    ['code' => 'ph', 'name' => 'Philippines',              'flag' => 'https://flagcdn.com/w160/ph.png'],
    ['code' => 'pl', 'name' => 'Poland',                   'flag' => 'https://flagcdn.com/w160/pl.png'],
    ['code' => 'pt', 'name' => 'Portugal',                 'flag' => 'https://flagcdn.com/w160/pt.png'],
    ['code' => 'pr', 'name' => 'Puerto Rico',              'flag' => 'https://flagcdn.com/w160/pr.png'],
    // Q
    ['code' => 'qa', 'name' => 'Qatar',                    'flag' => 'https://flagcdn.com/w160/qa.png'],
    // R
    ['code' => 'ro', 'name' => 'Romania',                  'flag' => 'https://flagcdn.com/w160/ro.png'],
    ['code' => 'ru', 'name' => 'Russia',                   'flag' => 'https://flagcdn.com/w160/ru.png'],
    ['code' => 'rw', 'name' => 'Rwanda',                   'flag' => 'https://flagcdn.com/w160/rw.png'],
    // S
    ['code' => 'kn', 'name' => 'Saint Kitts and Nevis',            'flag' => 'https://flagcdn.com/w160/kn.png'],
    ['code' => 'lc', 'name' => 'Saint Lucia',                      'flag' => 'https://flagcdn.com/w160/lc.png'],
    ['code' => 'vc', 'name' => 'Saint Vincent and the Grenadines', 'flag' => 'https://flagcdn.com/w160/vc.png'],
    ['code' => 'ws', 'name' => 'Samoa',                            'flag' => 'https://flagcdn.com/w160/ws.png'],
    ['code' => 'sm', 'name' => 'San Marino',                       'flag' => 'https://flagcdn.com/w160/sm.png'],
    ['code' => 'st', 'name' => 'Sao Tome and Principe',            'flag' => 'https://flagcdn.com/w160/st.png'],
    ['code' => 'sa', 'name' => 'Saudi Arabia',                     'flag' => 'https://flagcdn.com/w160/sa.png'],
    ['code' => 'sn', 'name' => 'Senegal',                          'flag' => 'https://flagcdn.com/w160/sn.png'],
    ['code' => 'rs', 'name' => 'Serbia',                           'flag' => 'https://flagcdn.com/w160/rs.png'],
    ['code' => 'sc', 'name' => 'Seychelles',                       'flag' => 'https://flagcdn.com/w160/sc.png'],
    ['code' => 'sl', 'name' => 'Sierra Leone',                     'flag' => 'https://flagcdn.com/w160/sl.png'],
    ['code' => 'sg', 'name' => 'Singapore',                        'flag' => 'https://flagcdn.com/w160/sg.png'],
    ['code' => 'sk', 'name' => 'Slovakia',                         'flag' => 'https://flagcdn.com/w160/sk.png'],
    ['code' => 'si', 'name' => 'Slovenia',                         'flag' => 'https://flagcdn.com/w160/si.png'],
    ['code' => 'sb', 'name' => 'Solomon Islands',                  'flag' => 'https://flagcdn.com/w160/sb.png'],
    ['code' => 'so', 'name' => 'Somalia',                          'flag' => 'https://flagcdn.com/w160/so.png'],
    ['code' => 'za', 'name' => 'South Africa',                     'flag' => 'https://flagcdn.com/w160/za.png'],
    ['code' => 'ss', 'name' => 'South Sudan',                      'flag' => 'https://flagcdn.com/w160/ss.png'],
    ['code' => 'es', 'name' => 'Spain',                            'flag' => 'https://flagcdn.com/w160/es.png'],
    ['code' => 'lk', 'name' => 'Sri Lanka',                        'flag' => 'https://flagcdn.com/w160/lk.png'],
    ['code' => 'sd', 'name' => 'Sudan',                            'flag' => 'https://flagcdn.com/w160/sd.png'],
    ['code' => 'sr', 'name' => 'Suriname',                         'flag' => 'https://flagcdn.com/w160/sr.png'],
    ['code' => 'se', 'name' => 'Sweden',                           'flag' => 'https://flagcdn.com/w160/se.png'],
    ['code' => 'ch', 'name' => 'Switzerland',                      'flag' => 'https://flagcdn.com/w160/ch.png'],
    ['code' => 'sy', 'name' => 'Syria',                            'flag' => 'https://flagcdn.com/w160/sy.png'],
    // T
    ['code' => 'tw', 'name' => 'Taiwan',                   'flag' => 'https://flagcdn.com/w160/tw.png'],
    ['code' => 'tj', 'name' => 'Tajikistan',               'flag' => 'https://flagcdn.com/w160/tj.png'],
    ['code' => 'tz', 'name' => 'Tanzania',                 'flag' => 'https://flagcdn.com/w160/tz.png'],
    ['code' => 'th', 'name' => 'Thailand',                 'flag' => 'https://flagcdn.com/w160/th.png'],
    ['code' => 'tl', 'name' => 'Timor-Leste',              'flag' => 'https://flagcdn.com/w160/tl.png'],
    ['code' => 'tg', 'name' => 'Togo',                     'flag' => 'https://flagcdn.com/w160/tg.png'],
    ['code' => 'to', 'name' => 'Tonga',                    'flag' => 'https://flagcdn.com/w160/to.png'],
    ['code' => 'tt', 'name' => 'Trinidad and Tobago',      'flag' => 'https://flagcdn.com/w160/tt.png'],
    ['code' => 'tn', 'name' => 'Tunisia',                  'flag' => 'https://flagcdn.com/w160/tn.png'],
    ['code' => 'tr', 'name' => 'Turkey',                   'flag' => 'https://flagcdn.com/w160/tr.png'],
    ['code' => 'tm', 'name' => 'Turkmenistan',             'flag' => 'https://flagcdn.com/w160/tm.png'],
    ['code' => 'tv', 'name' => 'Tuvalu',                   'flag' => 'https://flagcdn.com/w160/tv.png'],
    // U
    ['code' => 'ug', 'name' => 'Uganda',                   'flag' => 'https://flagcdn.com/w160/ug.png'],
    ['code' => 'ua', 'name' => 'Ukraine',                  'flag' => 'https://flagcdn.com/w160/ua.png'],
    ['code' => 'ae', 'name' => 'United Arab Emirates',     'flag' => 'https://flagcdn.com/w160/ae.png'],
    ['code' => 'gb', 'name' => 'United Kingdom',           'flag' => 'https://flagcdn.com/w160/gb.png'],
    ['code' => 'us', 'name' => 'United States',            'flag' => 'https://flagcdn.com/w160/us.png'],
    ['code' => 'uy', 'name' => 'Uruguay',                  'flag' => 'https://flagcdn.com/w160/uy.png'],
    ['code' => 'uz', 'name' => 'Uzbekistan',               'flag' => 'https://flagcdn.com/w160/uz.png'],
    // V
    ['code' => 'vu', 'name' => 'Vanuatu',                  'flag' => 'https://flagcdn.com/w160/vu.png'],
    ['code' => 'va', 'name' => 'Vatican City',             'flag' => 'https://flagcdn.com/w160/va.png'],
    ['code' => 've', 'name' => 'Venezuela',                'flag' => 'https://flagcdn.com/w160/ve.png'],
    ['code' => 'vn', 'name' => 'Vietnam',                  'flag' => 'https://flagcdn.com/w160/vn.png'],
    // Y
    ['code' => 'ye', 'name' => 'Yemen',                    'flag' => 'https://flagcdn.com/w160/ye.png'],
    // Z
    ['code' => 'zm', 'name' => 'Zambia',                   'flag' => 'https://flagcdn.com/w160/zm.png'],
    ['code' => 'zw', 'name' => 'Zimbabwe',                 'flag' => 'https://flagcdn.com/w160/zw.png'],
];

// Sort alphabetically
usort($countries, function($a, $b) { return strcmp($a['name'], $b['name']); });
?>
  <title>Country Flags Reference - <?php echo $site_data['web_name']; ?></title>

  <!-- Container Fluid-->
  <div class="container-fluid" id="container-wrapper">
    <div class="d-sm-flex align-items-center justify-content-between mb-4">
      <h1 class="h3 mb-0 text-gray-800">Country Flags Reference</h1>
      <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="dashboard.php">Home</a></li>
        <li class="breadcrumb-item"><a href="countries.php">Countries</a></li>
        <li class="breadcrumb-item active" aria-current="page">Flag Reference</li>
      </ol>
    </div>

    <div class="row">
      <div class="col-lg-12">
        <div class="card mb-4">
          <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
            <h6 class="m-0 font-weight-bold text-primary">
              <i class="fas fa-flag mr-2"></i>Country Flags Reference
              <span class="badge badge-primary ml-2"><?php echo count($countries); ?> countries</span>
            </h6>
            <a href="countries.php" class="btn btn-sm btn-secondary">
              <i class="fas fa-arrow-left mr-1"></i> Back to Countries
            </a>
          </div>
          <div class="card-body">
            <div class="alert alert-info mb-3">
              <i class="fas fa-info-circle mr-2"></i>
              Click <strong>Copy URL</strong> on any flag card to copy its image URL to your clipboard. You can then paste it when adding or editing a country.
            </div>

            <!-- Search -->
            <div class="mb-4">
              <input type="text" id="searchCountry" class="form-control form-control-lg"
                     placeholder="🔍 Search country by name..." onkeyup="filterCountries()">
            </div>

            <!-- Flag Grid -->
            <div class="flag-grid" id="flagGrid">
              <?php foreach ($countries as $country): ?>
              <div class="flag-card" data-name="<?php echo strtolower($country['name']); ?>">
                <img src="<?php echo $country['flag']; ?>"
                     alt="<?php echo htmlspecialchars($country['name']); ?>"
                     class="flag-grid-img" loading="lazy"
                     onerror="this.style.opacity='0.2'">
                <div class="flag-card-name"><?php echo htmlspecialchars($country['name']); ?></div>
                <div class="flag-card-url"><?php echo $country['flag']; ?></div>
                <button class="btn btn-primary btn-sm btn-block mt-2"
                        onclick="copyFlagUrl('<?php echo $country['flag']; ?>', '<?php echo addslashes($country['name']); ?>')">
                  <i class="fas fa-copy mr-1"></i> Copy URL
                </button>
              </div>
              <?php endforeach; ?>
            </div>

            <!-- No results message -->
            <div id="noResults" class="text-center py-5 d-none">
              <i class="fas fa-search fa-3x text-muted mb-3"></i>
              <p class="text-muted">No countries matched your search.</p>
            </div>

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

  </div>
  <!-- End Container Fluid -->

  <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

  <script>
    function copyFlagUrl(url, countryName) {
      // Modern clipboard API with fallback
      if (navigator.clipboard && window.isSecureContext) {
        navigator.clipboard.writeText(url).then(function () {
          showCopied(countryName);
        }).catch(function () {
          fallbackCopy(url, countryName);
        });
      } else {
        fallbackCopy(url, countryName);
      }
    }

    function fallbackCopy(url, countryName) {
      var el = document.createElement('textarea');
      el.value = url;
      el.style.position = 'fixed';
      el.style.left = '-9999px';
      document.body.appendChild(el);
      el.focus();
      el.select();
      try {
        document.execCommand('copy');
        showCopied(countryName);
      } catch (err) {
        Swal.fire('Error', 'Could not copy to clipboard. Please copy manually:\n' + url, 'error');
      }
      document.body.removeChild(el);
    }

    function showCopied(countryName) {
      Swal.fire({
        title: 'Copied!',
        text: countryName + ' flag URL copied to clipboard.',
        icon: 'success',
        timer: 2000,
        showConfirmButton: false,
        toast: true,
        position: 'top-end'
      });
    }

    function filterCountries() {
      var filter = document.getElementById('searchCountry').value.toLowerCase().trim();
      var cards   = document.querySelectorAll('#flagGrid .flag-card');
      var visible = 0;

      cards.forEach(function (card) {
        var name = card.getAttribute('data-name');
        if (name.indexOf(filter) > -1) {
          card.style.display = '';
          visible++;
        } else {
          card.style.display = 'none';
        }
      });

      document.getElementById('noResults').classList.toggle('d-none', visible > 0);
    }
  </script>

  <style>
    .flag-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
      gap: 1rem;
      padding: 0.5rem 0;
    }
    .flag-card {
      background: #fff;
      border: 2px solid #e3e6f0;
      border-radius: 10px;
      padding: 1rem;
      transition: all 0.25s ease;
      cursor: default;
    }
    .flag-card:hover {
      border-color: #4e73df;
      box-shadow: 0 6px 14px rgba(78, 115, 223, 0.15);
      transform: translateY(-3px);
    }
    .flag-grid-img {
      width: 100%;
      height: 90px;
      object-fit: contain;
      background: #f8f9fc;
      border-radius: 6px;
      padding: 4px;
      margin-bottom: 0.6rem;
    }
    .flag-card-name {
      font-weight: 600;
      font-size: 0.875rem;
      color: #3a3b45;
      margin-bottom: 0.35rem;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .flag-card-url {
      font-size: 0.7rem;
      color: #858796;
      word-break: break-all;
      background: #f8f9fc;
      padding: 4px 6px;
      border-radius: 4px;
      margin-bottom: 0.5rem;
      font-family: 'Courier New', monospace;
    }
    @media (max-width: 576px) {
      .flag-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    }
  </style>

<?php include ('include/footer.php'); ?>