(()=>{var e={};e.id=3485,e.ids=[3485],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,T,t)=>{"use strict";let s;t.d(T,{A:()=>d});var r=t(3498),E=t.n(r),i=t(29021),a=t.n(i),n=t(33873),l=t.n(n);try{s=t(46293)}catch(e){console.warn("sql.js not installed or failed to load")}let o=null,c=null;try{o=E().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 u(){if(c)return c;if(!s)throw Error("sql.js is not available");console.log("Initializing in-memory SQLite database...");let e=new(await s()).Database;for(let T 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(T)}catch(e){console.warn("CREATE TABLE warning:",e.message)}try{let T=l().join(process.cwd(),"mobile_insights.sql");if(a().existsSync(T)){console.log("Loading mobile_insights.sql into SQLite...");let t=a().readFileSync(T,"utf8"),s=[],r="",E=!1;for(let e=0;e<t.length;e++){let T=t[e];if("'"===T&&"\\"!==t[e-1]&&(E=!E),";"!==T||E)r+=T;else{let e=r.trim();e&&!e.startsWith("--")&&s.push(e),r=""}}let i=0;for(let T of s)if(T)try{e.run(T),i++}catch(e){T.trimStart().toUpperCase().startsWith("INSERT")||console.warn("SQL init warning:",T.substring(0,80),"|",e.message)}console.log(`Loaded ${i}/${s.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=l().join(process.cwd(),"seed.sql");if(a().existsSync(t)){var T;for(let T of a().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(T=T.trim())try{e.run(T)}catch{}}}catch(e){console.error("Failed to load seed.sql:",e)}return c=e,console.log("In-memory SQLite database initialized successfully."),c}let d={execute:async(e,T=[])=>{if(o)try{return await o.execute(e,T)}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 u(),s=function(e){let T=e.replace(/\bUNSIGNED\b/gi,"INTEGER");return(T=T.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(s)){t.run(s,T);let e=0,r=0;try{let T=t.exec("SELECT last_insert_rowid()");T.length>0&&(e=T[0].values[0][0]);let s=t.exec("SELECT changes()");s.length>0&&(r=s[0].values[0][0])}catch(e){}return[{insertId:e,affectedRows:r},void 0]}{let e=t.exec(s,T);if(0===e.length)return[[],void 0];let r=e[0].columns;return[e[0].values.map(e=>{let T={};return r.forEach((t,s)=>{T[t]=e[s]}),T}),void 0]}}}},10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},21891:(e,T,t)=>{"use strict";t.d(T,{Or:()=>l,wZ:()=>a});var s=t(87806),r=t(77412),E=t(44999);let i=new TextEncoder().encode(process.env.JWT_SECRET||"mobilephonecompare-secret-2026-change-in-prod");async function a(e){return new s.P({...e,is_admin:!0}).setProtectedHeader({alg:"HS256"}).setIssuedAt().setExpirationTime("24h").sign(i)}async function n(e){try{let{payload:T}=await (0,r.V)(e,i);if(!T.is_admin)return null;return{sub:T.sub,name:T.name,email:T.email,is_admin:!0}}catch{return null}}async function l(){let e=await (0,E.UL)(),T=e.get("ps_admin_token")?.value;return T?n(T):null}},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")},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:()=>{},84319:(e,T,t)=>{"use strict";t.r(T),t.d(T,{patchFetch:()=>p,routeModule:()=>c,serverHooks:()=>N,workAsyncStorage:()=>u,workUnitAsyncStorage:()=>d});var s={};t.r(s),t.d(s,{PATCH:()=>o});var r=t(96559),E=t(48088),i=t(37719),a=t(32190),n=t(5069),l=t(21891);async function o(e,{params:T}){if(!await (0,l.Or)())return a.NextResponse.json({error:"Unauthorized"},{status:401});let{slug:t}=await T;try{let T=await e.json(),s=`https://www.gsmarena.com/${t}.php`;if((void 0!==T.summary||void 0!==T.thumbnail_url)&&await n.A.execute("UPDATE devices SET summary=COALESCE(?,summary), thumbnail_url=COALESCE(?,thumbnail_url) WHERE gsmarena_url=?",[T.summary??null,T.thumbnail_url??null,s]),void 0!==T.os||void 0!==T.chipset||void 0!==T.ram){let[e]=await n.A.execute("SELECT ds.id FROM device_specs ds JOIN devices d ON d.id=ds.device_id WHERE d.gsmarena_url=?",[s]);e.length&&await n.A.execute(`UPDATE device_specs SET os=COALESCE(?,os), chipset=COALESCE(?,chipset), ram=COALESCE(?,ram)
           WHERE id=?`,[T.os??null,T.chipset??null,T.ram??null,e[0].id])}return a.NextResponse.json({ok:!0})}catch(e){return console.error("admin devices PATCH error:",e),a.NextResponse.json({error:"Server error"},{status:500})}}let c=new r.AppRouteRouteModule({definition:{kind:E.RouteKind.APP_ROUTE,page:"/api/admin/devices/[slug]/route",pathname:"/api/admin/devices/[slug]",filename:"route",bundlePath:"app/api/admin/devices/[slug]/route"},resolvedPagePath:"C:\\Users\\Taukeer19\\Desktop\\Website\\mobile-site\\mobile-insights-hub\\src\\app\\api\\admin\\devices\\[slug]\\route.ts",nextConfigOutput:"standalone",userland:s}),{workAsyncStorage:u,workUnitAsyncStorage:d,serverHooks:N}=c;function p(){return(0,i.patchFetch)({workAsyncStorage:u,workUnitAsyncStorage:d})}},96487:()=>{}};var T=require("../../../../../webpack-runtime.js");T.C(e);var t=e=>T(T.s=e),s=T.X(0,[4447,580,4999,4553],()=>t(84319));module.exports=s})();