-- Theme, display, and visual branding options for the current shopping cart structure.
-- Safe to run more than once.
START TRANSACTION;

INSERT IGNORE INTO `options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`) VALUES
(1, 'o_brand_color', 1, '#f97316', 'Brand color', 'string', 150, 0, NULL),
(1, 'o_accent_color', 1, '#fb923c', 'Accent color', 'string', 151, 0, NULL),
(1, 'o_text_color', 1, '#1f2937', 'Text color', 'string', 152, 0, NULL),
(1, 'o_background_color', 1, '#ffffff', 'Content background', 'string', 153, 0, NULL),
(1, 'o_price_color', 1, '#f97316', 'Price color', 'string', 154, 0, NULL),
(1, 'o_page_background_color', 1, '#ffffff', 'Page background', 'string', 155, 0, NULL),
(1, 'o_font_family', 1, '', 'Font family', 'string', 156, 0, NULL),
(1, 'o_color_palette', 1, '0', 'Color palette', 'string', 157, 0, NULL);

INSERT IGNORE INTO `options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`) VALUES
(1, 'o_grid_cols_desktop', 2, '1|2|3|4|6::4', '1 column|2 columns|3 columns|4 columns|6 columns', 'enum', 51, 0, NULL),
(1, 'o_grid_cols_laptop', 2, '1|2|3|4|6::3', '1 column|2 columns|3 columns|4 columns|6 columns', 'enum', 52, 0, NULL),
(1, 'o_grid_cols_tablet', 2, '1|2|3|4|6::2', '1 column|2 columns|3 columns|4 columns|6 columns', 'enum', 53, 0, NULL),
(1, 'o_grid_cols_mobile', 2, '1|2|3|4|6::1', '1 column|2 columns|3 columns|4 columns|6 columns', 'enum', 54, 0, NULL),
(1, 'o_products_per_page_desktop', 2, '12', NULL, 'int', 55, 0, NULL),
(1, 'o_products_per_page_laptop', 2, '12', NULL, 'int', 56, 0, NULL),
(1, 'o_products_per_page_tablet', 2, '9', NULL, 'int', 57, 0, NULL),
(1, 'o_products_per_page_mobile', 2, '6', NULL, 'int', 58, 0, NULL),
(1, 'o_autoload_batch_desktop', 2, '12', NULL, 'int', 59, 0, NULL),
(1, 'o_autoload_batch_laptop', 2, '12', NULL, 'int', 60, 0, NULL),
(1, 'o_autoload_batch_tablet', 2, '9', NULL, 'int', 61, 0, NULL),
(1, 'o_autoload_batch_mobile', 2, '6', NULL, 'int', 62, 0, NULL),
(1, 'o_show_qty_listing', 2, 'Yes|No::No', 'Yes|No', 'enum', 63, 0, NULL),
(1, 'o_pagination_mode', 2, 'pagination|autoload::pagination', 'Pagination|Auto load', 'enum', 64, 0, NULL),
(1, 'o_cart_recs_popup_visible', 2, '3', NULL, 'int', 65, 0, NULL),
(1, 'o_cart_recs_cols_desktop', 2, '1|2|3|4::3', '1 column|2 columns|3 columns|4 columns', 'enum', 66, 0, NULL),
(1, 'o_cart_recs_cols_laptop', 2, '1|2|3|4::3', '1 column|2 columns|3 columns|4 columns', 'enum', 67, 0, NULL),
(1, 'o_cart_recs_cols_tablet', 2, '1|2|3::2', '1 column|2 columns|3 columns', 'enum', 68, 0, NULL),
(1, 'o_cart_recs_cols_mobile', 2, '1|2::1', '1 column|2 columns', 'enum', 69, 0, NULL);

