#!/usr/bin/env bash
set -Eeuo pipefail

APP="${CGHG_APP:-/home/cghggujarat/laravel_apps/cghg_portal}"
OLD_WEB="${CGHG_OLD_WEB:-/home/cghggujarat/public_html/website}"
PHP82="/opt/cpanel/ea-php82/root/usr/bin/php"
[ -x "$PHP82" ] || PHP82="$(command -v php)"
OWNER="cghggujarat:cghggujarat"
STAMP="$(date +%Y%m%d-%H%M%S)"
BACKUP="$APP/_migration_backups/website-folder-v2-$STAMP"

say(){ printf '\n\033[1;36m%s\033[0m\n' "$1"; }
fail(){ printf '\n\033[1;31mERROR: %s\033[0m\n' "$1" >&2; exit 1; }

[ -d "$APP" ] || fail "Laravel app not found: $APP"
[ -f "$APP/routes/web.php" ] || fail "routes/web.php not found"
[ -f "$APP/artisan" ] || fail "artisan not found"
cd "$APP"

say "CGHG LARAVEL WEBSITE-FOLDER INSTALLER V2"
echo "Laravel app : $APP"
echo "Backup      : $BACKUP"
echo "Old website : $OLD_WEB"

if grep -q 'CGHG_WEBSITE_FOLDER_V2_START' routes/web.php; then
    fail "Website-folder V2 is already installed. Nothing changed."
fi

mkdir -p "$BACKUP"
/bin/cp -a routes/web.php "$BACKUP/web.php.before"
[ -d resources/views/website ] && /bin/cp -a resources/views/website "$BACKUP/website-views.before" || true
[ -d public/assets/website ] && /bin/cp -a public/assets/website "$BACKUP/website-assets.before" || true

cat > "$BACKUP/ROLLBACK.sh" <<ROLLBACK
#!/usr/bin/env bash
set -e
APP="$APP"
BACKUP="$BACKUP"
/bin/cp -af "\$BACKUP/web.php.before" "\$APP/routes/web.php"
rm -rf "\$APP/resources/views/website"
if [ -d "\$BACKUP/website-views.before" ]; then /bin/cp -a "\$BACKUP/website-views.before" "\$APP/resources/views/website"; fi
rm -rf "\$APP/public/assets/website"
if [ -d "\$BACKUP/website-assets.before" ]; then mkdir -p "\$APP/public/assets"; /bin/cp -a "\$BACKUP/website-assets.before" "\$APP/public/assets/website"; fi
chown -R cghggujarat:cghggujarat "\$APP/routes/web.php" "\$APP/resources/views" "\$APP/public/assets" 2>/dev/null || true
cd "\$APP"
runuser -u cghggujarat -- env HOME=/home/cghggujarat /opt/cpanel/ea-php82/root/usr/bin/php artisan optimize:clear || true
echo "ROLLBACK COMPLETE"
ROLLBACK
chmod 750 "$BACKUP/ROLLBACK.sh"

rollback_on_error(){
    code=$?
    echo
    echo "INSTALL FAILED - restoring previous files..."
    bash "$BACKUP/ROLLBACK.sh" || true
    exit "$code"
}
trap rollback_on_error ERR

