<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

function aieo_dmm_custom_tabs_table() {
	global $wpdb;
	return $wpdb->prefix . 'aieo_dmm_custom_tabs';
}

function aieo_dmm_custom_tabs_create_table() {
	global $wpdb;

	$charset_collate = function_exists( 'aieo_get_charset_collate' )
		? aieo_get_charset_collate()
		: $wpdb->get_charset_collate();

	$t = aieo_dmm_custom_tabs_table();

	$sql = "CREATE TABLE IF NOT EXISTS `{$t}` (
		`id` bigint unsigned NOT NULL AUTO_INCREMENT,
		`product_id` bigint unsigned NOT NULL,
		`slot_index` tinyint unsigned NOT NULL,
		`content` longtext,
		`updated_at` datetime DEFAULT NULL,
		PRIMARY KEY (`id`),
		UNIQUE KEY `product_slot` (`product_id`,`slot_index`),
		KEY `slot_index` (`slot_index`)
	) {$charset_collate};";

	if ( function_exists( 'aieo_dbdelta' ) ) {
		aieo_dbdelta( $sql );
	} else {
		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
		dbDelta( $sql );
	}
}
