import { defineCommand, findRepoRoot, useLoader } from '@kb-labs/sdk';
import { pushCommits } from '@kb-labs/commit-core';

// src/cli/commands/push.ts
var push_default = defineCommand({
  id: "commit:push",
  description: "Push commits to remote",
  handler: {
    async execute(ctx, input) {
      const startTime = Date.now();
      const cwd = await findRepoRoot(ctx.cwd || process.cwd()) ?? process.cwd();
      const pushLoader = useLoader("Pushing commits...");
      pushLoader.start();
      const result = await pushCommits(cwd, {
        force: input.force
      });
      const output = {
        success: result.success,
        remote: result.remote,
        branch: result.branch,
        commits: result.commitsPushed
      };
      if (result.success) {
        if (result.commitsPushed > 0) {
          pushLoader.succeed(`Pushed ${result.commitsPushed} commit(s) to ${result.remote}/${result.branch}`);
        } else {
          pushLoader.succeed("Nothing to push - already up to date");
        }
      } else {
        pushLoader.fail(`Failed to push: ${result.error}`);
      }
      if (input.json) {
        ctx.ui?.json?.(output);
      } else if (!result.success) {
        ctx.ui?.error?.("Push Failed", {
          sections: [{
            header: "Details",
            items: [
              `Remote: ${result.remote || "unknown"}`,
              `Branch: ${result.branch || "unknown"}`,
              `Error: ${result.error || "Unknown error"}`
            ]
          }]
        });
      } else if (result.commitsPushed > 0) {
        ctx.ui?.success?.("Push Successful", {
          sections: [{
            header: "Details",
            items: [
              `Commits pushed: ${result.commitsPushed}`,
              `Remote: ${result.remote || "origin"}`,
              `Branch: ${result.branch || "main"}`,
              "Status: \u2705 Up to date"
            ]
          }]
        });
      }
      return {
        exitCode: result.success ? 0 : 1,
        result: output,
        meta: {
          timing: Date.now() - startTime
        }
      };
    }
  }
});

export { push_default as default };
//# sourceMappingURL=push.js.map
//# sourceMappingURL=push.js.map