/**
 * Bot cihaz profilini storage'dan okuyup MAIN world (tgoCartPromo) icin sessionStorage'a yazar.
 */
(function () {
  'use strict';

  var STORAGE_KEY = 'tgo_device_profile';
  var SESSION_KEY = 'km_tgo_device_profile';

  function syncProfile(profile) {
    if (!profile) return;
    try {
      sessionStorage.setItem(SESSION_KEY, JSON.stringify(profile));
    } catch (_) {}
  }

  chrome.storage.local.get([STORAGE_KEY], function (result) {
    if (result && result[STORAGE_KEY]) {
      syncProfile(result[STORAGE_KEY]);
    }
  });

  chrome.storage.onChanged.addListener(function (changes, area) {
    if (area !== 'local' || !changes[STORAGE_KEY]) return;
    syncProfile(changes[STORAGE_KEY].newValue || null);
  });
})();
