chromium/ios/chrome/browser/autofill/ui_bundled/card_expiration_date_fix_flow_view_bridge.h

// Copyright 2019 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_AUTOFILL_UI_BUNDLED_CARD_EXPIRATION_DATE_FIX_FLOW_VIEW_BRIDGE_H_
#define IOS_CHROME_BROWSER_AUTOFILL_UI_BUNDLED_CARD_EXPIRATION_DATE_FIX_FLOW_VIEW_BRIDGE_H_

#import <UIKit/UIKit.h>

#include <memory>
#include <string>

#import "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "components/autofill/core/browser/ui/payments/card_expiration_date_fix_flow_controller.h"
#include "components/autofill/core/browser/ui/payments/card_expiration_date_fix_flow_view.h"

namespace autofill {

class CardExpirationDateFixFlowViewBridge
    : public CardExpirationDateFixFlowView {
 public:
  CardExpirationDateFixFlowViewBridge(
      CardExpirationDateFixFlowController* controller,
      UIViewController* base_view_controller);

  CardExpirationDateFixFlowViewBridge(
      const CardExpirationDateFixFlowViewBridge&) = delete;
  CardExpirationDateFixFlowViewBridge& operator=(
      const CardExpirationDateFixFlowViewBridge&) = delete;

  ~CardExpirationDateFixFlowViewBridge() override;

  // CardExpirationDateFixFlowView:
  void Show() override;
  void ControllerGone() override;

  CardExpirationDateFixFlowController* GetController();

  // Called when the user confirms the expirationn date.
  void OnConfirmedExpirationDate(const std::u16string& month,
                                 const std::u16string& year);

  // Called when the user cancels the fix flow.
  void OnDismissed();

  // Closes the view.
  void PerformClose();

  // Deletes self. This should only be called by
  // CardExpirationDateFixFlowViewController after it finishes dismissing its
  // own UI elements.
  void DeleteSelf();

 protected:
  UIViewController* view_controller_;

 private:
  // The controller `this` queries for logic and state.
  raw_ptr<CardExpirationDateFixFlowController> controller_;  // weak

  // Weak reference to the view controller used to present UI.
  __weak UIViewController* presenting_view_controller_;

  base::WeakPtrFactory<CardExpirationDateFixFlowViewBridge> weak_ptr_factory_{
      this};
};

}  // namespace autofill

@interface CardExpirationDateFixFlowViewController : UITableViewController

// Designated initializer. `bridge` must not be null.
- (instancetype)initWithBridge:
    (autofill::CardExpirationDateFixFlowViewBridge*)bridge
    NS_DESIGNATED_INITIALIZER;

- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
- (instancetype)initWithStyle:(UITableViewStyle)style NS_UNAVAILABLE;
- (instancetype)initWithNibName:(NSString*)nibNameOrNil
                         bundle:(NSBundle*)nibBundleOrNil NS_UNAVAILABLE;

@end

#endif  // IOS_CHROME_BROWSER_AUTOFILL_UI_BUNDLED_CARD_EXPIRATION_DATE_FIX_FLOW_VIEW_BRIDGE_H_