import { a2 as push, ap as push_element, ar as pop_element, a4 as pop, au as validate_snippet_args, as as escape_html, a0 as FILENAME } from './exports-5bDEyudc.js';
import { p as prevent_snippet_stringification } from './validate-DIfOr8HB.js';
import dayjs from 'dayjs';
import './client-CmENaDmn.js';
import { B as Button, F as Form, T as Table } from './Tabs.svelte_svelte_type_style_lang-Dnl7UCWg.js';
import { a as formatNumber } from './utils2-BNPuf_o4.js';

_page[FILENAME] = "src/routes/dashboard/+page.svelte";
function _page($$payload, $$props) {
  push(_page);
  const { data } = $$props;
  const state = { selectedCardId: "" };
  $$payload.out.push(`<p>`);
  push_element($$payload, "p", 61, 0);
  $$payload.out.push(`How it works:</p>`);
  pop_element();
  $$payload.out.push(` <div class="mbe.4 flex flex.align.center">`);
  push_element($$payload, "div", 62, 0);
  Button($$payload, {
    href: "/dashboard/card",
    children: prevent_snippet_stringification(($$payload2) => {
      $$payload2.out.push(`<!---->Add Card`);
    }),
    $$slots: { default: true }
  });
  $$payload.out.push(`<!----> <p>`);
  push_element($$payload, "p", 64, 2);
  $$payload.out.push(`-> Connect bank -> Activate tracking -> Hit requirements -> Earn bonus</p>`);
  pop_element();
  $$payload.out.push(`</div>`);
  pop_element();
  $$payload.out.push(` `);
  {
    let content = function($$payload2, form) {
      validate_snippet_args($$payload2);
      Button($$payload2, {
        type: "submit",
        loading: form.isLoading,
        children: prevent_snippet_stringification(($$payload3) => {
          $$payload3.out.push(`<!---->Sync`);
        }),
        $$slots: { default: true }
      });
    };
    prevent_snippet_stringification(content);
    Form($$payload, {
      action: `?/sync`,
      onresponse: (response) => {
        return response.update({ invalidateAll: true });
      },
      content,
      $$slots: { content: true }
    });
  }
  $$payload.out.push(`<!----> `);
  {
    let nameTd = function($$payload2, item) {
      validate_snippet_args($$payload2);
      $$payload2.out.push(`<!---->${escape_html(item.nickname)}
    ${escape_html(item.plaidMask ? ` (${item.plaidMask})` : "")}`);
    }, bonusTd = function($$payload2, item) {
      validate_snippet_args($$payload2);
      const bonusDeadline = dayjs(item.bonusDeadline).format("MMM D, YYYY");
      $$payload2.out.push(`<!---->You can earn <b>`);
      push_element($$payload2, "b", 98, 4);
      $$payload2.out.push(`${escape_html(`${item.bonusType === "CASH" ? "$" : ""}${formatNumber(item.bonusAmount)}`)}
      ${escape_html(item.bonusType)}</b>`);
      pop_element();
      $$payload2.out.push(` if you spend <b>`);
      push_element($$payload2, "b", 103, 4);
      $$payload2.out.push(`$${escape_html(formatNumber(item.bonusSpend))}</b>`);
      pop_element();
      $$payload2.out.push(` by <b>`);
      push_element($$payload2, "b", 106, 7);
      $$payload2.out.push(`${escape_html(bonusDeadline)}</b>`);
      pop_element();
    }, statusTd = function($$payload2, item) {
      validate_snippet_args($$payload2);
      if (item.closedAt) {
        $$payload2.out.push("<!--[-->");
        $$payload2.out.push(`🚫 Closed ${escape_html(dayjs(item.closedAt).format("MMM D, YYYY"))}`);
      } else {
        $$payload2.out.push("<!--[!-->");
        if (item.bonusDeadline && item.bonusDeadline < /* @__PURE__ */ new Date() && item.totalSpent < item.bonusSpend) {
          $$payload2.out.push("<!--[-->");
          $$payload2.out.push(`☹️ Missed bonus`);
        } else {
          $$payload2.out.push("<!--[!-->");
          if (item.bonusSpend && item.bonusSpend <= item.totalSpent) {
            $$payload2.out.push("<!--[-->");
            $$payload2.out.push(`🎉 Hit bonus (<a href="/">`);
            push_element($$payload2, "a", 120, 20);
            $$payload2.out.push(`new card?</a>`);
            pop_element();
            $$payload2.out.push(`)`);
          } else {
            $$payload2.out.push("<!--[!-->");
            if (!item.plaidAccessToken) {
              $$payload2.out.push("<!--[-->");
              $$payload2.out.push(`🏦 Link bank`);
            } else {
              $$payload2.out.push("<!--[!-->");
              if (!item.paymentId) {
                $$payload2.out.push("<!--[-->");
                $$payload2.out.push(`🕵️ Activate tracking`);
              } else {
                $$payload2.out.push("<!--[!-->");
                const difference = item.bonusSpend - item.totalSpent;
                const bonusSpendRemaining = Math.max(difference, 0);
                $$payload2.out.push(`💲 ${escape_html(formatNumber(bonusSpendRemaining))} until bonus`);
              }
              $$payload2.out.push(`<!--]-->`);
            }
            $$payload2.out.push(`<!--]-->`);
          }
          $$payload2.out.push(`<!--]-->`);
        }
        $$payload2.out.push(`<!--]-->`);
      }
      $$payload2.out.push(`<!--]-->`);
    }, actionsTd = function($$payload2, item) {
      validate_snippet_args($$payload2);
      if (item.closedAt) {
        $$payload2.out.push("<!--[-->");
      } else {
        $$payload2.out.push("<!--[!-->");
        if (!item.plaidAccessToken) {
          $$payload2.out.push("<!--[-->");
          Button($$payload2, {
            loading: state.selectedCardId === item.id,
            onclick: () => {
              state.selectedCardId = item.id;
            },
            children: prevent_snippet_stringification(($$payload3) => {
              $$payload3.out.push(`<!---->Connect`);
            }),
            $$slots: { default: true }
          });
        } else {
          $$payload2.out.push("<!--[!-->");
          if (!item.paymentId) {
            $$payload2.out.push("<!--[-->");
            {
              let content = function($$payload3, form) {
                validate_snippet_args($$payload3);
                Button($$payload3, {
                  type: "submit",
                  loading: form.isLoading,
                  children: prevent_snippet_stringification(($$payload4) => {
                    $$payload4.out.push(`<!---->Activate`);
                  }),
                  $$slots: { default: true }
                });
              };
              prevent_snippet_stringification(content);
              Form($$payload2, {
                action: `?/activate&cardId=${item.id}`,
                onresponse: (response) => {
                  return response.update({ invalidateAll: true });
                },
                content,
                $$slots: { content: true }
              });
            }
          } else {
            $$payload2.out.push("<!--[!-->");
          }
          $$payload2.out.push(`<!--]-->`);
        }
        $$payload2.out.push(`<!--]-->`);
      }
      $$payload2.out.push(`<!--]--> `);
      if (!item.closedAt) {
        $$payload2.out.push("<!--[-->");
        {
          let content = function($$payload3, form) {
            validate_snippet_args($$payload3);
            Button($$payload3, {
              type: "submit",
              loading: form.isLoading,
              children: prevent_snippet_stringification(($$payload4) => {
                $$payload4.out.push(`<!---->Close`);
              }),
              $$slots: { default: true }
            });
          };
          prevent_snippet_stringification(content);
          Form($$payload2, {
            action: `?/close&cardId=${item.id}`,
            onresponse: (response) => {
              return response.update({ invalidateAll: true });
            },
            content,
            $$slots: { content: true }
          });
        }
      } else {
        $$payload2.out.push("<!--[!-->");
      }
      $$payload2.out.push(`<!--]-->`);
    };
    prevent_snippet_stringification(nameTd);
    prevent_snippet_stringification(bonusTd);
    prevent_snippet_stringification(statusTd);
    prevent_snippet_stringification(actionsTd);
    Table($$payload, {
      items: data.cards,
      headers: [
        { key: "name", text: "Name" },
        { key: "bonus", text: "Bonus" },
        { key: "status", text: "Status" },
        { key: "actions", text: "Actions" },
        { key: "plaidBank", text: "Bank" }
      ],
      nameTd,
      bonusTd,
      statusTd,
      actionsTd,
      $$slots: { nameTd: true, bonusTd: true, statusTd: true, actionsTd: true }
    });
  }
  $$payload.out.push(`<!---->`);
  pop();
}
_page.render = function() {
  throw new Error("Component.render(...) is no longer valid in Svelte 5. See https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes for more information");
};

export { _page as default };
//# sourceMappingURL=_page.svelte-Oi6QNSnZ.js.map
