// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_CHROME_BROWSER_TAB_SWITCHER_UI_BUNDLED_TAB_GRID_GRID_GRID_COMMANDS_H_
#define IOS_CHROME_BROWSER_TAB_SWITCHER_UI_BUNDLED_TAB_GRID_GRID_GRID_COMMANDS_H_

#import <UIKit/UIKit.h>

#import <set>

#import "base/memory/weak_ptr.h"
#import "components/saved_tab_groups/public/types.h"
#import "ios/chrome/browser/shared/model/web_state_list/tab_utils.h"

class TabGroup;

namespace web {
class WebStateID;
}  // namespace web

// Commands issued to a model backing a grid UI.
@protocol GridCommands
// Tells the receiver to insert a new item at the end of the list. Return YES if
// it inserted an element, NO otherwise.
- (BOOL)addNewItem;
// Tells the receiver to select the item with identifier `itemID`. If there is
// no item with that identifier, no change in selection should be made.
- (BOOL)isItemWithIDSelected:(web::WebStateID)itemID;
// Tells the receiver to close the items with the`tabIDs` and `groupIDs`.
// IDs which are not associated with any item are ignored.
- (void)closeItemsWithTabIDs:(const std::set<web::WebStateID>&)tabIDs
                    groupIDs:(const std::set<tab_groups::TabGroupId>&)groupIDs
                    tabCount:(int)tabCount;
// Tells the receiver to close all items.
- (void)closeAllItems;

// Tells the receiver to perform a search using `searchText` and update the list
// of visible items based on the result.
- (void)searchItemsWithText:(NSString*)searchText;

// Tells the receiver to reset grid to contain all the items and select the
// active item.
- (void)resetToAllItems;

// Tells the receiver to select the item with identifier `itemID`. If there is
// no item with that identifier, no change in selection should be made.
// `pinnedState` is the selected item current pinned state.
// `isFirstActionOnTabGrid` is whether the item selection is the first action
// that happens since the user enters tab grid.
- (void)selectItemWithID:(web::WebStateID)itemID
               pinnedState:(WebStateSearchCriteria::PinnedState)pinnedState
    isFirstActionOnTabGrid:(BOOL)isFirstActionOnTabGrid;

// Tells the receiver to select the `tabGroup`.
- (void)selectTabGroup:(const TabGroup*)tabGroup;

// Tells the receiver to close the item with identifier `itemID`. If there is
// no item with that identifier, no item is closed.
- (void)closeItemWithID:(web::WebStateID)itemID;

// Tells the receiver to close all items except the one with identifier
// `itemID`. Pinned items are also kept.
- (void)closeTabsExceptID:(web::WebStateID)itemID;

// Tells the receiver to delete the `group`. `sourceView` is the view that the
// delete action originated from.
- (void)deleteTabGroup:(base::WeakPtr<const TabGroup>)group
            sourceView:(UIView*)sourceView;

// Tells the receiver to leave the shared group. `sourceView` is the view that
// the leave action originated from.
- (void)leaveSharedTabGroup:(base::WeakPtr<const TabGroup>)group
                 sourceView:(UIView*)sourceView;

// Tells the receiver to delete the shared group. `sourceView` is the view that
// the leave action originated from.
- (void)deleteSharedTabGroup:(base::WeakPtr<const TabGroup>)group
                  sourceView:(UIView*)sourceView;

// Tells the receiver to close the `group`.
- (void)closeTabGroup:(base::WeakPtr<const TabGroup>)group;

// Tells the receiver to ungroup the `group`. `sourceView` is the view that the
// ungroup action originated from.
- (void)ungroupTabGroup:(base::WeakPtr<const TabGroup>)group
             sourceView:(UIView*)sourceView;

// Tells the receiver to pin or unpin the tab with identifier `itemID`.
- (void)setPinState:(BOOL)pinState forItemWithID:(web::WebStateID)itemID;

@end

#endif  // IOS_CHROME_BROWSER_TAB_SWITCHER_UI_BUNDLED_TAB_GRID_GRID_GRID_COMMANDS_H_