INSERT IGNORE INTO `plugin_base_options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`) VALUES
(1, 'o_thumb_width', 1, '100', NULL, 'int', 8, 1, NULL),
(1, 'o_thumb_height', 1, '100', NULL, 'int', 9, 1, NULL),
(1, 'o_medium_width', 1, '480', NULL, 'int', 10, 1, NULL),
(1, 'o_medium_height', 1, '480', NULL, 'int', 11, 1, NULL),
(1, 'o_default_width', 1, '800', NULL, 'int', 12, 1, NULL),
(1, 'o_default_height', 1, '800', NULL, 'int', 13, 1, NULL),
(1, 'o_large_width', 1, '1920', NULL, 'int', 14, 1, NULL),
(1, 'o_large_height', 1, '1920', NULL, 'int', 15, 1, NULL),
(1, 'o_thumb_crop', 1, 'crop|resize::crop', 'Crop|Resize', 'enum', 16, 1, NULL),
(1, 'o_medium_crop', 1, 'crop|resize::crop', 'Crop|Resize', 'enum', 17, 1, NULL),
(1, 'o_default_crop', 1, 'crop|resize::resize', 'Crop|Resize', 'enum', 18, 1, NULL),
(1, 'o_large_crop', 1, 'crop|resize::resize', 'Crop|Resize', 'enum', 19, 1, NULL),
(1, 'o_admin_primary',           2, '#4B5563', 'Admin primary color',           'string', 60, 0, NULL),
(1, 'o_admin_secondary',         2, '#94A3B8', 'Admin secondary color',         'string', 61, 0, NULL),
(1, 'o_admin_sidebar',           2, '#111827', 'Admin sidebar color',           'string', 62, 0, NULL),
(1, 'o_admin_success',           2, '#84B66A', 'Admin success color',           'string', 63, 0, NULL),
(1, 'o_admin_warning',           2, '#F4C152', 'Admin warning color',           'string', 64, 0, NULL),
(1, 'o_admin_info',              2, '#94A3B8', 'Admin info color',              'string', 65, 0, NULL),
(1, 'o_admin_danger',            2, '#EF6B6B', 'Admin danger color',            'string', 66, 0, NULL),
(1, 'o_admin_table_density',     2, 'default', 'Admin table density',           'string', 67, 0, NULL),
(1, 'o_admin_brand_title',       2, 'Shopping Cart v5.0', 'Admin sidebar title','string', 69, 0, NULL),
(1, 'o_admin_brand_subtitle',    2, 'by PHPJabbers.com',  'Admin sidebar subtitle','string',70,0,NULL),
(1, 'o_admin_sidebar_secondary', 2, '#1F2937', 'Sidebar secondary bg',          'string', 71, 0, NULL),
(1, 'o_admin_sidebar_active',    2, '#374151', 'Sidebar active bg',             'string', 72, 0, NULL),
(1, 'o_admin_sidebar_text',      2, '#F3F4F6', 'Sidebar text color',            'string', 73, 0, NULL),
(1, 'o_admin_sidebar_muted',     2, '#9CA3AF', 'Sidebar muted text',            'string', 74, 0, NULL),
(1, 'o_admin_main_bg',           2, '#F5F6F8', 'Main page background',          'string', 75, 0, NULL),
(1, 'o_admin_card_bg2',          2, '#FFFFFF',  'Card background',              'string', 76, 0, NULL),
(1, 'o_admin_table_border',      2, '#E5E7EB', 'Table border color',            'string', 77, 0, NULL),
(1, 'o_admin_input_border',      2, '#E5E7EB', 'Input border color',            'string', 78, 0, NULL),
(1, 'o_admin_main_text',         2, '#111827', 'Main text color',               'string', 79, 0, NULL),
(1, 'o_admin_accent',            2, '#4B5563', 'Accent color',                  'string', 80, 0, NULL),
(1, 'o_admin_link_color',        2, '#9CA3AF', 'Link color',                    'string', 81, 0, NULL),
(1, 'o_admin_table_header_bg',   2, '#F3F4F6', 'Table header background',       'string', 82, 0, NULL),
(1, 'o_admin_table_row_bg',      2, '#FFFFFF',  'Table row background',         'string', 83, 0, NULL),
(1, 'o_admin_table_row_alt',     2, '#F9FAFB', 'Table alt row background',      'string', 84, 0, NULL),
(1, 'o_admin_table_row_hover',   2, '#F9FAFB', 'Table row hover background',    'string', 85, 0, NULL),
(1, 'o_admin_table_text',        2, '#374151', 'Table text color',              'string', 86, 0, NULL),
(1, 'o_admin_heading_text',      2, '#111827', 'Heading text color',            'string', 87, 0, NULL),
(1, 'o_admin_muted_text',        2, '#9CA3AF', 'Muted text color',              'string', 88, 0, NULL),
(1, 'o_admin_link_text',         2, '#4B5563', 'Link text color',               'string', 89, 0, NULL),
(1, 'o_admin_sidebar_icon',      2, '#F3F4F6', 'Sidebar icon color',            'string', 90, 0, NULL),
(1, 'o_admin_icon_color',        2, '#4B5563', 'Icon color',                    'string', 91, 0, NULL),
(1, 'o_admin_topbar_bg',         2, '#FFFFFF',  'Topbar background',            'string', 92, 0, NULL),
(1, 'o_admin_input_bg',          2, '#FFFFFF',  'Input background',             'string', 93, 0, NULL),
(1, 'o_admin_card_border',       2, '#E5E7EB', 'Card border color',             'string', 94, 0, NULL);

