/**** Start of imports. If edited, may not auto-convert in the playground. ****/
var palette = {"min":[0],"max":[1],"palette":["0c0c0c","071aff","ff0000","ffbd03","fbff05","fffdfd"]},
    HM_OVERALL = ee.ImageCollection("projects/sat-io/open-datasets/GHM/HM_1990_2020_OVERALL_300M"),
    HM_THREAT_GROUP = ee.ImageCollection("projects/sat-io/open-datasets/GHM/HM_1990_2020_THREAT_GROUPS_300M"),
    HM_300M = ee.ImageCollection("projects/sat-io/open-datasets/GHM/HM_2022_300M"),
    HM_90M = ee.ImageCollection("projects/sat-io/open-datasets/GHM/HM_2022_90M");
/***** End of imports. If edited, may not auto-convert in the playground. *****/
// Define visualization palette (provided by authors)
var paletteHM = ['4c6100','adda25','e2ff9b','ffff73','ffe629','ffd37f','ffaa00','e69808','e60000','a80000','730000'];
var visParams = {min: 0.0, max: 1.0, palette: paletteHM};
var changeVis = {min: -0.5, max: 0.5, palette: ['blue','white','red']};

// --- Example usage & visualization ---
Map.setCenter(0, 0, 2); // Global view

// Overall modification for 2020 (300 m)
var overall2020 = HM_OVERALL.filter(ee.Filter.eq('year', 2020)).first();
Map.addLayer(overall2020, visParams, 'GHM-v3 2020 Overall (300m)');

// Change in overall modification: 1990 → 2020 (from HM_OVERALL)
var overall1990 = HM_OVERALL.filter(ee.Filter.eq('year', 1990)).first();
var change90_20 = overall2020.subtract(overall1990);
Map.addLayer(change90_20, changeVis, 'Change GHM Overall 1990–2020 (300m)', false);

// 2022 agriculture modification at 90 m
var ag2022_90 = HM_90M.filter(ee.Filter.eq('threat_code', 'AG')).first();
Map.addLayer(ag2022_90, visParams, 'GHM-v3 2022 Agriculture (90m)', false);

// Print collection summaries
print('HM_OVERALL (1990–2020 300m):', HM_OVERALL);
print('HM_THREAT_GROUP (1990–2020 per threat 300m):', HM_THREAT_GROUP);
print('HM_300M (2022 300m static):', HM_300M);
print('HM_90M (2022 90m static):', HM_90M);