(()=>{var e={};e.id=6763,e.ids=[6763],e.modules={3295:e=>{"use strict";e.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},3498:e=>{"use strict";e.exports=require("mysql2/promise")},5069:(e,s,t)=>{"use strict";let T;t.d(s,{A:()=>u});var r=t(3498),a=t.n(r),i=t(29021),E=t.n(i),n=t(33873),o=t.n(n);try{T=t(46293)}catch(e){console.warn("sql.js not installed or failed to load")}let l=null,c=null;try{l=a().createPool({host:process.env.DB_HOST||"localhost",port:Number(process.env.DB_PORT)||3306,user:process.env.DB_USER||"root",password:process.env.DB_PASSWORD||"",database:process.env.DB_NAME||"mobile_insights",charset:"utf8mb4",waitForConnections:!0,connectionLimit:10,connectTimeout:1e3})}catch(e){console.warn("MySQL pool creation failed, using SQLite fallback:",e)}async function d(){if(c)return c;if(!T)throw Error("sql.js is not available");console.log("Initializing in-memory SQLite database...");let e=new(await T()).Database;for(let s of[`CREATE TABLE IF NOT EXISTS brands (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT NOT NULL UNIQUE,
      gsmarena_url TEXT NOT NULL,
      device_count INTEGER DEFAULT 0,
      scraped_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    )`,`CREATE TABLE IF NOT EXISTS devices (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      brand_id INTEGER NOT NULL,
      name TEXT NOT NULL,
      gsmarena_url TEXT NOT NULL UNIQUE,
      thumbnail_url TEXT DEFAULT NULL,
      summary TEXT DEFAULT NULL,
      scraped_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    )`,`CREATE TABLE IF NOT EXISTS device_specs (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      device_id INTEGER NOT NULL UNIQUE,
      announced TEXT, status TEXT, network TEXT, os TEXT,
      chipset TEXT, cpu TEXT, gpu TEXT,
      display_size TEXT, display_type TEXT, display_res TEXT,
      ram TEXT, storage TEXT,
      main_camera TEXT, selfie_camera TEXT,
      battery TEXT, charging TEXT,
      nfc TEXT, usb TEXT, bluetooth TEXT, wlan TEXT,
      colors TEXT, weight TEXT, dimensions TEXT,
      sim TEXT, sensors TEXT, popularity TEXT,
      fans TEXT, rating TEXT, full_specs_json TEXT,
      scraped_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    )`,`CREATE TABLE IF NOT EXISTS device_pictures (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      device_id INTEGER NOT NULL,
      url TEXT NOT NULL,
      position INTEGER DEFAULT 0,
      UNIQUE(device_id, url)
    )`,`CREATE TABLE IF NOT EXISTS wishlist (
      user_id INTEGER NOT NULL,
      device_slug TEXT NOT NULL,
      PRIMARY KEY (user_id, device_slug)
    )`,`CREATE TABLE IF NOT EXISTS comparisons_log (
      slug1 TEXT NOT NULL,
      slug2 TEXT NOT NULL,
      count INTEGER DEFAULT 1,
      last_compared TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      PRIMARY KEY (slug1, slug2)
    )`,`CREATE TABLE IF NOT EXISTS users (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT NOT NULL,
      email TEXT NOT NULL UNIQUE,
      password_hash TEXT NOT NULL,
      is_admin INTEGER DEFAULT 0,
      avatar_url TEXT,
      wishlist TEXT DEFAULT '[]',
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    )`,`CREATE TABLE IF NOT EXISTS seo_meta (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      page_key TEXT NOT NULL UNIQUE,
      title TEXT, description TEXT, keywords TEXT,
      og_title TEXT, og_image TEXT, canonical TEXT,
      json_ld TEXT, noindex INTEGER DEFAULT 0,
      twitter_card TEXT, twitter_title TEXT,
      twitter_description TEXT, twitter_image TEXT,
      schema_type TEXT
    )`,`CREATE TABLE IF NOT EXISTS site_settings (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      key_name TEXT NOT NULL UNIQUE,
      value TEXT
    )`,`CREATE TABLE IF NOT EXISTS news_articles (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      slug TEXT NOT NULL UNIQUE,
      title TEXT NOT NULL,
      excerpt TEXT,
      category TEXT DEFAULT 'news',
      author TEXT DEFAULT 'MobilePhoneCompare',
      thumbnail_url TEXT,
      related_device_slug TEXT,
      related_brand TEXT,
      published_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      is_featured INTEGER DEFAULT 0,
      views INTEGER DEFAULT 0
    )`,`CREATE TABLE IF NOT EXISTS upcoming_phones (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      slug TEXT NOT NULL UNIQUE,
      name TEXT NOT NULL,
      brand TEXT NOT NULL,
      brand_color TEXT DEFAULT '#ff6e14',
      expected_price TEXT,
      launch_quarter TEXT,
      launch_date TEXT,
      status TEXT DEFAULT 'Rumored',
      thumbnail_url TEXT,
      chipset TEXT, ram TEXT, camera TEXT, battery TEXT, display TEXT,
      hype INTEGER DEFAULT 0,
      followers TEXT DEFAULT '0',
      description TEXT,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    )`])try{e.run(s)}catch(e){console.warn("CREATE TABLE warning:",e.message)}try{let s=o().join(process.cwd(),"mobile_insights.sql");if(E().existsSync(s)){console.log("Loading mobile_insights.sql into SQLite...");let t=E().readFileSync(s,"utf8"),T=[],r="",a=!1;for(let e=0;e<t.length;e++){let s=t[e];if("'"===s&&"\\"!==t[e-1]&&(a=!a),";"!==s||a)r+=s;else{let e=r.trim();e&&!e.startsWith("--")&&T.push(e),r=""}}let i=0;for(let s of T)if(s)try{e.run(s),i++}catch(e){s.trimStart().toUpperCase().startsWith("INSERT")||console.warn("SQL init warning:",s.substring(0,80),"|",e.message)}console.log(`Loaded ${i}/${T.length} statements from mobile_insights.sql`)}else console.warn("mobile_insights.sql not found — run: node scripts/csv_to_sql.mjs")}catch(e){console.error("Failed to load mobile_insights.sql:",e)}try{let t=o().join(process.cwd(),"seed.sql");if(E().existsSync(t)){var s;for(let s of E().readFileSync(t,"utf8").replace(/^\s*--.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"").replace(/START TRANSACTION;/gi,"").replace(/COMMIT;/gi,"").replace(/LOCK TABLES `[^`]+` WRITE;/gi,"").replace(/UNLOCK TABLES;/gi,"").replace(/SET SQL_MODE[\s\S]*?;/gi,"").replace(/SET time_zone[\s\S]*?;/gi,"").replace(/ALTER TABLE `[^`]+`[\s\S]*?;/gi,"").replace(/ON UPDATE current_timestamp\(\)/gi,"").replace(/DEFAULT current_timestamp\(\)/gi,"DEFAULT CURRENT_TIMESTAMP").replace(/\b(?:int|integer|tinyint|smallint|mediumint|bigint)\(\d+\)(?:\s+unsigned)?/gi,"INTEGER").replace(/\b(?:double|decimal\(\d+,\d+\))\b/gi,"REAL").replace(/\bunsigned\b/gi,"").replace(/\bdatetime\b/gi,"TIMESTAMP").replace(/\blongtext\b/gi,"TEXT").replace(/COLLATE \w+/gi,"").replace(/CHARACTER SET \w+/gi,"").replace(/DEFAULT CHARSET=\w+/gi,"").replace(/ENGINE=InnoDB\b[^;]*;?/gi,";").replace(/\\'/g,"''").replace(/\\"/g,'"').replace(/INSERT IGNORE INTO/gi,"INSERT OR IGNORE INTO").split(";"))if(s=s.trim())try{e.run(s)}catch{}}}catch(e){console.error("Failed to load seed.sql:",e)}return c=e,console.log("In-memory SQLite database initialized successfully."),c}let u={execute:async(e,s=[])=>{if(l)try{return await l.execute(e,s)}catch(e){if(!("ECONNREFUSED"===e.code||"PROTOCOL_CONNECTION_LOST"===e.code||"ETIMEDOUT"===e.code||e.message?.includes("connect")))throw e;console.warn("MySQL connection failed. Falling back to SQLite database...")}let t=await d(),T=function(e){let s=e.replace(/\bUNSIGNED\b/gi,"INTEGER");return(s=s.replace(/\bNOW\(\)/gi,"datetime('now')")).replace(/ON DUPLICATE KEY UPDATE[\s\S]*$/gi,"")}(e);if(/^\s*(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|ALTER)/i.test(T)){t.run(T,s);let e=0,r=0;try{let s=t.exec("SELECT last_insert_rowid()");s.length>0&&(e=s[0].values[0][0]);let T=t.exec("SELECT changes()");T.length>0&&(r=T[0].values[0][0])}catch(e){}return[{insertId:e,affectedRows:r},void 0]}{let e=t.exec(T,s);if(0===e.length)return[[],void 0];let r=e[0].columns;return[e[0].values.map(e=>{let s={};return r.forEach((t,T)=>{s[t]=e[T]}),s}),void 0]}}}},10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},29021:e=>{"use strict";e.exports=require("fs")},29294:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-async-storage.external.js")},33873:e=>{"use strict";e.exports=require("path")},44870:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},46019:(e,s,t)=>{"use strict";t.r(s),t.d(s,{patchFetch:()=>N,routeModule:()=>c,serverHooks:()=>p,workAsyncStorage:()=>d,workUnitAsyncStorage:()=>u});var T={};t.r(T),t.d(T,{GET:()=>l});var r=t(96559),a=t(48088),i=t(37719),E=t(32190),n=t(5069);async function o(e){let s=`https://www.gsmarena.com/${e}.php`,[t]=await n.A.execute(`SELECT d.name, d.gsmarena_url, d.thumbnail_url, d.summary, b.name AS brand_name,
            ds.chipset, ds.ram, ds.storage, ds.main_camera, ds.selfie_camera,
            ds.battery, ds.charging, ds.display_size, ds.display_type, ds.display_res,
            ds.os, ds.network, ds.nfc, ds.bluetooth, ds.wlan,
            ds.colors, ds.weight, ds.dimensions, ds.sim, ds.sensors,
            ds.announced, ds.status, ds.fans, ds.rating
     FROM devices d
     JOIN brands b ON b.id = d.brand_id
     LEFT JOIN device_specs ds ON ds.device_id = d.id
     WHERE d.gsmarena_url = ?`,[s]);return t[0]?function(e){let s=function(e){let s=e.match(/\/([^/]+)\.php$/);return s?s[1]:e}(e.gsmarena_url||"");return{id:s,slug:s,name:e.name||"",brand:e.brand_name||"",thumbnail:e.thumbnail_url||"",summary:e.summary||"",chipset:e.chipset||"",ram:e.ram||"",storage:e.storage||"",main_camera:e.main_camera||"",selfie_camera:e.selfie_camera||"",battery:e.battery||"",charging:e.charging||"",display_size:e.display_size||"",display_type:e.display_type||"",display_res:e.display_res||"",os:e.os||"",network:e.network||"",nfc:e.nfc||"",bluetooth:e.bluetooth||"",wlan:e.wlan||"",weight:e.weight||"",dimensions:e.dimensions||"",colors:e.colors||"",sim:e.sim||"",sensors:e.sensors||"",announced:e.announced||"",status:e.status||"",fans:e.fans||null,rating:e.rating||null}}(t[0]):null}async function l(e){let s=e.nextUrl.searchParams,t=s.get("slug1")||"",T=s.get("slug2")||"";if(!t||!T)return E.NextResponse.json({error:"slug1 and slug2 required"},{status:400});try{let[e,s]=await Promise.all([o(t),o(T)]);if(!e||!s)return E.NextResponse.json({error:"One or both devices not found"},{status:404});let[r,a]=[t,T].sort();return await n.A.execute(`INSERT INTO comparisons_log (slug1, slug2, count) VALUES (?,?,1)
       ON DUPLICATE KEY UPDATE count=count+1, last_compared=NOW()`,[r,a]).catch(()=>{}),E.NextResponse.json({device1:e,device2:s})}catch(e){return console.error("compare error:",e),E.NextResponse.json({error:"Database error"},{status:500})}}let c=new r.AppRouteRouteModule({definition:{kind:a.RouteKind.APP_ROUTE,page:"/api/compare/route",pathname:"/api/compare",filename:"route",bundlePath:"app/api/compare/route"},resolvedPagePath:"C:\\Users\\Taukeer19\\Desktop\\Website\\mobile-site\\mobile-insights-hub\\src\\app\\api\\compare\\route.ts",nextConfigOutput:"standalone",userland:T}),{workAsyncStorage:d,workUnitAsyncStorage:u,serverHooks:p}=c;function N(){return(0,i.patchFetch)({workAsyncStorage:d,workUnitAsyncStorage:u})}},46293:e=>{"use strict";e.exports=require("sql.js")},63033:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},78335:()=>{},96487:()=>{}};var s=require("../../../webpack-runtime.js");s.C(e);var t=e=>s(s.s=e),T=s.X(0,[4447,580],()=>t(46019));module.exports=T})();