<?php
///////////////////////////////////////////////////////////////////////////

require_once 'lib/regular_screen.php';

abstract class AbstractRegularScreen implements RegularScreen
{
  private $id;

  private $folder_views;
  private $folder_view_index_attr_name;

    ///////////////////////////////////////////////////////////////////////

  protected function __construct($id, $folder_views)
  {
    $this->id = $id;

    $this->folder_views = $folder_views;
    $this->set_default_folder_view_index_attr_name();
  }

    ///////////////////////////////////////////////////////////////////////

  protected function set_folder_view_index_attr_name($s)
  {
    $this->folder_view_index_attr_name = $s;
  }

  protected function set_default_folder_view_index_attr_name()
  {
    $this->folder_view_index_attr_name = "screen." . $this->id . ".view_idx";
  }

    ///////////////////////////////////////////////////////////////////////

  public function get_id()
  { return $this->id; }

    ///////////////////////////////////////////////////////////////////////

  public function get_folder_view(MediaURL $media_url, &$plugin_cookies)
  {
        // hd_print("----> count: " . count($this->folder_views));

    $idx = $this->get_folder_view_index($plugin_cookies);

        // hd_print("----> idx: $idx");

    $folder_view = $this->folder_views[$idx];

    $folder_view[PluginRegularFolderView::actions] =
    $this->get_action_map($media_url, $plugin_cookies);

    $folder_view[PluginRegularFolderView::initial_range] = 
    $this->get_folder_range($media_url, 0, $plugin_cookies);

    $archive = $this->get_archive($media_url);
    $archive_def = is_null($archive) ? null :
    $archive->get_archive_def();

    return array
    (
      PluginFolderView::multiple_views_supported  => (count($this->folder_views) > 1 ? 1 : 0),
      PluginFolderView::archive                   => $archive_def,
      PluginFolderView::view_kind                 => PLUGIN_FOLDER_VIEW_REGULAR,
      PluginFolderView::data                      => $folder_view
      );
  }

    ///////////////////////////////////////////////////////////////////////

  public function get_next_folder_view(MediaURL $media_url, &$plugin_cookies)
  {
    $idx = $this->get_folder_view_index($plugin_cookies);

    ++$idx;

    if ($idx >= count($this->folder_views))
      $idx = 0;

    $plugin_cookies->{$this->folder_view_index_attr_name} = $idx;

    return $this->get_folder_view($media_url, $plugin_cookies);
  }

    ///////////////////////////////////////////////////////////////////////

  public function get_folder_view_index(&$plugin_cookies)
  {
    if (!isset($plugin_cookies->{$this->folder_view_index_attr_name}))
      return 0;

    $idx = $plugin_cookies->{$this->folder_view_index_attr_name};

    $cnt = count($this->folder_views);

    if ($idx < 0)
      $idx = 0;
    else if ($idx >= $cnt)
      $idx = $cnt - 1;

    return intval($idx);
  }

    ///////////////////////////////////////////////////////////////////////

  public function get_archive(MediaURL $media_url)
  { return null; }

  public function autopayment_setup_popup_defs(&$plugin_cookies, $handler, $add_params)
  {
    $defs = array();

    ControlFactory::add_label($defs, "Dear customer!", "");
    ControlFactory::add_text($defs,'',
      'We\'ve updated our autopay mechanism and it needs to be setup again for ' . 
      $this->session->service_name . ' service. You can do it via:
      1) Box, just press \'Setup autopayment\'
    2) Website, '. $this->session->autopayment_setup_store_url .'
    3) Phone, call our support team at '. $this->session->company_phone .'

    Payments will be taken each 30 days (not in specific day of the month).
    Thank you, team '. $this->session->company_name
    );

    ControlFactory::add_vgap($defs, 50);

    ControlFactory::add_close_dialog_and_apply_button($defs,
      $handler, $add_params, 'setup_autopayment', "Setup autopayment", 400);

    ControlFactory::add_vgap($defs, -3);
    ControlFactory::add_close_dialog_and_apply_button($defs,
      $handler, $add_params, 'dont_show_again', "Don't show again", 400);

    ControlFactory::add_vgap($defs, -3);
    ControlFactory::add_close_dialog_and_apply_button($defs,
      $handler, $add_params, 'remind_later', "Remind me later", 400);

    return $defs;
  }

  public function service_expiration_popup_defs(&$plugin_cookies, $handler, $add_params)
  {
    $defs = array();

    ControlFactory::add_label($defs, "Dear customer!", "");
    ControlFactory::add_text($defs,'',
      'Your '. $this->session->service_name .' service will expire on '. $this->session->service_expires_at .'.'
    );

    ControlFactory::add_vgap($defs, 50);

    ControlFactory::add_close_dialog_and_apply_button($defs,
      $handler, $add_params, 'pay_now', "Pay now", 400);

    ControlFactory::add_vgap($defs, -3);
    ControlFactory::add_close_dialog_and_apply_button($defs,
      $handler, $add_params, 'remind_later', "Close", 400);

    return $defs;
  }

}

///////////////////////////////////////////////////////////////////////////
?>
