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

#import "ios/chrome/browser/settings/ui_bundled/downloads/identity_button_item.h"

#import "google_apis/gaia/gaia_id.h"
#import "ios/chrome/browser/authentication/ui_bundled/views/identity_button_control.h"
#import "ios/chrome/browser/settings/ui_bundled/downloads/identity_button_cell.h"

namespace {

// Alpha value of IdentityButtonControl when disabled.
constexpr CGFloat kDisabledAlpha = 0.5;

}  // namespace

@implementation IdentityButtonItem

- (instancetype)initWithType:(NSInteger)type {
  self = [super initWithType:type];
  if (self) {
    self.cellClass = [IdentityButtonCell class];
    _identityEmail = @"";
    _identityName = @"";
    _arrowDirection = IdentityButtonControlArrowDown;
    _identityViewStyle = IdentityViewStyleDefault;
    _enabled = YES;
  }
  return self;
}

#pragma mark - TableViewItem

- (void)configureCell:(IdentityButtonCell*)cell {
  [super configureCell:cell];
  cell.identityButtonControl.arrowDirection = self.arrowDirection;
  cell.identityButtonControl.identityViewStyle = self.identityViewStyle;
  [cell.identityButtonControl setIdentityAvatar:self.identityAvatar];
  [cell.identityButtonControl setIdentityName:self.identityName
                                        email:self.identityEmail
                                      managed:self.identityManaged];
  cell.identityButtonControl.enabled = self.enabled;
  cell.identityButtonControl.alpha = self.enabled ? 1.0 : kDisabledAlpha;
  cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

@end