INSERT INTO `plugin_auth_permissions` (`parent_id`, `key`)
SELECT p.id, 'pjAdminOptions_pjActionGrid'
FROM `plugin_auth_permissions` p
WHERE p.`key` = 'pjAdminOptions'
  AND NOT EXISTS (SELECT 1 FROM `plugin_auth_permissions` WHERE `key` = 'pjAdminOptions_pjActionGrid')
LIMIT 1;

INSERT INTO `plugin_auth_permissions` (`parent_id`, `key`)
SELECT p.id, 'pjAdminOptions_pjActionSaveThemeColors'
FROM `plugin_auth_permissions` p
WHERE p.`key` = 'pjAdminOptions_pjActionPreview'
  AND NOT EXISTS (SELECT 1 FROM `plugin_auth_permissions` WHERE `key` = 'pjAdminOptions_pjActionSaveThemeColors')
LIMIT 1;

INSERT INTO `plugin_auth_permissions` (`parent_id`, `key`)
SELECT p.id, 'pjBaseOptions_pjActionImages'
FROM `plugin_auth_permissions` p
WHERE p.`key` = 'pjBaseOptions'
  AND NOT EXISTS (SELECT 1 FROM `plugin_auth_permissions` WHERE `key` = 'pjBaseOptions_pjActionImages')
LIMIT 1;

INSERT INTO `plugin_auth_permissions` (`parent_id`, `key`)
SELECT p.id, child_key.`key`
FROM `plugin_auth_permissions` p
JOIN (
  SELECT 'pjBaseOptions_pjActionUploadSidebarLogo' AS `key`
  UNION ALL
  SELECT 'pjBaseOptions_pjActionRemoveSidebarLogo' AS `key`
) AS child_key
WHERE p.`key` = 'pjBaseOptions_pjActionVisual'
  AND NOT EXISTS (SELECT 1 FROM `plugin_auth_permissions` WHERE `key` = child_key.`key`);

INSERT IGNORE INTO `plugin_auth_roles_permissions` (`role_id`, `permission_id`)
SELECT rp.role_id, child.id
FROM `plugin_auth_roles_permissions` rp
JOIN `plugin_auth_permissions` parent ON parent.id = rp.permission_id
JOIN `plugin_auth_permissions` child ON child.`key` IN ('pjAdminOptions_pjActionGrid', 'pjAdminOptions_pjActionSaveThemeColors')
WHERE parent.`key` = 'pjAdminOptions';

INSERT IGNORE INTO `plugin_auth_roles_permissions` (`role_id`, `permission_id`)
SELECT rp.role_id, child.id
FROM `plugin_auth_roles_permissions` rp
JOIN `plugin_auth_permissions` parent ON parent.id = rp.permission_id
JOIN `plugin_auth_permissions` child ON child.`key` = 'pjBaseOptions_pjActionImages'
WHERE parent.`key` = 'pjBaseOptions';

INSERT IGNORE INTO `plugin_auth_roles_permissions` (`role_id`, `permission_id`)
SELECT rp.role_id, child.id
FROM `plugin_auth_roles_permissions` rp
JOIN `plugin_auth_permissions` parent ON parent.id = rp.permission_id
JOIN `plugin_auth_permissions` child ON child.`key` IN ('pjBaseOptions_pjActionUploadSidebarLogo', 'pjBaseOptions_pjActionRemoveSidebarLogo')
WHERE parent.`key` = 'pjBaseOptions_pjActionVisual';

INSERT IGNORE INTO `plugin_auth_users_permissions` (`user_id`, `permission_id`)
SELECT up.user_id, child.id
FROM `plugin_auth_users_permissions` up
JOIN `plugin_auth_permissions` parent ON parent.id = up.permission_id
JOIN `plugin_auth_permissions` child ON child.`key` IN ('pjAdminOptions_pjActionGrid', 'pjAdminOptions_pjActionSaveThemeColors')
WHERE parent.`key` = 'pjAdminOptions';

INSERT IGNORE INTO `plugin_auth_users_permissions` (`user_id`, `permission_id`)
SELECT up.user_id, child.id
FROM `plugin_auth_users_permissions` up
JOIN `plugin_auth_permissions` parent ON parent.id = up.permission_id
JOIN `plugin_auth_permissions` child ON child.`key` = 'pjBaseOptions_pjActionImages'
WHERE parent.`key` = 'pjBaseOptions';

INSERT IGNORE INTO `plugin_auth_users_permissions` (`user_id`, `permission_id`)
SELECT up.user_id, child.id
FROM `plugin_auth_users_permissions` up
JOIN `plugin_auth_permissions` parent ON parent.id = up.permission_id
JOIN `plugin_auth_permissions` child ON child.`key` IN ('pjBaseOptions_pjActionUploadSidebarLogo', 'pjBaseOptions_pjActionRemoveSidebarLogo')
WHERE parent.`key` = 'pjBaseOptions_pjActionVisual';
COMMIT;
