<?php
namespace admin\controls;
class ShopTransport
{
  public static function transport_save()
  {
    $response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania rodzaju transportu wystąpił błąd. Proszę spróbować ponownie.' ];
    $values = json_decode( \S::get( 'values' ), true );

    if ( $id = \admin\factory\ShopTransport::transport_save(
            $values['id'], $values['name'], $values['name_visible'], $values['description'], $values['status'], $values['cost'], $values['payment_methods'], $values['max_wp'], $values['default'], $values['apilo_carrier_account_id'], $values['sellasist_shipment_method_id'], $values['delivery_free']
          ) )
      $response = [ 'status' => 'ok', 'msg' => 'Rodzaj transportu został zapisany.', 'id' => $id ];

    echo json_encode( $response );
    exit;
  }

  public static function transport_edit()
  {
    return \Tpl::view( 'shop-transport/transport-edit', [
      'transport_details' => \admin\factory\ShopTransport::transport_details( \S::get( 'id' ) ),
      'payments_list'     => \admin\factory\ShopPaymentMethod::payments_list(),
      'apilo_carrier_account_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'carrier-account-list' ) ),
      'sellasist_shipments_methods' => unserialize( \admin\factory\Integrations::sellasist_settings( 'shipments_methods' ) ),
    ] );
  }

  public static function view_list()
  {
    return \Tpl::view( 'shop-transport/view-list', [
      'apilo_carrier_account_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'carrier-account-list' ) ),
      'sellasist_shipments_methods' => unserialize( \admin\factory\Integrations::sellasist_settings( 'shipments_methods' ) ),
    ] );
  }
}