say "1/6  Creating premium multi-page public website"
mkdir -p resources/views/website/partials public/assets/website
cat > resources/views/website/layout.blade.php <<'BLADE'
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="theme-color" content="#081d36">
    <meta name="robots" content="index,follow">
    <title>@yield('title', 'Commandant General Home Guards Gujarat')</title>
    <meta name="description" content="@yield('meta_description', 'Commandant General Home Guards Gujarat digital portal.')">
    <style>
        :root{
            --navy:#071a31;--navy2:#0b294b;--blue:#0e4d7c;--gold:#d6a756;--gold2:#f0d799;
            --ink:#102033;--muted:#607084;--paper:#f5f7fb;--white:#fff;--line:#dde5ef;
            --saffron:#ff8a32;--green:#158467;--shadow:0 22px 60px rgba(7,26,49,.13);
            --radius:22px;--max:1240px;
        }
        *{box-sizing:border-box}html{scroll-behavior:smooth}body{margin:0;background:var(--paper);color:var(--ink);font-family:Inter,"Noto Sans Gujarati","Nirmala UI",system-ui,-apple-system,"Segoe UI",sans-serif;line-height:1.65;-webkit-font-smoothing:antialiased}
        a{color:inherit;text-decoration:none}img{max-width:100%;display:block}.container{width:min(calc(100% - 36px),var(--max));margin:auto}
        .top-tricolor{height:4px;background:linear-gradient(90deg,var(--saffron) 0 33.33%,#fff 33.33% 66.66%,var(--green) 66.66%)}
        .utility{background:#06162a;color:#dce8f4;font-size:12px}.utility .container{min-height:34px;display:flex;align-items:center;justify-content:space-between;gap:16px}.utility-right{display:flex;gap:18px;align-items:center}.utility a{opacity:.9}.utility a:hover{opacity:1;color:#fff}
        .site-header{position:sticky;top:0;z-index:70;background:rgba(255,255,255,.94);backdrop-filter:blur(18px);border-bottom:1px solid rgba(17,41,70,.08)}
        .brand-row{min-height:82px;display:flex;align-items:center;justify-content:space-between;gap:28px}.brand{display:flex;align-items:center;gap:14px;min-width:0}.brand-logo{width:58px;height:58px;object-fit:contain;border-radius:14px;background:#fff;box-shadow:0 10px 30px rgba(5,29,56,.12);padding:4px}.brand-copy{min-width:0}.brand-copy strong{font-size:18px;color:var(--navy);display:block;line-height:1.15}.brand-copy span{display:block;color:#6c7886;font-size:12px;margin-top:5px}
        .main-nav{display:flex;align-items:center;gap:4px}.main-nav a{padding:10px 12px;border-radius:11px;font-size:13px;font-weight:700;color:#2b3b4e}.main-nav a:hover,.main-nav a.active{background:#edf3f9;color:var(--navy)}
        .login-btn{display:inline-flex!important;align-items:center;gap:8px!important;background:var(--navy)!important;color:#fff!important;padding:11px 16px!important;box-shadow:0 10px 24px rgba(7,26,49,.18)}.login-btn:hover{background:#0b2a4b!important;transform:translateY(-1px)}
        .nav-toggle{display:none;border:0;background:#eef3f8;width:44px;height:44px;border-radius:12px;font-size:22px;color:var(--navy);cursor:pointer}
        main{min-height:58vh}.hero{position:relative;overflow:hidden;background:radial-gradient(circle at 78% 22%,rgba(214,167,86,.22),transparent 28%),linear-gradient(135deg,#06162b 0%,#09294d 62%,#0b3959 100%);color:#fff;padding:86px 0 76px}.hero:before{content:"";position:absolute;inset:0;background-image:linear-gradient(rgba(255,255,255,.035) 1px,transparent 1px),linear-gradient(90deg,rgba(255,255,255,.035) 1px,transparent 1px);background-size:42px 42px;mask-image:linear-gradient(to bottom,#000,transparent 88%)}.hero:after{content:"";position:absolute;width:420px;height:420px;border:1px solid rgba(240,215,153,.22);border-radius:50%;right:-90px;top:-150px;box-shadow:0 0 0 42px rgba(240,215,153,.035),0 0 0 84px rgba(240,215,153,.025)}
        .hero-grid{position:relative;z-index:2;display:grid;grid-template-columns:1.25fr .75fr;gap:54px;align-items:center}.eyebrow{display:inline-flex;align-items:center;gap:9px;padding:7px 12px;border:1px solid rgba(255,255,255,.2);border-radius:999px;background:rgba(255,255,255,.07);font-size:11px;font-weight:800;letter-spacing:.12em;text-transform:uppercase}.eyebrow:before{content:"";width:7px;height:7px;border-radius:50%;background:var(--gold2);box-shadow:0 0 0 5px rgba(240,215,153,.12)}.hero h1{font-size:clamp(36px,5.4vw,68px);line-height:1.03;margin:20px 0 16px;letter-spacing:-.035em;max-width:820px}.hero h1 .guj{display:block;font-size:.55em;line-height:1.35;margin-top:13px;color:#f6e5b9;letter-spacing:0}.hero p{max-width:770px;color:#d6e2ef;font-size:17px;margin:0}.hero-actions{display:flex;flex-wrap:wrap;gap:12px;margin-top:28px}.btn{display:inline-flex;align-items:center;justify-content:center;gap:9px;min-height:48px;padding:0 19px;border-radius:13px;font-size:13px;font-weight:800;border:1px solid transparent;transition:.2s ease}.btn-primary{background:linear-gradient(135deg,#e4bd72,#c99643);color:#17202a;box-shadow:0 12px 30px rgba(214,167,86,.22)}.btn-primary:hover{transform:translateY(-2px);box-shadow:0 16px 34px rgba(214,167,86,.3)}.btn-ghost{border-color:rgba(255,255,255,.25);color:#fff;background:rgba(255,255,255,.06)}.btn-ghost:hover{background:rgba(255,255,255,.12)}
        .hero-card{background:rgba(255,255,255,.09);border:1px solid rgba(255,255,255,.14);border-radius:26px;padding:26px;backdrop-filter:blur(12px);box-shadow:0 30px 70px rgba(0,0,0,.18)}.hero-card-label{font-size:11px;letter-spacing:.15em;text-transform:uppercase;color:#f0d799;font-weight:800}.hero-logo-wrap{height:190px;margin:20px 0;display:grid;place-items:center}.hero-logo-wrap img{max-height:180px;max-width:210px;filter:drop-shadow(0 18px 26px rgba(0,0,0,.22));border-radius:22px}.hero-card .mini{border-top:1px solid rgba(255,255,255,.13);padding-top:16px;color:#d6e2ef;font-size:13px}
        .section{padding:76px 0}.section.white{background:#fff}.section.dark{background:#071a31;color:#fff}.section-head{display:flex;justify-content:space-between;gap:28px;align-items:end;margin-bottom:34px}.section-kicker{font-size:11px;letter-spacing:.14em;text-transform:uppercase;font-weight:900;color:#9b7536}.section.dark .section-kicker{color:#f0d799}.section-head h2{font-size:clamp(28px,4vw,44px);line-height:1.1;margin:6px 0 0;color:var(--navy);letter-spacing:-.025em}.section.dark .section-head h2{color:#fff}.section-head p{max-width:560px;margin:0;color:var(--muted)}.section.dark .section-head p{color:#b9cadb}
        .mission-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:16px}.mission-card{background:#fff;border:1px solid var(--line);border-radius:20px;padding:24px;min-height:160px;box-shadow:0 10px 34px rgba(11,42,75,.045);position:relative;overflow:hidden;transition:.25s ease}.mission-card:before{content:"";position:absolute;top:0;left:0;width:4px;height:100%;background:linear-gradient(var(--saffron),var(--green));opacity:.85}.mission-card:hover{transform:translateY(-5px);box-shadow:var(--shadow)}.mission-icon{width:42px;height:42px;border-radius:13px;background:#edf3f8;display:grid;place-items:center;color:var(--navy);font-weight:900;margin-bottom:18px}.mission-card h3{font-size:17px;margin:0 0 6px;color:var(--navy)}.mission-card p{font-size:13px;color:var(--muted);margin:0}
        .leaders-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:18px}.leader-card{background:#fff;border:1px solid var(--line);border-radius:22px;overflow:hidden;box-shadow:0 10px 35px rgba(7,26,49,.05);transition:.25s ease}.leader-card:hover{transform:translateY(-5px);box-shadow:var(--shadow)}.leader-photo{height:280px;background:linear-gradient(135deg,#edf3f8,#dfe8f1);position:relative;overflow:hidden;display:grid;place-items:center}.leader-photo:before{content:"";position:absolute;inset:auto -40px -90px auto;width:220px;height:220px;border-radius:50%;background:rgba(214,167,86,.16)}.leader-photo img{width:100%;height:100%;object-fit:cover;object-position:center top;position:relative;z-index:1}.leader-fallback{font-size:42px;font-weight:900;color:#8aa0b4;position:absolute;z-index:0}.leader-body{padding:20px}.leader-body h3{margin:0;color:var(--navy);font-size:18px}.leader-body p{margin:7px 0 0;color:var(--muted);font-size:13px}
        .access-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:16px}.access-card{background:#fff;border:1px solid var(--line);border-radius:20px;padding:22px;transition:.22s ease}.access-card:hover{border-color:#b9c8d9;transform:translateY(-4px);box-shadow:0 18px 40px rgba(7,26,49,.09)}.access-card .num{font-size:11px;color:#a07939;font-weight:900;letter-spacing:.12em}.access-card h3{margin:10px 0 6px;color:var(--navy);font-size:17px}.access-card p{margin:0;color:var(--muted);font-size:13px}.access-card .arrow{display:inline-flex;margin-top:18px;color:var(--navy);font-weight:900;font-size:13px}
        .app-panel{display:grid;grid-template-columns:1fr auto;gap:32px;align-items:center;background:linear-gradient(135deg,#fff,#f1f5fa);border:1px solid var(--line);border-radius:26px;padding:32px;box-shadow:var(--shadow)}.app-panel h3{font-size:26px;color:var(--navy);margin:0 0 8px}.app-panel p{margin:0;color:var(--muted)}
        .page-hero{background:linear-gradient(135deg,#071a31,#0a355c);color:#fff;padding:58px 0;position:relative;overflow:hidden}.page-hero:after{content:"";position:absolute;right:-60px;top:-110px;width:300px;height:300px;border:1px solid rgba(240,215,153,.25);border-radius:50%;box-shadow:0 0 0 42px rgba(255,255,255,.025)}.page-hero .container{position:relative;z-index:2}.page-hero .crumb{color:#bcd0e4;font-size:12px;margin-bottom:12px}.page-hero h1{margin:0;font-size:clamp(32px,4vw,48px);line-height:1.1}.page-hero p{color:#ccdae7;max-width:720px;margin:12px 0 0}
        .content-grid{display:grid;grid-template-columns:minmax(0,1fr) 310px;gap:28px}.content-card{background:#fff;border:1px solid var(--line);border-radius:22px;padding:30px;box-shadow:0 12px 36px rgba(7,26,49,.05)}.content-card h2{color:var(--navy);margin:0 0 12px;font-size:24px}.content-card h3{color:var(--navy);margin:28px 0 8px;font-size:18px}.content-card p{color:#47596d}.policy-section{padding:22px 0;border-bottom:1px solid var(--line)}.policy-section:first-child{padding-top:0}.policy-section:last-child{border-bottom:0;padding-bottom:0}.policy-section h2{font-size:20px;margin-bottom:8px}.policy-section p,.policy-section li{color:#47596d}.policy-note{background:#f7f1e5;border:1px solid #ead8b4;border-radius:15px;padding:16px;color:#6a552d;margin-top:18px}
        .side-card{background:#071a31;color:#fff;border-radius:22px;padding:24px;position:sticky;top:112px;height:max-content}.side-card h3{margin:0 0 12px}.side-card p{color:#bfd0e1;font-size:13px}.side-links{display:grid;gap:9px;margin-top:18px}.side-links a{padding:11px 12px;background:rgba(255,255,255,.07);border:1px solid rgba(255,255,255,.1);border-radius:12px;font-size:13px;font-weight:700}.side-links a:hover{background:rgba(255,255,255,.12)}
        .contact-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:18px}.contact-card{background:#fff;border:1px solid var(--line);border-radius:20px;padding:26px}.contact-card .label{font-size:11px;letter-spacing:.12em;color:#8f6c32;text-transform:uppercase;font-weight:900}.contact-card h3{font-size:20px;color:var(--navy);margin:8px 0 6px}.contact-card p{margin:0;color:var(--muted)}
        .manual-list{display:grid;gap:12px}.manual-item{display:flex;justify-content:space-between;align-items:center;gap:18px;background:#fff;border:1px solid var(--line);border-radius:16px;padding:18px 20px}.manual-item h3{font-size:16px;margin:0;color:var(--navy)}.manual-item p{font-size:12px;color:var(--muted);margin:4px 0 0}
        .partner-band{background:#fff;border-top:1px solid var(--line);padding:28px 0}.partners{display:grid;grid-template-columns:repeat(8,1fr);gap:14px;align-items:center}.partner{height:58px;border:1px solid #e5ebf2;border-radius:11px;display:grid;place-items:center;padding:7px;background:#fff}.partner img{max-height:42px;object-fit:contain}.site-footer{background:#06162a;color:#d5e1ed;padding:50px 0 22px}.footer-grid{display:grid;grid-template-columns:1.25fr .7fr .8fr;gap:42px}.footer-brand{display:flex;gap:13px;align-items:center}.footer-brand img{width:52px;height:52px;object-fit:contain;background:#fff;border-radius:12px;padding:4px}.footer-brand strong{display:block;color:#fff;font-size:17px}.footer-brand span{font-size:12px;color:#9fb3c8}.footer-copy{max-width:480px;color:#9fb3c8;font-size:13px;margin-top:14px}.footer-title{font-size:12px;text-transform:uppercase;letter-spacing:.12em;color:#f0d799;font-weight:900;margin-bottom:12px}.footer-links{display:grid;gap:8px}.footer-links a{font-size:13px;color:#c8d7e6}.footer-links a:hover{color:#fff}.footer-bottom{margin-top:38px;padding-top:18px;border-top:1px solid rgba(255,255,255,.1);display:flex;justify-content:space-between;gap:16px;color:#8fa5ba;font-size:12px}
        .reveal{opacity:0;transform:translateY(14px);transition:opacity .55s ease,transform .55s ease}.reveal.visible{opacity:1;transform:none}
        @media(max-width:1050px){.main-nav{position:fixed;left:18px;right:18px;top:105px;background:#fff;box-shadow:0 28px 60px rgba(7,26,49,.2);border:1px solid var(--line);padding:12px;border-radius:18px;display:none;flex-direction:column;align-items:stretch}.main-nav.open{display:flex}.main-nav a{padding:12px}.nav-toggle{display:block}.hero-grid{grid-template-columns:1fr}.hero-card{max-width:520px}.leaders-grid{grid-template-columns:repeat(2,1fr)}.access-grid{grid-template-columns:repeat(2,1fr)}.partners{grid-template-columns:repeat(4,1fr)}.content-grid{grid-template-columns:1fr}.side-card{position:relative;top:auto}.footer-grid{grid-template-columns:1fr 1fr}}
        @media(max-width:720px){.utility .container{min-height:30px}.utility-right span{display:none}.brand-row{min-height:72px}.brand-logo{width:48px;height:48px}.brand-copy strong{font-size:14px}.brand-copy span{font-size:10px}.main-nav{top:94px}.hero{padding:62px 0 54px}.hero-grid{gap:28px}.hero p{font-size:15px}.hero-card{padding:20px}.hero-logo-wrap{height:135px}.hero-logo-wrap img{max-height:130px}.section{padding:56px 0}.section-head{display:block}.section-head p{margin-top:12px}.mission-grid,.leaders-grid,.access-grid,.contact-grid{grid-template-columns:1fr}.leader-photo{height:330px}.app-panel{grid-template-columns:1fr;padding:24px}.partners{grid-template-columns:repeat(2,1fr)}.footer-grid{grid-template-columns:1fr}.footer-bottom{display:block}.footer-bottom span{display:block;margin-top:5px}.content-card{padding:22px}.page-hero{padding:44px 0}}
        @media(prefers-reduced-motion:reduce){*{scroll-behavior:auto!important;transition:none!important}.reveal{opacity:1;transform:none}}
    </style>
    @stack('head')
</head>
<body>
<div class="top-tricolor"></div>
<div class="utility">
    <div class="container">
        <span>Home Guards Gujarat · Digital Portal</span>
        <div class="utility-right">
            <span>For authorised departmental use</span>
            <a href="mailto:support@gujarathomeguard.gov.in">support@gujarathomeguard.gov.in</a>
        </div>
    </div>
</div>
<header class="site-header">
    <div class="container brand-row">
        <a href="{{ route('website.home') }}" class="brand" aria-label="Home">
            <img class="brand-logo" src="{{ asset('assets/website/logo.png') }}" alt="Home Guards Gujarat Logo">
            <div class="brand-copy">
                <strong>કમાન્ડન્ટ જનરલ હોમગાર્ડઝ ગુજરાત</strong>
                <span>Commandant General Home Guards Gujarat</span>
            </div>
        </a>
        <button class="nav-toggle" type="button" aria-label="Open navigation" aria-expanded="false">☰</button>
        <nav class="main-nav" aria-label="Main navigation">
            <a class="{{ request()->routeIs('website.home') ? 'active' : '' }}" href="{{ route('website.home') }}">Home</a>
            <a class="{{ request()->routeIs('website.about') ? 'active' : '' }}" href="{{ route('website.about') }}">About</a>
            <a class="{{ request()->routeIs('website.leadership') ? 'active' : '' }}" href="{{ route('website.leadership') }}">Leadership</a>
            <a class="{{ request()->routeIs('website.manuals') ? 'active' : '' }}" href="{{ route('website.manuals') }}">Manuals</a>
            <a class="{{ request()->routeIs('website.software') ? 'active' : '' }}" href="{{ route('website.software') }}">Software</a>
            <a class="{{ request()->routeIs('website.contact') ? 'active' : '' }}" href="{{ route('website.contact') }}">Contact</a>
            <a class="login-btn" href="{{ route('login') }}">Officer Login <span>→</span></a>
        </nav>
    </div>
</header>
<main>@yield('content')</main>
<div class="partner-band">
    <div class="container partners">
        @foreach([
            ['logo3_v1CEOOffice.jpg','Public Service'],['digiLocker_Small.jpg','DigiLocker'],['HomeCEO_15_7_2016.jpg','Citizen Services'],['bannerindiagovin.gif','India.gov.in'],
            ['logo_statueofunity.png','Statue of Unity'],['ek-ped-maa-ke-naam.jpg','Ek Ped Maa Ke Naam'],['swatchh_bharat.jpg','Swachh Bharat'],['digital-india.jpg','Digital India']
        ] as $partner)
            <div class="partner"><img src="{{ asset('assets/website/'.$partner[0]) }}" alt="{{ $partner[1] }}" loading="lazy" onerror="this.parentElement.style.display='none'"></div>
        @endforeach
    </div>
</div>
<footer class="site-footer">
    <div class="container">
        <div class="footer-grid">
            <div>
                <div class="footer-brand">
                    <img src="{{ asset('assets/website/logo.png') }}" alt="Home Guards Gujarat Logo">
                    <div><strong>Home Guards Gujarat</strong><span>Commandant General · Gujarat</span></div>
                </div>
                <p class="footer-copy">A digital access point for organisational information, official resources, policies and secure officer access.</p>
            </div>
            <div>
                <div class="footer-title">Quick Links</div>
                <div class="footer-links">
                    <a href="{{ route('website.about') }}">About Us</a><a href="{{ route('website.leadership') }}">Leadership</a><a href="{{ route('website.manuals') }}">Manuals & Guides</a><a href="{{ route('website.software') }}">Software Used</a><a href="{{ route('login') }}">Officer Login</a>
                </div>
            </div>
            <div>
                <div class="footer-title">Policies</div>
                <div class="footer-links">
                    <a href="{{ route('website.privacy') }}">Privacy Policy</a><a href="{{ route('website.terms') }}">Terms & Conditions</a><a href="{{ route('website.data-deletion') }}">Data Deletion Policy</a><a href="{{ route('website.contact') }}">Contact Us</a>
                </div>
            </div>
        </div>
        <div class="footer-bottom"><span>© 2025 Gujarat Home Guard Department · Designed for Official Use</span><span>Contact: support@gujarathomeguard.gov.in · Helpline: +91-12345-67890</span></div>
    </div>
</footer>
<script>
(()=>{const b=document.querySelector('.nav-toggle'),n=document.querySelector('.main-nav');if(b&&n){b.addEventListener('click',()=>{const o=n.classList.toggle('open');b.setAttribute('aria-expanded',o?'true':'false')});n.querySelectorAll('a').forEach(a=>a.addEventListener('click',()=>n.classList.remove('open')))}const els=document.querySelectorAll('.reveal');if(!('IntersectionObserver'in window)){els.forEach(e=>e.classList.add('visible'));return}const io=new IntersectionObserver(es=>es.forEach(x=>{if(x.isIntersecting){x.target.classList.add('visible');io.unobserve(x.target)}}),{threshold:.08});els.forEach(e=>io.observe(e))})();
</script>
@stack('scripts')
</body>
</html>

BLADE

cat > resources/views/website/home.blade.php <<'BLADE'
@extends('website.layout')
@section('title','Commandant General Home Guards Gujarat')
@section('meta_description','Home Guards Gujarat public information, leadership, policies, resources and secure officer access.')
@section('content')
<section class="hero">
    <div class="container hero-grid">
        <div>
            <span class="eyebrow">Home Guards Gujarat</span>
            <h1>Commandant General Home Guards Gujarat <span class="guj">કમાન્ડન્ટ જનરલ હોમગાર્ડઝ ગુજરાત</span></h1>
            <p>The Home Guards organization in Gujarat plays a vital role in maintaining peace, security, and assisting in disaster management. Our dedicated volunteers work alongside law enforcement to ensure community safety and support during emergencies.</p>
            <p style="margin-top:14px;color:#f0d799">ગુજરાતમાં હોમગાર્ડઝ સંસ્થા શાંતિ, સુરક્ષા અને આપત્તિ વ્યવસ્થાપનમાં મહત્વપૂર્ણ ભૂમિકા ભજવે છે. અમારા સમર્પિત સ્વયંસેવકો કાયદાના અમલીકરણ સાથે મળીને સામુદાયિક સુરક્ષા અને કટોકટી દરમિયાન મદદ પૂરી પાડવા માટે કાર્યરત છે.</p>
            <div class="hero-actions"><a class="btn btn-primary" href="{{ route('login') }}">Secure Officer Login →</a><a class="btn btn-ghost" href="{{ route('website.about') }}">Explore Organisation</a></div>
        </div>
        <aside class="hero-card reveal">
            <div class="hero-card-label">Official Digital Access</div>
            <div class="hero-logo-wrap"><img src="{{ asset('assets/website/logo.png') }}" alt="Home Guards Gujarat"></div>
            <div class="mini">Secure officer authentication continues through the existing Laravel officer portal.</div>
        </aside>
    </div>
</section>
<section class="section white">
    <div class="container">
        <div class="section-head"><div><div class="section-kicker">Our Mission</div><h2>અમારું મિશન</h2></div><p>Core operational areas presented on the existing Home Guards Gujarat public website.</p></div>
        <div class="mission-grid">
            @foreach([
                ['01','Community Safety & Security','Supporting a safer community through disciplined volunteer service.'],
                ['02','Disaster Management Support','Supporting coordination and response during emergency situations.'],
                ['03','Public Order Maintenance','Assisting authorised agencies in maintaining public order.'],
                ['04','Emergency Response','Preparedness and support for urgent public-safety requirements.'],
                ['05','Volunteer Training Programs','Building readiness through structured training and discipline.'],
                ['06','Law Enforcement Assistance','Supporting law-enforcement operations within authorised duties.']
            ] as $item)
                <article class="mission-card reveal"><div class="mission-icon">{{ $item[0] }}</div><h3>{{ $item[1] }}</h3><p>{{ $item[2] }}</p></article>
            @endforeach
        </div>
    </div>
</section>
<section class="section">
    <div class="container">
        <div class="section-head"><div><div class="section-kicker">Leadership</div><h2>Department Leadership</h2></div><p>Leadership information carried forward from the existing CGHG public website.</p></div>
        @include('website.partials.leadership-grid')
        <div style="margin-top:24px"><a class="btn" style="background:#071a31;color:#fff" href="{{ route('website.leadership') }}">View Leadership →</a></div>
    </div>
</section>
<section class="section white">
    <div class="container">
        <div class="section-head"><div><div class="section-kicker">Quick Access</div><h2>Information & Services</h2></div><p>Fast access to public information, policy documents and the secure officer portal.</p></div>
        <div class="access-grid">
            <a class="access-card reveal" href="{{ route('website.about') }}"><div class="num">01 · ORGANISATION</div><h3>About Us</h3><p>History, vision and mission of Home Guards Gujarat.</p><span class="arrow">Open →</span></a>
            <a class="access-card reveal" href="{{ route('website.manuals') }}"><div class="num">02 · RESOURCES</div><h3>Manuals & Guides</h3><p>Official digital resources and application access.</p><span class="arrow">Open →</span></a>
            <a class="access-card reveal" href="{{ route('website.contact') }}"><div class="num">03 · SUPPORT</div><h3>Contact Us</h3><p>Official support and technical contact information.</p><span class="arrow">Open →</span></a>
            <a class="access-card reveal" href="{{ route('login') }}"><div class="num">04 · SECURE ACCESS</div><h3>Officer Portal</h3><p>Continue to the existing role-based Laravel officer login.</p><span class="arrow">Login →</span></a>
        </div>
    </div>
</section>
<section class="section">
    <div class="container">
        <div class="app-panel reveal"><div><div class="section-kicker">Mobile Application</div><h3>GHMS Mobile Access</h3><p>Download the Home Guard mobile application package currently provided by the existing public website.</p></div><a class="btn btn-primary" href="{{ file_exists(public_path('assets/website/cghg.apk')) ? asset('assets/website/cghg.apk') : 'https://cghggujarat.in/website/cghg.apk' }}">Download App</a></div>
    </div>
</section>
@endsection

BLADE

cat > resources/views/website/about.blade.php <<'BLADE'
@extends('website.layout')
@section('title','About Us | Home Guards Gujarat')
@section('content')
<section class="page-hero"><div class="container"><div class="crumb">Home / About Us</div><h1>About Us / અમારા વિશે</h1><p>હોમગાર્ડઝ ગુજરાત સંગઠન વિશે જાણો</p></div></section>
<section class="section"><div class="container content-grid"><article class="content-card reveal"><h2>Our History / અમારો ઇતિહાસ</h2><p>ગુજરાતમાં હોમગાર્ડઝ સંગઠન કાયદો અને વ્યવસ્થા જાળવવા તથા રાજ્યમાં શાંતિ અને સુરક્ષા સુનિશ્ચિત કરવા માટે સહાયક સેવા પૂરી પાડવાના હેતુથી સ્થાપવામાં આવ્યું હતું. અમારા સ્વયંસેવકો વિવિધ આકસ્મિક પરિસ્થિતિઓમાં મદદરૂપ થવા માટે ખડેપગે તૈયાર હોય છે.</p><h3>Our Vision / અમારી દ્રષ્ટિ</h3><p>સમુદાયની ભાગીદારી, સ્વયંસેવક સેવા અને કાયદા અમલી એજન્સીઓને વ્યાવસાયિક સહકાર દ્વારા વધુ સુરક્ષિત અને સલામત ગુજરાતનું નિર્માણ કરવું.</p><h3>Our Mission / અમારું મિશન</h3><div class="manual-list">@foreach(['Community Safety & Security','Disaster Management Support','Public Order Maintenance','Emergency Response','Volunteer Training Programs','Law Enforcement Assistance'] as $m)<div class="manual-item"><div><h3>{{ $m }}</h3></div><span>✓</span></div>@endforeach</div></article><aside class="side-card"><h3>Secure Officer Access</h3><p>Department officers can continue using the existing role-based Laravel login and dashboards.</p><div class="side-links"><a href="{{ route('login') }}">Officer Login →</a><a href="{{ route('website.leadership') }}">Leadership</a><a href="{{ route('website.contact') }}">Contact</a></div></aside></div></section>
@endsection

BLADE

cat > resources/views/website/leadership.blade.php <<'BLADE'
@extends('website.layout')
@section('title','Leadership | Home Guards Gujarat')
@section('content')
<section class="page-hero"><div class="container"><div class="crumb">Home / Leadership</div><h1>Leadership</h1><p>Leadership information reproduced from the current Commandant General Home Guards Gujarat public website.</p></div></section>
<section class="section"><div class="container">@include('website.partials.leadership-grid')</div></section>
@endsection

BLADE

cat > resources/views/website/manuals.blade.php <<'BLADE'
@extends('website.layout')
@section('title','Manuals & Guides | Home Guards Gujarat')
@section('content')
<section class="page-hero"><div class="container"><div class="crumb">Home / Manuals & Guides</div><h1>Manuals & Guides</h1><p>Official digital resources and application access.</p></div></section>
<section class="section"><div class="container content-grid"><article class="content-card reveal"><h2>Resources</h2><p>The existing public website currently identifies this area for manual downloads but does not publish a manual list. This page is ready for official manuals and guides as they are made available.</p><div class="manual-list" style="margin-top:22px"><div class="manual-item"><div><h3>GHMS Mobile Application</h3><p>Current Android application package provided by the existing public website.</p></div><a class="btn" style="background:#071a31;color:#fff;min-height:42px" href="{{ file_exists(public_path('assets/website/cghg.apk')) ? asset('assets/website/cghg.apk') : 'https://cghggujarat.in/website/cghg.apk' }}">Download</a></div><div class="manual-item"><div><h3>Official Manuals</h3><p>Manual downloads will appear here when formally published.</p></div><span style="font-size:12px;color:#607084">Coming soon</span></div></div></article><aside class="side-card"><h3>Need secure access?</h3><p>Officer tools and operational modules remain behind the existing Laravel authentication.</p><div class="side-links"><a href="{{ route('login') }}">Officer Login →</a><a href="{{ route('website.contact') }}">Technical Support</a></div></aside></div></section>
@endsection

BLADE

cat > resources/views/website/software.blade.php <<'BLADE'
@extends('website.layout')
@section('title','Software Used | Home Guards Gujarat')
@section('content')
<section class="page-hero"><div class="container"><div class="crumb">Home / Software Used</div><h1>Software Used</h1><p>Public software information section carried forward from the existing website.</p></div></section>
<section class="section"><div class="container content-grid"><article class="content-card reveal"><h2>Software Used</h2><p>Software details will go here.</p></article><aside class="side-card"><h3>Secure Officer Access</h3><p>Authorised officers continue through the existing Laravel login system.</p><div class="side-links"><a href="{{ route('login') }}">Officer Login →</a><a href="{{ route('website.manuals') }}">Manuals & Guides</a><a href="{{ route('website.contact') }}">Contact</a></div></aside></div></section>
@endsection

BLADE

cat > resources/views/website/contact.blade.php <<'BLADE'
@extends('website.layout')
@section('title','Contact Us | Home Guards Gujarat')
@section('content')
<section class="page-hero"><div class="container"><div class="crumb">Home / Contact</div><h1>Contact Us / અમારો સંપર્ક કરો</h1><p>Official support and technical access information.</p></div></section>
<section class="section"><div class="container"><div class="contact-grid"><article class="contact-card reveal"><div class="label">Email Support</div><h3>support@gujarathomeguard.gov.in</h3><p>For application, privacy-policy and official support queries.</p><div style="margin-top:18px"><a class="btn" style="background:#071a31;color:#fff" href="mailto:support@gujarathomeguard.gov.in">Send Email</a></div></article><article class="contact-card reveal"><div class="label">Helpline</div><h3>+91-12345-67890</h3><p>Helpline currently displayed on the existing public website.</p><div style="margin-top:18px"><a class="btn" style="background:#071a31;color:#fff" href="tel:+911234567890">Call Helpline</a></div></article></div><div class="app-panel reveal" style="margin-top:20px"><div><div class="section-kicker">Officer Access</div><h3>Already authorised?</h3><p>Continue to the existing secure Laravel officer login. No duplicate login system is used on this public website.</p></div><a class="btn btn-primary" href="{{ route('login') }}">Officer Login →</a></div></div></section>
@endsection

BLADE

cat > resources/views/website/privacy.blade.php <<'BLADE'
@extends('website.layout')
@section('title','Privacy Policy | Home Guards Gujarat')
@section('content')
<section class="page-hero"><div class="container"><div class="crumb">Home / Privacy Policy</div><h1>Privacy Policy / ગોપનીયતા નીતિ</h1><p>Privacy information carried forward from the existing CGHG public website.</p></div></section>
<section class="section"><div class="container content-grid"><article class="content-card reveal"><div class="policy-section"><h2>1. Information Collection</h2><p>The Commandant General Home Guards (CGHG) Gujarat application may collect personal information such as Name, Badge/ID Number, Phone Number, Location data, and Camera access. This is strictly for official verification, attendance recording, and deployment purposes.</p></div><div class="policy-section"><h2>2. Use of Information</h2><p>Data collected is used exclusively for official government purposes, including personnel management, emergency response coordination, and communication within the Home Guards organization.</p></div><div class="policy-section"><h2>3. Data Sharing and Security</h2><p>We do not share, sell, or rent personal information to third parties. Data is only shared with authorized law enforcement or government entities when legally required. All data is securely stored on government-approved servers following standard security protocols.</p></div><div class="policy-section"><h2>4. Contact Us</h2><p>If you have any questions regarding this privacy policy, please contact us at <a href="mailto:support@gujarathomeguard.gov.in"><strong>support@gujarathomeguard.gov.in</strong></a>.</p></div></article><aside class="side-card"><h3>Policy Navigation</h3><div class="side-links"><a href="{{ route('website.privacy') }}">Privacy Policy</a><a href="{{ route('website.terms') }}">Terms & Conditions</a><a href="{{ route('website.data-deletion') }}">Data Deletion Policy</a></div></aside></div></section>
@endsection

BLADE

cat > resources/views/website/terms.blade.php <<'BLADE'
@extends('website.layout')
@section('title','Terms & Conditions | Home Guards Gujarat')
@section('content')
<section class="page-hero"><div class="container"><div class="crumb">Home / Terms & Conditions</div><h1>Terms & Conditions / નિયમો અને શરતો</h1><p>Terms carried forward from the existing CGHG public website.</p></div></section>
<section class="section"><div class="container content-grid"><article class="content-card reveal"><div class="policy-section"><h2>1. Acceptance of Terms</h2><p>By downloading and using the CGHG Gujarat app, you agree to comply with these terms. This application is intended strictly for authorized Home Guards personnel and official stakeholders of the Government of Gujarat.</p></div><div class="policy-section"><h2>2. User Responsibilities</h2><p>Users must provide accurate information and maintain the confidentiality of their login credentials. Misuse of the application, unauthorized access, or sharing of official sensitive data is strictly prohibited and will result in disciplinary and legal action.</p></div><div class="policy-section"><h2>3. Service Availability</h2><p>While we strive for maximum uptime, the Government of Gujarat is not liable for any downtime, technical issues, or data loss.</p></div></article><aside class="side-card"><h3>Policy Navigation</h3><div class="side-links"><a href="{{ route('website.privacy') }}">Privacy Policy</a><a href="{{ route('website.terms') }}">Terms & Conditions</a><a href="{{ route('website.data-deletion') }}">Data Deletion Policy</a></div></aside></div></section>
@endsection

BLADE

cat > resources/views/website/data-deletion.blade.php <<'BLADE'
@extends('website.layout')
@section('title','Data Deletion Policy | Home Guards Gujarat')
@section('content')
<section class="page-hero"><div class="container"><div class="crumb">Home / Data Deletion Policy</div><h1>Data Deletion Policy / ડેટા કાઢી નાખવાની નીતિ</h1><p>Data-deletion information carried forward from the existing CGHG public website.</p></div></section>
<section class="section"><div class="container content-grid"><article class="content-card reveal"><div class="policy-section"><h2>Account and Data Deletion Request</h2><p>As per Google Play Store policies, users have the right to request the deletion of their personal data. However, because this is an official government service application, complete data deletion is subject to official administrative and record-keeping regulations of the Gujarat Home Guards.</p></div><div class="policy-section"><h2>How to Request Data Deletion</h2><ul><li><strong>Method 1 (In-App):</strong> If available, navigate to your Profile -&gt; Settings -&gt; "Request Account Deletion".</li><li style="margin-top:10px"><strong>Method 2 (Email Request):</strong> Send an email from your registered email address to support@gujarathomeguard.gov.in with the subject line "Data Deletion Request - [Your Full Name & Badge Number]".</li></ul><div class="policy-note"><strong>Note:</strong> Upon receiving a deletion request, we will process it within 30 days. Data essential for administrative, legal, payment, or security purposes may be retained as per the Government of Gujarat's official data retention policies.</div></div></article><aside class="side-card"><h3>Policy Navigation</h3><div class="side-links"><a href="{{ route('website.privacy') }}">Privacy Policy</a><a href="{{ route('website.terms') }}">Terms & Conditions</a><a href="{{ route('website.data-deletion') }}">Data Deletion Policy</a></div></aside></div></section>
@endsection

BLADE

cat > resources/views/website/partials/leadership-grid.blade.php <<'BLADE'
@php
$leaders = [
    ['image'=>'amit-shah.jpg','name'=>'શ્રી અમિત શાહ','role'=>'માનનીય કેન્દ્રીય ગૃહ અને સહકારિતા મંત્રી','fallback'=>'AS'],
    ['image'=>'bhupendra-patel.png','name'=>'શ્રી ભુપેન્દ્ર પટેલ','role'=>'માનનીય મુખ્યમંત્રીશ્રી, ગુજરાત રાજ્ય','fallback'=>'BP'],
    ['image'=>'harsh-sanghavi.png','name'=>'શ્રી હર્ષ સંઘવી','role'=>'માનનીય નાયબ મુખ્યમંત્રીશ્રી ગૃહ વિભાગ','fallback'=>'HS'],
    ['image'=>'kamlesh-patel.jpg','name'=>'શ્રી કમલેશભાઈ પટેલ','role'=>'માનનીય રાજ્યકક્ષાના મંત્રીશ્રી, ગૃહ રક્ષક દળ','fallback'=>'KP'],
    ['image'=>'sanjiv-kumar.jpg','name'=>'શ્રી સંજીવ કુમાર (આઈ.એ.એસ.)','role'=>'અગ્ર સચિવશ્રી (ગૃહ વિભાગ) I/C','fallback'=>'SK'],
    ['image'=>'sp-rajkumar.jpg','name'=>'ડૉ. એસ. પી. રાજકુમાર (આઇ. પી. એસ.)','role'=>'કમાન્ડન્ટ જનરલશ્રી, હોમગાર્ડઝ','fallback'=>'SPR'],
];
@endphp
<div class="leaders-grid">
@foreach($leaders as $leader)
    <article class="leader-card reveal">
        <div class="leader-photo">
            <span class="leader-fallback">{{ $leader['fallback'] }}</span>
            <img src="{{ asset('assets/website/'.$leader['image']) }}" alt="{{ $leader['name'] }}" loading="lazy" onerror="this.style.display='none'">
        </div>
        <div class="leader-body"><h3>{{ $leader['name'] }}</h3><p>{{ $leader['role'] }}</p></div>
    </article>
@endforeach
</div>

BLADE

say "2/6  Adding isolated /website routes (existing root/login untouched)"
python3 - <<'PYROUTES'
from pathlib import Path
p = Path('routes/web.php')
s = p.read_text()
if 'CGHG_PUBLIC_WEBSITE_V1_START' in s:
    raise SystemExit('Older public-website V1 marker found in routes/web.php; rollback that version before installing V2.')
if 'CGHG_WEBSITE_FOLDER_V2_START' in s:
    raise SystemExit('Website-folder V2 marker already exists.')
block = r'''/* CGHG_WEBSITE_FOLDER_V2_START */
Route::prefix('website')->name('website.')->group(function () {
    Route::view('/', 'website.home')->name('home');
    Route::view('/about-us', 'website.about')->name('about');
    Route::view('/leadership', 'website.leadership')->name('leadership');
    Route::view('/manuals-guides', 'website.manuals')->name('manuals');
    Route::view('/software-used', 'website.software')->name('software');
    Route::view('/contact-us', 'website.contact')->name('contact');
    Route::view('/privacy-policy', 'website.privacy')->name('privacy');
    Route::view('/terms-and-conditions', 'website.terms')->name('terms');
    Route::view('/data-deletion-policy', 'website.data-deletion')->name('data-deletion');
    Route::view('/privacy-policy.php', 'website.privacy')->name('privacy.legacy');
    Route::view('/data-deletion.php', 'website.data-deletion')->name('data-deletion.legacy');
});
/* CGHG_WEBSITE_FOLDER_V2_END */'''
s = s.rstrip() + "\n\n" + block + "\n"
p.write_text(s)
print('WEBSITE_PREFIX_ROUTES=ADDED')
PYROUTES

say "3/6  Copying existing CGHG public assets"
copy_asset(){
    src="$1"; dst="$2"
    if [ -f "$OLD_WEB/$src" ]; then
        /bin/cp -af "$OLD_WEB/$src" "public/assets/website/$dst"
        echo "COPIED: $src -> $dst"
    else
        echo "SKIP (not found): $OLD_WEB/$src"
    fi
}
copy_asset "logo.png" "logo.png"
copy_asset "amit_shahjpg.jpg" "amit-shah.jpg"
copy_asset "cm.png" "bhupendra-patel.png"
copy_asset "harsh sangvi.png" "harsh-sanghavi.png"
copy_asset "KAMLESHBHAI.jpg" "kamlesh-patel.jpg"
copy_asset "sanjiv.jpg" "sanjiv-kumar.jpg"
copy_asset "ips.jpg" "sp-rajkumar.jpg"
copy_asset "cghg.apk" "cghg.apk"
copy_asset "logo3_v1CEOOffice.jpg" "logo3_v1CEOOffice.jpg"
copy_asset "digiLocker_Small.jpg" "digiLocker_Small.jpg"
copy_asset "HomeCEO_15_7_2016.jpg" "HomeCEO_15_7_2016.jpg"
copy_asset "bannerindiagovin.gif" "bannerindiagovin.gif"
copy_asset "logo_statueofunity.png" "logo_statueofunity.png"
copy_asset "ek-ped-maa-ke-naam.jpg" "ek-ped-maa-ke-naam.jpg"
copy_asset "swatchh_bharat.jpg" "swatchh_bharat.jpg"
copy_asset "digital-india.jpg" "digital-india.jpg"

say "4/6  Ownership and static validation"
chown -R "$OWNER" resources/views/website public/assets/website routes/web.php
"$PHP82" -l routes/web.php

grep -q "Route::prefix('website')->name('website.')" routes/web.php
grep -q "route('login')" resources/views/website/layout.blade.php
grep -q "route('login')" resources/views/website/home.blade.php

echo "WEBSITE_PREFIX=OK"
echo "EXISTING_OFFICER_LOGIN_LINK=OK"

say "5/6  Laravel validation"
runuser -u cghggujarat -- env HOME=/home/cghggujarat "$PHP82" artisan optimize:clear
runuser -u cghggujarat -- env HOME=/home/cghggujarat "$PHP82" artisan view:cache
runuser -u cghggujarat -- env HOME=/home/cghggujarat "$PHP82" artisan view:clear

echo
runuser -u cghggujarat -- env HOME=/home/cghggujarat "$PHP82" artisan route:list | grep -E 'website\.|officer/login' | head -40

say "6/6  Final integrity checks"
"$PHP82" artisan route:list --name=website.home >/dev/null
"$PHP82" artisan route:list --name=website.privacy >/dev/null
"$PHP82" artisan route:list --name=website.data-deletion >/dev/null
"$PHP82" artisan route:list --name=login >/dev/null
"$PHP82" artisan route:list --name=officer.login.role >/dev/null

echo "WEBSITE_HOME_ROUTE=OK"
echo "WEBSITE_POLICY_ROUTES=OK"
echo "EXISTING_LOGIN_ROUTE=OK"
echo "EXISTING_ROLE_LOGIN_ROUTE=OK"

APP_URL=$(grep -E '^APP_URL=' .env 2>/dev/null | tail -1 | cut -d= -f2- | tr -d '"' | sed 's#/$##' || true)
if [ -n "$APP_URL" ]; then
    WEBSITE_URL="$APP_URL/website"
    HTTP_CODE=$(curl -L -sS -o /tmp/cghg-website-v2.html -w "%{http_code}" "$WEBSITE_URL" 2>/dev/null || true)
    echo "WEBSITE_URL=$WEBSITE_URL"
    echo "WEBSITE_HTTP=${HTTP_CODE:-unavailable}"
    if [ "$HTTP_CODE" = "200" ] && grep -qi "Commandant General Home Guards Gujarat" /tmp/cghg-website-v2.html; then
        echo "WEBSITE_HTTP_SMOKE=OK"
    else
        echo "WEBSITE_HTTP_SMOKE=WARNING (route validation passed; review URL manually)"
    fi
fi

trap - ERR

cat <<DONE

============================================================
CGHG WEBSITE-FOLDER V2 INSTALLED SUCCESSFULLY
============================================================
Website route  : Laravel base URL /website
Officer login  : Existing /officer/login (unchanged)
Root route     : Unchanged
Backup         : $BACKUP
Rollback       : bash $BACKUP/ROLLBACK.sh

Pages installed:
- Home
- About Us
- Leadership
- Manuals & Guides
- Software Used
- Contact Us
- Privacy Policy
- Terms & Conditions
- Data Deletion Policy

Existing officer authentication, roles, dashboards and the current /public_html/website folder were not replaced.
============================================================
DONE
