-- Vitrin footer menüsü: Kurumsal sütunu (Hakkımızda, İletişim). Idempotent.

INSERT INTO footer_menu_items (parent_id, sort_order, title, url, open_new_tab, is_active, show_in_footer, variant)
SELECT NULL, 0, 'Kurumsal', '#', 0, 1, 1, 'link'
WHERE NOT EXISTS (
  SELECT 1 FROM footer_menu_items WHERE parent_id IS NULL AND title = 'Kurumsal' AND url = '#'
);

SET @footer_kurumsal_id := (
  SELECT id FROM footer_menu_items
  WHERE parent_id IS NULL AND title = 'Kurumsal' AND url = '#'
  ORDER BY id ASC LIMIT 1
);

INSERT INTO footer_menu_items (parent_id, sort_order, title, url, open_new_tab, is_active, show_in_footer, variant)
SELECT @footer_kurumsal_id, 0, 'Hakkımızda', '/hakkimizda', 0, 1, 1, 'link'
WHERE @footer_kurumsal_id IS NOT NULL
  AND NOT EXISTS (
    SELECT 1 FROM footer_menu_items WHERE parent_id = @footer_kurumsal_id AND url = '/hakkimizda'
  );

INSERT INTO footer_menu_items (parent_id, sort_order, title, url, open_new_tab, is_active, show_in_footer, variant)
SELECT @footer_kurumsal_id, 1, 'İletişim', '/iletisim', 0, 1, 1, 'link'
WHERE @footer_kurumsal_id IS NOT NULL
  AND NOT EXISTS (
    SELECT 1 FROM footer_menu_items WHERE parent_id = @footer_kurumsal_id AND url = '/iletisim'
  );

INSERT INTO footer_menu_items (parent_id, sort_order, title, url, open_new_tab, is_active, show_in_footer, variant)
SELECT NULL, 1, 'Ürünler', '#', 0, 1, 1, 'link'
WHERE NOT EXISTS (
  SELECT 1 FROM footer_menu_items WHERE parent_id IS NULL AND title = 'Ürünler' AND url = '#'
);

SET @footer_urunler_id := (
  SELECT id FROM footer_menu_items
  WHERE parent_id IS NULL AND title = 'Ürünler' AND url = '#'
  ORDER BY id ASC LIMIT 1
);

INSERT INTO footer_menu_items (parent_id, sort_order, title, url, open_new_tab, is_active, show_in_footer, variant)
SELECT @footer_urunler_id, 0, 'Ürün kataloğu', '/listing', 0, 1, 1, 'link'
WHERE @footer_urunler_id IS NOT NULL
  AND NOT EXISTS (
    SELECT 1 FROM footer_menu_items WHERE parent_id = @footer_urunler_id AND url = '/listing'
  );
