"use strict";exports.id=2066,exports.ids=[2066],exports.modules={22066:(a,b,c)=>{c.d(b,{Iw:()=>r,zA:()=>s,p1:()=>t,query:()=>q});var d=c(29021),e=c.n(d),f=c(33873),g=c.n(f),h=c(3498),i=c.n(h),j=c(87550),k=c.n(j);let l=g().join(process.cwd(),"data","faqs.json"),m=g().join(process.cwd(),"data","database.sqlite");e().existsSync(g().join(process.cwd(),"data"))||e().mkdirSync(g().join(process.cwd(),"data"));let n=process.env.DB_HOST&&"localhost"!==process.env.DB_HOST?i().createPool({host:process.env.DB_HOST,user:process.env.DB_USER,password:process.env.DB_PASS,database:process.env.DB_NAME,port:parseInt(process.env.DB_PORT||"3306"),waitForConnections:!0,connectionLimit:10,queueLimit:0}):null,o=null,p=!1;async function q(a,b=[]){if(n){let[c]=await n.execute(a,b);return c}let c=function(){if(p)return o;if(n)return null;let a=a=>{let b=new(k())(a);return b.pragma("journal_mode = WAL"),b.pragma("synchronous = NORMAL"),b};try{o=a(m)}catch(b){if("SQLITE_CORRUPT"===b.code||b.message?.includes?.("malformed")){console.error("Database corrupted on open, recreating...",b.message);try{e().existsSync(m)&&(e().unlinkSync(m),e().existsSync(`${m}-wal`)&&e().unlinkSync(`${m}-wal`),e().existsSync(`${m}-shm`)&&e().unlinkSync(`${m}-shm`)),o=a(m)}catch(b){console.error("Failed to recreate database:",b),o=a(":memory:")}}else throw b}o.exec(`
    CREATE TABLE IF NOT EXISTS seo_audits (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      url TEXT NOT NULL,
      score INTEGER NOT NULL,
      report_data TEXT NOT NULL,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    CREATE TABLE IF NOT EXISTS tool_usage (
      ip TEXT NOT NULL,
      month TEXT NOT NULL,
      count INTEGER DEFAULT 1,
      PRIMARY KEY (ip, month)
    );
    CREATE TABLE IF NOT EXISTS companies (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT NOT NULL,
      slug TEXT UNIQUE,
      domain TEXT UNIQUE,
      plan TEXT DEFAULT 'free',
      status TEXT DEFAULT 'active',
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    CREATE TABLE IF NOT EXISTS roles (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT NOT NULL UNIQUE,
      description TEXT
    );
    CREATE TABLE IF NOT EXISTS users (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      company_id INTEGER NULL,
      username TEXT NOT NULL UNIQUE,
      email TEXT NOT NULL UNIQUE,
      password TEXT NOT NULL,
      role_id INTEGER DEFAULT 7,
      name TEXT,
      profession TEXT,
      social_media TEXT,
      contact TEXT,
      referred_by TEXT,
      username_changed INTEGER DEFAULT 0,
      avatar TEXT,
      bio TEXT,
      status TEXT DEFAULT 'active',
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (role_id) REFERENCES roles(id),
      FOREIGN KEY (company_id) REFERENCES companies(id) ON DELETE SET NULL
    );
    CREATE TABLE IF NOT EXISTS services (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      slug TEXT UNIQUE NOT NULL,
      category TEXT NOT NULL,
      title TEXT NOT NULL,
      subtitle TEXT NOT NULL,
      description TEXT NOT NULL,
      long_description TEXT NOT NULL,
      features TEXT NOT NULL,
      checklist TEXT,
      why_grid TEXT,
      faqs TEXT,
      testimonial TEXT,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
  `),o.exec(`
    CREATE TABLE IF NOT EXISTS password_resets (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      user_id INTEGER NOT NULL,
      token TEXT NOT NULL UNIQUE,
      expires_at TIMESTAMP NOT NULL,
      used INTEGER DEFAULT 0,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (user_id) REFERENCES users(id)
    );
    CREATE TABLE IF NOT EXISTS email_verifications (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      user_id INTEGER NOT NULL,
      token TEXT NOT NULL UNIQUE,
      expires_at TIMESTAMP NOT NULL,
      used INTEGER DEFAULT 0,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (user_id) REFERENCES users(id)
    );
  `);try{o.exec("ALTER TABLE users ADD COLUMN referred_by TEXT")}catch(a){}try{o.exec("ALTER TABLE users ADD COLUMN name TEXT")}catch(a){}try{o.exec("ALTER TABLE users ADD COLUMN profession TEXT")}catch(a){}try{o.exec("ALTER TABLE users ADD COLUMN social_media TEXT")}catch(a){}try{o.exec("ALTER TABLE users ADD COLUMN contact TEXT")}catch(a){}try{o.exec("ALTER TABLE users ADD COLUMN username_changed INTEGER DEFAULT 0")}catch(a){}try{o.exec("ALTER TABLE users ADD COLUMN email_verified INTEGER DEFAULT 0")}catch(a){}try{o.exec("ALTER TABLE posts ADD COLUMN author_id INTEGER")}catch(a){}try{o.exec("ALTER TABLE posts ADD COLUMN category_id INTEGER")}catch(a){}try{o.exec("ALTER TABLE affiliate_payouts RENAME TO payouts")}catch(a){}try{o.exec("ALTER TABLE portfolio RENAME TO portfolio_projects")}catch(a){}try{o.exec("ALTER TABLE portfolio_projects ADD COLUMN category_id INTEGER")}catch(a){}o.exec(`
    CREATE TABLE IF NOT EXISTS settings (
      key TEXT PRIMARY KEY,
      value TEXT,
      updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    CREATE TABLE IF NOT EXISTS pages (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      title TEXT NOT NULL,
      slug TEXT UNIQUE NOT NULL,
      content TEXT,
      status TEXT DEFAULT 'draft',
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    CREATE TABLE IF NOT EXISTS affiliates (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      user_id INTEGER,
      name TEXT NOT NULL,
      code TEXT NOT NULL UNIQUE,
      target_url TEXT NOT NULL,
      total_clicks INTEGER DEFAULT 0,
      total_earnings DECIMAL(10, 2) DEFAULT 0.00,
      status TEXT DEFAULT 'active',
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (user_id) REFERENCES users(id)
    );
    CREATE TABLE IF NOT EXISTS affiliate_earnings (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      affiliate_id INTEGER,
      amount DECIMAL(10, 2) NOT NULL,
      description TEXT,
      status TEXT DEFAULT 'pending',
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (affiliate_id) REFERENCES affiliates(id)
    );
    CREATE TABLE IF NOT EXISTS payouts (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      affiliate_id INTEGER,
      amount DECIMAL(10, 2) NOT NULL,
      method TEXT,
      status TEXT DEFAULT 'pending',
      processed_at TIMESTAMP NULL,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (affiliate_id) REFERENCES affiliates(id)
    );
    CREATE TABLE IF NOT EXISTS marketing_campaigns (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT NOT NULL,
      type TEXT NOT NULL,
      status TEXT DEFAULT 'active',
      budget DECIMAL(10, 2),
      spent DECIMAL(10, 2) DEFAULT 0.00,
      start_date DATE,
      end_date DATE,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    CREATE TABLE IF NOT EXISTS guest_submissions (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      user_id INTEGER,
      title TEXT NOT NULL,
      content TEXT NOT NULL,
      excerpt TEXT,
      status TEXT DEFAULT 'pending',
      admin_notes TEXT,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (user_id) REFERENCES users(id)
    );
    CREATE TABLE IF NOT EXISTS support_tickets (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      user_id INTEGER,
      subject TEXT NOT NULL,
      message TEXT NOT NULL,
      status TEXT DEFAULT 'open',
      priority TEXT DEFAULT 'medium',
      assigned_to INTEGER,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (user_id) REFERENCES users(id),
      FOREIGN KEY (assigned_to) REFERENCES users(id)
    );
    CREATE TABLE IF NOT EXISTS media (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT NOT NULL,
      path TEXT,
      type TEXT,
      mime_type TEXT,
      size INTEGER,
      is_folder INTEGER DEFAULT 0,
      parent_id INTEGER,
      user_id INTEGER,
      company_id INTEGER,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (user_id) REFERENCES users(id)
    );
    CREATE TABLE IF NOT EXISTS affiliate_logs (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      affiliate_id INTEGER,
      ip_address TEXT,
      user_agent TEXT,
      referrer TEXT,
      timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (affiliate_id) REFERENCES affiliates(id)
    );
    CREATE TABLE IF NOT EXISTS analytics_events (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      user_id INTEGER NULL,
      event_type TEXT NOT NULL,
      page_path TEXT,
      referrer TEXT,
      user_agent TEXT,
      ip_address TEXT,
      metadata TEXT,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
    );
    CREATE TABLE IF NOT EXISTS categories (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT NOT NULL,
      slug TEXT NOT NULL UNIQUE,
      description TEXT,
      type TEXT DEFAULT 'blog',
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    CREATE TABLE IF NOT EXISTS tags (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT NOT NULL,
      slug TEXT NOT NULL UNIQUE,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    CREATE TABLE IF NOT EXISTS post_tags (
      post_id INTEGER,
      tag_id INTEGER,
      PRIMARY KEY (post_id, tag_id),
      FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE,
      FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
    );
    CREATE TABLE IF NOT EXISTS posts (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      title TEXT NOT NULL,
      slug TEXT NOT NULL UNIQUE,
      content TEXT NOT NULL,
      excerpt TEXT,
      author_id INTEGER,
      author_name TEXT,
      author_credit TEXT,
      category_id INTEGER,
      category_name TEXT,
      tags TEXT,
      read_time TEXT,
      status TEXT DEFAULT 'draft',
      scheduled_at TIMESTAMP NULL,
      seo_title TEXT,
      seo_description TEXT,
      featured_image TEXT,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (author_id) REFERENCES users(id),
      FOREIGN KEY (category_id) REFERENCES categories(id)
    );
    CREATE TABLE IF NOT EXISTS jobs (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      title TEXT NOT NULL,
      slug TEXT NOT NULL UNIQUE,
      type TEXT,
      location TEXT,
      department TEXT,
      description TEXT,
      responsibilities TEXT, 
      requirements TEXT, 
      status TEXT DEFAULT 'open',
      seo_title TEXT,
      seo_description TEXT,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    CREATE TABLE IF NOT EXISTS faqs (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      question TEXT NOT NULL,
      answer TEXT NOT NULL,
      category TEXT,
      publish INTEGER DEFAULT 1,
      seo_keywords TEXT,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    CREATE TABLE IF NOT EXISTS portfolio_projects (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      title TEXT NOT NULL,
      slug TEXT NOT NULL UNIQUE,
      description TEXT,
      category_id INTEGER,
      client TEXT,
      year TEXT,
      image TEXT,
      content TEXT,
      status TEXT DEFAULT 'draft',
      seo_title TEXT,
      seo_description TEXT,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (category_id) REFERENCES categories(id)
    );
    CREATE TABLE IF NOT EXISTS portfolio_tags (
      project_id INTEGER,
      tag_id INTEGER,
      PRIMARY KEY (project_id, tag_id),
      FOREIGN KEY (project_id) REFERENCES portfolio_projects(id) ON DELETE CASCADE,
      FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
    );
    CREATE TABLE IF NOT EXISTS sheets_config (
      id INTEGER PRIMARY KEY CHECK (id = 1),
      sheet_url TEXT NOT NULL,
      last_sync TIMESTAMP
    );
    CREATE TABLE IF NOT EXISTS projects (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      title TEXT NOT NULL,
      description TEXT,
      client_id INTEGER,
      status TEXT DEFAULT 'active',
      budget DECIMAL(10, 2),
      start_date DATE,
      deadline DATE,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (client_id) REFERENCES users(id)
    );
    CREATE TABLE IF NOT EXISTS tasks (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      title TEXT NOT NULL,
      description TEXT,
      project_id INTEGER,
      assigned_to INTEGER,
      status TEXT DEFAULT 'pending',
      priority TEXT DEFAULT 'medium',
      due_date DATE,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (project_id) REFERENCES projects(id),
      FOREIGN KEY (assigned_to) REFERENCES users(id)
    );
    CREATE TABLE IF NOT EXISTS invoices (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      client_id INTEGER,
      amount DECIMAL(10, 2) NOT NULL,
      status TEXT DEFAULT 'unpaid',
      due_date DATE,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (client_id) REFERENCES users(id)
    );
    CREATE TABLE IF NOT EXISTS time_logs (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      task_id INTEGER,
      user_id INTEGER,
      hours DECIMAL(5, 2) NOT NULL,
      description TEXT,
      date DATE,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (task_id) REFERENCES tasks(id),
      FOREIGN KEY (user_id) REFERENCES users(id)
    );
    CREATE TABLE IF NOT EXISTS messages (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      sender_id INTEGER NOT NULL,
      receiver_id INTEGER NOT NULL,
      content TEXT NOT NULL,
      is_read INTEGER DEFAULT 0,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (sender_id) REFERENCES users(id),
      FOREIGN KEY (receiver_id) REFERENCES users(id)
    );
    CREATE TABLE IF NOT EXISTS notifications (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      user_id INTEGER NOT NULL,
      title TEXT NOT NULL,
      message TEXT,
      type TEXT DEFAULT 'info',
      is_read INTEGER DEFAULT 0,
      link TEXT,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
    );
    CREATE TABLE IF NOT EXISTS leave_requests (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      user_id INTEGER NOT NULL,
      type TEXT NOT NULL DEFAULT 'vacation',
      start_date DATE NOT NULL,
      end_date DATE NOT NULL,
      reason TEXT,
      status TEXT DEFAULT 'pending',
      reviewed_by INTEGER,
      reviewed_at TIMESTAMP,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (user_id) REFERENCES users(id),
      FOREIGN KEY (reviewed_by) REFERENCES users(id)
    );
  `),o.exec(`
    CREATE TABLE IF NOT EXISTS activity_logs (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      user_id INTEGER NOT NULL,
      action TEXT NOT NULL,
      ip TEXT,
      device TEXT,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (user_id) REFERENCES users(id)
    );
    CREATE TABLE IF NOT EXISTS permissions (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT NOT NULL UNIQUE,
      slug TEXT NOT NULL UNIQUE,
      module TEXT NOT NULL
    );
    CREATE TABLE IF NOT EXISTS role_permissions (
      role_id INTEGER NOT NULL,
      permission_id INTEGER NOT NULL,
      PRIMARY KEY (role_id, permission_id),
      FOREIGN KEY (role_id) REFERENCES roles(id) ON DELETE CASCADE,
      FOREIGN KEY (permission_id) REFERENCES permissions(id) ON DELETE CASCADE
    );
    CREATE TABLE IF NOT EXISTS api_keys (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT NOT NULL,
      key TEXT NOT NULL UNIQUE,
      user_id INTEGER,
      permissions TEXT,
      last_used_at TIMESTAMP,
      expires_at TIMESTAMP,
      status TEXT DEFAULT 'active',
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (user_id) REFERENCES users(id)
    );
    CREATE TABLE IF NOT EXISTS feature_flags (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      key TEXT NOT NULL UNIQUE,
      name TEXT NOT NULL,
      description TEXT,
      enabled INTEGER DEFAULT 0,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    CREATE TABLE IF NOT EXISTS webhooks (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT NOT NULL,
      url TEXT NOT NULL,
      events TEXT,
      secret TEXT,
      status TEXT DEFAULT 'active',
      last_triggered_at TIMESTAMP,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );
    CREATE TABLE IF NOT EXISTS sessions (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      user_id INTEGER NOT NULL,
      token TEXT NOT NULL UNIQUE,
      device TEXT,
      ip TEXT,
      last_activity TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
    );
  `);try{o.prepare("SELECT id FROM sheets_config WHERE id = 1").get()||o.prepare("INSERT INTO sheets_config (id, sheet_url) VALUES (1, ?)").run("https://docs.google.com/spreadsheets/d/1XQ0t_c7YqoJxWm8SLXZyPk9zeA1ijgcXaN_GRi4lwNA/edit?gid=0")}catch(a){console.warn("Initial sheets_config setup failed:",a)}try{let a=o.prepare("INSERT OR IGNORE INTO roles (id, name, description) VALUES (?, ?, ?)");a.run(1,"super_admin","Full system access across all companies"),a.run(2,"company_admin","Full access within a specific company"),a.run(3,"editor","Can manage content"),a.run(4,"content_manager","Can manage all content and media"),a.run(5,"marketing_manager","Can manage campaigns and analytics"),a.run(6,"employee","Internal staff access"),a.run(7,"client","Standard customer access")}catch(a){console.warn("Role seeding failed:",a)}try{let a=o.prepare("INSERT OR IGNORE INTO permissions (name, slug, module) VALUES (?, ?, ?)");for(let[b,c,d]of[["Create Users","users.create","users"],["Read Users","users.read","users"],["Update Users","users.update","users"],["Delete Users","users.delete","users"],["Create Posts","posts.create","posts"],["Read Posts","posts.read","posts"],["Update Posts","posts.update","posts"],["Delete Posts","posts.delete","posts"],["Create Pages","pages.create","pages"],["Read Pages","pages.read","pages"],["Update Pages","pages.update","pages"],["Delete Pages","pages.delete","pages"],["Upload Media","media.upload","media"],["Delete Media","media.delete","media"],["Read Settings","settings.read","settings"],["Update Settings","settings.update","settings"],["Manage Roles","roles.manage","roles"],["Manage API Keys","api_keys.manage","api_keys"],["Manage Webhooks","webhooks.manage","webhooks"],["Manage Features","features.manage","features"],["Read Audit Logs","audit.read","audit"],["Read Billing","billing.read","billing"],["Manage Billing","billing.manage","billing"],["Manage Affiliates","affiliates.manage","affiliates"],["Manage Support","support.manage","support"],["Manage Guest Posts","guest_posts.manage","guest_posts"]])a.run(b,c,d)}catch(a){console.warn("Permission seeding failed:",a)}try{let a=o.prepare("INSERT OR IGNORE INTO role_permissions (role_id, permission_id) VALUES (?, ?)");for(let b of o.prepare("SELECT id FROM permissions").all())a.run(1,b.id)}catch(a){console.warn("Role-permission seeding failed for super_admin:",a)}try{let a=o.prepare("INSERT OR IGNORE INTO role_permissions (role_id, permission_id) VALUES (?, ?)");for(let b of["users.create","users.read","users.update","users.delete","posts.create","posts.read","posts.update","posts.delete","pages.create","pages.read","pages.update","pages.delete","media.upload","media.delete","settings.read","settings.update","roles.manage","api_keys.manage","webhooks.manage","features.manage","audit.read","billing.read","billing.manage","affiliates.manage","support.manage","guest_posts.manage"]){let c=o.prepare("SELECT id FROM permissions WHERE slug = ?").get(b);c&&a.run(2,c.id)}}catch(a){console.warn("Role-permission seeding failed for company_admin:",a)}try{let a=o.prepare("INSERT OR IGNORE INTO role_permissions (role_id, permission_id) VALUES (?, ?)");for(let b of["users.create","users.read","users.update","users.delete","posts.create","posts.read","posts.update","posts.delete","pages.create","pages.read","pages.update","pages.delete","media.upload","media.delete","settings.read","settings.update","roles.manage","api_keys.manage","webhooks.manage","features.manage","audit.read","billing.read","billing.manage","affiliates.manage","support.manage","guest_posts.manage"]){let c=o.prepare("SELECT id FROM permissions WHERE slug = ?").get(b);c&&a.run(3,c.id)}}catch(a){console.warn("Role-permission seeding failed for admin:",a)}try{let a=o.prepare("INSERT OR IGNORE INTO role_permissions (role_id, permission_id) VALUES (?, ?)");for(let b of["posts.create","posts.read","posts.update","posts.delete","media.upload","pages.read"]){let c=o.prepare("SELECT id FROM permissions WHERE slug = ?").get(b);c&&a.run(4,c.id)}}catch(a){console.warn("Role-permission seeding failed for editor:",a)}try{let a=o.prepare("INSERT OR IGNORE INTO role_permissions (role_id, permission_id) VALUES (?, ?)");for(let b of["posts.create","posts.read","posts.update","posts.delete","pages.create","pages.read","pages.update","pages.delete","media.upload","media.delete","guest_posts.manage"]){let c=o.prepare("SELECT id FROM permissions WHERE slug = ?").get(b);c&&a.run(5,c.id)}}catch(a){console.warn("Role-permission seeding failed for content_manager:",a)}try{let a=o.prepare("INSERT OR IGNORE INTO role_permissions (role_id, permission_id) VALUES (?, ?)");for(let b of["posts.read","media.upload","affiliates.manage"]){let c=o.prepare("SELECT id FROM permissions WHERE slug = ?").get(b);c&&a.run(6,c.id)}}catch(a){console.warn("Role-permission seeding failed for marketing_manager:",a)}try{let a=o.prepare("INSERT OR IGNORE INTO webhooks (id, name, url, events, status) VALUES (?, ?, ?, ?, ?)");a.run(1,"Production Deploy","https://hooks.example.com/deploy",JSON.stringify(["deploy.completed","build.failed"]),"active"),a.run(2,"Staging Notify","https://hooks.example.com/staging",JSON.stringify(["deploy.started"]),"active")}catch(a){}try{let a=o.prepare("INSERT OR IGNORE INTO feature_flags (id, key, name, description, enabled) VALUES (?, ?, ?, ?, ?)");a.run(1,"new-onboarding","New User Onboarding","Enable the redesigned onboarding flow",1),a.run(2,"ai-content-suggestions","AI Content Suggestions","Show AI-powered content recommendations in editor",0),a.run(3,"dark-mode-v2","Dark Mode v2","Updated dark mode color scheme",1)}catch(a){}try{let a=o.prepare("INSERT OR IGNORE INTO activity_logs (id, user_id, action, ip, created_at) VALUES (?, ?, ?, ?, ?)");a.run(6,1,"User logged in","192.168.1.100","2026-07-08 09:00:00"),a.run(7,1,"Updated system settings","192.168.1.100","2026-07-08 08:45:00"),a.run(8,2,'Published blog post "10 SEO Tips"',"192.168.1.101","2026-07-08 08:30:00"),a.run(9,1,"Created new user: jane.doe@example.com","192.168.1.100","2026-07-07 16:20:00"),a.run(10,2,'Deleted draft post "Old Draft"',"192.168.1.101","2026-07-07 14:15:00"),a.run(11,1,"Modified role permissions for editor","192.168.1.100","2026-07-07 11:00:00"),a.run(12,1,"Generated API key: Production API","192.168.1.100","2026-07-06 15:30:00")}catch(a){}try{let a=o.prepare("INSERT OR IGNORE INTO users (id, username, email, password, role_id, status) VALUES (?, ?, ?, ?, ?, ?)");a.run(1,"AdminUser","admin@amarisbrand.com","$2b$10$ieQMt42rarCvaZPNLjUvPeR0zYD.xVB7om8lhq5z05v8FHX9C9Hn6",1,"active"),a.run(2,"EditorUser","editor@amarisbrand.com","$2b$10$SsJ9VakmHZYaMH2Jma3uHeLaVAw8thTs9z.5KyVVJFN7wrV8eSIDu",2,"active"),a.run(3,"ClientUser","client@amarisbrand.com","$2b$10$Ps6RQAoQMlrSwSdcuHRV7.J7xUGP1LuZzfbrOX57VadIHkY0H1IvW",7,"active"),a.run(4,"AffiliateUser","affiliate@amarisbrand.com","$2b$10$zTK8N70Y.Sx2uuZ7v/QfdOopBeC9yMyQj0ILhS.faIKTGKHYrcLTy",6,"active"),a.run(5,"EmployeeUser","employee@amarisbrand.com","$2b$10$0nv29KFqTAUPGDKfBWMgteBoy10z.9NrOuZMn2q7BxxkANqqLLCmu",6,"active")}catch(a){console.warn("Demo user seeding failed:",a)}try{let a=o.prepare("INSERT OR IGNORE INTO notifications (id, user_id, title, message, is_read, created_at) VALUES (?, ?, ?, ?, ?, ?)");a.run(1,3,"Invoice Ready","Your invoice for Q3 is ready for review.",0,"2026-07-01 10:00:00"),a.run(2,3,"Project Update","Web development phase 2 completed.",0,"2026-07-05 14:30:00"),a.run(3,3,"New Feature","Analytics dashboard now available.",0,"2026-07-07 09:00:00")}catch(a){}try{let a=o.prepare("INSERT OR IGNORE INTO activity_logs (id, user_id, action, ip, created_at) VALUES (?, ?, ?, ?, ?)");a.run(1,3,"Logged in from Chrome on Windows","192.168.1.1","2026-07-08 08:00:00"),a.run(2,3,"Viewed invoice INV-2026-0042","192.168.1.1","2026-07-07 16:30:00"),a.run(3,3,"Updated profile settings","192.168.1.1","2026-07-06 12:15:00"),a.run(4,3,"Generated support ticket #1284","192.168.1.1","2026-07-05 10:45:00"),a.run(5,3,"Downloaded project assets","192.168.1.1","2026-07-04 09:20:00")}catch(a){}try{let a=o.prepare("INSERT OR IGNORE INTO tasks (id, title, status, priority, assigned_to, due_date) VALUES (?, ?, ?, ?, ?, ?)");a.run(1,"Complete brand guidelines for Client X","in_progress","high",5,"2026-07-10"),a.run(2,"Design social media templates","pending","medium",5,"2026-07-12"),a.run(3,"Review SEO audit report","completed","low",5,"2026-07-08")}catch(a){}try{let a=o.prepare("INSERT OR IGNORE INTO messages (id, sender_id, receiver_id, content, is_read, created_at) VALUES (?, ?, ?, ?, ?, ?)");a.run(1,1,5,"Hey, can you review the brand guidelines by EOD?",0,"2026-07-08 09:00:00"),a.run(2,2,5,"The SEO audit report is ready for your feedback.",0,"2026-07-08 08:30:00"),a.run(3,5,1,"Sure, I'll have it done this afternoon.",1,"2026-07-08 09:15:00")}catch(a){}try{let a=o.prepare("INSERT OR IGNORE INTO notifications (id, user_id, title, message, type, is_read, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)");a.run(4,5,"Task Reminder","Design social media templates is due in 2 days","warning",0,"2026-07-08 07:00:00"),a.run(5,5,"New Message","AdminUser sent you a message","info",0,"2026-07-08 09:00:00"),a.run(6,5,"Performance Update","Your completion rate is 100% this week","success",1,"2026-07-07 18:00:00")}catch(a){}try{let a=o.prepare("INSERT OR IGNORE INTO leave_requests (id, user_id, type, start_date, end_date, reason, status, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");a.run(1,5,"vacation","2026-07-20","2026-07-25","Family trip","pending","2026-07-08 10:00:00"),a.run(2,5,"sick","2026-07-01","2026-07-02","Not feeling well","approved","2026-06-30 08:00:00"),a.run(3,5,"personal","2026-06-15","2026-06-15","Doctor appointment","approved","2026-06-12 14:00:00")}catch(a){}try{let a=o.prepare("INSERT OR IGNORE INTO payouts (id, status, amount, created_at) VALUES (?, ?, ?, ?)");a.run(1,"paid",12500,"2026-07-01"),a.run(2,"paid",8300,"2026-06-01"),a.run(3,"paid",15200,"2026-05-01")}catch(a){}try{o.exec(`
      CREATE TABLE IF NOT EXISTS payment_gateways (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        name TEXT NOT NULL,
        type TEXT NOT NULL,
        enabled INTEGER DEFAULT 0,
        config TEXT,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
      );
      CREATE TABLE IF NOT EXISTS guest_post_tiers (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        name TEXT NOT NULL,
        price DECIMAL(10,2) NOT NULL DEFAULT 0,
        description TEXT,
        benefits TEXT,
        status TEXT DEFAULT 'active',
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
      );
      CREATE TABLE IF NOT EXISTS user_seo_usage (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        user_id INTEGER NOT NULL,
        month TEXT NOT NULL,
        count INTEGER DEFAULT 0,
        FOREIGN KEY (user_id) REFERENCES users(id)
      );
      CREATE TABLE IF NOT EXISTS auth_attempts (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        email TEXT NOT NULL,
        attempted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
      );
    `)}catch(a){}try{o.exec(`
      CREATE TABLE IF NOT EXISTS support_messages (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        ticket_id INTEGER NOT NULL,
        user_id INTEGER NOT NULL,
        message TEXT NOT NULL,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        FOREIGN KEY (ticket_id) REFERENCES support_tickets(id) ON DELETE CASCADE,
        FOREIGN KEY (user_id) REFERENCES users(id)
      );
      CREATE TABLE IF NOT EXISTS support_replies (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        ticket_id INTEGER NOT NULL,
        user_id INTEGER NOT NULL,
        message TEXT NOT NULL,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        FOREIGN KEY (ticket_id) REFERENCES support_tickets(id) ON DELETE CASCADE,
        FOREIGN KEY (user_id) REFERENCES users(id)
      );
    `)}catch(a){}try{o.exec(`
      CREATE TABLE IF NOT EXISTS subscriptions (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        user_id INTEGER NOT NULL,
        plan TEXT DEFAULT 'free',
        status TEXT DEFAULT 'active',
        started_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        FOREIGN KEY (user_id) REFERENCES users(id)
      );
      CREATE TABLE IF NOT EXISTS transactions (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        user_id INTEGER NOT NULL,
        amount DECIMAL(10, 2) NOT NULL DEFAULT 0,
        status TEXT DEFAULT 'pending',
        type TEXT DEFAULT 'payment',
        description TEXT,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        FOREIGN KEY (user_id) REFERENCES users(id)
      );
      CREATE TABLE IF NOT EXISTS payments (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        user_id INTEGER NOT NULL,
        amount DECIMAL(10, 2) NOT NULL,
        method TEXT,
        status TEXT DEFAULT 'pending',
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        FOREIGN KEY (user_id) REFERENCES users(id)
      );
    `)}catch(a){}try{o.prepare("INSERT OR IGNORE INTO subscriptions (id, user_id, status) VALUES (?, ?, ?)").run(1,3,"active"),o.prepare("INSERT OR IGNORE INTO transactions (id, user_id) VALUES (?, ?)").run(1,3)}catch(a){}if("false"!==process.env.MIGRATIONS_AUTO_RUN)try{!function(a){let b,c=(b=g().join(process.cwd(),"migrate.json"),JSON.parse(e().readFileSync(b,"utf-8"))),d=g().resolve(process.cwd(),c.directory),f=g().resolve(process.cwd(),c.sqlite_path);if(!e().existsSync(d))return console.warn(`Migration directory not found: ${d}`);let h=[],i=[],j=[],l=!1;a||(e().existsSync(g().dirname(f))||e().mkdirSync(g().dirname(f),{recursive:!0}),(a=new(k())(f)).pragma("journal_mode = WAL"),l=!0),a.exec(`
    CREATE TABLE IF NOT EXISTS ${c.table} (
      id INTEGER PRIMARY KEY AUTOINCREMENT,
      name TEXT NOT NULL UNIQUE,
      applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    )
  `);let m=e().readdirSync(d).filter(a=>a.endsWith(".sql")).sort(),n=a.prepare(`INSERT INTO ${c.table} (name) VALUES (?)`);for(let b of m){if(a.prepare(`SELECT name FROM ${c.table} WHERE name = ?`).get(b)){i.push(b);continue}let f=e().readFileSync(g().join(d,b),"utf-8").split(";").map(a=>a.trim()).filter(a=>a.length>0&&!a.startsWith("--")),k=a.transaction(()=>{for(let b of f)try{a.exec(b)}catch(a){if(/^\s*ALTER\s+TABLE/i.test(b)&&function(a){let b=a.message?.toLowerCase()||"";return b.includes("duplicate column")||b.includes("already exists")||b.includes("no such table")}(a))continue;throw a}n.run(b)});try{k(),h.push(b)}catch(a){j.push({name:b,error:a.message})}}l&&a.close()}(o)}catch(a){console.error("[Migration] Auto-run failed:",a)}return p=!0,o}();if(c){let d=a.replace(/LONGTEXT/g,"TEXT").replace(/AUTO_INCREMENT/g,"AUTOINCREMENT").replace(/DATE_SUB\(NOW\(\), INTERVAL 10 DAY\)/g,"datetime('now', '-10 days')").replace(/NOW\(\)/g,"datetime('now')");try{let a=c.prepare(d);if(d.trim().toUpperCase().startsWith("SELECT"))return a.all(b);{let c=a.run(b);return{insertId:c.lastInsertRowid,affectedRows:c.changes}}}catch(a){throw(a.message?.includes?.("malformed")||"SQLITE_CORRUPT"===a.code)&&console.error("Database malformed during query execution. Redirecting to recovery might be needed."),a}}return[]}async function r(){let a=[];try{let b=await q("SELECT * FROM faqs WHERE publish = 1 ORDER BY created_at DESC");b&&b.length>0&&(a=b.map(a=>({id:a.id.toString(),question:a.question,answer:a.answer,category:a.category,publish:!!a.publish})))}catch(a){console.warn("DB FAQ fetch failed",a)}let b=[];if(e().existsSync(l)){let a=e().readFileSync(l,"utf-8");try{b=JSON.parse(a)}catch(a){}}let c=new Set(a.map(a=>a.question));return[...a,...b.filter(a=>!c.has(a.question))]}async function s(){try{return(await q("SELECT * FROM jobs WHERE status = 'open' ORDER BY created_at DESC")).map(a=>({...a,id:a.id.toString(),responsibilities:a.responsibilities?JSON.parse(a.responsibilities):[],requirements:a.requirements?JSON.parse(a.requirements):[]}))}catch(a){return console.error("getJobs error:",a),[]}}async function t(){try{return(await q("SELECT p.*, c.name as category_name FROM portfolio_projects p LEFT JOIN categories c ON p.category_id = c.id ORDER BY p.created_at DESC")).map(a=>({...a,layoutType:a.layoutType||"standard",gallery:a.gallery?JSON.parse(a.gallery):[a.image||"/images/workspace-laptop.jpg"],technologies:a.technologies?JSON.parse(a.technologies):["Digital Strategy"],results:a.results?JSON.parse(a.results):["Successfully delivered"],category:a.category_name||a.category||"Portfolio Project",date:a.date||a.year||new Date(a.created_at).getFullYear().toString(),role:a.role||"Partner"}))}catch(a){return[]}}}};