@component('mail::message')
  # Order

  @php
    $to = $form_data['to'];
    if($to == "buyer"){
      $link = route('checkOrder',['order_id'=>$form_data['order_id']]);
      $text = App\Media::where(['media_page'=>'order','media_section'=>'email-text'])->first();
      $locale = $text->locales()->where('locale',config('app.locale'))->first();
      if(empty($locale)){
        $text = $text;
      }else{
        $text = $locale;
      }
    }else{
      $link = route('checkOrderBackend',['order_id'=>$form_data['order_id']]);
    }

    $get = App\Settings::where('setting_name','currency')->first();
    if(empty($get)){
      $currency = "USD";
    }else{
      $currency = $get->setting_value;
    }
	@endphp

  @component('mail::panel')
    @component('mail::table')

    @php
          $shipmentCost = 0;
          $shipmentDestination = null;
          if (Cart::content()->count()) {
            $shipmentCost = Cart::content()->first()->options->shipment_cost ? Cart::content()->first()->options->shipment_cost : 0;
            $shipmentDestination = Cart::content()->first()->options->shipment_destination ? Cart::content()->first()->options->shipment_destination : 0;        
          }
          $shipmentCost = str_replace([',', '.'], "", $shipmentCost);
          $cartTotal = str_replace([',', '.'], "", Cart::total());
    @endphp
      <tbody>
        @if($to == "buyer" && isset($text->media_content))
        <tr>
          <td colspan="2">

                {{ $text->media_content or "" }}

          </td>
        </tr>
        @endif
        <tr>
          <td width="30%">Order ID</td><td><a href="{{$link}}">{{ $form_data['order_id'] }}</a></td>
        </tr>
        <tr>
          <td width="30%">Name</td><td>{{$form_data['fname']}} {{$form_data['lname']}}</td>
        </tr>
        <tr>
          <td width="30%">Email</td><td>{{$form_data['email']}}</td>
        </tr>
        <tr>
          <td width="30%">Phone</td><td>{{$form_data['phone']}}</td>
        </tr>
        <tr>
          <td width="30%">Address</td><td>{{$form_data['address']}}</td>
        </tr>
        @php
          $total = $form_data['total'] + $shipmentCost;
          if( $currency == "USD" ){
            $total = number_format($total,2,".",",");
          }elseif( $masterCurrency == "EUR" ){
            $total = number_format($total,2,",",".");
          }else{
            $total = number_format($total,0,",",".");
          }
        @endphp
        @if(isset($form_data['paypal_total']))
          <tr>
            <td width="30%">Total</td><td> {{$currency}} {{ $total }} ( USD {{$form_data['paypal_total']}} )</td>
          </tr>
        @else
          <tr>
            <td width="30%">Total</td><td> {{$currency}} {{ $total }}</td>
          </tr>
        @endif
        <tr>
          <td width="30%">Status</td><td> <strong>{{ title_case($form_data['status']) }}</strong> </td>
        </tr>
      </tbody>
    @endcomponent
  @endcomponent

  @component('mail::panel')
    @component('mail::table')
      <tbody>
          <tr style="background: #{{ $webColor[0] }};color: #{{ $webColor[1] }}">
              <th style="padding-top:8px">Name</th>
              <th style="padding-top:8px">Notes</th>
              <th style="padding-top:8px">Qty</th>
              <th style="padding-top:8px">Price</th>
              <th style="padding-top:8px">Subtotal</th>
          </tr>
        @foreach($cart as $row)
          <tr>
              <td align="center" width="25%" style="font-size:12px">
                  {{ $row->name }}
              </td>
              <td align="center" width="30%" style="font-size:12px">
                {{ ($row->options->notes!="") ? $row->options->notes : '-' }}
              </td>
              <td align="center" width="5%" style="font-size:12px">{{ $row->qty }}</td>
              @php
                if( $currency == "USD" ){
                  $price = number_format($row->price,2,".",",");
                  $total = number_format($row->total,2,".",",");
                }elseif( $masterCurrency == "EUR" ){
                  $price = number_format($row->price,2,",",".");
                  $total = number_format($row->total,2,",",".");
                }else{
                  $price = number_format($row->price,0,",",".");
                  $total = number_format($row->total,0,",",".");
                }
              @endphp
              <td align="center" width="20%" style="font-size:12px">{{$currency}} {{ $price or 0 }}</td>
              <td align="center" width="20%" style="font-size:12px">{{$currency}} {{ $total or 0 }}</td>
          </tr>
        @endforeach
        
        <tr>
          @if ($shipment->option == 'delivery')
            <td colspan="4" style="text-align: left">
              Shipment {{ $shipmentDestination ? 'to '.$shipmentDestination : '' }}
            </td>
            <td>{{ $masterCurrency }} {{ number_format($shipmentCost, 0, ".", ".") }}</td>
          @elseif($shipment->option == 'flat')
            @php
              $shipmentCost = $shipment->amount;
            @endphp
            <td colspan="4" style="text-align: left">
              Shipment(Flat)
            </td>
            <td>{{ $masterCurrency }} {{ number_format($shipment->amount, 0, ".", ".") }}</td>
          @else
            @php
              $shipmentCost = 0;
            @endphp
            <td colspan="4" style="text-align: left">
              Shipment(Free)
            </td>
            <td>{{ $masterCurrency }} {{ number_format(0, 0, ".", ".") }}</td>
          @endif
        </tr>
      </tbody>
    @endcomponent
  @endcomponent

  @component('mail::button', ['url' => $link])
  Check Order
  @endcomponent

  {{ $masterName }}
@endcomponent
