/** @jsxImportSource preact */
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {RecsBlock, numericGid} from './shared.jsx';

// Order status page (customer accounts): the Cart Lines API isn't available on
// this surface, so send the order id and let the server resolve the purchased
// products via the Admin API (cached server-side; an order never changes).
export default function extension(){
  render(<Extension />, document.body);
}

function Extension(){
  let orderId = '';
  try {
    const o = shopify.order;
    const order = 'value' in o ? o.value : o;
    orderId = numericGid(order && order.id);
  } catch (err) { /* no order context */ }
  return <RecsBlock params={orderId ? {order_id: orderId} : {}} />;
}
