<?
namespace admin\controls;

class ShopStatuses {

  // status_save
  public static function status_save()
  {
    $response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania statusu wystąpił błąd. Proszę spróbować ponownie.' ];
    $values = json_decode( \S::get( 'values' ), true );

    if ( $id = \admin\factory\ShopStatuses::status_save( $values['id'], $values['color'], $values['apilo_status_id'], $values['sellasist_status_id'], $values['baselinker_status_id'] ) )
      $response = [ 'status' => 'ok', 'msg' => 'Status został zapisany.', 'id' => $id ];

    echo json_encode( $response );
    exit;
  }

  // status_edit
  public static function status_edit()
  {
    return \Tpl::view( 'shop-statuses/status-edit', [
      'status' => \admin\factory\ShopStatuses::get_status( \S::get( 'id' ) ),
      'apilo_order_status_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'status-types-list' ) ),
      'sellasist_order_status_list' => unserialize( \admin\factory\Integrations::sellasist_settings( 'status_types_list' ) ),
      'baselinker_order_status_list' => unserialize( \admin\factory\Integrations::baselinker_settings( 'order_status_list' ) ),
    ] );
  }

  static public function view_list()
  {
    return \Tpl::view( 'shop-statuses/view-list', [
      'apilo_order_status_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'status-types-list' ) ),
      'sellasist_order_status_list' => unserialize( \admin\factory\Integrations::sellasist_settings( 'status_types_list' ) ),
      'baselinker_order_status_list' => unserialize( \admin\factory\Integrations::baselinker_settings( 'order_status_list' ) ),
    ] );
  }
}