-- nav_menu_items + footer_menu_items: locale ('' = TR varsayılan)
USE faunamix;

SET @nav_col = (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'nav_menu_items' AND COLUMN_NAME = 'locale'
);
SET @sql = IF(
  @nav_col = 0,
  "ALTER TABLE nav_menu_items ADD COLUMN locale VARCHAR(16) NOT NULL DEFAULT '' AFTER id",
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @footer_col = (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'footer_menu_items' AND COLUMN_NAME = 'locale'
);
SET @sql = IF(
  @footer_col = 0,
  "ALTER TABLE footer_menu_items ADD COLUMN locale VARCHAR(16) NOT NULL DEFAULT '' AFTER id",
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- EN menü: TR kök öğelerin kopyası (başlık/URL localized)
INSERT INTO nav_menu_items (locale, parent_id, sort_order, title, url, open_new_tab, is_active, show_in_nav, variant)
SELECT
  'en',
  NULL,
  n.sort_order,
  n.title,
  CASE TRIM(n.url)
    WHEN '/iletisim' THEN '/contact'
    WHEN '/hakkimizda' THEN '/about-us'
    ELSE TRIM(n.url)
  END,
  n.open_new_tab,
  n.is_active,
  COALESCE(n.show_in_nav, 1),
  n.variant
FROM nav_menu_items n
WHERE n.locale = ''
  AND n.parent_id IS NULL
  AND NOT EXISTS (
    SELECT 1 FROM nav_menu_items e
    WHERE e.locale = 'en' AND e.parent_id IS NULL AND e.url = CASE TRIM(n.url)
      WHEN '/iletisim' THEN '/contact'
      WHEN '/hakkimizda' THEN '/about-us'
      ELSE TRIM(n.url)
    END
  );

INSERT INTO footer_menu_items (locale, parent_id, sort_order, title, url, open_new_tab, is_active, show_in_footer, variant)
SELECT
  'en',
  NULL,
  f.sort_order,
  f.title,
  CASE TRIM(f.url)
    WHEN '/iletisim' THEN '/contact'
    WHEN '/hakkimizda' THEN '/about-us'
    WHEN '/gizlilik' THEN '/privacy'
    WHEN '/kullanim' THEN '/terms'
    ELSE TRIM(f.url)
  END,
  f.open_new_tab,
  f.is_active,
  f.show_in_footer,
  f.variant
FROM footer_menu_items f
WHERE f.locale = ''
  AND f.parent_id IS NULL
  AND NOT EXISTS (SELECT 1 FROM footer_menu_items e WHERE e.locale = 'en' AND e.parent_id IS NULL AND e.sort_order = f.sort_order)
LIMIT 30;
